summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Greiling <mike@pixelcog.com>2017-01-29 16:54:08 -0600
committerMike Greiling <mike@pixelcog.com>2017-02-05 23:51:39 -0600
commit55d05bf8d8e4ecab456e751b550a5046a966d3b2 (patch)
treed35d5e0538a2530279c902afc1ee1d7d0638d58c
parent70c3b984f4293090e4a4b68368572fbe4a3dd5bc (diff)
downloadgitlab-ce-fix-ace-editor-modules.tar.gz
lazy-load ace config so that we can ensure window.gon existsfix-ace-editor-modules
-rw-r--r--app/assets/javascripts/lib/ace/ace_config_paths.js.erb27
1 files changed, 17 insertions, 10 deletions
diff --git a/app/assets/javascripts/lib/ace/ace_config_paths.js.erb b/app/assets/javascripts/lib/ace/ace_config_paths.js.erb
index 5cb1037bc86..976769ba84a 100644
--- a/app/assets/javascripts/lib/ace/ace_config_paths.js.erb
+++ b/app/assets/javascripts/lib/ace/ace_config_paths.js.erb
@@ -7,21 +7,28 @@ ace_modes = Dir[ace_gem_path + '/vendor/assets/javascripts/ace/mode-*.js'].sort.
File.basename(file, '.js').sub(/^mode-/, '')
end
%>
-
+// Lazy-load configuration when ace.edit is called
(function() {
- window.gon = window.gon || {};
- var basePath = (window.gon.relative_url_root || '').replace(/\/$/, '') + '/assets/ace';
- ace.config.set('basePath', basePath);
+ var basePath;
+ var ace = window.ace;
+ var edit = ace.edit;
+ ace.edit = function() {
+ window.gon = window.gon || {};
+ basePath = (window.gon.relative_url_root || '').replace(/\/$/, '') + '/assets/ace';
+ ace.config.set('basePath', basePath);
- // configure paths for all worker modules
+ // configure paths for all worker modules
<% ace_workers.each do |worker| %>
- <% filename = File.basename(asset_path("ace/worker-#{worker}.js")) %>
- ace.config.setModuleUrl('ace/mode/<%= worker %>_worker', basePath + '/<%= filename %>');
+ ace.config.setModuleUrl('ace/mode/<%= worker %>_worker', basePath + '/<%= File.basename(asset_path("ace/worker-#{worker}.js")) %>');
<% end %>
- // configure paths for all mode modules
+ // configure paths for all mode modules
<% ace_modes.each do |mode| %>
- <% filename = File.basename(asset_path("ace/mode-#{mode}.js")) %>
- ace.config.setModuleUrl('ace/mode/<%= mode %>', basePath + '/<%= filename %>');
+ ace.config.setModuleUrl('ace/mode/<%= mode %>', basePath + '/<%= File.basename(asset_path("ace/mode-#{mode}.js")) %>');
<% end %>
+
+ // restore original method
+ ace.edit = edit;
+ return ace.edit.apply(ace, arguments);
+ };
})();