You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Vestride_Shuffle/dist/jquery.shuffle.modernizr.mi...

11 lines
13 KiB
JavaScript

/*!
* jQuery Shuffle Plugin
* Uses CSS Transforms to filter down a grid of items.
* Dependencies: jQuery 1.9+, Modernizr 2.6.2.
* Inspired by Isotope http://isotope.metafizzy.co/
* Modified 2014-03-08
* @license MIT license
* @author Glen Cheney <cheney.glen@gmail.com>
* @version 2.0.6
*/
window.Modernizr=function(a,b,c){function d(a){s.cssText=a}function e(a,b){return typeof a===b}function f(a,b){return!!~(""+a).indexOf(b)}function g(a,b){for(var d in a){var e=a[d];if(!f(e,"-")&&s[e]!==c)return"pfx"==b?e:!0}return!1}function h(a,b,d){for(var f in a){var g=b[a[f]];if(g!==c)return d===!1?a[f]:e(g,"function")?g.bind(d||b):g}return!1}function i(a,b,c){var d=a.charAt(0).toUpperCase()+a.slice(1),f=(a+" "+v.join(d+" ")+d).split(" ");return e(b,"string")||e(b,"undefined")?g(f,b):(f=(a+" "+w.join(d+" ")+d).split(" "),h(f,b,c))}var j,k,l,m="2.6.2",n={},o=!0,p=b.documentElement,q="modernizr",r=b.createElement(q),s=r.style,t=({}.toString," -webkit- -moz- -o- -ms- ".split(" ")),u="Webkit Moz O ms",v=u.split(" "),w=u.toLowerCase().split(" "),x={},y=[],z=y.slice,A=function(a,c,d,e){var f,g,h,i,j=b.createElement("div"),k=b.body,l=k||b.createElement("body");if(parseInt(d,10))for(;d--;)h=b.createElement("div"),h.id=e?e[d]:q+(d+1),j.appendChild(h);return f=["&#173;",'<style id="s',q,'">',a,"</style>"].join(""),j.id=q,(k?j:l).innerHTML+=f,l.appendChild(j),k||(l.style.background="",l.style.overflow="hidden",i=p.style.overflow,p.style.overflow="hidden",p.appendChild(l)),g=c(j,a),k?j.parentNode.removeChild(j):(l.parentNode.removeChild(l),p.style.overflow=i),!!g},B={}.hasOwnProperty;l=e(B,"undefined")||e(B.call,"undefined")?function(a,b){return b in a&&e(a.constructor.prototype[b],"undefined")}:function(a,b){return B.call(a,b)},Function.prototype.bind||(Function.prototype.bind=function(a){var b=this;if("function"!=typeof b)throw new TypeError;var c=z.call(arguments,1),d=function(){if(this instanceof d){var e=function(){};e.prototype=b.prototype;var f=new e,g=b.apply(f,c.concat(z.call(arguments)));return Object(g)===g?g:f}return b.apply(a,c.concat(z.call(arguments)))};return d}),x.csstransforms=function(){return!!i("transform")},x.csstransforms3d=function(){var a=!!i("perspective");return a&&"webkitPerspective"in p.style&&A("@media (transform-3d),(-webkit-transform-3d){#modernizr{left:9px;position:absolute;height:3px;}}",function(b){a=9===b.offsetLeft&&3===b.offsetHeight}),a},x.csstransitions=function(){return i("transition")};for(var C in x)l(x,C)&&(k=C.toLowerCase(),n[k]=x[C](),y.push((n[k]?"":"no-")+k));return n.addTest=function(a,b){if("object"==typeof a)for(var d in a)l(a,d)&&n.addTest(d,a[d]);else{if(a=a.toLowerCase(),n[a]!==c)return n;b="function"==typeof b?b():b,"undefined"!=typeof o&&o&&(p.className+=" "+(b?"":"no-")+a),n[a]=b}return n},d(""),r=j=null,n._version=m,n._prefixes=t,n._domPrefixes=w,n._cssomPrefixes=v,n.testProp=function(a){return g([a])},n.testAllProps=i,n.testStyles=A,n.prefixed=function(a,b,c){return b?i(a,b,c):i(a,"pfx")},p.className=p.className.replace(/(^|\s)no-js(\s|$)/,"$1$2")+(o?" js "+y.join(" "):""),n}(this,this.document),function(a,b,c){"use strict";function d(b,c,d){var e,f,g,h=null,i=0;d=d||{};var j=function(){i=d.leading===!1?0:a.now(),h=null,g=b.apply(e,f),e=f=null};return function(){var k=a.now();i||d.leading!==!1||(i=k);var l=c-(k-i);return e=this,f=arguments,0>=l||l>c?(clearTimeout(h),h=null,i=k,g=b.apply(e,f),e=f=null):h||d.trailing===!1||(h=setTimeout(j,l)),g}}function e(a){return a?a.replace(/([A-Z])/g,function(a,b){return"-"+b.toLowerCase()}).replace(/^ms-/,"-ms-"):""}var f=0,g=b.prefixed("transition"),h=b.prefixed("transitionDelay"),i=b.prefixed("transitionDuration"),j={WebkitTransition:"webkitTransitionEnd",transition:"transitionend"}[g],k=b.prefixed("transform"),l=e(k),m=b.csstransforms&&b.csstransitions,n=b.csstransforms3d,o="shuffle",p="all",q="groups",r=function(b,c){c=c||{},a.extend(this,r.options,c,r.settings),this.$el=a(b),this.$window=a(window),this.unique="shuffle_"+f++,this._fire(r.EventType.LOADING),this._init(),setTimeout(a.proxy(this._fire,this,r.EventType.DONE),16)};r.EventType={LOADING:"loading",DONE:"done",SHRINK:"shrink",SHRUNK:"shrunk",FILTER:"filter",FILTERED:"filtered",SORTED:"sorted",LAYOUT:"layout",REMOVED:"removed"},r.prototype={_init:function(){var b,c,d=this,e=a.proxy(d._onResize,d),f=d.throttle?d.throttle(e,d.throttleTime):e,h=d.initialSort?d.initialSort:null;d._setVars(),d._resetCols(),d._addClasses(),d._initItems(),d.$window.on("resize."+o+"."+d.unique,f),b=d.$el.css(["paddingLeft","paddingRight","position"]),c=d._getOuterWidth(d.$el[0]),"static"===b.position&&(d.$el[0].style.position="relative"),d.offset={left:parseInt(b.paddingLeft,10)||0,top:parseInt(b.paddingTop,10)||0},d._setColumns(parseInt(c,10)),d.shuffle(d.group,h),d.supported&&setTimeout(function(){d._setTransitions(),d.$el[0].style[g]="height "+d.speed+"ms "+d.easing},0)},_addClasses:function(){this.$el.addClass(o),this.$items.addClass("shuffle-item filtered")},_setVars:function(){var b=this,c=b.columnWidth;b.$items=b._getItems(),b.isFluid=c&&a.isFunction(b.columnWidth),0===c&&null!==b.sizer&&(c=b.sizer),"string"==typeof c?b.$sizer=b.$el.find(c):c&&c.nodeType&&1===c.nodeType?b.$sizer=a(c):c&&c.jquery&&(b.$sizer=c),b.$sizer&&b.$sizer.length&&(b.useSizer=!0,b.sizer=b.$sizer[0])},_filter:function(b,d){var e=this,f=d!==c,g=f?d:e.$items,h=a();return b=b||e.lastFilter,e._fire(r.EventType.FILTER),a.isFunction(b)?g.each(function(){var c=a(this);b.call(c[0],c,e)&&(h=h.add(c))}):(e.group=b,b===p?h=g:g.each(function(){var c=a(this),d=c.data(q),f=e.delimeter&&!a.isArray(d)?d.split(e.delimeter):d;a.inArray(b,f)>-1&&(h=h.add(c))})),e._toggleFilterClasses(g,h),g=null,d=null,h},_toggleFilterClasses:function(b,c){var d="concealed",e="filtered";b.filter(c).each(function(){var b=a(this);b.hasClass(d)&&b.removeClass(d),b.hasClass(e)||b.addClass(e)}),b.not(c).each(function(){var b=a(this);b.hasClass(d)||b.addClass(d),b.hasClass(e)&&b.removeClass(e)})},_initItems:function(a){return a=a||this.$items,a.css(this.itemCss)},_updateItemCount:function(){return this.visibleItems=this.$items.filter(".filtered").length,this},_setTransition:function(a){var b=this;return a.style[g]=l+" "+b.speed+"ms "+b.easing+", opacity "+b.speed+"ms "+b.easing,a},_setTransitions:function(a){var b=this;return a=a||b.$items,a.each(function(){b._setTransition(this)}),b},_setSequentialDelay:function(b){var c=this;c.supported&&a.each(b,function(b){this.style[h]="0ms,"+(b+1)*c.sequentialFadeDelay+"ms",a(this).one(j,function(){this.style[h]="0ms"})})},_getItems:function(){return this.$el.children(this.itemSelector)},_getPreciseDimension:function(b,c){var d;return d=window.getComputedStyle?window.getComputedStyle(b,null)[c]:a(b).css(c),parseFloat(d)},_getOuterWidth:function(a,b){var c=a.offsetWidth;if(b){var d=Math.round(parseFloat(a.style.marginLeft))||0,e=Math.round(parseFloat(a.style.marginRight))||0;c+=d+e}return c},_getColumnSize:function(a,b){var c;return c=this.isFluid?this.columnWidth(b):this.useSizer?this._getPreciseDimension(this.sizer,"width"):this.columnWidth?this.columnWidth:this.$items.length>0?this._getOuterWidth(this.$items[0],!0):b,0===c&&(c=b),c+a},_getGutterSize:function(b){var c;return c=a.isFunction(this.gutterWidth)?this.gutterWidth(b):this.useSizer?this._getPreciseDimension(this.sizer,"marginLeft"):this.gutterWidth},_setColumns:function(a){var b=a||this._getOuterWidth(this.$el[0]),c=this._getGutterSize(b),d=this._getColumnSize(c,b),e=(b+c)/d;Math.abs(Math.round(e)-e)<.03&&(e=Math.round(e)),this.cols=Math.max(Math.floor(e),1),this.containerWidth=b,this.colWidth=d},_setContainerSize:function(){this.$el.css("height",Math.max.apply(Math,this.colYs))},_fire:function(a,b){this.$el.trigger(a+"."+o,b&&b.length?b:[this])},_layout:function(b,c,d,e){var f=this;c=c||f.filterEnd,f.layoutTransitionEnded=!1,a.each(b,function(b,g){var h=a(g),i=f._getOuterWidth(g,!0),j=i/f.colWidth;Math.abs(Math.round(j)-j)<.03&&(j=Math.round(j));var k=Math.min(Math.ceil(j),f.cols);if(1===k)f._placeItem(h,f.colYs,c,d,e);else{var l,m,n=f.cols+1-k,o=[];for(m=0;n>m;m++)l=f.colYs.slice(m,m+k),o[m]=Math.max.apply(Math,l);f._placeItem(h,o,c,d,e)}}),f._processStyleQueue(),f._setContainerSize()},_resetCols:function(){var a=this.cols;for(this.colYs=[];a--;)this.colYs.push(0)},_reLayout:function(a,b){var c=this;a=a||c.filterEnd,c._resetCols(),c.keepSorted&&c.lastSort?c.sort(c.lastSort,!0,b):c._layout(c.$items.filter(".filtered").get(),c.filterEnd,b)},_placeItem:function(a,b,c,d,e){for(var f=this,g=Math.min.apply(Math,b),h=0,i=0,j=b.length;j>i;i++)if(b[i]>=g-f.buffer&&b[i]<=g+f.buffer){h=i;break}var k=f.colWidth*h,l=g;k=Math.round(k+f.offset.left),l=Math.round(l+f.offset.top),a.data({x:k,y:l});var m=g+a.outerHeight(!0),n=f.cols+1-j;for(i=0;n>i;i++)f.colYs[h+i]=m;var o={from:"layout",$this:a,x:k,y:l,scale:1};d?o.skipTransition=!0:(o.opacity=1,o.callback=c),e&&(o.opacity=0),f.styleQueue.push(o)},_shrink:function(b,c){var d=this,e=b||d.$items.filter(".concealed"),f={},g=c||d.shrinkEnd;e.length&&(d._fire(r.EventType.SHRINK),d.shrinkTransitionEnded=!1,e.each(function(){var b=a(this),c=b.data();f={from:"shrink",$this:b,x:c.x,y:c.y,scale:.001,opacity:0,callback:g},d.styleQueue.push(f)}))},_onResize:function(){if(this.enabled&&!this.destroyed){var a=this._getOuterWidth(this.$el[0]);a!==this.containerWidth&&this.resized()}},transition:function(b){var d,e=this,f=function(){e.layoutTransitionEnded||"layout"!==b.from?e.shrinkTransitionEnded||"shrink"!==b.from||(b.callback.call(e),e.shrinkTransitionEnded=!0):(e._fire(r.EventType.LAYOUT),b.callback.call(e),e.layoutTransitionEnded=!0)};if(b.callback=b.callback||a.noop,e.supported)b.scale===c&&(b.scale=1),d=n?"translate3d("+b.x+"px, "+b.y+"px, 0) scale3d("+b.scale+", "+b.scale+", 1)":"translate("+b.x+"px, "+b.y+"px) scale("+b.scale+", "+b.scale+")",b.x!==c&&b.$this.css(k,d),b.opacity!==c&&b.$this.css("opacity",b.opacity),b.$this.one(j,f);else{var g={left:b.x,top:b.y,opacity:b.opacity};b.$this.stop(!0).animate(g,e.speed,"swing",f)}},_processStyleQueue:function(){var b=this,c=b.styleQueue;a.each(c,function(a,c){c.skipTransition?b._skipTransition(c.$this[0],function(){b.transition(c)}):b.transition(c)}),b.styleQueue.length=0},shrinkEnd:function(){this._fire(r.EventType.SHRUNK)},filterEnd:function(){this._fire(r.EventType.FILTERED)},sortEnd:function(){this._fire(r.EventType.SORTED)},_skipTransition:function(b,c,d){var e,f=b.style[i];b.style[i]="0ms",a.isFunction(c)?c():b.style[c]=d,e=b.offsetWidth,b.style[i]=f},_addItems:function(a,b,d){var e,f,g=this;g.supported||(b=!1),a.addClass("shuffle-item"),g._initItems(a),g._setTransitions(a),g.$items=g._getItems(),a.css("opacity",0),e=g._filter(c,a),f=e.get(),g._updateItemCount(),b?(g._layout(f,null,!0,!0),d&&g._setSequentialDelay(e),g._revealAppended(e)):g._layout(f)},_revealAppended:function(b){var c=this;setTimeout(function(){b.each(function(b,d){c.transition({from:"reveal",$this:a(d),opacity:1})})},c.revealAppendedDelay)},shuffle:function(a,b){var c=this;c.enabled&&(a||(a=p),c._filter(a),c.lastFilter=a,c._updateItemCount(),c._resetCols(),c._shrink(),b&&(c.lastSort=b),c._reLayout())},sort:function(a,b,c){var d=this,e=d.$items.filter(".filtered").sorted(a);b||d._resetCols(),d._layout(e,function(){b&&d.filterEnd(),d.sortEnd()},c),d.lastSort=a},resized:function(a){this.enabled&&(a||this._setColumns(),this._reLayout())},layout:function(){this.update(!0)},update:function(a){this.resized(a)},appended:function(a,b,c){b=b===!1?!1:!0,c=c===!1?!1:!0,this._addItems(a,b,c)},disable:function(){this.enabled=!1},enable:function(a){this.enabled=!0,a!==!1&&this.update()},remove:function(a){if(a.length&&a.jquery){var b=this;return b._shrink(a,function(){var b=this;a.remove(),setTimeout(function(){b.$items=b._getItems(),b.layout(),b._updateItemCount(),b._fire(r.EventType.REMOVED,[a,b]),a=null},0)}),b._processStyleQueue(),b}},destroy:function(){var a=this;a.$window.off("."+a.unique),a.$el.removeClass(o).removeAttr("style").removeData(o),a.$items.removeAttr("style").removeClass("concealed filtered shuffle-item"),a.$window=null,a.$items=null,a.$el=null,a.$sizer=null,a.sizer=null,a.destroyed=!0}},r.options={group:p,speed:250,easing:"ease-out",itemSelector:"",sizer:null,gutterWidth:0,columnWidth:0,delimeter:null,buffer:0,initialSort:null,throttle:d,throttleTime:300,sequentialFadeDelay:150,supported:m},r.settings={$sizer:null,useSizer:!1,itemCss:{position:"absolute",top:0,left:0},offset:{top:0,left:0},revealAppendedDelay:300,keepSorted:!0,enabled:!0,destroyed:!1,styleQueue:[]},a.fn.shuffle=function(b){var c=Array.prototype.slice.call(arguments,1);return this.each(function(){var d=a(this),e=d.data(o);e||(e=new r(d,b),d.data(o,e)),"string"==typeof b&&e[b]&&e[b].apply(e,c)})},a.fn.sorted=function(b){var d=a.extend({},a.fn.sorted.defaults,b),e=this.get(),f=!1;return e.length?d.randomize?a.fn.sorted.randomize(e):(d.by!==a.noop&&null!==d.by&&d.by!==c&&e.sort(function(b,e){if(f)return 0;var g=d.by(a(b)),h=d.by(a(e));return g===c&&h===c?(f=!0,0):"sortFirst"===g||"sortLast"===h?-1:"sortLast"===g||"sortFirst"===h?1:h>g?-1:g>h?1:0}),f?this.get():(d.reverse&&e.reverse(),e)):[]},a.fn.sorted.defaults={reverse:!1,by:null,randomize:!1},a.fn.sorted.randomize=function(a){var b,c,d=a.length;if(!d)return a;for(;--d;)c=Math.floor(Math.random()*(d+1)),b=a[c],a[c]=a[d],a[d]=b;return a}}(jQuery,Modernizr);