Support for automatic registering of initializers from plugins.
This commit is contained in:
parent
ba8b45792c
commit
63bf03ba5b
|
@ -114,6 +114,16 @@ window.Discourse = Ember.Application.createWithMixins(Discourse.Ajax, {
|
||||||
@method start
|
@method start
|
||||||
**/
|
**/
|
||||||
start: function() {
|
start: function() {
|
||||||
|
|
||||||
|
// Load any ES6 initializers
|
||||||
|
Ember.keys(requirejs._eak_seen).filter(function(key) {
|
||||||
|
return (/\/initializers\//).test(key);
|
||||||
|
}).forEach(function(moduleName) {
|
||||||
|
var module = require(moduleName, null, null, true);
|
||||||
|
if (!module) { throw new Error(moduleName + ' must export an initializer.'); }
|
||||||
|
Discourse.initializer(module.default);
|
||||||
|
});
|
||||||
|
|
||||||
var initializers = this.initializers;
|
var initializers = this.initializers;
|
||||||
if (initializers) {
|
if (initializers) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
@ -127,6 +137,7 @@ window.Discourse = Ember.Application.createWithMixins(Discourse.Ajax, {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
requiresRefresh: function(){
|
requiresRefresh: function(){
|
||||||
|
@ -164,10 +175,3 @@ window.Discourse = Ember.Application.createWithMixins(Discourse.Ajax, {
|
||||||
}.property("isReadOnly")
|
}.property("isReadOnly")
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Discourse.initializer({
|
|
||||||
name: "register-discourse-location",
|
|
||||||
initialize: function(container, application) {
|
|
||||||
application.register('location:discourse-location', Ember.DiscourseLocation);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
/**
|
|
||||||
Default settings for bootbox
|
|
||||||
**/
|
|
||||||
Discourse.addInitializer(function() {
|
|
||||||
|
|
||||||
bootbox.animate(false);
|
|
||||||
|
|
||||||
// clicking outside a bootbox modal closes it
|
|
||||||
bootbox.backdrop(true);
|
|
||||||
|
|
||||||
}, true);
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
/**
|
||||||
|
Default settings for bootbox
|
||||||
|
**/
|
||||||
|
export default {
|
||||||
|
name: "bootbox",
|
||||||
|
initialize: function() {
|
||||||
|
bootbox.animate(false);
|
||||||
|
|
||||||
|
// clicking outside a bootbox modal closes it
|
||||||
|
bootbox.backdrop(true);
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,18 @@
|
||||||
|
/**
|
||||||
|
Append our CSRF token to AJAX requests when necessary.
|
||||||
|
**/
|
||||||
|
export default {
|
||||||
|
name: "csrf-token",
|
||||||
|
initialize: function() {
|
||||||
|
var session = Discourse.Session;
|
||||||
|
|
||||||
|
// Add a CSRF token to all AJAX requests
|
||||||
|
session.currentProp('csrfToken', $('meta[name=csrf-token]').attr('content'));
|
||||||
|
|
||||||
|
$.ajaxPrefilter(function(options, originalOptions, xhr) {
|
||||||
|
if (!options.crossDomain) {
|
||||||
|
xhr.setRequestHeader('X-CSRF-Token', session.currentProp('csrfToken'));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
|
@ -1,19 +0,0 @@
|
||||||
/**
|
|
||||||
Append our CSRF token to AJAX requests when necessary.
|
|
||||||
**/
|
|
||||||
|
|
||||||
Discourse.addInitializer(function() {
|
|
||||||
|
|
||||||
var session = Discourse.Session;
|
|
||||||
|
|
||||||
// Add a CSRF token to all AJAX requests
|
|
||||||
session.currentProp('csrfToken', $('meta[name=csrf-token]').attr('content'));
|
|
||||||
|
|
||||||
$.ajaxPrefilter(function(options, originalOptions, xhr) {
|
|
||||||
if (!options.crossDomain) {
|
|
||||||
xhr.setRequestHeader('X-CSRF-Token', session.currentProp('csrfToken'));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}, true);
|
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
export default {
|
||||||
|
name: "register-discourse-location",
|
||||||
|
initialize: function(container, application) {
|
||||||
|
application.register('location:discourse-location', Ember.DiscourseLocation);
|
||||||
|
}
|
||||||
|
};
|
Loading…
Reference in New Issue