Apply behaviors correctly on startup

This commit is contained in:
Matthias Jentsch 2014-09-10 10:44:22 +02:00
parent d99d50b3c4
commit 5d2e849491
2 changed files with 11 additions and 13 deletions

View File

@ -97,7 +97,7 @@
this.history = new Icinga.History(this);
var self = this;
$.each(Icinga.Behaviors, function(name, Behavior) {
self.behaviors[name.toLowerCase()] = new Behavior();
self.behaviors[name.toLowerCase()] = new Behavior(self);
});
this.timezone.initialize();

View File

@ -32,26 +32,17 @@
initialize: function () {
this.applyGlobalDefaults();
this.applyHandlers($('#layout'));
var self = this;
// define global site behavior
$.each(self.icinga.behaviors, function (name, behavior) {
behavior.bind();
});
// prepare container html
$('.container').each(function(idx, el) {
// apply event handlers
icinga.events.applyHandlers($(el));
icinga.ui.initializeControls($(el));
$.each(self.icinga.behaviors, function (name, behavior) {
behavior.apply(el);
});
});
},
// TODO: What's this?
applyHandlers: function (el) {
$.each(this.icinga.behaviors, function (name, behavior) {
behavior.apply(el);
});
var icinga = this.icinga;
@ -152,6 +143,10 @@
* Global default event handlers
*/
applyGlobalDefaults: function () {
$.each(self.icinga.behaviors, function (name, behavior) {
behavior.bind();
});
// We catch resize events
$(window).on('resize', { self: this.icinga.ui }, this.icinga.ui.onWindowResize);
@ -673,6 +668,9 @@
*/
unbindGlobalHandlers: function () {
$.each(self.icinga.behaviors, function (name, behavior) {
behavior.unbind();
});
$(window).off('resize', this.onWindowResize);
$(window).off('load', this.onLoad);
$(window).off('unload', this.onUnload);