Browse Source

remove elements from filteredItems as well

pull/726/head
David DeSandro 11 years ago
parent
commit
8e2650024c
  1. 64
      js/isotope.js

64
js/isotope.js

@ -40,6 +40,48 @@ var getText = docElem.textContent ?
return elem.innerText; return elem.innerText;
}; };
var objToString = Object.prototype.toString;
function isArray( obj ) {
return objToString.call( obj ) === '[object Array]';
}
// index of helper cause IE8
var indexOf = Array.prototype.indexOf ? function( ary, obj ) {
return ary.indexOf( obj );
} : function( ary, obj ) {
for ( var i=0, len = ary.length; i < len; i++ ) {
if ( ary[i] === obj ) {
return i;
}
}
return -1;
};
// turn element or nodeList into an array
function makeArray( obj ) {
var ary = [];
if ( isArray( obj ) ) {
// use object if already an array
ary = obj;
} else if ( obj && typeof obj.length === 'number' ) {
// convert nodeList to array
for ( var i=0, len = obj.length; i < len; i++ ) {
ary.push( obj[i] );
}
} else {
// array of single index
ary.push( obj );
}
return ary;
}
function removeFrom( obj, ary ) {
var index = indexOf( ary, obj );
if ( index !== -1 ) {
ary.splice( index, 1 );
}
}
// -------------------------- isotopeDefinition -------------------------- // // -------------------------- isotopeDefinition -------------------------- //
// used for AMD definition and requires // used for AMD definition and requires
@ -144,7 +186,7 @@ function isotopeDefinition( Outlayer, getSize, matchesSelector, Item, LayoutMode
// set any options pass // set any options pass
this.option( opts ); this.option( opts );
this._getIsInstant(); this._getIsInstant();
// where the magic happens, amirite // filter, sort, and layout
this.filteredItems = this._filter( this.items ); this.filteredItems = this._filter( this.items );
this._sort(); this._sort();
this._layout(); this._layout();
@ -412,6 +454,26 @@ function isotopeDefinition( Outlayer, getSize, matchesSelector, Item, LayoutMode
this._mode().resize(); this._mode().resize();
}; };
// -------------------------- remove -------------------------- //
var _remove = Isotope.prototype.remove;
Isotope.prototype.remove = function( elems ) {
elems = makeArray( elems );
var removeItems = this.getItems( elems );
// do regular thing
_remove.call( this, elems );
// bail if no items to remove
if ( !removeItems || !removeItems.length ) {
return;
}
// remove elems from filteredItems
for ( var i=0, len = removeItems.length; i < len; i++ ) {
var item = removeItems[i];
// remove item from collection
removeFrom( item, this.filteredItems );
}
};
// ----- ----- // // ----- ----- //
return Isotope; return Isotope;

Loading…
Cancel
Save