FIX: Load order bug

This commit is contained in:
Robin Ward 2013-12-03 15:11:33 -05:00
parent 274743b877
commit 50fe117d7c
11 changed files with 23 additions and 18 deletions

View file

@ -100,10 +100,12 @@ Discourse = Ember.Application.createWithMixins(Discourse.Ajax, {
@method addInitializer
@param {Function} init the initializer to add.
@param {Boolean} immediate whether to execute the function right away.
Default is false, for next run loop. If unsure, use false.
**/
addInitializer: function(init) {
addInitializer: function(init, immediate) {
Discourse.initializers = Discourse.initializers || [];
Discourse.initializers.push(init);
Discourse.initializers.push({fn: init, immediate: !!immediate});
},
/**
@ -115,10 +117,14 @@ Discourse = Ember.Application.createWithMixins(Discourse.Ajax, {
var initializers = this.initializers;
if (initializers) {
var self = this;
Em.run.next(function() {
initializers.forEach(function (init) {
init.call(self);
});
initializers.forEach(function (init) {
if (init.immediate) {
init.fn.call(self);
} else {
Em.run.next(function() {
init.fn.call(self);
});
}
});
}
}

View file

@ -29,4 +29,4 @@ Discourse.addInitializer(function() {
return false;
});
});
}, true);

View file

@ -5,4 +5,4 @@ Discourse.addInitializer(function() {
Discourse.MessageBus.alwaysLongPoll = Discourse.Environment === "development";
Discourse.MessageBus.start();
Discourse.KeyValueStore.init("discourse_", Discourse.MessageBus);
});
}, true);

View file

@ -8,4 +8,4 @@ Discourse.addInitializer(function() {
// clicking outside a bootbox modal closes it
bootbox.backdrop(true);
});
}, true);

View file

@ -15,5 +15,5 @@ Discourse.addInitializer(function() {
}
});
});
}, true);

View file

@ -13,4 +13,4 @@ Discourse.addInitializer(function() {
self.set('hasFocus', false);
});
});
}, true);

View file

@ -3,5 +3,5 @@
**/
Discourse.addInitializer(function() {
Discourse.Mobile.init();
});
}, true);

View file

@ -3,8 +3,6 @@
**/
Discourse.addInitializer(function() {
console.log('live reloading');
// subscribe to any site customizations that are loaded
$('link.custom-css').each(function() {
var split = this.href.split("/"),
@ -70,4 +68,4 @@ Discourse.addInitializer(function() {
});
});
});
}, true);

View file

@ -8,5 +8,5 @@ Discourse.addInitializer(function() {
Discourse.Formatter.updateRelativeAge($('.relative-date'));
}, 60 * 1000);
});
}, true);

View file

@ -23,4 +23,4 @@ Discourse.addInitializer(function() {
// iPads should report as 1024.
caps.set('highRes', Modernizr.mq("only screen and (min-width: 1280px)"));
});
}, true);

View file

@ -28,5 +28,6 @@ Discourse.addInitializer(function() {
});
});
}
});
}, true);