angus
(Angus McLeod)
24.Сентябрь.2020 23:13:41
2
Раньше я решал эту проблему, упаковывая кнопки в HTML-хелпер, который рендерит «сырой» HTML в «сырых» шаблонах. Затем его можно вставить через «сырой» плагин-аутлет. Вот пример:
https://github.com/paviliondev/discourse-topic-previews/blob/master/assets/javascripts/discourse/helpers/preview-helpers.js.es6#L8
Обработка клика по кнопке выполняется в компоненте topic-list-item, например:
https://github.com/paviliondev/discourse-topic-previews/blob/master/assets/javascripts/discourse/initializers/preview-edits.js.es6#L332
@merefield , возможно, тоже захочет поделиться мыслями
Также, вероятно, вам стоит использовать структуру папок JavaScript темы вместо добавления скриптов в header.html. См.:
Complex theme javascript can be split into multiple files, to keep things nicely organised.
To use this functionality, simply add files to the /javascripts folder in your theme directory. These files can not be edited from the Discourse UI, so you must use the Theme CLI or source the theme from git .
Javascript files are treated exactly the same as they are in core/plugins, so you should follow the same file/folder structure. Theme files are loaded after core/plugins, so if the filenames match,…