Support for automatic registering of initializers from plugins.

This commit is contained in:
Robin Ward 2014-05-15 17:01:01 -04:00
parent ba8b45792c
commit 63bf03ba5b
6 changed files with 47 additions and 37 deletions

View File

@ -114,6 +114,16 @@ window.Discourse = Ember.Application.createWithMixins(Discourse.Ajax, {
@method start
**/
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;
if (initializers) {
var self = this;
@ -127,6 +137,7 @@ window.Discourse = Ember.Application.createWithMixins(Discourse.Ajax, {
}
});
}
},
requiresRefresh: function(){
@ -164,10 +175,3 @@ window.Discourse = Ember.Application.createWithMixins(Discourse.Ajax, {
}.property("isReadOnly")
});
Discourse.initializer({
name: "register-discourse-location",
initialize: function(container, application) {
application.register('location:discourse-location', Ember.DiscourseLocation);
}
});

View File

@ -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);

View File

@ -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);
}
};

View File

@ -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'));
}
});
}
};

View File

@ -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);

View File

@ -0,0 +1,6 @@
export default {
name: "register-discourse-location",
initialize: function(container, application) {
application.register('location:discourse-location', Ember.DiscourseLocation);
}
};