Skip to content

Commit

Permalink
better target support on resizable
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Lasky committed Jun 29, 2015
1 parent 801b3ae commit 4291ec6
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions src/shared/behaviors/Resizable.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,48 @@

(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() {
_backoff += _backoff_inc;
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;
}
}
Expand All @@ -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) {
Expand Down

0 comments on commit 4291ec6

Please sign in to comment.