diff --git a/src/shared/behaviors/Resizable.js b/src/shared/behaviors/Resizable.js index 8638d350..e1d7266e 100644 --- a/src/shared/behaviors/Resizable.js +++ b/src/shared/behaviors/Resizable.js @@ -7,26 +7,30 @@ (function (scope) { - var _cache = []; var _instances = []; var _il = 0; var _backoff = 0; var _backoff_inc = 200; var _backoff_max = 2000; - function _addInstance(instance) { - _instances.push(instance); - _cache.push({ - width:instance.offsetWidth, - height:instance.offsetHeight, + function _addInstance(instance, target) { + _instances.push({ + target:target, + instance: instance, + width:target.offsetWidth, + height:target.offsetHeight, }); _il++; requestAnimationFrame(_measure); } function _removeInstance(instance) { - _instances.splice(_instances.indexOf(instance), 1); - _il--; + _instances.filter(function(meta) { + return meta.instance === instance; + }).forEach(function(target) { + _instances.splice(_instances.indexOf(target), 1); + _il--; + }); } function _measure() { @@ -34,18 +38,17 @@ if (_backoff > _backoff_max) _backoff = _backoff_max; for(var i=0; i<_il; i++) { - var inst = _instances[i]; - var w = inst.offsetWidth; - var h = inst.offsetHeight; - var cache = _cache[i]; - if (cache.width !== w) { - cache.width = w; - inst.elementResize(w,null); + var meta = _instances[i]; + var w = meta.target.offsetWidth; + var h = meta.target.offsetHeight; + if (meta.width !== w) { + meta.width = w; + meta.instance.elementResize(w,null,meta.target); _backoff = 0; } - if (cache.height !== h) { - cache.height = h; - inst.elementResize(null, h); + if (meta.height !== h) { + meta.height = h; + meta.instance.elementResize(null, h, meta.target); _backoff = 0; } } @@ -62,15 +65,15 @@ resizeTarget:{ type:Object, value: function() { return this; } - } + }, }, attached:function() { - _addInstance(this.resizeTarget); + _addInstance(this, this.resizeTarget); }, detached:function() { - _removeInstance(this.resizeTarget); + _removeInstance(this); }, elementResize: function(e) {