Добавление кнопки с Onclick

Я явно что-то упускаю.
Я пытаюсь добавить кнопку и повесить на неё обработчик события onclick.

В HTML компоненте я добавил:

<button id="button_test" class="bottone">Prova</button>

А в разделе /head добавил:

$('#button_test').on('click', moreDetails);
function moreDetails(e){
console.log(`Listening to: ${e.target.value}`);
}

Но ничего не срабатывает.

Я такой тупой?

Ф.

Помните, что Discourse — это приложение на Ember.js, поэтому вам необходимо соблюдать правила Ember при написании кода на JavaScript.

Я полагаю, что jQuery скоро будет полностью удалён из Ember, поэтому использование $ не сулит ничего хорошего.

Спасибо, @codinghorror,

можно ли это реализовать с помощью компонента или нужен плагин?

Всем привет,

В итоге я создал виджет в секции /head моего компонента и добавил его в шаблон Handlebar.

let currentLocale = I18n.currentLocale();
I18n.translations[currentLocale].js.custom_modal_title = “Мое модальное окно”;

const showModal = require("discourse/lib/show-modal").default;
const h = require("virtual-dom").h;

api.createWidget("modal-button", {
  tagName: "button.btn.btn-primary",

  html(arg) {
    return arg;
  },

  click(arg) {
      if(arg.target.innerText=="+ Nuovo Wisper") {
        $('#create-topic').click();
      } else if(arg.target.innerText=="Aiuta") {
          window.location.replace("/c/supporto/11");
      } else {
          window.location.replace("/t/invita-amici-a-mywisper/26");
      }
  }
});

api.createWidget("banner", {
  tagName: "div.wrap",
  html() {
    let contents = [];
    contents.push(h("div.hc-column","Чем больше нас, тем лучше работает. Поделись с друзьями, это бесплатно!"));
    contents.push(h("div.hc-column","Войдите и опубликуйте свой запрос о помощи"));
    contents.push(h("div.hc-column","Хотите помочь? Ищите Wisper в вашем городе"));
    let row1 = h("div.row-cont", contents);
    let h1 = h('div.top-spot',h('h1','myWisper — это место, где можно предлагать и искать помощь'));
    let inner = [];
    let bottoni = [];
    bottoni.push(h("div.hc-column",this.attach('modal-button','Пригласить')))
    bottoni.push(h("div.hc-column",this.attach('modal-button','+ Новый Wisper')))
    bottoni.push(h("div.hc-column",this.attach('modal-button','Помочь')))
    let row2 = h("div.row-cont", bottoni);
    inner.push(h1,row1,row2);
    return h("div.hc-banner",inner);
  },
});

api.createWidget("banner_mobile", {
  tagName: "div.wrap",
  html() {
    let h1 = h('div.top-spot',h('h1','myWisper — это место, где можно предлагать и искать помощь.'));
    let inner = [];
    let bottoni = [];
    bottoni.push(h("div.hc-column-mobile",this.attach('modal-button','Пригласить')))
    bottoni.push(h("div.hc-column-mobile",this.attach('modal-button','+ Новый Wisper')))
    bottoni.push(h("div.hc-column-mobile",this.attach('modal-button','Помочь')))
    let row2 = h("div.row-cont", bottoni);
    inner.push(h("h1.mobile-header","myWisper — это место, где можно предлагать и искать помощь"));
    inner.push(row2);
    return h("div.hc-banner-mobile",inner);
  },
});
</script>