Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add logic to shortcut BoundsInfo positionChanged and sizeChanged meth…

…ods so that when it is the first time the object is queried they return true right away without invoking getBoundingClientRect.
  • Loading branch information...
commit a03632e73bd9cc03e72c807efbec3126c400b662 1 parent 3f4f000
Jason Johnston authored
Showing with 10 additions and 7 deletions.
  1. +10 −7 sources/BoundsInfo.js
17 sources/BoundsInfo.js
View
@@ -8,18 +8,18 @@ PIE.BoundsInfo = function( el ) {
};
PIE.BoundsInfo.prototype = {
- _lastBounds: {},
+ _locked: 0,
positionChanged: function() {
var last = this._lastBounds,
- bounds = this.getBounds();
- return !last || last.x !== bounds.x || last.y !== bounds.y;
+ bounds;
+ return !last || ( ( bounds = this.getBounds() ) && ( last.x !== bounds.x || last.y !== bounds.y ) );
},
sizeChanged: function() {
var last = this._lastBounds,
- bounds = this.getBounds();
- return !last || last.w !== bounds.w || last.h !== bounds.h;
+ bounds;
+ return !last || ( ( bounds = this.getBounds() ) && ( last.w !== bounds.w || last.h !== bounds.h ) );
},
getLiveBounds: function() {
@@ -33,16 +33,19 @@ PIE.BoundsInfo.prototype = {
},
getBounds: function() {
- return this._lockedBounds || this.getLiveBounds();
+ return this._locked ?
+ ( this._lockedBounds || ( this._lockedBounds = this.getLiveBounds() ) ) :
+ this.getLiveBounds();
},
lock: function() {
- this._lockedBounds = this.getLiveBounds();
+ this._locked++;
},
unlock: function() {
this._lastBounds = this._lockedBounds;
this._lockedBounds = null;
+ this._locked--;
}
};
Please sign in to comment.
Something went wrong with that request. Please try again.