From 1ab21c8e1b3212679d8f2756bf13b6a2174ea03b Mon Sep 17 00:00:00 2001 From: David DeSandro Date: Mon, 23 Dec 2013 08:33:54 -0500 Subject: [PATCH] appended & prepended changes filteredItems :cherries: fixes #586 --- bower.json | 2 +- js/isotope.js | 71 +++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 59 insertions(+), 14 deletions(-) diff --git a/bower.json b/bower.json index b32e4f5..cd920f8 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "isotope", - "version": "2.0.0-beta.3", + "version": "2.0.0-beta.4", "description": "Filter and sort magical layouts", "main": [ "js/item.js", diff --git a/js/isotope.js b/js/isotope.js index 339171a..6083c13 100644 --- a/js/isotope.js +++ b/js/isotope.js @@ -1,5 +1,5 @@ /*! - * Isotope v2.0.0-beta.3 + * Isotope v2.0.0-beta.4 * Magical sorting and filtering layouts * http://isotope.metafizzy.co */ @@ -133,17 +133,6 @@ function isotopeDefinition( Outlayer, getSize, matchesSelector, Item, LayoutMode return items; }; - /** - * Filter, sort, and layout newly-appended item elements - * @param {Array or NodeList or Element} elems - */ - Isotope.prototype.insert = function( elems ) { - var items = this.addItems( elems ); - if ( !items.length ) { - return; - } - this.arrange(); - }; // -------------------------- layout -------------------------- // @@ -454,7 +443,63 @@ function isotopeDefinition( Outlayer, getSize, matchesSelector, Item, LayoutMode this._mode().resize(); }; - // -------------------------- remove -------------------------- // + // -------------------------- adding & removing -------------------------- // + + // HEADS UP overwrites default Outlayer appended + Isotope.prototype.appended = function( elems ) { + var items = this.addItems( elems ); + if ( !items.length ) { + return; + } + var filteredItems = this._filterRevealAdded( items ); + // add to filteredItems + this.filteredItems = this.filteredItems.concat( filteredItems ); + }; + + // HEADS UP overwrites default Outlayer prepended + Isotope.prototype.prepended = function( elems ) { + var items = this._itemize( elems ); + if ( !items.length ) { + return; + } + // add items to beginning of collection + var previousItems = this.items.slice(0); + this.items = items.concat( previousItems ); + // start new layout + this._resetLayout(); + this._manageStamps(); + // layout new stuff without transition + var filteredItems = this._filterRevealAdded( items ); + // layout previous items + this.layoutItems( previousItems ); + // add to filteredItems + this.filteredItems = filteredItems.concat( this.filteredItems ); + }; + + Isotope.prototype._filterRevealAdded = function( items ) { + // disable transition for filtering + var transitionDuration = this.options.transitionDuration; + this.options.transitionDuration = 0; + var filteredItems = this._filter( items ); + // re-enable transition for reveal + this.options.transitionDuration = transitionDuration; + // layout and reveal just the new items + this.layoutItems( filteredItems, true ); + this.reveal( filteredItems ); + return items; + }; + + /** + * Filter, sort, and layout newly-appended item elements + * @param {Array or NodeList or Element} elems + */ + Isotope.prototype.insert = function( elems ) { + var items = this.addItems( elems ); + if ( !items.length ) { + return; + } + this.arrange(); + }; var _remove = Isotope.prototype.remove; Isotope.prototype.remove = function( elems ) {