From a2a238968347199842dd7e2d552741d5a63c90b9 Mon Sep 17 00:00:00 2001 From: David DeSandro Date: Tue, 3 May 2011 17:28:32 -0400 Subject: [PATCH 1/3] src : convert isoTransform to a bunch of vars --- jquery.isotope.js | 131 +++++++++++++++++++++--------------------- jquery.isotope.min.js | 22 +++---- 2 files changed, 77 insertions(+), 76 deletions(-) diff --git a/jquery.isotope.js b/jquery.isotope.js index f8ea485..8873e63 100644 --- a/jquery.isotope.js +++ b/jquery.isotope.js @@ -50,6 +50,8 @@ return getStyleProperty; }()); + var transformProp = getStyleProperty('transform'); + // ========================= miniModernizr =============================== // <3<3<3 and thanks to Faruk and Paul for doing the heavy lifting @@ -78,7 +80,7 @@ { name : 'csstransforms', getResult : function() { - return !!getStyleProperty('transform'); + return !!transformProp; } }, { @@ -155,16 +157,16 @@ // ========================= isoTransform =============================== /** - * provides hooks for .css({ scale: value, translate: x y }) + * provides hooks for .css({ scale: value, translate: [x, y] }) * Progressively enhanced CSS transforms * Uses hardware accelerated 3D transforms for Safari * or falls back to 2D transforms. */ - var isoTransform = { - - transformProp : getStyleProperty('transform'), + + if ( Modernizr.csstransforms ) { - fnUtils : Modernizr.csstransforms3d ? + // i.e. transformFnNotations.scale(0.5) >> 'scale3d( 0.5, 0.5, 1)' + var transformFnNotations = Modernizr.csstransforms3d ? { // 3D transform functions translate : function ( position ) { return 'translate3d(' + position[0] + 'px, ' + position[1] + 'px, 0) '; @@ -177,19 +179,20 @@ translate : function ( position ) { return 'translate(' + position[0] + 'px, ' + position[1] + 'px) '; }, - scale : function ( scale ) { + scale : function ( scale ) { return 'scale(' + scale + ') '; } } - , - - set : function( elem, name, value ) { + ; + + function setIsoTransform ( elem, name, value ) { var $elem = $(elem), // unpack current transform data data = $elem.data('isoTransform') || {}, newData = {}, fnName, - transformObj = {}; + transformObj = {}, + transformValue; // i.e. newData.scale = 0.5 newData[ name ] = value; @@ -197,9 +200,8 @@ $.extend( data, newData ); for ( fnName in data ) { - var transformValue = data[ fnName ], - getFn = isoTransform.fnUtils[ fnName ]; - transformObj[ fnName ] = getFn( transformValue ); + transformValue = data[ fnName ]; + transformObj[ fnName ] = transformFnNotations[ fnName ]( transformValue ); } // get proper order @@ -214,69 +216,68 @@ $elem.data( 'isoTransform', data ); // set name to vendor specific property - elem.style[ isoTransform.transformProp ] = valueFns; - + elem.style[ transformProp ] = valueFns; } - }; - - // ==================== scale =================== + + // ==================== scale =================== - $.cssNumber.scale = true; + $.cssNumber.scale = true; - $.cssHooks.scale = { - set: function( elem, value ) { + $.cssHooks.scale = { + set: function( elem, value ) { - if ( typeof value === 'string' ) { - value = parseFloat( value ); - } + if ( typeof value === 'string' ) { + value = parseFloat( value ); + } - isoTransform.set( elem, 'scale', value ); + setIsoTransform( elem, 'scale', value ); - }, - get: function( elem, computed ) { - var transform = $.data( elem, 'transform' ); - return transform && transform.scale ? transform.scale : 1; - } - }; + }, + get: function( elem, computed ) { + var transform = $.data( elem, 'isoTransform' ); + return transform && transform.scale ? transform.scale : 1; + } + }; - $.fx.step.scale = function( fx ) { - $.cssHooks.scale.set( fx.elem, fx.now+fx.unit ); - }; + $.fx.step.scale = function( fx ) { + $.cssHooks.scale.set( fx.elem, fx.now+fx.unit ); + }; - // ==================== translate =================== + // ==================== translate =================== - $.cssNumber.translate = true; + $.cssNumber.translate = true; - $.cssHooks.translate = { - set: function( elem, value ) { - - // all this would be for public ease-of-use, - // but we're leaving it out since this add-on is - // only for internal-plugin use - // if ( typeof value === 'string' ) { - // value = value.split(' '); - // } - // - // - // var i, val; - // for ( i = 0; i < 2; i++ ) { - // val = value[i]; - // if ( typeof val === 'string' ) { - // val = parseInt( val ); - // } - // } - - isoTransform.set( elem, 'translate', value ); - - }, + $.cssHooks.translate = { + set: function( elem, value ) { + + // all this would be for public ease-of-use, + // but we're leaving it out since this add-on is + // only for internal-plugin use + // if ( typeof value === 'string' ) { + // value = value.split(' '); + // } + // + // + // var i, val; + // for ( i = 0; i < 2; i++ ) { + // val = value[i]; + // if ( typeof val === 'string' ) { + // val = parseInt( val ); + // } + // } + + setIsoTransform( elem, 'translate', value ); + + }, - get: function( elem, computed ) { - var transform = $.data( elem, 'transform' ); - return transform && transform.translate ? transform.translate : [ 0, 0 ]; - } - }; + get: function( elem, computed ) { + var transform = $.data( elem, 'isoTransform' ); + return transform && transform.translate ? transform.translate : [ 0, 0 ]; + } + }; + } @@ -728,7 +729,7 @@ this.style.left = null; this.style.opacity = null; if ( usingTransforms ) { - this.style[ isoTransform.transformProp ] = null; + this.style[ transformProp ] = null; } }); diff --git a/jquery.isotope.min.js b/jquery.isotope.min.js index b06f2c4..2f740b8 100644 --- a/jquery.isotope.min.js +++ b/jquery.isotope.min.js @@ -8,23 +8,23 @@ * * Copyright 2011 David DeSandro / Metafizzy */ -(function(l,f,s){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,t;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(t=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"); From 7528e89d5f57db3629021e5d4d1af105f97a67ad Mon Sep 17 00:00:00 2001 From: David DeSandro Date: Tue, 3 May 2011 17:35:54 -0400 Subject: [PATCH 2/3] src : whitespace and comment fixes around isoTransform --- jquery.isotope.js | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/jquery.isotope.js b/jquery.isotope.js index 8873e63..6dc2eae 100644 --- a/jquery.isotope.js +++ b/jquery.isotope.js @@ -225,13 +225,11 @@ $.cssHooks.scale = { set: function( elem, value ) { - + // properly parse strings if ( typeof value === 'string' ) { value = parseFloat( value ); } - setIsoTransform( elem, 'scale', value ); - }, get: function( elem, computed ) { var transform = $.data( elem, 'isoTransform' ); @@ -251,14 +249,12 @@ $.cssHooks.translate = { set: function( elem, value ) { - // all this would be for public ease-of-use, - // but we're leaving it out since this add-on is - // only for internal-plugin use + // all this would be for public use + // properly parsing strings and whatnot // if ( typeof value === 'string' ) { // value = value.split(' '); // } // - // // var i, val; // for ( i = 0; i < 2; i++ ) { // val = value[i]; @@ -268,7 +264,6 @@ // } setIsoTransform( elem, 'translate', value ); - }, get: function( elem, computed ) { From bd008396aa3b4e1a553c7c22518b761ed364979a Mon Sep 17 00:00:00 2001 From: David DeSandro Date: Tue, 3 May 2011 17:45:43 -0400 Subject: [PATCH 3/3] src : un-cached version of getStyleProperty https://github.com/kangax/cft/blob/master/getStyleProperty.js; function assignment for setIsoTransform --- jquery.isotope.js | 31 ++++++++-------------- jquery.isotope.min.js | 60 +++++++++++++++++++++---------------------- 2 files changed, 40 insertions(+), 51 deletions(-) diff --git a/jquery.isotope.js b/jquery.isotope.js index 6dc2eae..ba82175 100644 --- a/jquery.isotope.js +++ b/jquery.isotope.js @@ -17,38 +17,27 @@ var getStyleProperty = (function(){ var prefixes = ['Moz', 'Webkit', 'Khtml', 'O', 'Ms']; - var _cache = { }; function getStyleProperty(propName, element) { element = element || document.documentElement; var style = element.style, - prefixed, - uPropName, - i, l; + prefixed; - // check cache only when no element is given - if (arguments.length === 1 && typeof _cache[propName] === 'string') { - return _cache[propName]; - } // test standard property first - if (typeof style[propName] === 'string') { - return (_cache[propName] = propName); - } - + if (typeof style[propName] == 'string') return propName; + // capitalize - uPropName = propName.charAt(0).toUpperCase() + propName.slice(1); + propName = propName.charAt(0).toUpperCase() + propName.slice(1); // test vendor specific properties - for (i=0, l=prefixes.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===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); +(function(k,f,s){var m=function(){var a=["Moz","Webkit","Khtml","O","Ms"];return function(b,c){c=c||document.documentElement;var d=c.style,e;if(typeof d[b]=="string")return b;b=b.charAt(0).toUpperCase()+b.slice(1);for(var g=0,h=a.length;gh?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);