diff --git a/assets/javascripts/wizard-custom-lib.js b/assets/javascripts/wizard-custom-globals.js similarity index 68% rename from assets/javascripts/wizard-custom-lib.js rename to assets/javascripts/wizard-custom-globals.js index 9767141d..e37648e5 100644 --- a/assets/javascripts/wizard-custom-lib.js +++ b/assets/javascripts/wizard-custom-globals.js @@ -1,7 +1,5 @@ window.Discourse = {} window.Wizard = {}; Wizard.SiteSettings = {}; -Wizard.RAW_TEMPLATES = {}; Discourse.__widget_helpers = {}; -window.__DISCOURSE_RAW_TEMPLATES = {}; Discourse.SiteSettings = Wizard.SiteSettings; \ No newline at end of file diff --git a/assets/javascripts/wizard-custom.js b/assets/javascripts/wizard-custom.js index bcdabeb1..19290d2c 100644 --- a/assets/javascripts/wizard-custom.js +++ b/assets/javascripts/wizard-custom.js @@ -117,6 +117,7 @@ //= require discourse/app/templates/emoji-selector-autocomplete //= require discourse/app/templates/user-selector-autocomplete +//= require discourse/app/initializers/jquery-plugins //= require discourse/app/pre-initializers/sniff-capabilities //= require ember-addons/decorator-alias diff --git a/assets/javascripts/wizard-raw-templates.js.erb b/assets/javascripts/wizard-raw-templates.js.erb index b6a5b7f7..75a44abc 100644 --- a/assets/javascripts/wizard-raw-templates.js.erb +++ b/assets/javascripts/wizard-raw-templates.js.erb @@ -8,24 +8,30 @@ Discourse.unofficial_plugins.each do |plugin| files = [] plugin.each_globbed_asset do |f, is_dir| - files.push(f) if f.include? "raw.hbs" + files.push(f) if f.include? "hbr" end - Dir.glob("#{Rails.root}/app/assets/javascripts/discourse/templates/*.raw.hbs").each do |f| + Dir.glob("#{Rails.root}/app/assets/javascripts/discourse/app/templates/*.hbr").each do |f| files.push(f) end files.each do |f| - name = File.basename(f, ".raw.hbs") + name = File.basename(f, ".hbr") compiled = Barber::Precompiler.new().compile(File.read(f)) result << " (function() { - if ('Wizard' in window) { - window.__DISCOURSE_RAW_TEMPLATES['javascripts/#{name}'] = requirejs('discourse-common/lib/raw-handlebars').template(#{compiled}); - } + const { addRawTemplate } = requirejs('discourse-common/lib/raw-templates'); + addRawTemplate(#{compiled}); })(); " end + + result << " + (function() { + const rawTemplates = requirejs('discourse-common/lib/raw-templates'); + window.__DISCOURSE_RAW_TEMPLATES = rawTemplates.__DISCOURSE_RAW_TEMPLATES; + })(); + " end end result diff --git a/assets/javascripts/wizard/components/wizard-composer-editor.js.es6 b/assets/javascripts/wizard/components/wizard-composer-editor.js.es6 index 2b745c6f..12dbadfe 100644 --- a/assets/javascripts/wizard/components/wizard-composer-editor.js.es6 +++ b/assets/javascripts/wizard/components/wizard-composer-editor.js.es6 @@ -3,7 +3,11 @@ import { default as computed, on } from "discourse-common/utils/decorators"; import { findRawTemplate } from "discourse-common/lib/raw-templates"; import { throttle } from "@ember/runloop"; import { scheduleOnce } from "@ember/runloop"; -import { safariHacksDisabled } from "discourse/lib/utilities"; +import { + safariHacksDisabled, + caretPosition, + inCodeBlock, +} from "discourse/lib/utilities"; import highlightSyntax from "discourse/lib/highlight-syntax"; import { getToken } from "wizard/lib/ajax"; import { validateUploadedFiles } from "discourse/lib/uploads"; @@ -29,14 +33,18 @@ export default ComposerEditor.extend({ const $preview = $(this.element.querySelector(".d-editor-preview-wrapper")); if (this.siteSettings.enable_mentions) { + console.log('initializing autocomplete', findRawTemplate("user-selector-autocomplete")) $input.autocomplete({ template: findRawTemplate("user-selector-autocomplete"), dataSource: (term) => this.userSearchTerm.call(this, term), key: "@", transformComplete: (v) => v.username || v.name, - afterComplete() { + afterComplete: (value) => { + this.composer.set("reply", value); scheduleOnce("afterRender", () => $input.blur().focus()); }, + triggerRule: (textarea) => + !inCodeBlock(textarea.value, caretPosition(textarea)) }); } diff --git a/views/layouts/wizard.html.erb b/views/layouts/wizard.html.erb index 5979a464..feaa041b 100644 --- a/views/layouts/wizard.html.erb +++ b/views/layouts/wizard.html.erb @@ -10,7 +10,8 @@ <%= preload_script "ember_jquery" %> <%= preload_script "wizard-vendor" %> <%= preload_script "wizard-application" %> - <%= preload_script "wizard-custom-lib" %> + <%= preload_script "wizard-custom-globals" %> + <%= preload_script "wizard-raw-templates" %> <%= preload_script "wizard-custom" %> <%= preload_script "wizard-plugin" %> <%= preload_script "pretty-text-bundle" %> @@ -41,7 +42,6 @@ <%- if current_user %> <%= preload_script 'wizard-custom-start' %> - <%= preload_script 'wizard-raw-templates' %> <%- else %> <%= preload_script 'wizard-custom-guest' %> <%- end %>