أنا بالتأكيد أفتقد شيئًا ما هنا.
أحاول إضافة زر وربط حدث 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','Invita')))
bottoni.push(h("div.hc-column",this.attach('modal-button','+ Nuovo Wisper')))
bottoni.push(h("div.hc-column",this.attach('modal-button','Aiuta')))
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','Invita')))
bottoni.push(h("div.hc-column-mobile",this.attach('modal-button','+ Nuovo Wisper')))
bottoni.push(h("div.hc-column-mobile",this.attach('modal-button','Aiuta')))
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>