From aeffe90c1709b5b54d3a010a1138929bc66fce1e Mon Sep 17 00:00:00 2001 From: David DeSandro Date: Mon, 28 Mar 2011 07:26:57 -0400 Subject: [PATCH 1/2] src : use `elem.style.foo` = null to re-apply original styles with destroy method. Closes #35 --- _posts/tests/2011-03-27-destroy01.html | 37 ++++++++++++++++ jquery.isotope.js | 47 +++++++++++++------- jquery.isotope.min.js | 61 +++++++++++++------------- 3 files changed, 99 insertions(+), 46 deletions(-) create mode 100644 _posts/tests/2011-03-27-destroy01.html diff --git a/_posts/tests/2011-03-27-destroy01.html b/_posts/tests/2011-03-27-destroy01.html new file mode 100644 index 0000000..94f31de --- /dev/null +++ b/_posts/tests/2011-03-27-destroy01.html @@ -0,0 +1,37 @@ +--- +title: destroy01 +layout: demo +category: tests +--- + + + +
+

After destroy-ing Isotope, original CSS gets re-applied

+
+ +
+ {% for element in site.elements limit:20 %} + {% include element-partial.html %} + {% endfor %} +
+ + + + \ No newline at end of file diff --git a/jquery.isotope.js b/jquery.isotope.js index 2e24594..c43c9c0 100644 --- a/jquery.isotope.js +++ b/jquery.isotope.js @@ -1,5 +1,5 @@ /** - * Isotope v1.0.110325 + * Isotope v1.0.110328 * An exquisite jQuery plugin for magical layouts * http://isotope.metafizzy.co * @@ -331,6 +331,9 @@ this._create( options ); this._init(); }; + + // styles of container element we want to keep track of + var isoContainerStyles = [ 'overflow', 'position', 'width', 'height' ]; $.Isotope.prototype = { @@ -371,6 +374,14 @@ this.elemCount = 0; // need to get atoms this.$allAtoms = this._filterFind( this.element.children(), this.options.itemSelector ); + + // get original styles in case we re-apply them in .destroy() + var elemStyle = this.element[0].style; + this.originalStyle = {}; + for ( var i=0, len = isoContainerStyles.length; i < len; i++ ) { + var prop = isoContainerStyles[i]; + this.originalStyle[ prop ] = elemStyle[ prop ] || null; + } this.element.css({ overflow : 'hidden', @@ -719,25 +730,29 @@ // destroys widget, returns elements and container back (close) to original style destroy : function() { - var atomUnstyle = $.extend( this.options.visibleStyle, { - position: 'relative', - top: 'auto', - left: 'auto' - }); + + var usingTransforms = this.usingTransforms; + + this.$allAtoms + .removeClass( this.options.hiddenClass + ' ' + this.options.itemClass ) + .each(function(){ + this.style.position = null; + this.style.top = null; + this.style.left = null; + this.style.opacity = null; + if ( usingTransforms ) { + this.style[ isoTransform.transformProp ] = null; + } + }); - if ( this.usingTransforms ) { - atomUnstyle[ isoTransform.transformProp ] = 'none'; + // re-apply saved container styles + var elemStyle = this.element[0].style; + for ( var i=0, len = isoContainerStyles.length; i < len; i++ ) { + var prop = isoContainerStyles[i]; + elemStyle[ prop ] = this.originalStyle[ prop ]; } - this.$allAtoms - .css( atomUnstyle ) - .removeClass( this.options.hiddenClass + ' ' + this.options.itemClass ); - this.element - .css({ - width: 'auto', - height: 'auto' - }) .unbind('.isotope') .removeClass( this.options.containerClass ) .removeData('isotope'); diff --git a/jquery.isotope.min.js b/jquery.isotope.min.js index ed04698..81361cb 100644 --- a/jquery.isotope.min.js +++ b/jquery.isotope.min.js @@ -1,5 +1,5 @@ /** - * Isotope v1.0.110325 + * Isotope v1.0.110328 * An exquisite jQuery plugin for magical layouts * http://isotope.metafizzy.co * @@ -8,33 +8,34 @@ * * Copyright 2011 David DeSandro / Metafizzy */ -(function(l,f,r){var m=function(){var a=["Moz","Webkit","Khtml","O","Ms"],b={};return function(c,d){d=d||document.documentElement;var e=d.style,g,h,i,s;if(arguments.length===1&&typeof b[c]==="string")return b[c];if(typeof e[c]==="string")return b[c]=c;h=c.charAt(0).toUpperCase()+c.slice(1);i=0;for(s=a.length;ih?1:gb.width){b.fitRows.x=0;b.fitRows.y=b.fitRows.height}b._pushPosition(c,b.fitRows.x+b.posLeft,b.fitRows.y+b.posTop);b.fitRows.height=Math.max(b.fitRows.y+e,b.fitRows.height);b.fitRows.x+=d});return this},_fitRowsReset:function(){this.fitRows={x:0,y:0,height:0};return this},_fitRowsGetContainerSize:function(){return{height:this.fitRows.height}},_fitRowsResize:function(){return this.reLayout()}, -_cellsByRowReset:function(){this.cellsByRow={};this._getSegments("cellsByRow");this.cellsByRow.rowHeight=this.options.cellsByRow.rowHeight||this.$allAtoms.outerHeight(true);return this},_cellsByRowLayout:function(a){var b=this,c=this.cellsByRow.cols;this.cellsByRow.atomsLen=a.length;a.each(function(d){var e=f(this),g=(d%c+0.5)*b.cellsByRow.columnWidth-e.outerWidth(true)/2+b.posLeft;d=(~~(d/c)+0.5)*b.cellsByRow.rowHeight-e.outerHeight(true)/2+b.posTop;b._pushPosition(e,g,d)});return this},_cellsByRowGetContainerSize:function(){return{height:Math.ceil(this.cellsByRow.atomsLen/ -this.cellsByRow.cols)*this.cellsByRow.rowHeight+this.posTop}},_cellsByRowResize:function(){var a=this.cellsByRow.cols;this._getSegments("cellsByRow");this.cellsByRow.cols!==a&&this.reLayout();return this},_straightDownReset:function(){this.straightDown={y:0};return this},_straightDownLayout:function(a){var b=this;a.each(function(){var c=f(this);b._pushPosition(c,b.posLeft,b.straightDown.y+b.posTop);b.straightDown.y+=c.outerHeight(true)});return this},_straightDownGetContainerSize:function(){return{height:this.straightDown.y+ -this.posTop}},_straightDownResize:function(){this.reLayout();return this},_masonryHorizontalPlaceBrick:function(a,b,c){b=Math.min.apply(Math,c);for(var d=b+a.outerWidth(true),e=c.length,g=e,h=this.masonryHorizontal.rows+1-e;e--;)if(c[e]===b)g=e;this._pushPosition(a,b,this.masonryHorizontal.rowHeight*g+this.posTop);for(e=0;eb.height){b.fitColumns.x=b.fitColumns.width;b.fitColumns.y=0}b._pushPosition(c,b.fitColumns.x+b.posLeft,b.fitColumns.y+b.posTop);b.fitColumns.width=Math.max(b.fitColumns.x+d,b.fitColumns.width);b.fitColumns.y+=e});return this},_fitColumnsGetContainerSize:function(){return{width:this.fitColumns.width}},_fitColumnsResize:function(){return this.reLayout()},_cellsByColumnReset:function(){this.cellsByColumn={};this._getSegments("cellsByColumn", -true);this.cellsByColumn.columnWidth=this.options.cellsByColumn.columnWidth||this.$allAtoms.outerHeight(true);return this},_cellsByColumnLayout:function(a){var b=this,c=this.cellsByColumn.rows;this.cellsByColumn.atomsLen=a.length;a.each(function(d){var e=f(this),g=(~~(d/c)+0.5)*b.cellsByColumn.columnWidth-e.outerWidth(true)/2+b.posLeft;d=(d%c+0.5)*b.cellsByColumn.rowHeight-e.outerHeight(true)/2+b.posTop;b._pushPosition(e,g,d)});return this},_cellsByColumnGetContainerSize:function(){return{width:Math.ceil(this.cellsByColumn.atomsLen/ -this.cellsByColumn.rows)*this.cellsByColumn.columnWidth+this.posLeft}},_cellsByColumnResize:function(){var a=this.cellsByColumn.rows;this._getSegments("cellsByColumn",true);this.cellsByColumn.rows!==a&&this.reLayout();return this}};f.fn.imagesLoaded=function(a){var b=this.find("img"),c=b.length,d=this;b.length||a.call(this);b.bind("load",function(){--c<=0&&a.call(d)}).each(function(){if(this.complete||this.complete===r){var e=this.src;this.src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw=="; -this.src=e}});return this};f.widget=f.widget||{};f.widget.bridge=f.widget.bridge||function(a,b){f.fn[a]=function(c){var d=typeof c==="string",e=Array.prototype.slice.call(arguments,1),g=this;c=!d&&e.length?f.extend.apply(null,[true,c].concat(e)):c;if(d&&c.charAt(0)==="_")return g;d?this.each(function(){var h=f.data(this,a);if(!h)return f.error("cannot call methods on "+a+" prior to initialization; attempted to call method '"+c+"'");if(!f.isFunction(h[c]))return f.error("no such method '"+c+"' for "+ -a+" widget instance");var i=h[c].apply(h,e);if(i!==h&&i!==r){g=i;return false}}):this.each(function(){var h=f.data(this,a);h?h.option(c||{})._init():f.data(this,a,new b(c,this))});return g}};f.widget.bridge("isotope",f.Isotope)})(window,jQuery); +a.scale?a.scale:1}};f.fx.step.scale=function(a){f.cssHooks.scale.set(a.elem,a.now+a.unit)};f.cssNumber.translate=true;f.cssHooks.translate={set:function(a,b){k.set(a,"translate",b)},get:function(a){return(a=f.data(a,"transform"))&&a.translate?a.translate:[0,0]}};var q=f.event,r;q.special.smartresize={setup:function(){f(this).bind("resize",q.special.smartresize.handler)},teardown:function(){f(this).unbind("resize",q.special.smartresize.handler)},handler:function(a,b){var c=this,d=arguments;a.type= +"smartresize";r&&clearTimeout(r);r=setTimeout(function(){jQuery.event.handle.apply(c,d)},b==="execAsap"?0:100)}};f.fn.smartresize=function(a){return a?this.bind("smartresize",a):this.trigger("smartresize",["execAsap"])};f.Isotope=function(a,b){this.element=f(b);this._create(a);this._init()};var n=["overflow","position","width","height"];f.Isotope.prototype={options:{resizable:true,layoutMode:"masonry",containerClass:"isotope",itemClass:"isotope-item",hiddenClass:"isotope-hidden",hiddenStyle:Modernizr.csstransforms&& +!f.browser.opera?{opacity:0,scale:0.0010}:{opacity:0},visibleStyle:Modernizr.csstransforms&&!f.browser.opera?{opacity:1,scale:1}:{opacity:1},animationEngine:f.browser.opera?"jquery":"best-available",animationOptions:{queue:false,duration:800},sortBy:"original-order",sortAscending:true,resizesContainer:true,transformsEnabled:true},_filterFind:function(a,b){return b?a.filter(b).add(a.find(b)):a},_create:function(a){this.options=f.extend(true,{},this.options,a);this.isNew={};this.styleQueue=[];this.elemCount= +0;this.$allAtoms=this._filterFind(this.element.children(),this.options.itemSelector);a=this.element[0].style;this.originalStyle={};for(var b=0,c=n.length;bh?1:gb.width){b.fitRows.x=0;b.fitRows.y=b.fitRows.height}b._pushPosition(c,b.fitRows.x+b.posLeft,b.fitRows.y+b.posTop);b.fitRows.height=Math.max(b.fitRows.y+e,b.fitRows.height);b.fitRows.x+=d}); +return this},_fitRowsReset:function(){this.fitRows={x:0,y:0,height:0};return this},_fitRowsGetContainerSize:function(){return{height:this.fitRows.height}},_fitRowsResize:function(){return this.reLayout()},_cellsByRowReset:function(){this.cellsByRow={};this._getSegments("cellsByRow");this.cellsByRow.rowHeight=this.options.cellsByRow.rowHeight||this.$allAtoms.outerHeight(true);return this},_cellsByRowLayout:function(a){var b=this,c=this.cellsByRow.cols;this.cellsByRow.atomsLen=a.length;a.each(function(d){var e= +f(this),g=(d%c+0.5)*b.cellsByRow.columnWidth-e.outerWidth(true)/2+b.posLeft;d=(~~(d/c)+0.5)*b.cellsByRow.rowHeight-e.outerHeight(true)/2+b.posTop;b._pushPosition(e,g,d)});return this},_cellsByRowGetContainerSize:function(){return{height:Math.ceil(this.cellsByRow.atomsLen/this.cellsByRow.cols)*this.cellsByRow.rowHeight+this.posTop}},_cellsByRowResize:function(){var a=this.cellsByRow.cols;this._getSegments("cellsByRow");this.cellsByRow.cols!==a&&this.reLayout();return this},_straightDownReset:function(){this.straightDown= +{y:0};return this},_straightDownLayout:function(a){var b=this;a.each(function(){var c=f(this);b._pushPosition(c,b.posLeft,b.straightDown.y+b.posTop);b.straightDown.y+=c.outerHeight(true)});return this},_straightDownGetContainerSize:function(){return{height:this.straightDown.y+this.posTop}},_straightDownResize:function(){this.reLayout();return this},_masonryHorizontalPlaceBrick:function(a,b,c){b=Math.min.apply(Math,c);for(var d=b+a.outerWidth(true),e=c.length,g=e,h=this.masonryHorizontal.rows+1-e;e--;)if(c[e]=== +b)g=e;this._pushPosition(a,b,this.masonryHorizontal.rowHeight*g+this.posTop);for(e=0;eb.height){b.fitColumns.x=b.fitColumns.width;b.fitColumns.y=0}b._pushPosition(c,b.fitColumns.x+b.posLeft,b.fitColumns.y+ +b.posTop);b.fitColumns.width=Math.max(b.fitColumns.x+d,b.fitColumns.width);b.fitColumns.y+=e});return this},_fitColumnsGetContainerSize:function(){return{width:this.fitColumns.width}},_fitColumnsResize:function(){return this.reLayout()},_cellsByColumnReset:function(){this.cellsByColumn={};this._getSegments("cellsByColumn",true);this.cellsByColumn.columnWidth=this.options.cellsByColumn.columnWidth||this.$allAtoms.outerHeight(true);return this},_cellsByColumnLayout:function(a){var b=this,c=this.cellsByColumn.rows; +this.cellsByColumn.atomsLen=a.length;a.each(function(d){var e=f(this),g=(~~(d/c)+0.5)*b.cellsByColumn.columnWidth-e.outerWidth(true)/2+b.posLeft;d=(d%c+0.5)*b.cellsByColumn.rowHeight-e.outerHeight(true)/2+b.posTop;b._pushPosition(e,g,d)});return this},_cellsByColumnGetContainerSize:function(){return{width:Math.ceil(this.cellsByColumn.atomsLen/this.cellsByColumn.rows)*this.cellsByColumn.columnWidth+this.posLeft}},_cellsByColumnResize:function(){var a=this.cellsByColumn.rows;this._getSegments("cellsByColumn", +true);this.cellsByColumn.rows!==a&&this.reLayout();return this}};f.fn.imagesLoaded=function(a){var b=this.find("img"),c=b.length,d=this;b.length||a.call(this);b.bind("load",function(){--c<=0&&a.call(d)}).each(function(){if(this.complete||this.complete===s){var e=this.src;this.src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==";this.src=e}});return this};f.widget=f.widget||{};f.widget.bridge=f.widget.bridge||function(a,b){f.fn[a]=function(c){var d=typeof c==="string",e=Array.prototype.slice.call(arguments, +1),g=this;c=!d&&e.length?f.extend.apply(null,[true,c].concat(e)):c;if(d&&c.charAt(0)==="_")return g;d?this.each(function(){var h=f.data(this,a);if(!h)return f.error("cannot call methods on "+a+" prior to initialization; attempted to call method '"+c+"'");if(!f.isFunction(h[c]))return f.error("no such method '"+c+"' for "+a+" widget instance");var i=h[c].apply(h,e);if(i!==h&&i!==s){g=i;return false}}):this.each(function(){var h=f.data(this,a);h?h.option(c||{})._init():f.data(this,a,new b(c,this))}); +return g}};f.widget.bridge("isotope",f.Isotope)})(window,jQuery); From 31aa9198ac201a11d7ad756cc4af5b0688ee8760 Mon Sep 17 00:00:00 2001 From: David DeSandro Date: Mon, 28 Mar 2011 07:28:22 -0400 Subject: [PATCH 2/2] src : jsHint : move `-` to previous line --- jquery.isotope.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/jquery.isotope.js b/jquery.isotope.js index c43c9c0..2370e31 100644 --- a/jquery.isotope.js +++ b/jquery.isotope.js @@ -951,10 +951,10 @@ this.cellsByRow.atomsLen = $elems.length; $elems.each( function( i ){ var $this = $(this), - x = ( i % cols + 0.5 ) * instance.cellsByRow.columnWidth - - $this.outerWidth(true) / 2 + instance.posLeft, - y = ( ~~( i / cols ) + 0.5 ) * instance.cellsByRow.rowHeight - - $this.outerHeight(true) / 2 + instance.posTop; + x = ( i % cols + 0.5 ) * instance.cellsByRow.columnWidth - + $this.outerWidth(true) / 2 + instance.posLeft, + y = ( ~~( i / cols ) + 0.5 ) * instance.cellsByRow.rowHeight - + $this.outerHeight(true) / 2 + instance.posTop; instance._pushPosition( $this, x, y ); }); return this; @@ -1162,10 +1162,10 @@ this.cellsByColumn.atomsLen = $elems.length; $elems.each( function( i ){ var $this = $(this), - x = ( ~~( i / rows ) + 0.5 ) * instance.cellsByColumn.columnWidth - - $this.outerWidth(true) / 2 + instance.posLeft, - y = ( i % rows + 0.5 ) * instance.cellsByColumn.rowHeight - - $this.outerHeight(true) / 2 + instance.posTop; + x = ( ~~( i / rows ) + 0.5 ) * instance.cellsByColumn.columnWidth - + $this.outerWidth(true) / 2 + instance.posLeft, + y = ( i % rows + 0.5 ) * instance.cellsByColumn.rowHeight - + $this.outerHeight(true) / 2 + instance.posTop; instance._pushPosition( $this, x, y ); }); return this;