From f9b06ebf337306d26ad301648b9c9dcdec386dee Mon Sep 17 00:00:00 2001 From: David DeSandro Date: Sun, 14 Feb 2016 14:31:04 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=9B=A0=20remove=20len=20var=20in=20loops?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/isotope.js | 38 ++++++++++++++++++-------------------- sandbox/filter-sort.html | 4 +++- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/js/isotope.js b/js/isotope.js index 6622f66..0a4c94a 100644 --- a/js/isotope.js +++ b/js/isotope.js @@ -118,7 +118,7 @@ var trim = String.prototype.trim ? Isotope.prototype._itemize = function() { var items = Outlayer.prototype._itemize.apply( this, arguments ); // 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]; item.id = this.itemGUID++; } @@ -174,18 +174,12 @@ var trim = String.prototype.trim ? var filtered = this._filter( this.items ); this.filteredItems = filtered.matches; - var _this = this; - function hideReveal() { - _this.reveal( filtered.needReveal ); - _this.hide( filtered.needHide ); - } - this._bindArrangeComplete(); if ( this._isInstant ) { - this._noTransition( hideReveal ); + this._noTransition( this._hideReveal, [ filtered ] ); } else { - hideReveal(); + this._hideReveal( filtered ); } this._sort(); @@ -194,11 +188,16 @@ var trim = String.prototype.trim ? // alias to _init for main plugin method Isotope.prototype._init = Isotope.prototype.arrange; + Isotope.prototype._hideReveal = function( filtered ) { + this.reveal( filtered.needReveal ); + this.hide( filtered.needHide ); + }; + // HACK // Don't animate/transition first layout // Or don't animate/transition other layouts Isotope.prototype._getIsInstant = function() { - var isLayoutInstant = this._getOption('layoutInstant') + var isLayoutInstant = this._getOption('layoutInstant'); var isInstant = isLayoutInstant !== undefined ? isLayoutInstant : !this._isLayoutInited; this._isInstant = isInstant; @@ -242,7 +241,7 @@ var trim = String.prototype.trim ? var test = this._getFilterTest( filter ); // 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]; if ( item.isIgnored ) { continue; @@ -424,7 +423,7 @@ var trim = String.prototype.trim ? function getItemSorter( sortBys, sortAsc ) { return function sorter( itemA, itemB ) { // 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 a = itemA.sortData[ sortBy ]; var b = itemB.sortData[ sortBy ]; @@ -570,7 +569,7 @@ var trim = String.prototype.trim ? Isotope.prototype.shuffle = function() { // 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]; item.sortData.random = Math.random(); } @@ -583,16 +582,17 @@ var trim = String.prototype.trim ? * trigger fn without transition * kind of hacky to have this in the first place * @param {Function} fn + * @param {Array} args * @returns ret * @private */ - Isotope.prototype._noTransition = function( fn ) { + Isotope.prototype._noTransition = function( fn, args ) { // save transitionDuration before disabling var transitionDuration = this.options.transitionDuration; // disable transition this.options.transitionDuration = 0; // do it - var returnValue = fn.call( this ); + var returnValue = fn.apply( this, args ); // re-enable transition for reveal this.options.transitionDuration = transitionDuration; return returnValue; @@ -605,11 +605,9 @@ var trim = String.prototype.trim ? * @returns {Array} elems - collection of item elements */ Isotope.prototype.getFilteredItemElements = function() { - var elems = []; - for ( var i=0, len = this.filteredItems.length; i < len; i++ ) { - elems.push( this.filteredItems[i].element ); - } - return elems; + return this.filteredItems.map( function( item ) { + return item.element; + }); }; // ----- ----- // diff --git a/sandbox/filter-sort.html b/sandbox/filter-sort.html index d50f9ab..355aa96 100644 --- a/sandbox/filter-sort.html +++ b/sandbox/filter-sort.html @@ -166,6 +166,7 @@ var iso = window.iso = new Isotope( container, { columnWidth: 130, rowHeight: 140, }, + // filter: '.transition', getSortData: { number: '.number parseInt', symbol: '.symbol', @@ -173,7 +174,8 @@ var iso = window.iso = new Isotope( container, { category: '[data-category]', weight: function( itemElem ) { // remove parenthesis - return parseFloat( getText( itemElem.querySelector('.weight') ).replace( /[\(\)]/g, '') ); + var weight = itemElem.querySelector('.weight').textContent; + return parseFloat( weight.replace( /[\(\)]/g, '') ); } } });