lazy-load ace config so that we can ensure window.gon exists
This commit is contained in:
parent
70c3b984f4
commit
55d05bf8d8
|
@ -7,21 +7,28 @@ ace_modes = Dir[ace_gem_path + '/vendor/assets/javascripts/ace/mode-*.js'].sort.
|
||||||
File.basename(file, '.js').sub(/^mode-/, '')
|
File.basename(file, '.js').sub(/^mode-/, '')
|
||||||
end
|
end
|
||||||
%>
|
%>
|
||||||
|
// Lazy-load configuration when ace.edit is called
|
||||||
(function() {
|
(function() {
|
||||||
window.gon = window.gon || {};
|
var basePath;
|
||||||
var basePath = (window.gon.relative_url_root || '').replace(/\/$/, '') + '/assets/ace';
|
var ace = window.ace;
|
||||||
ace.config.set('basePath', basePath);
|
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| %>
|
<% ace_workers.each do |worker| %>
|
||||||
<% filename = File.basename(asset_path("ace/worker-#{worker}.js")) %>
|
ace.config.setModuleUrl('ace/mode/<%= worker %>_worker', basePath + '/<%= File.basename(asset_path("ace/worker-#{worker}.js")) %>');
|
||||||
ace.config.setModuleUrl('ace/mode/<%= worker %>_worker', basePath + '/<%= filename %>');
|
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
// configure paths for all mode modules
|
// configure paths for all mode modules
|
||||||
<% ace_modes.each do |mode| %>
|
<% ace_modes.each do |mode| %>
|
||||||
<% filename = File.basename(asset_path("ace/mode-#{mode}.js")) %>
|
ace.config.setModuleUrl('ace/mode/<%= mode %>', basePath + '/<%= File.basename(asset_path("ace/mode-#{mode}.js")) %>');
|
||||||
ace.config.setModuleUrl('ace/mode/<%= mode %>', basePath + '/<%= filename %>');
|
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
// restore original method
|
||||||
|
ace.edit = edit;
|
||||||
|
return ace.edit.apply(ace, arguments);
|
||||||
|
};
|
||||||
})();
|
})();
|
||||||
|
|
Loading…
Reference in New Issue