Browse Source

🛠 remove len var in loops

pull/1127/head
David DeSandro 9 years ago
parent
commit
f9b06ebf33
  1. 38
      js/isotope.js
  2. 4
      sandbox/filter-sort.html

38
js/isotope.js

@ -118,7 +118,7 @@ var trim = String.prototype.trim ?
Isotope.prototype._itemize = function() { Isotope.prototype._itemize = function() {
var items = Outlayer.prototype._itemize.apply( this, arguments ); var items = Outlayer.prototype._itemize.apply( this, arguments );
// assign ID for original-order // assign ID for original-order
for ( var i=0, len = items.length; i < len; i++ ) { for ( var i=0; i < items.length; i++ ) {
var item = items[i]; var item = items[i];
item.id = this.itemGUID++; item.id = this.itemGUID++;
} }
@ -174,18 +174,12 @@ var trim = String.prototype.trim ?
var filtered = this._filter( this.items ); var filtered = this._filter( this.items );
this.filteredItems = filtered.matches; this.filteredItems = filtered.matches;
var _this = this;
function hideReveal() {
_this.reveal( filtered.needReveal );
_this.hide( filtered.needHide );
}
this._bindArrangeComplete(); this._bindArrangeComplete();
if ( this._isInstant ) { if ( this._isInstant ) {
this._noTransition( hideReveal ); this._noTransition( this._hideReveal, [ filtered ] );
} else { } else {
hideReveal(); this._hideReveal( filtered );
} }
this._sort(); this._sort();
@ -194,11 +188,16 @@ var trim = String.prototype.trim ?
// alias to _init for main plugin method // alias to _init for main plugin method
Isotope.prototype._init = Isotope.prototype.arrange; Isotope.prototype._init = Isotope.prototype.arrange;
Isotope.prototype._hideReveal = function( filtered ) {
this.reveal( filtered.needReveal );
this.hide( filtered.needHide );
};
// HACK // HACK
// Don't animate/transition first layout // Don't animate/transition first layout
// Or don't animate/transition other layouts // Or don't animate/transition other layouts
Isotope.prototype._getIsInstant = function() { Isotope.prototype._getIsInstant = function() {
var isLayoutInstant = this._getOption('layoutInstant') var isLayoutInstant = this._getOption('layoutInstant');
var isInstant = isLayoutInstant !== undefined ? isLayoutInstant : var isInstant = isLayoutInstant !== undefined ? isLayoutInstant :
!this._isLayoutInited; !this._isLayoutInited;
this._isInstant = isInstant; this._isInstant = isInstant;
@ -242,7 +241,7 @@ var trim = String.prototype.trim ?
var test = this._getFilterTest( filter ); var test = this._getFilterTest( filter );
// test each item // test each item
for ( var i=0, len = items.length; i < len; i++ ) { for ( var i=0; i < items.length; i++ ) {
var item = items[i]; var item = items[i];
if ( item.isIgnored ) { if ( item.isIgnored ) {
continue; continue;
@ -424,7 +423,7 @@ var trim = String.prototype.trim ?
function getItemSorter( sortBys, sortAsc ) { function getItemSorter( sortBys, sortAsc ) {
return function sorter( itemA, itemB ) { return function sorter( itemA, itemB ) {
// cycle through all sortKeys // cycle through all sortKeys
for ( var i = 0, len = sortBys.length; i < len; i++ ) { for ( var i = 0; i < sortBys.length; i++ ) {
var sortBy = sortBys[i]; var sortBy = sortBys[i];
var a = itemA.sortData[ sortBy ]; var a = itemA.sortData[ sortBy ];
var b = itemB.sortData[ sortBy ]; var b = itemB.sortData[ sortBy ];
@ -570,7 +569,7 @@ var trim = String.prototype.trim ?
Isotope.prototype.shuffle = function() { Isotope.prototype.shuffle = function() {
// update random sortData // update random sortData
for ( var i=0, len = this.items.length; i < len; i++ ) { for ( var i=0; i < this.items.length; i++ ) {
var item = this.items[i]; var item = this.items[i];
item.sortData.random = Math.random(); item.sortData.random = Math.random();
} }
@ -583,16 +582,17 @@ var trim = String.prototype.trim ?
* trigger fn without transition * trigger fn without transition
* kind of hacky to have this in the first place * kind of hacky to have this in the first place
* @param {Function} fn * @param {Function} fn
* @param {Array} args
* @returns ret * @returns ret
* @private * @private
*/ */
Isotope.prototype._noTransition = function( fn ) { Isotope.prototype._noTransition = function( fn, args ) {
// save transitionDuration before disabling // save transitionDuration before disabling
var transitionDuration = this.options.transitionDuration; var transitionDuration = this.options.transitionDuration;
// disable transition // disable transition
this.options.transitionDuration = 0; this.options.transitionDuration = 0;
// do it // do it
var returnValue = fn.call( this ); var returnValue = fn.apply( this, args );
// re-enable transition for reveal // re-enable transition for reveal
this.options.transitionDuration = transitionDuration; this.options.transitionDuration = transitionDuration;
return returnValue; return returnValue;
@ -605,11 +605,9 @@ var trim = String.prototype.trim ?
* @returns {Array} elems - collection of item elements * @returns {Array} elems - collection of item elements
*/ */
Isotope.prototype.getFilteredItemElements = function() { Isotope.prototype.getFilteredItemElements = function() {
var elems = []; return this.filteredItems.map( function( item ) {
for ( var i=0, len = this.filteredItems.length; i < len; i++ ) { return item.element;
elems.push( this.filteredItems[i].element ); });
}
return elems;
}; };
// ----- ----- // // ----- ----- //

4
sandbox/filter-sort.html

@ -166,6 +166,7 @@ var iso = window.iso = new Isotope( container, {
columnWidth: 130, columnWidth: 130,
rowHeight: 140, rowHeight: 140,
}, },
// filter: '.transition',
getSortData: { getSortData: {
number: '.number parseInt', number: '.number parseInt',
symbol: '.symbol', symbol: '.symbol',
@ -173,7 +174,8 @@ var iso = window.iso = new Isotope( container, {
category: '[data-category]', category: '[data-category]',
weight: function( itemElem ) { weight: function( itemElem ) {
// remove parenthesis // remove parenthesis
return parseFloat( getText( itemElem.querySelector('.weight') ).replace( /[\(\)]/g, '') ); var weight = itemElem.querySelector('.weight').textContent;
return parseFloat( weight.replace( /[\(\)]/g, '') );
} }
} }
}); });

Loading…
Cancel
Save