(function($) { var Modernizr = window.Modernizr; // helper function var capitalize = function( str ) { return str.charAt(0).toUpperCase() + str.slice(1); }; // ========================= getStyleProperty by kangax =============================== // http://perfectionkills.com/feature-testing-css-properties/ var prefixes = 'Moz Webkit O Ms'.split(' '); var getStyleProperty = function( propName ) { var style = document.documentElement.style, prefixed; // test standard property first if ( typeof style[propName] === 'string' ) { return propName; } // capitalize propName = capitalize( propName ); // test vendor specific properties for ( var i=0, len = prefixes.length; i < len; i++ ) { prefixed = prefixes[i] + propName; if ( typeof style[ prefixed ] === 'string' ) { return prefixed; } } }; var transformProp = getStyleProperty('transform'), transitionProp = getStyleProperty('transitionProperty'); // ========================= isoTransform =============================== /** * 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. */ if ( Modernizr.csstransforms ) { // 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) '; }, scale : function ( scale ) { return 'scale3d(' + scale + ', ' + scale + ', 1) '; } } : { // 2D transform functions translate : function ( position ) { return 'translate(' + position[0] + 'px, ' + position[1] + 'px) '; }, scale : function ( scale ) { return 'scale(' + scale + ') '; } } ; var setIsoTransform = function ( elem, name, value ) { // unpack current transform data var data = $.data( elem, 'isoTransform' ) || {}, newData = {}, fnName, transformObj = {}, transformValue; // i.e. newData.scale = 0.5 newData[ name ] = value; // extend new value over current data $.extend( data, newData ); for ( fnName in data ) { transformValue = data[ fnName ]; transformObj[ fnName ] = transformFnNotations[ fnName ]( transformValue ); } // get proper order // ideally, we could loop through this give an array, but since we only have // a couple transforms we're keeping track of, we'll do it like so var translateFn = transformObj.translate || '', scaleFn = transformObj.scale || '', // sorting so translate always comes first valueFns = translateFn + scaleFn; // set data back in elem $.data( elem, 'isoTransform', data ); // set name to vendor specific property elem.style[ transformProp ] = valueFns; }; // ==================== scale =================== $.cssNumber.scale = true; $.cssHooks.scale = { set: function( elem, value ) { // uncomment this bit if you want to properly parse strings // if ( typeof value === 'string' ) { // value = parseFloat( value ); // } setIsoTransform( elem, 'scale', value ); }, 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 ); }; // ==================== translate =================== $.cssNumber.translate = true; $.cssHooks.translate = { set: function( elem, value ) { // uncomment this bit if you want to properly parse strings // 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, 'isoTransform' ); return transform && transform.translate ? transform.translate : [ 0, 0 ]; } }; } // ========================= get transition-end event =============================== var transitionEndEvent, transitionDurProp; if ( Modernizr.csstransitions ) { transitionEndEvent = { WebkitTransitionProperty: 'webkitTransitionEnd', // webkit MozTransitionProperty: 'transitionend', OTransitionProperty: 'oTransitionEnd otransitionend', transitionProperty: 'transitionend' }[ transitionProp ]; transitionDurProp = getStyleProperty('transitionDuration'); } var hideStyle = { opacity: 0, zoom: 0.001 }; var showStyle = { opacity: 1, zoom: 1 }; if(Modernizr.csstransforms && Modernizr.csstransitions) { hideStyle = { opacity: 0, scale: 0.001 }; showStyle = { opacity: 1, scale: 1 }; } // ====================== Filtering ====================== $.Mason.prototype.filter = function(items, selector, callback) { var filtered = items.filter(selector); var hiddenClass = 'hidden', hiddenSelector = '.' + hiddenClass, $hiddenItems = items.filter(hiddenSelector), $itemsToShow = $hiddenItems, $itemsToHide; if(selector !== '*') { $itemsToShow = $hiddenItems.filter(selector); $itemsToHide = items.not(hiddenSelector).not(selector).addClass(hiddenClass); this.styleQueue.push({ $el: $itemsToHide, style: hideStyle }); $itemsToHide.each(function() { var item = $(this); item.data('_originalDimensions') || item.data('_originalDimensions', { width : item.width(), height : item.height() }); }); } this.styleQueue.push({ $el: $itemsToShow, style: showStyle }); $itemsToShow.removeClass(hiddenClass); this.reload(); return filtered; }; })(jQuery);