|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499 |
- /*!
- * Masonry PACKAGED v4.2.0
- * Cascading grid layout library
- * http://masonry.desandro.com
- * MIT License
- * by David DeSandro
- */
-
- /**
- * Bridget makes jQuery widgets
- * v2.0.1
- * MIT license
- */
-
- /* jshint browser: true, strict: true, undef: true, unused: true */
-
- ( function( window, factory ) {
- // universal module definition
- /*jshint strict: false */ /* globals define, module, require */
- if ( typeof define == 'function' && define.amd ) {
- // AMD
- define( 'jquery-bridget/jquery-bridget',[ 'jquery' ], function( jQuery ) {
- return factory( window, jQuery );
- });
- } else if ( typeof module == 'object' && module.exports ) {
- // CommonJS
- module.exports = factory(
- window,
- require('jquery')
- );
- } else {
- // browser global
- window.jQueryBridget = factory(
- window,
- window.jQuery
- );
- }
-
- }( window, function factory( window, jQuery ) {
- 'use strict';
-
- // ----- utils ----- //
-
- var arraySlice = Array.prototype.slice;
-
- // helper function for logging errors
- // $.error breaks jQuery chaining
- var console = window.console;
- var logError = typeof console == 'undefined' ? function() {} :
- function( message ) {
- console.error( message );
- };
-
- // ----- jQueryBridget ----- //
-
- function jQueryBridget( namespace, PluginClass, $ ) {
- $ = $ || jQuery || window.jQuery;
- if ( !$ ) {
- return;
- }
-
- // add option method -> $().plugin('option', {...})
- if ( !PluginClass.prototype.option ) {
- // option setter
- PluginClass.prototype.option = function( opts ) {
- // bail out if not an object
- if ( !$.isPlainObject( opts ) ){
- return;
- }
- this.options = $.extend( true, this.options, opts );
- };
- }
-
- // make jQuery plugin
- $.fn[ namespace ] = function( arg0 /*, arg1 */ ) {
- if ( typeof arg0 == 'string' ) {
- // method call $().plugin( 'methodName', { options } )
- // shift arguments by 1
- var args = arraySlice.call( arguments, 1 );
- return methodCall( this, arg0, args );
- }
- // just $().plugin({ options })
- plainCall( this, arg0 );
- return this;
- };
-
- // $().plugin('methodName')
- function methodCall( $elems, methodName, args ) {
- var returnValue;
- var pluginMethodStr = '$().' + namespace + '("' + methodName + '")';
-
- $elems.each( function( i, elem ) {
- // get instance
- var instance = $.data( elem, namespace );
- if ( !instance ) {
- logError( namespace + ' not initialized. Cannot call methods, i.e. ' +
- pluginMethodStr );
- return;
- }
-
- var method = instance[ methodName ];
- if ( !method || methodName.charAt(0) == '_' ) {
- logError( pluginMethodStr + ' is not a valid method' );
- return;
- }
-
- // apply method, get return value
- var value = method.apply( instance, args );
- // set return value if value is returned, use only first value
- returnValue = returnValue === undefined ? value : returnValue;
- });
-
- return returnValue !== undefined ? returnValue : $elems;
- }
-
- function plainCall( $elems, options ) {
- $elems.each( function( i, elem ) {
- var instance = $.data( elem, namespace );
- if ( instance ) {
- // set options & init
- instance.option( options );
- instance._init();
- } else {
- // initialize new instance
- instance = new PluginClass( elem, options );
- $.data( elem, namespace, instance );
- }
- });
- }
-
- updateJQuery( $ );
-
- }
-
- // ----- updateJQuery ----- //
-
- // set $.bridget for v1 backwards compatibility
- function updateJQuery( $ ) {
- if ( !$ || ( $ && $.bridget ) ) {
- return;
- }
- $.bridget = jQueryBridget;
- }
-
- updateJQuery( jQuery || window.jQuery );
-
- // ----- ----- //
-
- return jQueryBridget;
-
- }));
-
- /**
- * EvEmitter v1.0.3
- * Lil' event emitter
- * MIT License
- */
-
- /* jshint unused: true, undef: true, strict: true */
-
- ( function( global, factory ) {
- // universal module definition
- /* jshint strict: false */ /* globals define, module, window */
- if ( typeof define == 'function' && define.amd ) {
- // AMD - RequireJS
- define( 'ev-emitter/ev-emitter',factory );
- } else if ( typeof module == 'object' && module.exports ) {
- // CommonJS - Browserify, Webpack
- module.exports = factory();
- } else {
- // Browser globals
- global.EvEmitter = factory();
- }
-
- }( typeof window != 'undefined' ? window : this, function() {
-
-
-
- function EvEmitter() {}
-
- var proto = EvEmitter.prototype;
-
- proto.on = function( eventName, listener ) {
- if ( !eventName || !listener ) {
- return;
- }
- // set events hash
- var events = this._events = this._events || {};
- // set listeners array
- var listeners = events[ eventName ] = events[ eventName ] || [];
- // only add once
- if ( listeners.indexOf( listener ) == -1 ) {
- listeners.push( listener );
- }
-
- return this;
- };
-
- proto.once = function( eventName, listener ) {
- if ( !eventName || !listener ) {
- return;
- }
- // add event
- this.on( eventName, listener );
- // set once flag
- // set onceEvents hash
- var onceEvents = this._onceEvents = this._onceEvents || {};
- // set onceListeners object
- var onceListeners = onceEvents[ eventName ] = onceEvents[ eventName ] || {};
- // set flag
- onceListeners[ listener ] = true;
-
- return this;
- };
-
- proto.off = function( eventName, listener ) {
- var listeners = this._events && this._events[ eventName ];
- if ( !listeners || !listeners.length ) {
- return;
- }
- var index = listeners.indexOf( listener );
- if ( index != -1 ) {
- listeners.splice( index, 1 );
- }
-
- return this;
- };
-
- proto.emitEvent = function( eventName, args ) {
- var listeners = this._events && this._events[ eventName ];
- if ( !listeners || !listeners.length ) {
- return;
- }
- var i = 0;
- var listener = listeners[i];
- args = args || [];
- // once stuff
- var onceListeners = this._onceEvents && this._onceEvents[ eventName ];
-
- while ( listener ) {
- var isOnce = onceListeners && onceListeners[ listener ];
- if ( isOnce ) {
- // remove listener
- // remove before trigger to prevent recursion
- this.off( eventName, listener );
- // unset once flag
- delete onceListeners[ listener ];
- }
- // trigger listener
- listener.apply( this, args );
- // get next listener
- i += isOnce ? 0 : 1;
- listener = listeners[i];
- }
-
- return this;
- };
-
- return EvEmitter;
-
- }));
-
- /*!
- * getSize v2.0.2
- * measure size of elements
- * MIT license
- */
-
- /*jshint browser: true, strict: true, undef: true, unused: true */
- /*global define: false, module: false, console: false */
-
- ( function( window, factory ) {
- 'use strict';
-
- if ( typeof define == 'function' && define.amd ) {
- // AMD
- define( 'get-size/get-size',[],function() {
- return factory();
- });
- } else if ( typeof module == 'object' && module.exports ) {
- // CommonJS
- module.exports = factory();
- } else {
- // browser global
- window.getSize = factory();
- }
-
- })( window, function factory() {
- 'use strict';
-
- // -------------------------- helpers -------------------------- //
-
- // get a number from a string, not a percentage
- function getStyleSize( value ) {
- var num = parseFloat( value );
- // not a percent like '100%', and a number
- var isValid = value.indexOf('%') == -1 && !isNaN( num );
- return isValid && num;
- }
-
- function noop() {}
-
- var logError = typeof console == 'undefined' ? noop :
- function( message ) {
- console.error( message );
- };
-
- // -------------------------- measurements -------------------------- //
-
- var measurements = [
- 'paddingLeft',
- 'paddingRight',
- 'paddingTop',
- 'paddingBottom',
- 'marginLeft',
- 'marginRight',
- 'marginTop',
- 'marginBottom',
- 'borderLeftWidth',
- 'borderRightWidth',
- 'borderTopWidth',
- 'borderBottomWidth'
- ];
-
- var measurementsLength = measurements.length;
-
- function getZeroSize() {
- var size = {
- width: 0,
- height: 0,
- innerWidth: 0,
- innerHeight: 0,
- outerWidth: 0,
- outerHeight: 0
- };
- for ( var i=0; i < measurementsLength; i++ ) {
- var measurement = measurements[i];
- size[ measurement ] = 0;
- }
- return size;
- }
-
- // -------------------------- getStyle -------------------------- //
-
- /**
- * getStyle, get style of element, check for Firefox bug
- * https://bugzilla.mozilla.org/show_bug.cgi?id=548397
- */
- function getStyle( elem ) {
- var style = getComputedStyle( elem );
- if ( !style ) {
- logError( 'Style returned ' + style +
- '. Are you running this code in a hidden iframe on Firefox? ' +
- 'See http://bit.ly/getsizebug1' );
- }
- return style;
- }
-
- // -------------------------- setup -------------------------- //
-
- var isSetup = false;
-
- var isBoxSizeOuter;
-
- /**
- * setup
- * check isBoxSizerOuter
- * do on first getSize() rather than on page load for Firefox bug
- */
- function setup() {
- // setup once
- if ( isSetup ) {
- return;
- }
- isSetup = true;
-
- // -------------------------- box sizing -------------------------- //
-
- /**
- * WebKit measures the outer-width on style.width on border-box elems
- * IE & Firefox<29 measures the inner-width
- */
- var div = document.createElement('div');
- div.style.width = '200px';
- div.style.padding = '1px 2px 3px 4px';
- div.style.borderStyle = 'solid';
- div.style.borderWidth = '1px 2px 3px 4px';
- div.style.boxSizing = 'border-box';
-
- var body = document.body || document.documentElement;
- body.appendChild( div );
- var style = getStyle( div );
-
- getSize.isBoxSizeOuter = isBoxSizeOuter = getStyleSize( style.width ) == 200;
- body.removeChild( div );
-
- }
-
- // -------------------------- getSize -------------------------- //
-
- function getSize( elem ) {
- setup();
-
- // use querySeletor if elem is string
- if ( typeof elem == 'string' ) {
- elem = document.querySelector( elem );
- }
-
- // do not proceed on non-objects
- if ( !elem || typeof elem != 'object' || !elem.nodeType ) {
- return;
- }
-
- var style = getStyle( elem );
-
- // if hidden, everything is 0
- if ( style.display == 'none' ) {
- return getZeroSize();
- }
-
- var size = {};
- size.width = elem.offsetWidth;
- size.height = elem.offsetHeight;
-
- var isBorderBox = size.isBorderBox = style.boxSizing == 'border-box';
-
- // get all measurements
- for ( var i=0; i < measurementsLength; i++ ) {
- var measurement = measurements[i];
- var value = style[ measurement ];
- var num = parseFloat( value );
- // any 'auto', 'medium' value will be 0
- size[ measurement ] = !isNaN( num ) ? num : 0;
- }
-
- var paddingWidth = size.paddingLeft + size.paddingRight;
- var paddingHeight = size.paddingTop + size.paddingBottom;
- var marginWidth = size.marginLeft + size.marginRight;
- var marginHeight = size.marginTop + size.marginBottom;
- var borderWidth = size.borderLeftWidth + size.borderRightWidth;
- var borderHeight = size.borderTopWidth + size.borderBottomWidth;
-
- var isBorderBoxSizeOuter = isBorderBox && isBoxSizeOuter;
-
- // overwrite width and height if we can get it from style
- var styleWidth = getStyleSize( style.width );
- if ( styleWidth !== false ) {
- size.width = styleWidth +
- // add padding and border unless it's already including it
- ( isBorderBoxSizeOuter ? 0 : paddingWidth + borderWidth );
- }
-
- var styleHeight = getStyleSize( style.height );
- if ( styleHeight !== false ) {
- size.height = styleHeight +
- // add padding and border unless it's already including it
- ( isBorderBoxSizeOuter ? 0 : paddingHeight + borderHeight );
- }
-
- size.innerWidth = size.width - ( paddingWidth + borderWidth );
- size.innerHeight = size.height - ( paddingHeight + borderHeight );
-
- size.outerWidth = size.width + marginWidth;
- size.outerHeight = size.height + marginHeight;
-
- return size;
- }
-
- return getSize;
-
- });
-
- /**
- * matchesSelector v2.0.2
- * matchesSelector( element, '.selector' )
- * MIT license
- */
-
- /*jshint browser: true, strict: true, undef: true, unused: true */
-
- ( function( window, factory ) {
- /*global define: false, module: false */
- 'use strict';
- // universal module definition
- if ( typeof define == 'function' && define.amd ) {
- // AMD
- define( 'desandro-matches-selector/matches-selector',factory );
- } else if ( typeof module == 'object' && module.exports ) {
- // CommonJS
- module.exports = factory();
- } else {
- // browser global
- window.matchesSelector = factory();
- }
-
- }( window, function factory() {
- 'use strict';
-
- var matchesMethod = ( function() {
- var ElemProto = window.Element.prototype;
- // check for the standard method name first
- if ( ElemProto.matches ) {
- return 'matches';
- }
- // check un-prefixed
- if ( ElemProto.matchesSelector ) {
- return 'matchesSelector';
- }
- // check vendor prefixes
- var prefixes = [ 'webkit', 'moz', 'ms', 'o' ];
-
- for ( var i=0; i < prefixes.length; i++ ) {
- var prefix = prefixes[i];
- var method = prefix + 'MatchesSelector';
- if ( ElemProto[ method ] ) {
- return method;
- }
- }
- })();
-
- return function matchesSelector( elem, selector ) {
- return elem[ matchesMethod ]( selector );
- };
-
- }));
-
- /**
- * Fizzy UI utils v2.0.4
- * MIT license
- */
-
- /*jshint browser: true, undef: true, unused: true, strict: true */
-
- ( function( window, factory ) {
- // universal module definition
- /*jshint strict: false */ /*globals define, module, require */
-
- if ( typeof define == 'function' && define.amd ) {
- // AMD
- define( 'fizzy-ui-utils/utils',[
- 'desandro-matches-selector/matches-selector'
- ], function( matchesSelector ) {
- return factory( window, matchesSelector );
- });
- } else if ( typeof module == 'object' && module.exports ) {
- // CommonJS
- module.exports = factory(
- window,
- require('desandro-matches-selector')
- );
- } else {
- // browser global
- window.fizzyUIUtils = factory(
- window,
- window.matchesSelector
- );
- }
-
- }( window, function factory( window, matchesSelector ) {
-
-
-
- var utils = {};
-
- // ----- extend ----- //
-
- // extends objects
- utils.extend = function( a, b ) {
- for ( var prop in b ) {
- a[ prop ] = b[ prop ];
- }
- return a;
- };
-
- // ----- modulo ----- //
-
- utils.modulo = function( num, div ) {
- return ( ( num % div ) + div ) % div;
- };
-
- // ----- makeArray ----- //
-
- // turn element or nodeList into an array
- utils.makeArray = function( obj ) {
- var ary = [];
- if ( Array.isArray( obj ) ) {
- // use object if already an array
- ary = obj;
- } else if ( obj && typeof obj == 'object' &&
- typeof obj.length == 'number' ) {
- // convert nodeList to array
- for ( var i=0; i < obj.length; i++ ) {
- ary.push( obj[i] );
- }
- } else {
- // array of single index
- ary.push( obj );
- }
- return ary;
- };
-
- // ----- removeFrom ----- //
-
- utils.removeFrom = function( ary, obj ) {
- var index = ary.indexOf( obj );
- if ( index != -1 ) {
- ary.splice( index, 1 );
- }
- };
-
- // ----- getParent ----- //
-
- utils.getParent = function( elem, selector ) {
- while ( elem != document.body ) {
- elem = elem.parentNode;
- if ( matchesSelector( elem, selector ) ) {
- return elem;
- }
- }
- };
-
- // ----- getQueryElement ----- //
-
- // use element as selector string
- utils.getQueryElement = function( elem ) {
- if ( typeof elem == 'string' ) {
- return document.querySelector( elem );
- }
- return elem;
- };
-
- // ----- handleEvent ----- //
-
- // enable .ontype to trigger from .addEventListener( elem, 'type' )
- utils.handleEvent = function( event ) {
- var method = 'on' + event.type;
- if ( this[ method ] ) {
- this[ method ]( event );
- }
- };
-
- // ----- filterFindElements ----- //
-
- utils.filterFindElements = function( elems, selector ) {
- // make array of elems
- elems = utils.makeArray( elems );
- var ffElems = [];
-
- elems.forEach( function( elem ) {
- // check that elem is an actual element
- if ( !( elem instanceof HTMLElement ) ) {
- return;
- }
- // add elem if no selector
- if ( !selector ) {
- ffElems.push( elem );
- return;
- }
- // filter & find items if we have a selector
- // filter
- if ( matchesSelector( elem, selector ) ) {
- ffElems.push( elem );
- }
- // find children
- var childElems = elem.querySelectorAll( selector );
- // concat childElems to filterFound array
- for ( var i=0; i < childElems.length; i++ ) {
- ffElems.push( childElems[i] );
- }
- });
-
- return ffElems;
- };
-
- // ----- debounceMethod ----- //
-
- utils.debounceMethod = function( _class, methodName, threshold ) {
- // original method
- var method = _class.prototype[ methodName ];
- var timeoutName = methodName + 'Timeout';
-
- _class.prototype[ methodName ] = function() {
- var timeout = this[ timeoutName ];
- if ( timeout ) {
- clearTimeout( timeout );
- }
- var args = arguments;
-
- var _this = this;
- this[ timeoutName ] = setTimeout( function() {
- method.apply( _this, args );
- delete _this[ timeoutName ];
- }, threshold || 100 );
- };
- };
-
- // ----- docReady ----- //
-
- utils.docReady = function( callback ) {
- var readyState = document.readyState;
- if ( readyState == 'complete' || readyState == 'interactive' ) {
- // do async to allow for other scripts to run. metafizzy/flickity#441
- setTimeout( callback );
- } else {
- document.addEventListener( 'DOMContentLoaded', callback );
- }
- };
-
- // ----- htmlInit ----- //
-
- // http://jamesroberts.name/blog/2010/02/22/string-functions-for-javascript-trim-to-camel-case-to-dashed-and-to-underscore/
- utils.toDashed = function( str ) {
- return str.replace( /(.)([A-Z])/g, function( match, $1, $2 ) {
- return $1 + '-' + $2;
- }).toLowerCase();
- };
-
- var console = window.console;
- /**
- * allow user to initialize classes via [data-namespace] or .js-namespace class
- * htmlInit( Widget, 'widgetName' )
- * options are parsed from data-namespace-options
- */
- utils.htmlInit = function( WidgetClass, namespace ) {
- utils.docReady( function() {
- var dashedNamespace = utils.toDashed( namespace );
- var dataAttr = 'data-' + dashedNamespace;
- var dataAttrElems = document.querySelectorAll( '[' + dataAttr + ']' );
- var jsDashElems = document.querySelectorAll( '.js-' + dashedNamespace );
- var elems = utils.makeArray( dataAttrElems )
- .concat( utils.makeArray( jsDashElems ) );
- var dataOptionsAttr = dataAttr + '-options';
- var jQuery = window.jQuery;
-
- elems.forEach( function( elem ) {
- var attr = elem.getAttribute( dataAttr ) ||
- elem.getAttribute( dataOptionsAttr );
- var options;
- try {
- options = attr && JSON.parse( attr );
- } catch ( error ) {
- // log error, do not initialize
- if ( console ) {
- console.error( 'Error parsing ' + dataAttr + ' on ' + elem.className +
- ': ' + error );
- }
- return;
- }
- // initialize
- var instance = new WidgetClass( elem, options );
- // make available via $().data('namespace')
- if ( jQuery ) {
- jQuery.data( elem, namespace, instance );
- }
- });
-
- });
- };
-
- // ----- ----- //
-
- return utils;
-
- }));
-
- /**
- * Outlayer Item
- */
-
- ( function( window, factory ) {
- // universal module definition
- /* jshint strict: false */ /* globals define, module, require */
- if ( typeof define == 'function' && define.amd ) {
- // AMD - RequireJS
- define( 'outlayer/item',[
- 'ev-emitter/ev-emitter',
- 'get-size/get-size'
- ],
- factory
- );
- } else if ( typeof module == 'object' && module.exports ) {
- // CommonJS - Browserify, Webpack
- module.exports = factory(
- require('ev-emitter'),
- require('get-size')
- );
- } else {
- // browser global
- window.Outlayer = {};
- window.Outlayer.Item = factory(
- window.EvEmitter,
- window.getSize
- );
- }
-
- }( window, function factory( EvEmitter, getSize ) {
- 'use strict';
-
- // ----- helpers ----- //
-
- function isEmptyObj( obj ) {
- for ( var prop in obj ) {
- return false;
- }
- prop = null;
- return true;
- }
-
- // -------------------------- CSS3 support -------------------------- //
-
-
- var docElemStyle = document.documentElement.style;
-
- var transitionProperty = typeof docElemStyle.transition == 'string' ?
- 'transition' : 'WebkitTransition';
- var transformProperty = typeof docElemStyle.transform == 'string' ?
- 'transform' : 'WebkitTransform';
-
- var transitionEndEvent = {
- WebkitTransition: 'webkitTransitionEnd',
- transition: 'transitionend'
- }[ transitionProperty ];
-
- // cache all vendor properties that could have vendor prefix
- var vendorProperties = {
- transform: transformProperty,
- transition: transitionProperty,
- transitionDuration: transitionProperty + 'Duration',
- transitionProperty: transitionProperty + 'Property',
- transitionDelay: transitionProperty + 'Delay'
- };
-
- // -------------------------- Item -------------------------- //
-
- function Item( element, layout ) {
- if ( !element ) {
- return;
- }
-
- this.element = element;
- // parent layout class, i.e. Masonry, Isotope, or Packery
- this.layout = layout;
- this.position = {
- x: 0,
- y: 0
- };
-
- this._create();
- }
-
- // inherit EvEmitter
- var proto = Item.prototype = Object.create( EvEmitter.prototype );
- proto.constructor = Item;
-
- proto._create = function() {
- // transition objects
- this._transn = {
- ingProperties: {},
- clean: {},
- onEnd: {}
- };
-
- this.css({
- position: 'absolute'
- });
- };
-
- // trigger specified handler for event type
- proto.handleEvent = function( event ) {
- var method = 'on' + event.type;
- if ( this[ method ] ) {
- this[ method ]( event );
- }
- };
-
- proto.getSize = function() {
- this.size = getSize( this.element );
- };
-
- /**
- * apply CSS styles to element
- * @param {Object} style
- */
- proto.css = function( style ) {
- var elemStyle = this.element.style;
-
- for ( var prop in style ) {
- // use vendor property if available
- var supportedProp = vendorProperties[ prop ] || prop;
- elemStyle[ supportedProp ] = style[ prop ];
- }
- };
-
- // measure position, and sets it
- proto.getPosition = function() {
- var style = getComputedStyle( this.element );
- var isOriginLeft = this.layout._getOption('originLeft');
- var isOriginTop = this.layout._getOption('originTop');
- var xValue = style[ isOriginLeft ? 'left' : 'right' ];
- var yValue = style[ isOriginTop ? 'top' : 'bottom' ];
- // convert percent to pixels
- var layoutSize = this.layout.size;
- var x = xValue.indexOf('%') != -1 ?
- ( parseFloat( xValue ) / 100 ) * layoutSize.width : parseInt( xValue, 10 );
- var y = yValue.indexOf('%') != -1 ?
- ( parseFloat( yValue ) / 100 ) * layoutSize.height : parseInt( yValue, 10 );
-
- // clean up 'auto' or other non-integer values
- x = isNaN( x ) ? 0 : x;
- y = isNaN( y ) ? 0 : y;
- // remove padding from measurement
- x -= isOriginLeft ? layoutSize.paddingLeft : layoutSize.paddingRight;
- y -= isOriginTop ? layoutSize.paddingTop : layoutSize.paddingBottom;
-
- this.position.x = x;
- this.position.y = y;
- };
-
- // set settled position, apply padding
- proto.layoutPosition = function() {
- var layoutSize = this.layout.size;
- var style = {};
- var isOriginLeft = this.layout._getOption('originLeft');
- var isOriginTop = this.layout._getOption('originTop');
-
- // x
- var xPadding = isOriginLeft ? 'paddingLeft' : 'paddingRight';
- var xProperty = isOriginLeft ? 'left' : 'right';
- var xResetProperty = isOriginLeft ? 'right' : 'left';
-
- var x = this.position.x + layoutSize[ xPadding ];
- // set in percentage or pixels
- style[ xProperty ] = this.getXValue( x );
- // reset other property
- style[ xResetProperty ] = '';
-
- // y
- var yPadding = isOriginTop ? 'paddingTop' : 'paddingBottom';
- var yProperty = isOriginTop ? 'top' : 'bottom';
- var yResetProperty = isOriginTop ? 'bottom' : 'top';
-
- var y = this.position.y + layoutSize[ yPadding ];
- // set in percentage or pixels
- style[ yProperty ] = this.getYValue( y );
- // reset other property
- style[ yResetProperty ] = '';
-
- this.css( style );
- this.emitEvent( 'layout', [ this ] );
- };
-
- proto.getXValue = function( x ) {
- var isHorizontal = this.layout._getOption('horizontal');
- return this.layout.options.percentPosition && !isHorizontal ?
- ( ( x / this.layout.size.width ) * 100 ) + '%' : x + 'px';
- };
-
- proto.getYValue = function( y ) {
- var isHorizontal = this.layout._getOption('horizontal');
- return this.layout.options.percentPosition && isHorizontal ?
- ( ( y / this.layout.size.height ) * 100 ) + '%' : y + 'px';
- };
-
- proto._transitionTo = function( x, y ) {
- this.getPosition();
- // get current x & y from top/left
- var curX = this.position.x;
- var curY = this.position.y;
-
- var compareX = parseInt( x, 10 );
- var compareY = parseInt( y, 10 );
- var didNotMove = compareX === this.position.x && compareY === this.position.y;
-
- // save end position
- this.setPosition( x, y );
-
- // if did not move and not transitioning, just go to layout
- if ( didNotMove && !this.isTransitioning ) {
- this.layoutPosition();
- return;
- }
-
- var transX = x - curX;
- var transY = y - curY;
- var transitionStyle = {};
- transitionStyle.transform = this.getTranslate( transX, transY );
-
- this.transition({
- to: transitionStyle,
- onTransitionEnd: {
- transform: this.layoutPosition
- },
- isCleaning: true
- });
- };
-
- proto.getTranslate = function( x, y ) {
- // flip cooridinates if origin on right or bottom
- var isOriginLeft = this.layout._getOption('originLeft');
- var isOriginTop = this.layout._getOption('originTop');
- x = isOriginLeft ? x : -x;
- y = isOriginTop ? y : -y;
- return 'translate3d(' + x + 'px, ' + y + 'px, 0)';
- };
-
- // non transition + transform support
- proto.goTo = function( x, y ) {
- this.setPosition( x, y );
- this.layoutPosition();
- };
-
- proto.moveTo = proto._transitionTo;
-
- proto.setPosition = function( x, y ) {
- this.position.x = parseInt( x, 10 );
- this.position.y = parseInt( y, 10 );
- };
-
- // ----- transition ----- //
-
- /**
- * @param {Object} style - CSS
- * @param {Function} onTransitionEnd
- */
-
- // non transition, just trigger callback
- proto._nonTransition = function( args ) {
- this.css( args.to );
- if ( args.isCleaning ) {
- this._removeStyles( args.to );
- }
- for ( var prop in args.onTransitionEnd ) {
- args.onTransitionEnd[ prop ].call( this );
- }
- };
-
- /**
- * proper transition
- * @param {Object} args - arguments
- * @param {Object} to - style to transition to
- * @param {Object} from - style to start transition from
- * @param {Boolean} isCleaning - removes transition styles after transition
- * @param {Function} onTransitionEnd - callback
- */
- proto.transition = function( args ) {
- // redirect to nonTransition if no transition duration
- if ( !parseFloat( this.layout.options.transitionDuration ) ) {
- this._nonTransition( args );
- return;
- }
-
- var _transition = this._transn;
- // keep track of onTransitionEnd callback by css property
- for ( var prop in args.onTransitionEnd ) {
- _transition.onEnd[ prop ] = args.onTransitionEnd[ prop ];
- }
- // keep track of properties that are transitioning
- for ( prop in args.to ) {
- _transition.ingProperties[ prop ] = true;
- // keep track of properties to clean up when transition is done
- if ( args.isCleaning ) {
- _transition.clean[ prop ] = true;
- }
- }
-
- // set from styles
- if ( args.from ) {
- this.css( args.from );
- // force redraw. http://blog.alexmaccaw.com/css-transitions
- var h = this.element.offsetHeight;
- // hack for JSHint to hush about unused var
- h = null;
- }
- // enable transition
- this.enableTransition( args.to );
- // set styles that are transitioning
- this.css( args.to );
-
- this.isTransitioning = true;
-
- };
-
- // dash before all cap letters, including first for
- // WebkitTransform => -webkit-transform
- function toDashedAll( str ) {
- return str.replace( /([A-Z])/g, function( $1 ) {
- return '-' + $1.toLowerCase();
- });
- }
-
- var transitionProps = 'opacity,' + toDashedAll( transformProperty );
-
- proto.enableTransition = function(/* style */) {
- // HACK changing transitionProperty during a transition
- // will cause transition to jump
- if ( this.isTransitioning ) {
- return;
- }
-
- // make `transition: foo, bar, baz` from style object
- // HACK un-comment this when enableTransition can work
- // while a transition is happening
- // var transitionValues = [];
- // for ( var prop in style ) {
- // // dash-ify camelCased properties like WebkitTransition
- // prop = vendorProperties[ prop ] || prop;
- // transitionValues.push( toDashedAll( prop ) );
- // }
- // munge number to millisecond, to match stagger
- var duration = this.layout.options.transitionDuration;
- duration = typeof duration == 'number' ? duration + 'ms' : duration;
- // enable transition styles
- this.css({
- transitionProperty: transitionProps,
- transitionDuration: duration,
- transitionDelay: this.staggerDelay || 0
- });
- // listen for transition end event
- this.element.addEventListener( transitionEndEvent, this, false );
- };
-
- // ----- events ----- //
-
- proto.onwebkitTransitionEnd = function( event ) {
- this.ontransitionend( event );
- };
-
- proto.onotransitionend = function( event ) {
- this.ontransitionend( event );
- };
-
- // properties that I munge to make my life easier
- var dashedVendorProperties = {
- '-webkit-transform': 'transform'
- };
-
- proto.ontransitionend = function( event ) {
- // disregard bubbled events from children
- if ( event.target !== this.element ) {
- return;
- }
- var _transition = this._transn;
- // get property name of transitioned property, convert to prefix-free
- var propertyName = dashedVendorProperties[ event.propertyName ] || event.propertyName;
-
- // remove property that has completed transitioning
- delete _transition.ingProperties[ propertyName ];
- // check if any properties are still transitioning
- if ( isEmptyObj( _transition.ingProperties ) ) {
- // all properties have completed transitioning
- this.disableTransition();
- }
- // clean style
- if ( propertyName in _transition.clean ) {
- // clean up style
- this.element.style[ event.propertyName ] = '';
- delete _transition.clean[ propertyName ];
- }
- // trigger onTransitionEnd callback
- if ( propertyName in _transition.onEnd ) {
- var onTransitionEnd = _transition.onEnd[ propertyName ];
- onTransitionEnd.call( this );
- delete _transition.onEnd[ propertyName ];
- }
-
- this.emitEvent( 'transitionEnd', [ this ] );
- };
-
- proto.disableTransition = function() {
- this.removeTransitionStyles();
- this.element.removeEventListener( transitionEndEvent, this, false );
- this.isTransitioning = false;
- };
-
- /**
- * removes style property from element
- * @param {Object} style
- **/
- proto._removeStyles = function( style ) {
- // clean up transition styles
- var cleanStyle = {};
- for ( var prop in style ) {
- cleanStyle[ prop ] = '';
- }
- this.css( cleanStyle );
- };
-
- var cleanTransitionStyle = {
- transitionProperty: '',
- transitionDuration: '',
- transitionDelay: ''
- };
-
- proto.removeTransitionStyles = function() {
- // remove transition
- this.css( cleanTransitionStyle );
- };
-
- // ----- stagger ----- //
-
- proto.stagger = function( delay ) {
- delay = isNaN( delay ) ? 0 : delay;
- this.staggerDelay = delay + 'ms';
- };
-
- // ----- show/hide/remove ----- //
-
- // remove element from DOM
- proto.removeElem = function() {
- this.element.parentNode.removeChild( this.element );
- // remove display: none
- this.css({ display: '' });
- this.emitEvent( 'remove', [ this ] );
- };
-
- proto.remove = function() {
- // just remove element if no transition support or no transition
- if ( !transitionProperty || !parseFloat( this.layout.options.transitionDuration ) ) {
- this.removeElem();
- return;
- }
-
- // start transition
- this.once( 'transitionEnd', function() {
- this.removeElem();
- });
- this.hide();
- };
-
- proto.reveal = function() {
- delete this.isHidden;
- // remove display: none
- this.css({ display: '' });
-
- var options = this.layout.options;
-
- var onTransitionEnd = {};
- var transitionEndProperty = this.getHideRevealTransitionEndProperty('visibleStyle');
- onTransitionEnd[ transitionEndProperty ] = this.onRevealTransitionEnd;
-
- this.transition({
- from: options.hiddenStyle,
- to: options.visibleStyle,
- isCleaning: true,
- onTransitionEnd: onTransitionEnd
- });
- };
-
- proto.onRevealTransitionEnd = function() {
- // check if still visible
- // during transition, item may have been hidden
- if ( !this.isHidden ) {
- this.emitEvent('reveal');
- }
- };
-
- /**
- * get style property use for hide/reveal transition end
- * @param {String} styleProperty - hiddenStyle/visibleStyle
- * @returns {String}
- */
- proto.getHideRevealTransitionEndProperty = function( styleProperty ) {
- var optionStyle = this.layout.options[ styleProperty ];
- // use opacity
- if ( optionStyle.opacity ) {
- return 'opacity';
- }
- // get first property
- for ( var prop in optionStyle ) {
- return prop;
- }
- };
-
- proto.hide = function() {
- // set flag
- this.isHidden = true;
- // remove display: none
- this.css({ display: '' });
-
- var options = this.layout.options;
-
- var onTransitionEnd = {};
- var transitionEndProperty = this.getHideRevealTransitionEndProperty('hiddenStyle');
- onTransitionEnd[ transitionEndProperty ] = this.onHideTransitionEnd;
-
- this.transition({
- from: options.visibleStyle,
- to: options.hiddenStyle,
- // keep hidden stuff hidden
- isCleaning: true,
- onTransitionEnd: onTransitionEnd
- });
- };
-
- proto.onHideTransitionEnd = function() {
- // check if still hidden
- // during transition, item may have been un-hidden
- if ( this.isHidden ) {
- this.css({ display: 'none' });
- this.emitEvent('hide');
- }
- };
-
- proto.destroy = function() {
- this.css({
- position: '',
- left: '',
- right: '',
- top: '',
- bottom: '',
- transition: '',
- transform: ''
- });
- };
-
- return Item;
-
- }));
-
- /*!
- * Outlayer v2.1.0
- * the brains and guts of a layout library
- * MIT license
- */
-
- ( function( window, factory ) {
- 'use strict';
- // universal module definition
- /* jshint strict: false */ /* globals define, module, require */
- if ( typeof define == 'function' && define.amd ) {
- // AMD - RequireJS
- define( 'outlayer/outlayer',[
- 'ev-emitter/ev-emitter',
- 'get-size/get-size',
- 'fizzy-ui-utils/utils',
- './item'
- ],
- function( EvEmitter, getSize, utils, Item ) {
- return factory( window, EvEmitter, getSize, utils, Item);
- }
- );
- } else if ( typeof module == 'object' && module.exports ) {
- // CommonJS - Browserify, Webpack
- module.exports = factory(
- window,
- require('ev-emitter'),
- require('get-size'),
- require('fizzy-ui-utils'),
- require('./item')
- );
- } else {
- // browser global
- window.Outlayer = factory(
- window,
- window.EvEmitter,
- window.getSize,
- window.fizzyUIUtils,
- window.Outlayer.Item
- );
- }
-
- }( window, function factory( window, EvEmitter, getSize, utils, Item ) {
- 'use strict';
-
- // ----- vars ----- //
-
- var console = window.console;
- var jQuery = window.jQuery;
- var noop = function() {};
-
- // -------------------------- Outlayer -------------------------- //
-
- // globally unique identifiers
- var GUID = 0;
- // internal store of all Outlayer intances
- var instances = {};
-
-
- /**
- * @param {Element, String} element
- * @param {Object} options
- * @constructor
- */
- function Outlayer( element, options ) {
- var queryElement = utils.getQueryElement( element );
- if ( !queryElement ) {
- if ( console ) {
- console.error( 'Bad element for ' + this.constructor.namespace +
- ': ' + ( queryElement || element ) );
- }
- return;
- }
- this.element = queryElement;
- // add jQuery
- if ( jQuery ) {
- this.$element = jQuery( this.element );
- }
-
- // options
- this.options = utils.extend( {}, this.constructor.defaults );
- this.option( options );
-
- // add id for Outlayer.getFromElement
- var id = ++GUID;
- this.element.outlayerGUID = id; // expando
- instances[ id ] = this; // associate via id
-
- // kick it off
- this._create();
-
- var isInitLayout = this._getOption('initLayout');
- if ( isInitLayout ) {
- this.layout();
- }
- }
-
- // settings are for internal use only
- Outlayer.namespace = 'outlayer';
- Outlayer.Item = Item;
-
- // default options
- Outlayer.defaults = {
- containerStyle: {
- position: 'relative'
- },
- initLayout: true,
- originLeft: true,
- originTop: true,
- resize: true,
- resizeContainer: true,
- // item options
- transitionDuration: '0.4s',
- hiddenStyle: {
- opacity: 0,
- transform: 'scale(0.001)'
- },
- visibleStyle: {
- opacity: 1,
- transform: 'scale(1)'
- }
- };
-
- var proto = Outlayer.prototype;
- // inherit EvEmitter
- utils.extend( proto, EvEmitter.prototype );
-
- /**
- * set options
- * @param {Object} opts
- */
- proto.option = function( opts ) {
- utils.extend( this.options, opts );
- };
-
- /**
- * get backwards compatible option value, check old name
- */
- proto._getOption = function( option ) {
- var oldOption = this.constructor.compatOptions[ option ];
- return oldOption && this.options[ oldOption ] !== undefined ?
- this.options[ oldOption ] : this.options[ option ];
- };
-
- Outlayer.compatOptions = {
- // currentName: oldName
- initLayout: 'isInitLayout',
- horizontal: 'isHorizontal',
- layoutInstant: 'isLayoutInstant',
- originLeft: 'isOriginLeft',
- originTop: 'isOriginTop',
- resize: 'isResizeBound',
- resizeContainer: 'isResizingContainer'
- };
-
- proto._create = function() {
- // get items from children
- this.reloadItems();
- // elements that affect layout, but are not laid out
- this.stamps = [];
- this.stamp( this.options.stamp );
- // set container style
- utils.extend( this.element.style, this.options.containerStyle );
-
- // bind resize method
- var canBindResize = this._getOption('resize');
- if ( canBindResize ) {
- this.bindResize();
- }
- };
-
- // goes through all children again and gets bricks in proper order
- proto.reloadItems = function() {
- // collection of item elements
- this.items = this._itemize( this.element.children );
- };
-
-
- /**
- * turn elements into Outlayer.Items to be used in layout
- * @param {Array or NodeList or HTMLElement} elems
- * @returns {Array} items - collection of new Outlayer Items
- */
- proto._itemize = function( elems ) {
-
- var itemElems = this._filterFindItemElements( elems );
- var Item = this.constructor.Item;
-
- // create new Outlayer Items for collection
- var items = [];
- for ( var i=0; i < itemElems.length; i++ ) {
- var elem = itemElems[i];
- var item = new Item( elem, this );
- items.push( item );
- }
-
- return items;
- };
-
- /**
- * get item elements to be used in layout
- * @param {Array or NodeList or HTMLElement} elems
- * @returns {Array} items - item elements
- */
- proto._filterFindItemElements = function( elems ) {
- return utils.filterFindElements( elems, this.options.itemSelector );
- };
-
- /**
- * getter method for getting item elements
- * @returns {Array} elems - collection of item elements
- */
- proto.getItemElements = function() {
- return this.items.map( function( item ) {
- return item.element;
- });
- };
-
- // ----- init & layout ----- //
-
- /**
- * lays out all items
- */
- proto.layout = function() {
- this._resetLayout();
- this._manageStamps();
-
- // don't animate first layout
- var layoutInstant = this._getOption('layoutInstant');
- var isInstant = layoutInstant !== undefined ?
- layoutInstant : !this._isLayoutInited;
- this.layoutItems( this.items, isInstant );
-
- // flag for initalized
- this._isLayoutInited = true;
- };
-
- // _init is alias for layout
- proto._init = proto.layout;
-
- /**
- * logic before any new layout
- */
- proto._resetLayout = function() {
- this.getSize();
- };
-
-
- proto.getSize = function() {
- this.size = getSize( this.element );
- };
-
- /**
- * get measurement from option, for columnWidth, rowHeight, gutter
- * if option is String -> get element from selector string, & get size of element
- * if option is Element -> get size of element
- * else use option as a number
- *
- * @param {String} measurement
- * @param {String} size - width or height
- * @private
- */
- proto._getMeasurement = function( measurement, size ) {
- var option = this.options[ measurement ];
- var elem;
- if ( !option ) {
- // default to 0
- this[ measurement ] = 0;
- } else {
- // use option as an element
- if ( typeof option == 'string' ) {
- elem = this.element.querySelector( option );
- } else if ( option instanceof HTMLElement ) {
- elem = option;
- }
- // use size of element, if element
- this[ measurement ] = elem ? getSize( elem )[ size ] : option;
- }
- };
-
- /**
- * layout a collection of item elements
- * @api public
- */
- proto.layoutItems = function( items, isInstant ) {
- items = this._getItemsForLayout( items );
-
- this._layoutItems( items, isInstant );
-
- this._postLayout();
- };
-
- /**
- * get the items to be laid out
- * you may want to skip over some items
- * @param {Array} items
- * @returns {Array} items
- */
- proto._getItemsForLayout = function( items ) {
- return items.filter( function( item ) {
- return !item.isIgnored;
- });
- };
-
- /**
- * layout items
- * @param {Array} items
- * @param {Boolean} isInstant
- */
- proto._layoutItems = function( items, isInstant ) {
- this._emitCompleteOnItems( 'layout', items );
-
- if ( !items || !items.length ) {
- // no items, emit event with empty array
- return;
- }
-
- var queue = [];
-
- items.forEach( function( item ) {
- // get x/y object from method
- var position = this._getItemLayoutPosition( item );
- // enqueue
- position.item = item;
- position.isInstant = isInstant || item.isLayoutInstant;
- queue.push( position );
- }, this );
-
- this._processLayoutQueue( queue );
- };
-
- /**
- * get item layout position
- * @param {Outlayer.Item} item
- * @returns {Object} x and y position
- */
- proto._getItemLayoutPosition = function( /* item */ ) {
- return {
- x: 0,
- y: 0
- };
- };
-
- /**
- * iterate over array and position each item
- * Reason being - separating this logic prevents 'layout invalidation'
- * thx @paul_irish
- * @param {Array} queue
- */
- proto._processLayoutQueue = function( queue ) {
- this.updateStagger();
- queue.forEach( function( obj, i ) {
- this._positionItem( obj.item, obj.x, obj.y, obj.isInstant, i );
- }, this );
- };
-
- // set stagger from option in milliseconds number
- proto.updateStagger = function() {
- var stagger = this.options.stagger;
- if ( stagger === null || stagger === undefined ) {
- this.stagger = 0;
- return;
- }
- this.stagger = getMilliseconds( stagger );
- return this.stagger;
- };
-
- /**
- * Sets position of item in DOM
- * @param {Outlayer.Item} item
- * @param {Number} x - horizontal position
- * @param {Number} y - vertical position
- * @param {Boolean} isInstant - disables transitions
- */
- proto._positionItem = function( item, x, y, isInstant, i ) {
- if ( isInstant ) {
- // if not transition, just set CSS
- item.goTo( x, y );
- } else {
- item.stagger( i * this.stagger );
- item.moveTo( x, y );
- }
- };
-
- /**
- * Any logic you want to do after each layout,
- * i.e. size the container
- */
- proto._postLayout = function() {
- this.resizeContainer();
- };
-
- proto.resizeContainer = function() {
- var isResizingContainer = this._getOption('resizeContainer');
- if ( !isResizingContainer ) {
- return;
- }
- var size = this._getContainerSize();
- if ( size ) {
- this._setContainerMeasure( size.width, true );
- this._setContainerMeasure( size.height, false );
- }
- };
-
- /**
- * Sets width or height of container if returned
- * @returns {Object} size
- * @param {Number} width
- * @param {Number} height
- */
- proto._getContainerSize = noop;
-
- /**
- * @param {Number} measure - size of width or height
- * @param {Boolean} isWidth
- */
- proto._setContainerMeasure = function( measure, isWidth ) {
- if ( measure === undefined ) {
- return;
- }
-
- var elemSize = this.size;
- // add padding and border width if border box
- if ( elemSize.isBorderBox ) {
- measure += isWidth ? elemSize.paddingLeft + elemSize.paddingRight +
- elemSize.borderLeftWidth + elemSize.borderRightWidth :
- elemSize.paddingBottom + elemSize.paddingTop +
- elemSize.borderTopWidth + elemSize.borderBottomWidth;
- }
-
- measure = Math.max( measure, 0 );
- this.element.style[ isWidth ? 'width' : 'height' ] = measure + 'px';
- };
-
- /**
- * emit eventComplete on a collection of items events
- * @param {String} eventName
- * @param {Array} items - Outlayer.Items
- */
- proto._emitCompleteOnItems = function( eventName, items ) {
- var _this = this;
- function onComplete() {
- _this.dispatchEvent( eventName + 'Complete', null, [ items ] );
- }
-
- var count = items.length;
- if ( !items || !count ) {
- onComplete();
- return;
- }
-
- var doneCount = 0;
- function tick() {
- doneCount++;
- if ( doneCount == count ) {
- onComplete();
- }
- }
-
- // bind callback
- items.forEach( function( item ) {
- item.once( eventName, tick );
- });
- };
-
- /**
- * emits events via EvEmitter and jQuery events
- * @param {String} type - name of event
- * @param {Event} event - original event
- * @param {Array} args - extra arguments
- */
- proto.dispatchEvent = function( type, event, args ) {
- // add original event to arguments
- var emitArgs = event ? [ event ].concat( args ) : args;
- this.emitEvent( type, emitArgs );
-
- if ( jQuery ) {
- // set this.$element
- this.$element = this.$element || jQuery( this.element );
- if ( event ) {
- // create jQuery event
- var $event = jQuery.Event( event );
- $event.type = type;
- this.$element.trigger( $event, args );
- } else {
- // just trigger with type if no event available
- this.$element.trigger( type, args );
- }
- }
- };
-
- // -------------------------- ignore & stamps -------------------------- //
-
-
- /**
- * keep item in collection, but do not lay it out
- * ignored items do not get skipped in layout
- * @param {Element} elem
- */
- proto.ignore = function( elem ) {
- var item = this.getItem( elem );
- if ( item ) {
- item.isIgnored = true;
- }
- };
-
- /**
- * return item to layout collection
- * @param {Element} elem
- */
- proto.unignore = function( elem ) {
- var item = this.getItem( elem );
- if ( item ) {
- delete item.isIgnored;
- }
- };
-
- /**
- * adds elements to stamps
- * @param {NodeList, Array, Element, or String} elems
- */
- proto.stamp = function( elems ) {
- elems = this._find( elems );
- if ( !elems ) {
- return;
- }
-
- this.stamps = this.stamps.concat( elems );
- // ignore
- elems.forEach( this.ignore, this );
- };
-
- /**
- * removes elements to stamps
- * @param {NodeList, Array, or Element} elems
- */
- proto.unstamp = function( elems ) {
- elems = this._find( elems );
- if ( !elems ){
- return;
- }
-
- elems.forEach( function( elem ) {
- // filter out removed stamp elements
- utils.removeFrom( this.stamps, elem );
- this.unignore( elem );
- }, this );
- };
-
- /**
- * finds child elements
- * @param {NodeList, Array, Element, or String} elems
- * @returns {Array} elems
- */
- proto._find = function( elems ) {
- if ( !elems ) {
- return;
- }
- // if string, use argument as selector string
- if ( typeof elems == 'string' ) {
- elems = this.element.querySelectorAll( elems );
- }
- elems = utils.makeArray( elems );
- return elems;
- };
-
- proto._manageStamps = function() {
- if ( !this.stamps || !this.stamps.length ) {
- return;
- }
-
- this._getBoundingRect();
-
- this.stamps.forEach( this._manageStamp, this );
- };
-
- // update boundingLeft / Top
- proto._getBoundingRect = function() {
- // get bounding rect for container element
- var boundingRect = this.element.getBoundingClientRect();
- var size = this.size;
- this._boundingRect = {
- left: boundingRect.left + size.paddingLeft + size.borderLeftWidth,
- top: boundingRect.top + size.paddingTop + size.borderTopWidth,
- right: boundingRect.right - ( size.paddingRight + size.borderRightWidth ),
- bottom: boundingRect.bottom - ( size.paddingBottom + size.borderBottomWidth )
- };
- };
-
- /**
- * @param {Element} stamp
- **/
- proto._manageStamp = noop;
-
- /**
- * get x/y position of element relative to container element
- * @param {Element} elem
- * @returns {Object} offset - has left, top, right, bottom
- */
- proto._getElementOffset = function( elem ) {
- var boundingRect = elem.getBoundingClientRect();
- var thisRect = this._boundingRect;
- var size = getSize( elem );
- var offset = {
- left: boundingRect.left - thisRect.left - size.marginLeft,
- top: boundingRect.top - thisRect.top - size.marginTop,
- right: thisRect.right - boundingRect.right - size.marginRight,
- bottom: thisRect.bottom - boundingRect.bottom - size.marginBottom
- };
- return offset;
- };
-
- // -------------------------- resize -------------------------- //
-
- // enable event handlers for listeners
- // i.e. resize -> onresize
- proto.handleEvent = utils.handleEvent;
-
- /**
- * Bind layout to window resizing
- */
- proto.bindResize = function() {
- window.addEventListener( 'resize', this );
- this.isResizeBound = true;
- };
-
- /**
- * Unbind layout to window resizing
- */
- proto.unbindResize = function() {
- window.removeEventListener( 'resize', this );
- this.isResizeBound = false;
- };
-
- proto.onresize = function() {
- this.resize();
- };
-
- utils.debounceMethod( Outlayer, 'onresize', 100 );
-
- proto.resize = function() {
- // don't trigger if size did not change
- // or if resize was unbound. See #9
- if ( !this.isResizeBound || !this.needsResizeLayout() ) {
- return;
- }
-
- this.layout();
- };
-
- /**
- * check if layout is needed post layout
- * @returns Boolean
- */
- proto.needsResizeLayout = function() {
- var size = getSize( this.element );
- // check that this.size and size are there
- // IE8 triggers resize on body size change, so they might not be
- var hasSizes = this.size && size;
- return hasSizes && size.innerWidth !== this.size.innerWidth;
- };
-
- // -------------------------- methods -------------------------- //
-
- /**
- * add items to Outlayer instance
- * @param {Array or NodeList or Element} elems
- * @returns {Array} items - Outlayer.Items
- **/
- proto.addItems = function( elems ) {
- var items = this._itemize( elems );
- // add items to collection
- if ( items.length ) {
- this.items = this.items.concat( items );
- }
- return items;
- };
-
- /**
- * Layout newly-appended item elements
- * @param {Array or NodeList or Element} elems
- */
- proto.appended = function( elems ) {
- var items = this.addItems( elems );
- if ( !items.length ) {
- return;
- }
- // layout and reveal just the new items
- this.layoutItems( items, true );
- this.reveal( items );
- };
-
- /**
- * Layout prepended elements
- * @param {Array or NodeList or Element} elems
- */
- proto.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
- this.layoutItems( items, true );
- this.reveal( items );
- // layout previous items
- this.layoutItems( previousItems );
- };
-
- /**
- * reveal a collection of items
- * @param {Array of Outlayer.Items} items
- */
- proto.reveal = function( items ) {
- this._emitCompleteOnItems( 'reveal', items );
- if ( !items || !items.length ) {
- return;
- }
- var stagger = this.updateStagger();
- items.forEach( function( item, i ) {
- item.stagger( i * stagger );
- item.reveal();
- });
- };
-
- /**
- * hide a collection of items
- * @param {Array of Outlayer.Items} items
- */
- proto.hide = function( items ) {
- this._emitCompleteOnItems( 'hide', items );
- if ( !items || !items.length ) {
- return;
- }
- var stagger = this.updateStagger();
- items.forEach( function( item, i ) {
- item.stagger( i * stagger );
- item.hide();
- });
- };
-
- /**
- * reveal item elements
- * @param {Array}, {Element}, {NodeList} items
- */
- proto.revealItemElements = function( elems ) {
- var items = this.getItems( elems );
- this.reveal( items );
- };
-
- /**
- * hide item elements
- * @param {Array}, {Element}, {NodeList} items
- */
- proto.hideItemElements = function( elems ) {
- var items = this.getItems( elems );
- this.hide( items );
- };
-
- /**
- * get Outlayer.Item, given an Element
- * @param {Element} elem
- * @param {Function} callback
- * @returns {Outlayer.Item} item
- */
- proto.getItem = function( elem ) {
- // loop through items to get the one that matches
- for ( var i=0; i < this.items.length; i++ ) {
- var item = this.items[i];
- if ( item.element == elem ) {
- // return item
- return item;
- }
- }
- };
-
- /**
- * get collection of Outlayer.Items, given Elements
- * @param {Array} elems
- * @returns {Array} items - Outlayer.Items
- */
- proto.getItems = function( elems ) {
- elems = utils.makeArray( elems );
- var items = [];
- elems.forEach( function( elem ) {
- var item = this.getItem( elem );
- if ( item ) {
- items.push( item );
- }
- }, this );
-
- return items;
- };
-
- /**
- * remove element(s) from instance and DOM
- * @param {Array or NodeList or Element} elems
- */
- proto.remove = function( elems ) {
- var removeItems = this.getItems( elems );
-
- this._emitCompleteOnItems( 'remove', removeItems );
-
- // bail if no items to remove
- if ( !removeItems || !removeItems.length ) {
- return;
- }
-
- removeItems.forEach( function( item ) {
- item.remove();
- // remove item from collection
- utils.removeFrom( this.items, item );
- }, this );
- };
-
- // ----- destroy ----- //
-
- // remove and disable Outlayer instance
- proto.destroy = function() {
- // clean up dynamic styles
- var style = this.element.style;
- style.height = '';
- style.position = '';
- style.width = '';
- // destroy items
- this.items.forEach( function( item ) {
- item.destroy();
- });
-
- this.unbindResize();
-
- var id = this.element.outlayerGUID;
- delete instances[ id ]; // remove reference to instance by id
- delete this.element.outlayerGUID;
- // remove data for jQuery
- if ( jQuery ) {
- jQuery.removeData( this.element, this.constructor.namespace );
- }
-
- };
-
- // -------------------------- data -------------------------- //
-
- /**
- * get Outlayer instance from element
- * @param {Element} elem
- * @returns {Outlayer}
- */
- Outlayer.data = function( elem ) {
- elem = utils.getQueryElement( elem );
- var id = elem && elem.outlayerGUID;
- return id && instances[ id ];
- };
-
-
- // -------------------------- create Outlayer class -------------------------- //
-
- /**
- * create a layout class
- * @param {String} namespace
- */
- Outlayer.create = function( namespace, options ) {
- // sub-class Outlayer
- var Layout = subclass( Outlayer );
- // apply new options and compatOptions
- Layout.defaults = utils.extend( {}, Outlayer.defaults );
- utils.extend( Layout.defaults, options );
- Layout.compatOptions = utils.extend( {}, Outlayer.compatOptions );
-
- Layout.namespace = namespace;
-
- Layout.data = Outlayer.data;
-
- // sub-class Item
- Layout.Item = subclass( Item );
-
- // -------------------------- declarative -------------------------- //
-
- utils.htmlInit( Layout, namespace );
-
- // -------------------------- jQuery bridge -------------------------- //
-
- // make into jQuery plugin
- if ( jQuery && jQuery.bridget ) {
- jQuery.bridget( namespace, Layout );
- }
-
- return Layout;
- };
-
- function subclass( Parent ) {
- function SubClass() {
- Parent.apply( this, arguments );
- }
-
- SubClass.prototype = Object.create( Parent.prototype );
- SubClass.prototype.constructor = SubClass;
-
- return SubClass;
- }
-
- // ----- helpers ----- //
-
- // how many milliseconds are in each unit
- var msUnits = {
- ms: 1,
- s: 1000
- };
-
- // munge time-like parameter into millisecond number
- // '0.4s' -> 40
- function getMilliseconds( time ) {
- if ( typeof time == 'number' ) {
- return time;
- }
- var matches = time.match( /(^\d*\.?\d*)(\w*)/ );
- var num = matches && matches[1];
- var unit = matches && matches[2];
- if ( !num.length ) {
- return 0;
- }
- num = parseFloat( num );
- var mult = msUnits[ unit ] || 1;
- return num * mult;
- }
-
- // ----- fin ----- //
-
- // back in global
- Outlayer.Item = Item;
-
- return Outlayer;
-
- }));
-
- /*!
- * Masonry v4.2.0
- * Cascading grid layout library
- * http://masonry.desandro.com
- * MIT License
- * by David DeSandro
- */
-
- ( function( window, factory ) {
- // universal module definition
- /* jshint strict: false */ /*globals define, module, require */
- if ( typeof define == 'function' && define.amd ) {
- // AMD
- define( [
- 'outlayer/outlayer',
- 'get-size/get-size'
- ],
- factory );
- } else if ( typeof module == 'object' && module.exports ) {
- // CommonJS
- module.exports = factory(
- require('outlayer'),
- require('get-size')
- );
- } else {
- // browser global
- window.Masonry = factory(
- window.Outlayer,
- window.getSize
- );
- }
-
- }( window, function factory( Outlayer, getSize ) {
-
-
-
- // -------------------------- masonryDefinition -------------------------- //
-
- // create an Outlayer layout class
- var Masonry = Outlayer.create('masonry');
- // isFitWidth -> fitWidth
- Masonry.compatOptions.fitWidth = 'isFitWidth';
-
- var proto = Masonry.prototype;
-
- proto._resetLayout = function() {
- this.getSize();
- this._getMeasurement( 'columnWidth', 'outerWidth' );
- this._getMeasurement( 'gutter', 'outerWidth' );
- this.measureColumns();
-
- // reset column Y
- this.colYs = [];
- for ( var i=0; i < this.cols; i++ ) {
- this.colYs.push( 0 );
- }
-
- this.maxY = 0;
- this.horizontalColIndex = 0;
- };
-
- proto.measureColumns = function() {
- this.getContainerWidth();
- // if columnWidth is 0, default to outerWidth of first item
- if ( !this.columnWidth ) {
- var firstItem = this.items[0];
- var firstItemElem = firstItem && firstItem.element;
- // columnWidth fall back to item of first element
- this.columnWidth = firstItemElem && getSize( firstItemElem ).outerWidth ||
- // if first elem has no width, default to size of container
- this.containerWidth;
- }
-
- var columnWidth = this.columnWidth += this.gutter;
-
- // calculate columns
- var containerWidth = this.containerWidth + this.gutter;
- var cols = containerWidth / columnWidth;
- // fix rounding errors, typically with gutters
- var excess = columnWidth - containerWidth % columnWidth;
- // if overshoot is less than a pixel, round up, otherwise floor it
- var mathMethod = excess && excess < 1 ? 'round' : 'floor';
- cols = Math[ mathMethod ]( cols );
- this.cols = Math.max( cols, 1 );
- };
-
- proto.getContainerWidth = function() {
- // container is parent if fit width
- var isFitWidth = this._getOption('fitWidth');
- var container = isFitWidth ? this.element.parentNode : this.element;
- // check that this.size and size are there
- // IE8 triggers resize on body size change, so they might not be
- var size = getSize( container );
- this.containerWidth = size && size.innerWidth;
- };
-
- proto._getItemLayoutPosition = function( item ) {
- item.getSize();
- // how many columns does this brick span
- var remainder = item.size.outerWidth % this.columnWidth;
- var mathMethod = remainder && remainder < 1 ? 'round' : 'ceil';
- // round if off by 1 pixel, otherwise use ceil
- var colSpan = Math[ mathMethod ]( item.size.outerWidth / this.columnWidth );
- colSpan = Math.min( colSpan, this.cols );
- // use horizontal or top column position
- var colPosMethod = this.options.horizontalOrder ?
- '_getHorizontalColPosition' : '_getTopColPosition';
- var colPosition = this[ colPosMethod ]( colSpan, item );
- // position the brick
- var position = {
- x: this.columnWidth * colPosition.col,
- y: colPosition.y
- };
- // apply setHeight to necessary columns
- var setHeight = colPosition.y + item.size.outerHeight;
- var setMax = colSpan + colPosition.col;
- for ( var i = colPosition.col; i < setMax; i++ ) {
- this.colYs[i] = setHeight;
- }
-
- return position;
- };
-
- proto._getTopColPosition = function( colSpan ) {
- var colGroup = this._getTopColGroup( colSpan );
- // get the minimum Y value from the columns
- var minimumY = Math.min.apply( Math, colGroup );
-
- return {
- col: colGroup.indexOf( minimumY ),
- y: minimumY,
- };
- };
-
- /**
- * @param {Number} colSpan - number of columns the element spans
- * @returns {Array} colGroup
- */
- proto._getTopColGroup = function( colSpan ) {
- if ( colSpan < 2 ) {
- // if brick spans only one column, use all the column Ys
- return this.colYs;
- }
-
- var colGroup = [];
- // how many different places could this brick fit horizontally
- var groupCount = this.cols + 1 - colSpan;
- // for each group potential horizontal position
- for ( var i = 0; i < groupCount; i++ ) {
- colGroup[i] = this._getColGroupY( i, colSpan );
- }
- return colGroup;
- };
-
- proto._getColGroupY = function( col, colSpan ) {
- if ( colSpan < 2 ) {
- return this.colYs[ col ];
- }
- // make an array of colY values for that one group
- var groupColYs = this.colYs.slice( col, col + colSpan );
- // and get the max value of the array
- return Math.max.apply( Math, groupColYs );
- };
-
- // get column position based on horizontal index. #873
- proto._getHorizontalColPosition = function( colSpan, item ) {
- var col = this.horizontalColIndex % this.cols;
- var isOver = colSpan > 1 && col + colSpan > this.cols;
- // shift to next row if item can't fit on current row
- col = isOver ? 0 : col;
- // don't let zero-size items take up space
- var hasSize = item.size.outerWidth && item.size.outerHeight;
- this.horizontalColIndex = hasSize ? col + colSpan : this.horizontalColIndex;
-
- return {
- col: col,
- y: this._getColGroupY( col, colSpan ),
- };
- };
-
- proto._manageStamp = function( stamp ) {
- var stampSize = getSize( stamp );
- var offset = this._getElementOffset( stamp );
- // get the columns that this stamp affects
- var isOriginLeft = this._getOption('originLeft');
- var firstX = isOriginLeft ? offset.left : offset.right;
- var lastX = firstX + stampSize.outerWidth;
- var firstCol = Math.floor( firstX / this.columnWidth );
- firstCol = Math.max( 0, firstCol );
- var lastCol = Math.floor( lastX / this.columnWidth );
- // lastCol should not go over if multiple of columnWidth #425
- lastCol -= lastX % this.columnWidth ? 0 : 1;
- lastCol = Math.min( this.cols - 1, lastCol );
- // set colYs to bottom of the stamp
-
- var isOriginTop = this._getOption('originTop');
- var stampMaxY = ( isOriginTop ? offset.top : offset.bottom ) +
- stampSize.outerHeight;
- for ( var i = firstCol; i <= lastCol; i++ ) {
- this.colYs[i] = Math.max( stampMaxY, this.colYs[i] );
- }
- };
-
- proto._getContainerSize = function() {
- this.maxY = Math.max.apply( Math, this.colYs );
- var size = {
- height: this.maxY
- };
-
- if ( this._getOption('fitWidth') ) {
- size.width = this._getContainerFitWidth();
- }
-
- return size;
- };
-
- proto._getContainerFitWidth = function() {
- var unusedCols = 0;
- // count unused columns
- var i = this.cols;
- while ( --i ) {
- if ( this.colYs[i] !== 0 ) {
- break;
- }
- unusedCols++;
- }
- // fit container to columns that have been used
- return ( this.cols - unusedCols ) * this.columnWidth - this.gutter;
- };
-
- proto.needsResizeLayout = function() {
- var previousWidth = this.containerWidth;
- this.getContainerWidth();
- return previousWidth != this.containerWidth;
- };
-
- return Masonry;
-
- }));
-
|