attach window resize handlers in a way that doesn't overwrite previous handler

10.3.x-maintenance
cTn 2014-10-06 19:16:48 +02:00
parent 3d64b87578
commit 341416c180
2 changed files with 10 additions and 6 deletions

View File

@ -96,7 +96,7 @@ TABS.receiver.initialize = function (callback) {
});
// correct inner label margin on window resize (i don't know how we could do this in css)
$(window).resize(function () {
self.resize = function () {
var containerWidth = $('.meter:first', bar_container).width(),
labelWidth = $('.meter .label:first', bar_container).width(),
margin = (containerWidth / 2) - (labelWidth / 2);
@ -104,7 +104,9 @@ TABS.receiver.initialize = function (callback) {
for (var i = 0; i < meter_label_array.length; i++) {
meter_label_array[i].css('margin-left', margin);
}
}).resize(); // trigger so labels get correctly aligned on creation
};
$(window).on('resize', self.resize).resize(); // trigger so labels get correctly aligned on creation
// handle rcmap & rssi aux channel
if (bit_check(CONFIG.capability, 30)) {
@ -416,7 +418,7 @@ TABS.receiver.initialize = function (callback) {
};
TABS.receiver.cleanup = function (callback) {
$(window).unbind('resize');
$(window).off('resize', this.resize);
if (callback) callback();
};

View File

@ -427,17 +427,19 @@ TABS.setup.initialize3D = function (compatibility) {
};
// handle canvas resize
$(window).resize(function () {
this.resize3D = function () {
renderer.setSize(wrapper.width(), wrapper.height());
camera.aspect = wrapper.width() / wrapper.height();
camera.updateProjectionMatrix();
self.render3D();
});
};
$(window).on('resize', this.resize3D);
};
TABS.setup.cleanup = function (callback) {
$(window).unbind('resize');
$(window).off('resize', this.resize3D);
if (callback) callback();
};