isotope.pkgd.js 89 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563
  1. /*!
  2. * Isotope PACKAGED v3.0.6
  3. *
  4. * Licensed GPLv3 for open source use
  5. * or Isotope Commercial License for commercial use
  6. *
  7. * https://isotope.metafizzy.co
  8. * Copyright 2010-2018 Metafizzy
  9. */
  10. /**
  11. * Bridget makes jQuery widgets
  12. * v2.0.1
  13. * MIT license
  14. */
  15. /* jshint browser: true, strict: true, undef: true, unused: true */
  16. ( function( window, factory ) {
  17. // universal module definition
  18. /*jshint strict: false */ /* globals define, module, require */
  19. if ( typeof define == 'function' && define.amd ) {
  20. // AMD
  21. define( 'jquery-bridget/jquery-bridget',[ 'jquery' ], function( jQuery ) {
  22. return factory( window, jQuery );
  23. });
  24. } else if ( typeof module == 'object' && module.exports ) {
  25. // CommonJS
  26. module.exports = factory(
  27. window,
  28. require('jquery')
  29. );
  30. } else {
  31. // browser global
  32. window.jQueryBridget = factory(
  33. window,
  34. window.jQuery
  35. );
  36. }
  37. }( window, function factory( window, jQuery ) {
  38. 'use strict';
  39. // ----- utils ----- //
  40. var arraySlice = Array.prototype.slice;
  41. // helper function for logging errors
  42. // $.error breaks jQuery chaining
  43. var console = window.console;
  44. var logError = typeof console == 'undefined' ? function() {} :
  45. function( message ) {
  46. console.error( message );
  47. };
  48. // ----- jQueryBridget ----- //
  49. function jQueryBridget( namespace, PluginClass, $ ) {
  50. $ = $ || jQuery || window.jQuery;
  51. if ( !$ ) {
  52. return;
  53. }
  54. // add option method -> $().plugin('option', {...})
  55. if ( !PluginClass.prototype.option ) {
  56. // option setter
  57. PluginClass.prototype.option = function( opts ) {
  58. // bail out if not an object
  59. if ( !$.isPlainObject( opts ) ){
  60. return;
  61. }
  62. this.options = $.extend( true, this.options, opts );
  63. };
  64. }
  65. // make jQuery plugin
  66. $.fn[ namespace ] = function( arg0 /*, arg1 */ ) {
  67. if ( typeof arg0 == 'string' ) {
  68. // method call $().plugin( 'methodName', { options } )
  69. // shift arguments by 1
  70. var args = arraySlice.call( arguments, 1 );
  71. return methodCall( this, arg0, args );
  72. }
  73. // just $().plugin({ options })
  74. plainCall( this, arg0 );
  75. return this;
  76. };
  77. // $().plugin('methodName')
  78. function methodCall( $elems, methodName, args ) {
  79. var returnValue;
  80. var pluginMethodStr = '$().' + namespace + '("' + methodName + '")';
  81. $elems.each( function( i, elem ) {
  82. // get instance
  83. var instance = $.data( elem, namespace );
  84. if ( !instance ) {
  85. logError( namespace + ' not initialized. Cannot call methods, i.e. ' +
  86. pluginMethodStr );
  87. return;
  88. }
  89. var method = instance[ methodName ];
  90. if ( !method || methodName.charAt(0) == '_' ) {
  91. logError( pluginMethodStr + ' is not a valid method' );
  92. return;
  93. }
  94. // apply method, get return value
  95. var value = method.apply( instance, args );
  96. // set return value if value is returned, use only first value
  97. returnValue = returnValue === undefined ? value : returnValue;
  98. });
  99. return returnValue !== undefined ? returnValue : $elems;
  100. }
  101. function plainCall( $elems, options ) {
  102. $elems.each( function( i, elem ) {
  103. var instance = $.data( elem, namespace );
  104. if ( instance ) {
  105. // set options & init
  106. instance.option( options );
  107. instance._init();
  108. } else {
  109. // initialize new instance
  110. instance = new PluginClass( elem, options );
  111. $.data( elem, namespace, instance );
  112. }
  113. });
  114. }
  115. updateJQuery( $ );
  116. }
  117. // ----- updateJQuery ----- //
  118. // set $.bridget for v1 backwards compatibility
  119. function updateJQuery( $ ) {
  120. if ( !$ || ( $ && $.bridget ) ) {
  121. return;
  122. }
  123. $.bridget = jQueryBridget;
  124. }
  125. updateJQuery( jQuery || window.jQuery );
  126. // ----- ----- //
  127. return jQueryBridget;
  128. }));
  129. /**
  130. * EvEmitter v1.1.0
  131. * Lil' event emitter
  132. * MIT License
  133. */
  134. /* jshint unused: true, undef: true, strict: true */
  135. ( function( global, factory ) {
  136. // universal module definition
  137. /* jshint strict: false */ /* globals define, module, window */
  138. if ( typeof define == 'function' && define.amd ) {
  139. // AMD - RequireJS
  140. define( 'ev-emitter/ev-emitter',factory );
  141. } else if ( typeof module == 'object' && module.exports ) {
  142. // CommonJS - Browserify, Webpack
  143. module.exports = factory();
  144. } else {
  145. // Browser globals
  146. global.EvEmitter = factory();
  147. }
  148. }( typeof window != 'undefined' ? window : this, function() {
  149. function EvEmitter() {}
  150. var proto = EvEmitter.prototype;
  151. proto.on = function( eventName, listener ) {
  152. if ( !eventName || !listener ) {
  153. return;
  154. }
  155. // set events hash
  156. var events = this._events = this._events || {};
  157. // set listeners array
  158. var listeners = events[ eventName ] = events[ eventName ] || [];
  159. // only add once
  160. if ( listeners.indexOf( listener ) == -1 ) {
  161. listeners.push( listener );
  162. }
  163. return this;
  164. };
  165. proto.once = function( eventName, listener ) {
  166. if ( !eventName || !listener ) {
  167. return;
  168. }
  169. // add event
  170. this.on( eventName, listener );
  171. // set once flag
  172. // set onceEvents hash
  173. var onceEvents = this._onceEvents = this._onceEvents || {};
  174. // set onceListeners object
  175. var onceListeners = onceEvents[ eventName ] = onceEvents[ eventName ] || {};
  176. // set flag
  177. onceListeners[ listener ] = true;
  178. return this;
  179. };
  180. proto.off = function( eventName, listener ) {
  181. var listeners = this._events && this._events[ eventName ];
  182. if ( !listeners || !listeners.length ) {
  183. return;
  184. }
  185. var index = listeners.indexOf( listener );
  186. if ( index != -1 ) {
  187. listeners.splice( index, 1 );
  188. }
  189. return this;
  190. };
  191. proto.emitEvent = function( eventName, args ) {
  192. var listeners = this._events && this._events[ eventName ];
  193. if ( !listeners || !listeners.length ) {
  194. return;
  195. }
  196. // copy over to avoid interference if .off() in listener
  197. listeners = listeners.slice(0);
  198. args = args || [];
  199. // once stuff
  200. var onceListeners = this._onceEvents && this._onceEvents[ eventName ];
  201. for ( var i=0; i < listeners.length; i++ ) {
  202. var listener = listeners[i]
  203. var isOnce = onceListeners && onceListeners[ listener ];
  204. if ( isOnce ) {
  205. // remove listener
  206. // remove before trigger to prevent recursion
  207. this.off( eventName, listener );
  208. // unset once flag
  209. delete onceListeners[ listener ];
  210. }
  211. // trigger listener
  212. listener.apply( this, args );
  213. }
  214. return this;
  215. };
  216. proto.allOff = function() {
  217. delete this._events;
  218. delete this._onceEvents;
  219. };
  220. return EvEmitter;
  221. }));
  222. /*!
  223. * getSize v2.0.3
  224. * measure size of elements
  225. * MIT license
  226. */
  227. /* jshint browser: true, strict: true, undef: true, unused: true */
  228. /* globals console: false */
  229. ( function( window, factory ) {
  230. /* jshint strict: false */ /* globals define, module */
  231. if ( typeof define == 'function' && define.amd ) {
  232. // AMD
  233. define( 'get-size/get-size',factory );
  234. } else if ( typeof module == 'object' && module.exports ) {
  235. // CommonJS
  236. module.exports = factory();
  237. } else {
  238. // browser global
  239. window.getSize = factory();
  240. }
  241. })( window, function factory() {
  242. 'use strict';
  243. // -------------------------- helpers -------------------------- //
  244. // get a number from a string, not a percentage
  245. function getStyleSize( value ) {
  246. var num = parseFloat( value );
  247. // not a percent like '100%', and a number
  248. var isValid = value.indexOf('%') == -1 && !isNaN( num );
  249. return isValid && num;
  250. }
  251. function noop() {}
  252. var logError = typeof console == 'undefined' ? noop :
  253. function( message ) {
  254. console.error( message );
  255. };
  256. // -------------------------- measurements -------------------------- //
  257. var measurements = [
  258. 'paddingLeft',
  259. 'paddingRight',
  260. 'paddingTop',
  261. 'paddingBottom',
  262. 'marginLeft',
  263. 'marginRight',
  264. 'marginTop',
  265. 'marginBottom',
  266. 'borderLeftWidth',
  267. 'borderRightWidth',
  268. 'borderTopWidth',
  269. 'borderBottomWidth'
  270. ];
  271. var measurementsLength = measurements.length;
  272. function getZeroSize() {
  273. var size = {
  274. width: 0,
  275. height: 0,
  276. innerWidth: 0,
  277. innerHeight: 0,
  278. outerWidth: 0,
  279. outerHeight: 0
  280. };
  281. for ( var i=0; i < measurementsLength; i++ ) {
  282. var measurement = measurements[i];
  283. size[ measurement ] = 0;
  284. }
  285. return size;
  286. }
  287. // -------------------------- getStyle -------------------------- //
  288. /**
  289. * getStyle, get style of element, check for Firefox bug
  290. * https://bugzilla.mozilla.org/show_bug.cgi?id=548397
  291. */
  292. function getStyle( elem ) {
  293. var style = getComputedStyle( elem );
  294. if ( !style ) {
  295. logError( 'Style returned ' + style +
  296. '. Are you running this code in a hidden iframe on Firefox? ' +
  297. 'See https://bit.ly/getsizebug1' );
  298. }
  299. return style;
  300. }
  301. // -------------------------- setup -------------------------- //
  302. var isSetup = false;
  303. var isBoxSizeOuter;
  304. /**
  305. * setup
  306. * check isBoxSizerOuter
  307. * do on first getSize() rather than on page load for Firefox bug
  308. */
  309. function setup() {
  310. // setup once
  311. if ( isSetup ) {
  312. return;
  313. }
  314. isSetup = true;
  315. // -------------------------- box sizing -------------------------- //
  316. /**
  317. * Chrome & Safari measure the outer-width on style.width on border-box elems
  318. * IE11 & Firefox<29 measures the inner-width
  319. */
  320. var div = document.createElement('div');
  321. div.style.width = '200px';
  322. div.style.padding = '1px 2px 3px 4px';
  323. div.style.borderStyle = 'solid';
  324. div.style.borderWidth = '1px 2px 3px 4px';
  325. div.style.boxSizing = 'border-box';
  326. var body = document.body || document.documentElement;
  327. body.appendChild( div );
  328. var style = getStyle( div );
  329. // round value for browser zoom. desandro/masonry#928
  330. isBoxSizeOuter = Math.round( getStyleSize( style.width ) ) == 200;
  331. getSize.isBoxSizeOuter = isBoxSizeOuter;
  332. body.removeChild( div );
  333. }
  334. // -------------------------- getSize -------------------------- //
  335. function getSize( elem ) {
  336. setup();
  337. // use querySeletor if elem is string
  338. if ( typeof elem == 'string' ) {
  339. elem = document.querySelector( elem );
  340. }
  341. // do not proceed on non-objects
  342. if ( !elem || typeof elem != 'object' || !elem.nodeType ) {
  343. return;
  344. }
  345. var style = getStyle( elem );
  346. // if hidden, everything is 0
  347. if ( style.display == 'none' ) {
  348. return getZeroSize();
  349. }
  350. var size = {};
  351. size.width = elem.offsetWidth;
  352. size.height = elem.offsetHeight;
  353. var isBorderBox = size.isBorderBox = style.boxSizing == 'border-box';
  354. // get all measurements
  355. for ( var i=0; i < measurementsLength; i++ ) {
  356. var measurement = measurements[i];
  357. var value = style[ measurement ];
  358. var num = parseFloat( value );
  359. // any 'auto', 'medium' value will be 0
  360. size[ measurement ] = !isNaN( num ) ? num : 0;
  361. }
  362. var paddingWidth = size.paddingLeft + size.paddingRight;
  363. var paddingHeight = size.paddingTop + size.paddingBottom;
  364. var marginWidth = size.marginLeft + size.marginRight;
  365. var marginHeight = size.marginTop + size.marginBottom;
  366. var borderWidth = size.borderLeftWidth + size.borderRightWidth;
  367. var borderHeight = size.borderTopWidth + size.borderBottomWidth;
  368. var isBorderBoxSizeOuter = isBorderBox && isBoxSizeOuter;
  369. // overwrite width and height if we can get it from style
  370. var styleWidth = getStyleSize( style.width );
  371. if ( styleWidth !== false ) {
  372. size.width = styleWidth +
  373. // add padding and border unless it's already including it
  374. ( isBorderBoxSizeOuter ? 0 : paddingWidth + borderWidth );
  375. }
  376. var styleHeight = getStyleSize( style.height );
  377. if ( styleHeight !== false ) {
  378. size.height = styleHeight +
  379. // add padding and border unless it's already including it
  380. ( isBorderBoxSizeOuter ? 0 : paddingHeight + borderHeight );
  381. }
  382. size.innerWidth = size.width - ( paddingWidth + borderWidth );
  383. size.innerHeight = size.height - ( paddingHeight + borderHeight );
  384. size.outerWidth = size.width + marginWidth;
  385. size.outerHeight = size.height + marginHeight;
  386. return size;
  387. }
  388. return getSize;
  389. });
  390. /**
  391. * matchesSelector v2.0.2
  392. * matchesSelector( element, '.selector' )
  393. * MIT license
  394. */
  395. /*jshint browser: true, strict: true, undef: true, unused: true */
  396. ( function( window, factory ) {
  397. /*global define: false, module: false */
  398. 'use strict';
  399. // universal module definition
  400. if ( typeof define == 'function' && define.amd ) {
  401. // AMD
  402. define( 'desandro-matches-selector/matches-selector',factory );
  403. } else if ( typeof module == 'object' && module.exports ) {
  404. // CommonJS
  405. module.exports = factory();
  406. } else {
  407. // browser global
  408. window.matchesSelector = factory();
  409. }
  410. }( window, function factory() {
  411. 'use strict';
  412. var matchesMethod = ( function() {
  413. var ElemProto = window.Element.prototype;
  414. // check for the standard method name first
  415. if ( ElemProto.matches ) {
  416. return 'matches';
  417. }
  418. // check un-prefixed
  419. if ( ElemProto.matchesSelector ) {
  420. return 'matchesSelector';
  421. }
  422. // check vendor prefixes
  423. var prefixes = [ 'webkit', 'moz', 'ms', 'o' ];
  424. for ( var i=0; i < prefixes.length; i++ ) {
  425. var prefix = prefixes[i];
  426. var method = prefix + 'MatchesSelector';
  427. if ( ElemProto[ method ] ) {
  428. return method;
  429. }
  430. }
  431. })();
  432. return function matchesSelector( elem, selector ) {
  433. return elem[ matchesMethod ]( selector );
  434. };
  435. }));
  436. /**
  437. * Fizzy UI utils v2.0.7
  438. * MIT license
  439. */
  440. /*jshint browser: true, undef: true, unused: true, strict: true */
  441. ( function( window, factory ) {
  442. // universal module definition
  443. /*jshint strict: false */ /*globals define, module, require */
  444. if ( typeof define == 'function' && define.amd ) {
  445. // AMD
  446. define( 'fizzy-ui-utils/utils',[
  447. 'desandro-matches-selector/matches-selector'
  448. ], function( matchesSelector ) {
  449. return factory( window, matchesSelector );
  450. });
  451. } else if ( typeof module == 'object' && module.exports ) {
  452. // CommonJS
  453. module.exports = factory(
  454. window,
  455. require('desandro-matches-selector')
  456. );
  457. } else {
  458. // browser global
  459. window.fizzyUIUtils = factory(
  460. window,
  461. window.matchesSelector
  462. );
  463. }
  464. }( window, function factory( window, matchesSelector ) {
  465. var utils = {};
  466. // ----- extend ----- //
  467. // extends objects
  468. utils.extend = function( a, b ) {
  469. for ( var prop in b ) {
  470. a[ prop ] = b[ prop ];
  471. }
  472. return a;
  473. };
  474. // ----- modulo ----- //
  475. utils.modulo = function( num, div ) {
  476. return ( ( num % div ) + div ) % div;
  477. };
  478. // ----- makeArray ----- //
  479. var arraySlice = Array.prototype.slice;
  480. // turn element or nodeList into an array
  481. utils.makeArray = function( obj ) {
  482. if ( Array.isArray( obj ) ) {
  483. // use object if already an array
  484. return obj;
  485. }
  486. // return empty array if undefined or null. #6
  487. if ( obj === null || obj === undefined ) {
  488. return [];
  489. }
  490. var isArrayLike = typeof obj == 'object' && typeof obj.length == 'number';
  491. if ( isArrayLike ) {
  492. // convert nodeList to array
  493. return arraySlice.call( obj );
  494. }
  495. // array of single index
  496. return [ obj ];
  497. };
  498. // ----- removeFrom ----- //
  499. utils.removeFrom = function( ary, obj ) {
  500. var index = ary.indexOf( obj );
  501. if ( index != -1 ) {
  502. ary.splice( index, 1 );
  503. }
  504. };
  505. // ----- getParent ----- //
  506. utils.getParent = function( elem, selector ) {
  507. while ( elem.parentNode && elem != document.body ) {
  508. elem = elem.parentNode;
  509. if ( matchesSelector( elem, selector ) ) {
  510. return elem;
  511. }
  512. }
  513. };
  514. // ----- getQueryElement ----- //
  515. // use element as selector string
  516. utils.getQueryElement = function( elem ) {
  517. if ( typeof elem == 'string' ) {
  518. return document.querySelector( elem );
  519. }
  520. return elem;
  521. };
  522. // ----- handleEvent ----- //
  523. // enable .ontype to trigger from .addEventListener( elem, 'type' )
  524. utils.handleEvent = function( event ) {
  525. var method = 'on' + event.type;
  526. if ( this[ method ] ) {
  527. this[ method ]( event );
  528. }
  529. };
  530. // ----- filterFindElements ----- //
  531. utils.filterFindElements = function( elems, selector ) {
  532. // make array of elems
  533. elems = utils.makeArray( elems );
  534. var ffElems = [];
  535. elems.forEach( function( elem ) {
  536. // check that elem is an actual element
  537. if ( !( elem instanceof HTMLElement ) ) {
  538. return;
  539. }
  540. // add elem if no selector
  541. if ( !selector ) {
  542. ffElems.push( elem );
  543. return;
  544. }
  545. // filter & find items if we have a selector
  546. // filter
  547. if ( matchesSelector( elem, selector ) ) {
  548. ffElems.push( elem );
  549. }
  550. // find children
  551. var childElems = elem.querySelectorAll( selector );
  552. // concat childElems to filterFound array
  553. for ( var i=0; i < childElems.length; i++ ) {
  554. ffElems.push( childElems[i] );
  555. }
  556. });
  557. return ffElems;
  558. };
  559. // ----- debounceMethod ----- //
  560. utils.debounceMethod = function( _class, methodName, threshold ) {
  561. threshold = threshold || 100;
  562. // original method
  563. var method = _class.prototype[ methodName ];
  564. var timeoutName = methodName + 'Timeout';
  565. _class.prototype[ methodName ] = function() {
  566. var timeout = this[ timeoutName ];
  567. clearTimeout( timeout );
  568. var args = arguments;
  569. var _this = this;
  570. this[ timeoutName ] = setTimeout( function() {
  571. method.apply( _this, args );
  572. delete _this[ timeoutName ];
  573. }, threshold );
  574. };
  575. };
  576. // ----- docReady ----- //
  577. utils.docReady = function( callback ) {
  578. var readyState = document.readyState;
  579. if ( readyState == 'complete' || readyState == 'interactive' ) {
  580. // do async to allow for other scripts to run. metafizzy/flickity#441
  581. setTimeout( callback );
  582. } else {
  583. document.addEventListener( 'DOMContentLoaded', callback );
  584. }
  585. };
  586. // ----- htmlInit ----- //
  587. // http://jamesroberts.name/blog/2010/02/22/string-functions-for-javascript-trim-to-camel-case-to-dashed-and-to-underscore/
  588. utils.toDashed = function( str ) {
  589. return str.replace( /(.)([A-Z])/g, function( match, $1, $2 ) {
  590. return $1 + '-' + $2;
  591. }).toLowerCase();
  592. };
  593. var console = window.console;
  594. /**
  595. * allow user to initialize classes via [data-namespace] or .js-namespace class
  596. * htmlInit( Widget, 'widgetName' )
  597. * options are parsed from data-namespace-options
  598. */
  599. utils.htmlInit = function( WidgetClass, namespace ) {
  600. utils.docReady( function() {
  601. var dashedNamespace = utils.toDashed( namespace );
  602. var dataAttr = 'data-' + dashedNamespace;
  603. var dataAttrElems = document.querySelectorAll( '[' + dataAttr + ']' );
  604. var jsDashElems = document.querySelectorAll( '.js-' + dashedNamespace );
  605. var elems = utils.makeArray( dataAttrElems )
  606. .concat( utils.makeArray( jsDashElems ) );
  607. var dataOptionsAttr = dataAttr + '-options';
  608. var jQuery = window.jQuery;
  609. elems.forEach( function( elem ) {
  610. var attr = elem.getAttribute( dataAttr ) ||
  611. elem.getAttribute( dataOptionsAttr );
  612. var options;
  613. try {
  614. options = attr && JSON.parse( attr );
  615. } catch ( error ) {
  616. // log error, do not initialize
  617. if ( console ) {
  618. console.error( 'Error parsing ' + dataAttr + ' on ' + elem.className +
  619. ': ' + error );
  620. }
  621. return;
  622. }
  623. // initialize
  624. var instance = new WidgetClass( elem, options );
  625. // make available via $().data('namespace')
  626. if ( jQuery ) {
  627. jQuery.data( elem, namespace, instance );
  628. }
  629. });
  630. });
  631. };
  632. // ----- ----- //
  633. return utils;
  634. }));
  635. /**
  636. * Outlayer Item
  637. */
  638. ( function( window, factory ) {
  639. // universal module definition
  640. /* jshint strict: false */ /* globals define, module, require */
  641. if ( typeof define == 'function' && define.amd ) {
  642. // AMD - RequireJS
  643. define( 'outlayer/item',[
  644. 'ev-emitter/ev-emitter',
  645. 'get-size/get-size'
  646. ],
  647. factory
  648. );
  649. } else if ( typeof module == 'object' && module.exports ) {
  650. // CommonJS - Browserify, Webpack
  651. module.exports = factory(
  652. require('ev-emitter'),
  653. require('get-size')
  654. );
  655. } else {
  656. // browser global
  657. window.Outlayer = {};
  658. window.Outlayer.Item = factory(
  659. window.EvEmitter,
  660. window.getSize
  661. );
  662. }
  663. }( window, function factory( EvEmitter, getSize ) {
  664. 'use strict';
  665. // ----- helpers ----- //
  666. function isEmptyObj( obj ) {
  667. for ( var prop in obj ) {
  668. return false;
  669. }
  670. prop = null;
  671. return true;
  672. }
  673. // -------------------------- CSS3 support -------------------------- //
  674. var docElemStyle = document.documentElement.style;
  675. var transitionProperty = typeof docElemStyle.transition == 'string' ?
  676. 'transition' : 'WebkitTransition';
  677. var transformProperty = typeof docElemStyle.transform == 'string' ?
  678. 'transform' : 'WebkitTransform';
  679. var transitionEndEvent = {
  680. WebkitTransition: 'webkitTransitionEnd',
  681. transition: 'transitionend'
  682. }[ transitionProperty ];
  683. // cache all vendor properties that could have vendor prefix
  684. var vendorProperties = {
  685. transform: transformProperty,
  686. transition: transitionProperty,
  687. transitionDuration: transitionProperty + 'Duration',
  688. transitionProperty: transitionProperty + 'Property',
  689. transitionDelay: transitionProperty + 'Delay'
  690. };
  691. // -------------------------- Item -------------------------- //
  692. function Item( element, layout ) {
  693. if ( !element ) {
  694. return;
  695. }
  696. this.element = element;
  697. // parent layout class, i.e. Masonry, Isotope, or Packery
  698. this.layout = layout;
  699. this.position = {
  700. x: 0,
  701. y: 0
  702. };
  703. this._create();
  704. }
  705. // inherit EvEmitter
  706. var proto = Item.prototype = Object.create( EvEmitter.prototype );
  707. proto.constructor = Item;
  708. proto._create = function() {
  709. // transition objects
  710. this._transn = {
  711. ingProperties: {},
  712. clean: {},
  713. onEnd: {}
  714. };
  715. this.css({
  716. position: 'absolute'
  717. });
  718. };
  719. // trigger specified handler for event type
  720. proto.handleEvent = function( event ) {
  721. var method = 'on' + event.type;
  722. if ( this[ method ] ) {
  723. this[ method ]( event );
  724. }
  725. };
  726. proto.getSize = function() {
  727. this.size = getSize( this.element );
  728. };
  729. /**
  730. * apply CSS styles to element
  731. * @param {Object} style
  732. */
  733. proto.css = function( style ) {
  734. var elemStyle = this.element.style;
  735. for ( var prop in style ) {
  736. // use vendor property if available
  737. var supportedProp = vendorProperties[ prop ] || prop;
  738. elemStyle[ supportedProp ] = style[ prop ];
  739. }
  740. };
  741. // measure position, and sets it
  742. proto.getPosition = function() {
  743. var style = getComputedStyle( this.element );
  744. var isOriginLeft = this.layout._getOption('originLeft');
  745. var isOriginTop = this.layout._getOption('originTop');
  746. var xValue = style[ isOriginLeft ? 'left' : 'right' ];
  747. var yValue = style[ isOriginTop ? 'top' : 'bottom' ];
  748. var x = parseFloat( xValue );
  749. var y = parseFloat( yValue );
  750. // convert percent to pixels
  751. var layoutSize = this.layout.size;
  752. if ( xValue.indexOf('%') != -1 ) {
  753. x = ( x / 100 ) * layoutSize.width;
  754. }
  755. if ( yValue.indexOf('%') != -1 ) {
  756. y = ( y / 100 ) * layoutSize.height;
  757. }
  758. // clean up 'auto' or other non-integer values
  759. x = isNaN( x ) ? 0 : x;
  760. y = isNaN( y ) ? 0 : y;
  761. // remove padding from measurement
  762. x -= isOriginLeft ? layoutSize.paddingLeft : layoutSize.paddingRight;
  763. y -= isOriginTop ? layoutSize.paddingTop : layoutSize.paddingBottom;
  764. this.position.x = x;
  765. this.position.y = y;
  766. };
  767. // set settled position, apply padding
  768. proto.layoutPosition = function() {
  769. var layoutSize = this.layout.size;
  770. var style = {};
  771. var isOriginLeft = this.layout._getOption('originLeft');
  772. var isOriginTop = this.layout._getOption('originTop');
  773. // x
  774. var xPadding = isOriginLeft ? 'paddingLeft' : 'paddingRight';
  775. var xProperty = isOriginLeft ? 'left' : 'right';
  776. var xResetProperty = isOriginLeft ? 'right' : 'left';
  777. var x = this.position.x + layoutSize[ xPadding ];
  778. // set in percentage or pixels
  779. style[ xProperty ] = this.getXValue( x );
  780. // reset other property
  781. style[ xResetProperty ] = '';
  782. // y
  783. var yPadding = isOriginTop ? 'paddingTop' : 'paddingBottom';
  784. var yProperty = isOriginTop ? 'top' : 'bottom';
  785. var yResetProperty = isOriginTop ? 'bottom' : 'top';
  786. var y = this.position.y + layoutSize[ yPadding ];
  787. // set in percentage or pixels
  788. style[ yProperty ] = this.getYValue( y );
  789. // reset other property
  790. style[ yResetProperty ] = '';
  791. this.css( style );
  792. this.emitEvent( 'layout', [ this ] );
  793. };
  794. proto.getXValue = function( x ) {
  795. var isHorizontal = this.layout._getOption('horizontal');
  796. return this.layout.options.percentPosition && !isHorizontal ?
  797. ( ( x / this.layout.size.width ) * 100 ) + '%' : x + 'px';
  798. };
  799. proto.getYValue = function( y ) {
  800. var isHorizontal = this.layout._getOption('horizontal');
  801. return this.layout.options.percentPosition && isHorizontal ?
  802. ( ( y / this.layout.size.height ) * 100 ) + '%' : y + 'px';
  803. };
  804. proto._transitionTo = function( x, y ) {
  805. this.getPosition();
  806. // get current x & y from top/left
  807. var curX = this.position.x;
  808. var curY = this.position.y;
  809. var didNotMove = x == this.position.x && y == this.position.y;
  810. // save end position
  811. this.setPosition( x, y );
  812. // if did not move and not transitioning, just go to layout
  813. if ( didNotMove && !this.isTransitioning ) {
  814. this.layoutPosition();
  815. return;
  816. }
  817. var transX = x - curX;
  818. var transY = y - curY;
  819. var transitionStyle = {};
  820. transitionStyle.transform = this.getTranslate( transX, transY );
  821. this.transition({
  822. to: transitionStyle,
  823. onTransitionEnd: {
  824. transform: this.layoutPosition
  825. },
  826. isCleaning: true
  827. });
  828. };
  829. proto.getTranslate = function( x, y ) {
  830. // flip cooridinates if origin on right or bottom
  831. var isOriginLeft = this.layout._getOption('originLeft');
  832. var isOriginTop = this.layout._getOption('originTop');
  833. x = isOriginLeft ? x : -x;
  834. y = isOriginTop ? y : -y;
  835. return 'translate3d(' + x + 'px, ' + y + 'px, 0)';
  836. };
  837. // non transition + transform support
  838. proto.goTo = function( x, y ) {
  839. this.setPosition( x, y );
  840. this.layoutPosition();
  841. };
  842. proto.moveTo = proto._transitionTo;
  843. proto.setPosition = function( x, y ) {
  844. this.position.x = parseFloat( x );
  845. this.position.y = parseFloat( y );
  846. };
  847. // ----- transition ----- //
  848. /**
  849. * @param {Object} style - CSS
  850. * @param {Function} onTransitionEnd
  851. */
  852. // non transition, just trigger callback
  853. proto._nonTransition = function( args ) {
  854. this.css( args.to );
  855. if ( args.isCleaning ) {
  856. this._removeStyles( args.to );
  857. }
  858. for ( var prop in args.onTransitionEnd ) {
  859. args.onTransitionEnd[ prop ].call( this );
  860. }
  861. };
  862. /**
  863. * proper transition
  864. * @param {Object} args - arguments
  865. * @param {Object} to - style to transition to
  866. * @param {Object} from - style to start transition from
  867. * @param {Boolean} isCleaning - removes transition styles after transition
  868. * @param {Function} onTransitionEnd - callback
  869. */
  870. proto.transition = function( args ) {
  871. // redirect to nonTransition if no transition duration
  872. if ( !parseFloat( this.layout.options.transitionDuration ) ) {
  873. this._nonTransition( args );
  874. return;
  875. }
  876. var _transition = this._transn;
  877. // keep track of onTransitionEnd callback by css property
  878. for ( var prop in args.onTransitionEnd ) {
  879. _transition.onEnd[ prop ] = args.onTransitionEnd[ prop ];
  880. }
  881. // keep track of properties that are transitioning
  882. for ( prop in args.to ) {
  883. _transition.ingProperties[ prop ] = true;
  884. // keep track of properties to clean up when transition is done
  885. if ( args.isCleaning ) {
  886. _transition.clean[ prop ] = true;
  887. }
  888. }
  889. // set from styles
  890. if ( args.from ) {
  891. this.css( args.from );
  892. // force redraw. http://blog.alexmaccaw.com/css-transitions
  893. var h = this.element.offsetHeight;
  894. // hack for JSHint to hush about unused var
  895. h = null;
  896. }
  897. // enable transition
  898. this.enableTransition( args.to );
  899. // set styles that are transitioning
  900. this.css( args.to );
  901. this.isTransitioning = true;
  902. };
  903. // dash before all cap letters, including first for
  904. // WebkitTransform => -webkit-transform
  905. function toDashedAll( str ) {
  906. return str.replace( /([A-Z])/g, function( $1 ) {
  907. return '-' + $1.toLowerCase();
  908. });
  909. }
  910. var transitionProps = 'opacity,' + toDashedAll( transformProperty );
  911. proto.enableTransition = function(/* style */) {
  912. // HACK changing transitionProperty during a transition
  913. // will cause transition to jump
  914. if ( this.isTransitioning ) {
  915. return;
  916. }
  917. // make `transition: foo, bar, baz` from style object
  918. // HACK un-comment this when enableTransition can work
  919. // while a transition is happening
  920. // var transitionValues = [];
  921. // for ( var prop in style ) {
  922. // // dash-ify camelCased properties like WebkitTransition
  923. // prop = vendorProperties[ prop ] || prop;
  924. // transitionValues.push( toDashedAll( prop ) );
  925. // }
  926. // munge number to millisecond, to match stagger
  927. var duration = this.layout.options.transitionDuration;
  928. duration = typeof duration == 'number' ? duration + 'ms' : duration;
  929. // enable transition styles
  930. this.css({
  931. transitionProperty: transitionProps,
  932. transitionDuration: duration,
  933. transitionDelay: this.staggerDelay || 0
  934. });
  935. // listen for transition end event
  936. this.element.addEventListener( transitionEndEvent, this, false );
  937. };
  938. // ----- events ----- //
  939. proto.onwebkitTransitionEnd = function( event ) {
  940. this.ontransitionend( event );
  941. };
  942. proto.onotransitionend = function( event ) {
  943. this.ontransitionend( event );
  944. };
  945. // properties that I munge to make my life easier
  946. var dashedVendorProperties = {
  947. '-webkit-transform': 'transform'
  948. };
  949. proto.ontransitionend = function( event ) {
  950. // disregard bubbled events from children
  951. if ( event.target !== this.element ) {
  952. return;
  953. }
  954. var _transition = this._transn;
  955. // get property name of transitioned property, convert to prefix-free
  956. var propertyName = dashedVendorProperties[ event.propertyName ] || event.propertyName;
  957. // remove property that has completed transitioning
  958. delete _transition.ingProperties[ propertyName ];
  959. // check if any properties are still transitioning
  960. if ( isEmptyObj( _transition.ingProperties ) ) {
  961. // all properties have completed transitioning
  962. this.disableTransition();
  963. }
  964. // clean style
  965. if ( propertyName in _transition.clean ) {
  966. // clean up style
  967. this.element.style[ event.propertyName ] = '';
  968. delete _transition.clean[ propertyName ];
  969. }
  970. // trigger onTransitionEnd callback
  971. if ( propertyName in _transition.onEnd ) {
  972. var onTransitionEnd = _transition.onEnd[ propertyName ];
  973. onTransitionEnd.call( this );
  974. delete _transition.onEnd[ propertyName ];
  975. }
  976. this.emitEvent( 'transitionEnd', [ this ] );
  977. };
  978. proto.disableTransition = function() {
  979. this.removeTransitionStyles();
  980. this.element.removeEventListener( transitionEndEvent, this, false );
  981. this.isTransitioning = false;
  982. };
  983. /**
  984. * removes style property from element
  985. * @param {Object} style
  986. **/
  987. proto._removeStyles = function( style ) {
  988. // clean up transition styles
  989. var cleanStyle = {};
  990. for ( var prop in style ) {
  991. cleanStyle[ prop ] = '';
  992. }
  993. this.css( cleanStyle );
  994. };
  995. var cleanTransitionStyle = {
  996. transitionProperty: '',
  997. transitionDuration: '',
  998. transitionDelay: ''
  999. };
  1000. proto.removeTransitionStyles = function() {
  1001. // remove transition
  1002. this.css( cleanTransitionStyle );
  1003. };
  1004. // ----- stagger ----- //
  1005. proto.stagger = function( delay ) {
  1006. delay = isNaN( delay ) ? 0 : delay;
  1007. this.staggerDelay = delay + 'ms';
  1008. };
  1009. // ----- show/hide/remove ----- //
  1010. // remove element from DOM
  1011. proto.removeElem = function() {
  1012. this.element.parentNode.removeChild( this.element );
  1013. // remove display: none
  1014. this.css({ display: '' });
  1015. this.emitEvent( 'remove', [ this ] );
  1016. };
  1017. proto.remove = function() {
  1018. // just remove element if no transition support or no transition
  1019. if ( !transitionProperty || !parseFloat( this.layout.options.transitionDuration ) ) {
  1020. this.removeElem();
  1021. return;
  1022. }
  1023. // start transition
  1024. this.once( 'transitionEnd', function() {
  1025. this.removeElem();
  1026. });
  1027. this.hide();
  1028. };
  1029. proto.reveal = function() {
  1030. delete this.isHidden;
  1031. // remove display: none
  1032. this.css({ display: '' });
  1033. var options = this.layout.options;
  1034. var onTransitionEnd = {};
  1035. var transitionEndProperty = this.getHideRevealTransitionEndProperty('visibleStyle');
  1036. onTransitionEnd[ transitionEndProperty ] = this.onRevealTransitionEnd;
  1037. this.transition({
  1038. from: options.hiddenStyle,
  1039. to: options.visibleStyle,
  1040. isCleaning: true,
  1041. onTransitionEnd: onTransitionEnd
  1042. });
  1043. };
  1044. proto.onRevealTransitionEnd = function() {
  1045. // check if still visible
  1046. // during transition, item may have been hidden
  1047. if ( !this.isHidden ) {
  1048. this.emitEvent('reveal');
  1049. }
  1050. };
  1051. /**
  1052. * get style property use for hide/reveal transition end
  1053. * @param {String} styleProperty - hiddenStyle/visibleStyle
  1054. * @returns {String}
  1055. */
  1056. proto.getHideRevealTransitionEndProperty = function( styleProperty ) {
  1057. var optionStyle = this.layout.options[ styleProperty ];
  1058. // use opacity
  1059. if ( optionStyle.opacity ) {
  1060. return 'opacity';
  1061. }
  1062. // get first property
  1063. for ( var prop in optionStyle ) {
  1064. return prop;
  1065. }
  1066. };
  1067. proto.hide = function() {
  1068. // set flag
  1069. this.isHidden = true;
  1070. // remove display: none
  1071. this.css({ display: '' });
  1072. var options = this.layout.options;
  1073. var onTransitionEnd = {};
  1074. var transitionEndProperty = this.getHideRevealTransitionEndProperty('hiddenStyle');
  1075. onTransitionEnd[ transitionEndProperty ] = this.onHideTransitionEnd;
  1076. this.transition({
  1077. from: options.visibleStyle,
  1078. to: options.hiddenStyle,
  1079. // keep hidden stuff hidden
  1080. isCleaning: true,
  1081. onTransitionEnd: onTransitionEnd
  1082. });
  1083. };
  1084. proto.onHideTransitionEnd = function() {
  1085. // check if still hidden
  1086. // during transition, item may have been un-hidden
  1087. if ( this.isHidden ) {
  1088. this.css({ display: 'none' });
  1089. this.emitEvent('hide');
  1090. }
  1091. };
  1092. proto.destroy = function() {
  1093. this.css({
  1094. position: '',
  1095. left: '',
  1096. right: '',
  1097. top: '',
  1098. bottom: '',
  1099. transition: '',
  1100. transform: ''
  1101. });
  1102. };
  1103. return Item;
  1104. }));
  1105. /*!
  1106. * Outlayer v2.1.1
  1107. * the brains and guts of a layout library
  1108. * MIT license
  1109. */
  1110. ( function( window, factory ) {
  1111. 'use strict';
  1112. // universal module definition
  1113. /* jshint strict: false */ /* globals define, module, require */
  1114. if ( typeof define == 'function' && define.amd ) {
  1115. // AMD - RequireJS
  1116. define( 'outlayer/outlayer',[
  1117. 'ev-emitter/ev-emitter',
  1118. 'get-size/get-size',
  1119. 'fizzy-ui-utils/utils',
  1120. './item'
  1121. ],
  1122. function( EvEmitter, getSize, utils, Item ) {
  1123. return factory( window, EvEmitter, getSize, utils, Item);
  1124. }
  1125. );
  1126. } else if ( typeof module == 'object' && module.exports ) {
  1127. // CommonJS - Browserify, Webpack
  1128. module.exports = factory(
  1129. window,
  1130. require('ev-emitter'),
  1131. require('get-size'),
  1132. require('fizzy-ui-utils'),
  1133. require('./item')
  1134. );
  1135. } else {
  1136. // browser global
  1137. window.Outlayer = factory(
  1138. window,
  1139. window.EvEmitter,
  1140. window.getSize,
  1141. window.fizzyUIUtils,
  1142. window.Outlayer.Item
  1143. );
  1144. }
  1145. }( window, function factory( window, EvEmitter, getSize, utils, Item ) {
  1146. 'use strict';
  1147. // ----- vars ----- //
  1148. var console = window.console;
  1149. var jQuery = window.jQuery;
  1150. var noop = function() {};
  1151. // -------------------------- Outlayer -------------------------- //
  1152. // globally unique identifiers
  1153. var GUID = 0;
  1154. // internal store of all Outlayer intances
  1155. var instances = {};
  1156. /**
  1157. * @param {Element, String} element
  1158. * @param {Object} options
  1159. * @constructor
  1160. */
  1161. function Outlayer( element, options ) {
  1162. var queryElement = utils.getQueryElement( element );
  1163. if ( !queryElement ) {
  1164. if ( console ) {
  1165. console.error( 'Bad element for ' + this.constructor.namespace +
  1166. ': ' + ( queryElement || element ) );
  1167. }
  1168. return;
  1169. }
  1170. this.element = queryElement;
  1171. // add jQuery
  1172. if ( jQuery ) {
  1173. this.$element = jQuery( this.element );
  1174. }
  1175. // options
  1176. this.options = utils.extend( {}, this.constructor.defaults );
  1177. this.option( options );
  1178. // add id for Outlayer.getFromElement
  1179. var id = ++GUID;
  1180. this.element.outlayerGUID = id; // expando
  1181. instances[ id ] = this; // associate via id
  1182. // kick it off
  1183. this._create();
  1184. var isInitLayout = this._getOption('initLayout');
  1185. if ( isInitLayout ) {
  1186. this.layout();
  1187. }
  1188. }
  1189. // settings are for internal use only
  1190. Outlayer.namespace = 'outlayer';
  1191. Outlayer.Item = Item;
  1192. // default options
  1193. Outlayer.defaults = {
  1194. containerStyle: {
  1195. position: 'relative'
  1196. },
  1197. initLayout: true,
  1198. originLeft: true,
  1199. originTop: true,
  1200. resize: true,
  1201. resizeContainer: true,
  1202. // item options
  1203. transitionDuration: '0.4s',
  1204. hiddenStyle: {
  1205. opacity: 0,
  1206. transform: 'scale(0.001)'
  1207. },
  1208. visibleStyle: {
  1209. opacity: 1,
  1210. transform: 'scale(1)'
  1211. }
  1212. };
  1213. var proto = Outlayer.prototype;
  1214. // inherit EvEmitter
  1215. utils.extend( proto, EvEmitter.prototype );
  1216. /**
  1217. * set options
  1218. * @param {Object} opts
  1219. */
  1220. proto.option = function( opts ) {
  1221. utils.extend( this.options, opts );
  1222. };
  1223. /**
  1224. * get backwards compatible option value, check old name
  1225. */
  1226. proto._getOption = function( option ) {
  1227. var oldOption = this.constructor.compatOptions[ option ];
  1228. return oldOption && this.options[ oldOption ] !== undefined ?
  1229. this.options[ oldOption ] : this.options[ option ];
  1230. };
  1231. Outlayer.compatOptions = {
  1232. // currentName: oldName
  1233. initLayout: 'isInitLayout',
  1234. horizontal: 'isHorizontal',
  1235. layoutInstant: 'isLayoutInstant',
  1236. originLeft: 'isOriginLeft',
  1237. originTop: 'isOriginTop',
  1238. resize: 'isResizeBound',
  1239. resizeContainer: 'isResizingContainer'
  1240. };
  1241. proto._create = function() {
  1242. // get items from children
  1243. this.reloadItems();
  1244. // elements that affect layout, but are not laid out
  1245. this.stamps = [];
  1246. this.stamp( this.options.stamp );
  1247. // set container style
  1248. utils.extend( this.element.style, this.options.containerStyle );
  1249. // bind resize method
  1250. var canBindResize = this._getOption('resize');
  1251. if ( canBindResize ) {
  1252. this.bindResize();
  1253. }
  1254. };
  1255. // goes through all children again and gets bricks in proper order
  1256. proto.reloadItems = function() {
  1257. // collection of item elements
  1258. this.items = this._itemize( this.element.children );
  1259. };
  1260. /**
  1261. * turn elements into Outlayer.Items to be used in layout
  1262. * @param {Array or NodeList or HTMLElement} elems
  1263. * @returns {Array} items - collection of new Outlayer Items
  1264. */
  1265. proto._itemize = function( elems ) {
  1266. var itemElems = this._filterFindItemElements( elems );
  1267. var Item = this.constructor.Item;
  1268. // create new Outlayer Items for collection
  1269. var items = [];
  1270. for ( var i=0; i < itemElems.length; i++ ) {
  1271. var elem = itemElems[i];
  1272. var item = new Item( elem, this );
  1273. items.push( item );
  1274. }
  1275. return items;
  1276. };
  1277. /**
  1278. * get item elements to be used in layout
  1279. * @param {Array or NodeList or HTMLElement} elems
  1280. * @returns {Array} items - item elements
  1281. */
  1282. proto._filterFindItemElements = function( elems ) {
  1283. return utils.filterFindElements( elems, this.options.itemSelector );
  1284. };
  1285. /**
  1286. * getter method for getting item elements
  1287. * @returns {Array} elems - collection of item elements
  1288. */
  1289. proto.getItemElements = function() {
  1290. return this.items.map( function( item ) {
  1291. return item.element;
  1292. });
  1293. };
  1294. // ----- init & layout ----- //
  1295. /**
  1296. * lays out all items
  1297. */
  1298. proto.layout = function() {
  1299. this._resetLayout();
  1300. this._manageStamps();
  1301. // don't animate first layout
  1302. var layoutInstant = this._getOption('layoutInstant');
  1303. var isInstant = layoutInstant !== undefined ?
  1304. layoutInstant : !this._isLayoutInited;
  1305. this.layoutItems( this.items, isInstant );
  1306. // flag for initalized
  1307. this._isLayoutInited = true;
  1308. };
  1309. // _init is alias for layout
  1310. proto._init = proto.layout;
  1311. /**
  1312. * logic before any new layout
  1313. */
  1314. proto._resetLayout = function() {
  1315. this.getSize();
  1316. };
  1317. proto.getSize = function() {
  1318. this.size = getSize( this.element );
  1319. };
  1320. /**
  1321. * get measurement from option, for columnWidth, rowHeight, gutter
  1322. * if option is String -> get element from selector string, & get size of element
  1323. * if option is Element -> get size of element
  1324. * else use option as a number
  1325. *
  1326. * @param {String} measurement
  1327. * @param {String} size - width or height
  1328. * @private
  1329. */
  1330. proto._getMeasurement = function( measurement, size ) {
  1331. var option = this.options[ measurement ];
  1332. var elem;
  1333. if ( !option ) {
  1334. // default to 0
  1335. this[ measurement ] = 0;
  1336. } else {
  1337. // use option as an element
  1338. if ( typeof option == 'string' ) {
  1339. elem = this.element.querySelector( option );
  1340. } else if ( option instanceof HTMLElement ) {
  1341. elem = option;
  1342. }
  1343. // use size of element, if element
  1344. this[ measurement ] = elem ? getSize( elem )[ size ] : option;
  1345. }
  1346. };
  1347. /**
  1348. * layout a collection of item elements
  1349. * @api public
  1350. */
  1351. proto.layoutItems = function( items, isInstant ) {
  1352. items = this._getItemsForLayout( items );
  1353. this._layoutItems( items, isInstant );
  1354. this._postLayout();
  1355. };
  1356. /**
  1357. * get the items to be laid out
  1358. * you may want to skip over some items
  1359. * @param {Array} items
  1360. * @returns {Array} items
  1361. */
  1362. proto._getItemsForLayout = function( items ) {
  1363. return items.filter( function( item ) {
  1364. return !item.isIgnored;
  1365. });
  1366. };
  1367. /**
  1368. * layout items
  1369. * @param {Array} items
  1370. * @param {Boolean} isInstant
  1371. */
  1372. proto._layoutItems = function( items, isInstant ) {
  1373. this._emitCompleteOnItems( 'layout', items );
  1374. if ( !items || !items.length ) {
  1375. // no items, emit event with empty array
  1376. return;
  1377. }
  1378. var queue = [];
  1379. items.forEach( function( item ) {
  1380. // get x/y object from method
  1381. var position = this._getItemLayoutPosition( item );
  1382. // enqueue
  1383. position.item = item;
  1384. position.isInstant = isInstant || item.isLayoutInstant;
  1385. queue.push( position );
  1386. }, this );
  1387. this._processLayoutQueue( queue );
  1388. };
  1389. /**
  1390. * get item layout position
  1391. * @param {Outlayer.Item} item
  1392. * @returns {Object} x and y position
  1393. */
  1394. proto._getItemLayoutPosition = function( /* item */ ) {
  1395. return {
  1396. x: 0,
  1397. y: 0
  1398. };
  1399. };
  1400. /**
  1401. * iterate over array and position each item
  1402. * Reason being - separating this logic prevents 'layout invalidation'
  1403. * thx @paul_irish
  1404. * @param {Array} queue
  1405. */
  1406. proto._processLayoutQueue = function( queue ) {
  1407. this.updateStagger();
  1408. queue.forEach( function( obj, i ) {
  1409. this._positionItem( obj.item, obj.x, obj.y, obj.isInstant, i );
  1410. }, this );
  1411. };
  1412. // set stagger from option in milliseconds number
  1413. proto.updateStagger = function() {
  1414. var stagger = this.options.stagger;
  1415. if ( stagger === null || stagger === undefined ) {
  1416. this.stagger = 0;
  1417. return;
  1418. }
  1419. this.stagger = getMilliseconds( stagger );
  1420. return this.stagger;
  1421. };
  1422. /**
  1423. * Sets position of item in DOM
  1424. * @param {Outlayer.Item} item
  1425. * @param {Number} x - horizontal position
  1426. * @param {Number} y - vertical position
  1427. * @param {Boolean} isInstant - disables transitions
  1428. */
  1429. proto._positionItem = function( item, x, y, isInstant, i ) {
  1430. if ( isInstant ) {
  1431. // if not transition, just set CSS
  1432. item.goTo( x, y );
  1433. } else {
  1434. item.stagger( i * this.stagger );
  1435. item.moveTo( x, y );
  1436. }
  1437. };
  1438. /**
  1439. * Any logic you want to do after each layout,
  1440. * i.e. size the container
  1441. */
  1442. proto._postLayout = function() {
  1443. this.resizeContainer();
  1444. };
  1445. proto.resizeContainer = function() {
  1446. var isResizingContainer = this._getOption('resizeContainer');
  1447. if ( !isResizingContainer ) {
  1448. return;
  1449. }
  1450. var size = this._getContainerSize();
  1451. if ( size ) {
  1452. this._setContainerMeasure( size.width, true );
  1453. this._setContainerMeasure( size.height, false );
  1454. }
  1455. };
  1456. /**
  1457. * Sets width or height of container if returned
  1458. * @returns {Object} size
  1459. * @param {Number} width
  1460. * @param {Number} height
  1461. */
  1462. proto._getContainerSize = noop;
  1463. /**
  1464. * @param {Number} measure - size of width or height
  1465. * @param {Boolean} isWidth
  1466. */
  1467. proto._setContainerMeasure = function( measure, isWidth ) {
  1468. if ( measure === undefined ) {
  1469. return;
  1470. }
  1471. var elemSize = this.size;
  1472. // add padding and border width if border box
  1473. if ( elemSize.isBorderBox ) {
  1474. measure += isWidth ? elemSize.paddingLeft + elemSize.paddingRight +
  1475. elemSize.borderLeftWidth + elemSize.borderRightWidth :
  1476. elemSize.paddingBottom + elemSize.paddingTop +
  1477. elemSize.borderTopWidth + elemSize.borderBottomWidth;
  1478. }
  1479. measure = Math.max( measure, 0 );
  1480. this.element.style[ isWidth ? 'width' : 'height' ] = measure + 'px';
  1481. };
  1482. /**
  1483. * emit eventComplete on a collection of items events
  1484. * @param {String} eventName
  1485. * @param {Array} items - Outlayer.Items
  1486. */
  1487. proto._emitCompleteOnItems = function( eventName, items ) {
  1488. var _this = this;
  1489. function onComplete() {
  1490. _this.dispatchEvent( eventName + 'Complete', null, [ items ] );
  1491. }
  1492. var count = items.length;
  1493. if ( !items || !count ) {
  1494. onComplete();
  1495. return;
  1496. }
  1497. var doneCount = 0;
  1498. function tick() {
  1499. doneCount++;
  1500. if ( doneCount == count ) {
  1501. onComplete();
  1502. }
  1503. }
  1504. // bind callback
  1505. items.forEach( function( item ) {
  1506. item.once( eventName, tick );
  1507. });
  1508. };
  1509. /**
  1510. * emits events via EvEmitter and jQuery events
  1511. * @param {String} type - name of event
  1512. * @param {Event} event - original event
  1513. * @param {Array} args - extra arguments
  1514. */
  1515. proto.dispatchEvent = function( type, event, args ) {
  1516. // add original event to arguments
  1517. var emitArgs = event ? [ event ].concat( args ) : args;
  1518. this.emitEvent( type, emitArgs );
  1519. if ( jQuery ) {
  1520. // set this.$element
  1521. this.$element = this.$element || jQuery( this.element );
  1522. if ( event ) {
  1523. // create jQuery event
  1524. var $event = jQuery.Event( event );
  1525. $event.type = type;
  1526. this.$element.trigger( $event, args );
  1527. } else {
  1528. // just trigger with type if no event available
  1529. this.$element.trigger( type, args );
  1530. }
  1531. }
  1532. };
  1533. // -------------------------- ignore & stamps -------------------------- //
  1534. /**
  1535. * keep item in collection, but do not lay it out
  1536. * ignored items do not get skipped in layout
  1537. * @param {Element} elem
  1538. */
  1539. proto.ignore = function( elem ) {
  1540. var item = this.getItem( elem );
  1541. if ( item ) {
  1542. item.isIgnored = true;
  1543. }
  1544. };
  1545. /**
  1546. * return item to layout collection
  1547. * @param {Element} elem
  1548. */
  1549. proto.unignore = function( elem ) {
  1550. var item = this.getItem( elem );
  1551. if ( item ) {
  1552. delete item.isIgnored;
  1553. }
  1554. };
  1555. /**
  1556. * adds elements to stamps
  1557. * @param {NodeList, Array, Element, or String} elems
  1558. */
  1559. proto.stamp = function( elems ) {
  1560. elems = this._find( elems );
  1561. if ( !elems ) {
  1562. return;
  1563. }
  1564. this.stamps = this.stamps.concat( elems );
  1565. // ignore
  1566. elems.forEach( this.ignore, this );
  1567. };
  1568. /**
  1569. * removes elements to stamps
  1570. * @param {NodeList, Array, or Element} elems
  1571. */
  1572. proto.unstamp = function( elems ) {
  1573. elems = this._find( elems );
  1574. if ( !elems ){
  1575. return;
  1576. }
  1577. elems.forEach( function( elem ) {
  1578. // filter out removed stamp elements
  1579. utils.removeFrom( this.stamps, elem );
  1580. this.unignore( elem );
  1581. }, this );
  1582. };
  1583. /**
  1584. * finds child elements
  1585. * @param {NodeList, Array, Element, or String} elems
  1586. * @returns {Array} elems
  1587. */
  1588. proto._find = function( elems ) {
  1589. if ( !elems ) {
  1590. return;
  1591. }
  1592. // if string, use argument as selector string
  1593. if ( typeof elems == 'string' ) {
  1594. elems = this.element.querySelectorAll( elems );
  1595. }
  1596. elems = utils.makeArray( elems );
  1597. return elems;
  1598. };
  1599. proto._manageStamps = function() {
  1600. if ( !this.stamps || !this.stamps.length ) {
  1601. return;
  1602. }
  1603. this._getBoundingRect();
  1604. this.stamps.forEach( this._manageStamp, this );
  1605. };
  1606. // update boundingLeft / Top
  1607. proto._getBoundingRect = function() {
  1608. // get bounding rect for container element
  1609. var boundingRect = this.element.getBoundingClientRect();
  1610. var size = this.size;
  1611. this._boundingRect = {
  1612. left: boundingRect.left + size.paddingLeft + size.borderLeftWidth,
  1613. top: boundingRect.top + size.paddingTop + size.borderTopWidth,
  1614. right: boundingRect.right - ( size.paddingRight + size.borderRightWidth ),
  1615. bottom: boundingRect.bottom - ( size.paddingBottom + size.borderBottomWidth )
  1616. };
  1617. };
  1618. /**
  1619. * @param {Element} stamp
  1620. **/
  1621. proto._manageStamp = noop;
  1622. /**
  1623. * get x/y position of element relative to container element
  1624. * @param {Element} elem
  1625. * @returns {Object} offset - has left, top, right, bottom
  1626. */
  1627. proto._getElementOffset = function( elem ) {
  1628. var boundingRect = elem.getBoundingClientRect();
  1629. var thisRect = this._boundingRect;
  1630. var size = getSize( elem );
  1631. var offset = {
  1632. left: boundingRect.left - thisRect.left - size.marginLeft,
  1633. top: boundingRect.top - thisRect.top - size.marginTop,
  1634. right: thisRect.right - boundingRect.right - size.marginRight,
  1635. bottom: thisRect.bottom - boundingRect.bottom - size.marginBottom
  1636. };
  1637. return offset;
  1638. };
  1639. // -------------------------- resize -------------------------- //
  1640. // enable event handlers for listeners
  1641. // i.e. resize -> onresize
  1642. proto.handleEvent = utils.handleEvent;
  1643. /**
  1644. * Bind layout to window resizing
  1645. */
  1646. proto.bindResize = function() {
  1647. window.addEventListener( 'resize', this );
  1648. this.isResizeBound = true;
  1649. };
  1650. /**
  1651. * Unbind layout to window resizing
  1652. */
  1653. proto.unbindResize = function() {
  1654. window.removeEventListener( 'resize', this );
  1655. this.isResizeBound = false;
  1656. };
  1657. proto.onresize = function() {
  1658. this.resize();
  1659. };
  1660. utils.debounceMethod( Outlayer, 'onresize', 100 );
  1661. proto.resize = function() {
  1662. // don't trigger if size did not change
  1663. // or if resize was unbound. See #9
  1664. if ( !this.isResizeBound || !this.needsResizeLayout() ) {
  1665. return;
  1666. }
  1667. this.layout();
  1668. };
  1669. /**
  1670. * check if layout is needed post layout
  1671. * @returns Boolean
  1672. */
  1673. proto.needsResizeLayout = function() {
  1674. var size = getSize( this.element );
  1675. // check that this.size and size are there
  1676. // IE8 triggers resize on body size change, so they might not be
  1677. var hasSizes = this.size && size;
  1678. return hasSizes && size.innerWidth !== this.size.innerWidth;
  1679. };
  1680. // -------------------------- methods -------------------------- //
  1681. /**
  1682. * add items to Outlayer instance
  1683. * @param {Array or NodeList or Element} elems
  1684. * @returns {Array} items - Outlayer.Items
  1685. **/
  1686. proto.addItems = function( elems ) {
  1687. var items = this._itemize( elems );
  1688. // add items to collection
  1689. if ( items.length ) {
  1690. this.items = this.items.concat( items );
  1691. }
  1692. return items;
  1693. };
  1694. /**
  1695. * Layout newly-appended item elements
  1696. * @param {Array or NodeList or Element} elems
  1697. */
  1698. proto.appended = function( elems ) {
  1699. var items = this.addItems( elems );
  1700. if ( !items.length ) {
  1701. return;
  1702. }
  1703. // layout and reveal just the new items
  1704. this.layoutItems( items, true );
  1705. this.reveal( items );
  1706. };
  1707. /**
  1708. * Layout prepended elements
  1709. * @param {Array or NodeList or Element} elems
  1710. */
  1711. proto.prepended = function( elems ) {
  1712. var items = this._itemize( elems );
  1713. if ( !items.length ) {
  1714. return;
  1715. }
  1716. // add items to beginning of collection
  1717. var previousItems = this.items.slice(0);
  1718. this.items = items.concat( previousItems );
  1719. // start new layout
  1720. this._resetLayout();
  1721. this._manageStamps();
  1722. // layout new stuff without transition
  1723. this.layoutItems( items, true );
  1724. this.reveal( items );
  1725. // layout previous items
  1726. this.layoutItems( previousItems );
  1727. };
  1728. /**
  1729. * reveal a collection of items
  1730. * @param {Array of Outlayer.Items} items
  1731. */
  1732. proto.reveal = function( items ) {
  1733. this._emitCompleteOnItems( 'reveal', items );
  1734. if ( !items || !items.length ) {
  1735. return;
  1736. }
  1737. var stagger = this.updateStagger();
  1738. items.forEach( function( item, i ) {
  1739. item.stagger( i * stagger );
  1740. item.reveal();
  1741. });
  1742. };
  1743. /**
  1744. * hide a collection of items
  1745. * @param {Array of Outlayer.Items} items
  1746. */
  1747. proto.hide = function( items ) {
  1748. this._emitCompleteOnItems( 'hide', items );
  1749. if ( !items || !items.length ) {
  1750. return;
  1751. }
  1752. var stagger = this.updateStagger();
  1753. items.forEach( function( item, i ) {
  1754. item.stagger( i * stagger );
  1755. item.hide();
  1756. });
  1757. };
  1758. /**
  1759. * reveal item elements
  1760. * @param {Array}, {Element}, {NodeList} items
  1761. */
  1762. proto.revealItemElements = function( elems ) {
  1763. var items = this.getItems( elems );
  1764. this.reveal( items );
  1765. };
  1766. /**
  1767. * hide item elements
  1768. * @param {Array}, {Element}, {NodeList} items
  1769. */
  1770. proto.hideItemElements = function( elems ) {
  1771. var items = this.getItems( elems );
  1772. this.hide( items );
  1773. };
  1774. /**
  1775. * get Outlayer.Item, given an Element
  1776. * @param {Element} elem
  1777. * @param {Function} callback
  1778. * @returns {Outlayer.Item} item
  1779. */
  1780. proto.getItem = function( elem ) {
  1781. // loop through items to get the one that matches
  1782. for ( var i=0; i < this.items.length; i++ ) {
  1783. var item = this.items[i];
  1784. if ( item.element == elem ) {
  1785. // return item
  1786. return item;
  1787. }
  1788. }
  1789. };
  1790. /**
  1791. * get collection of Outlayer.Items, given Elements
  1792. * @param {Array} elems
  1793. * @returns {Array} items - Outlayer.Items
  1794. */
  1795. proto.getItems = function( elems ) {
  1796. elems = utils.makeArray( elems );
  1797. var items = [];
  1798. elems.forEach( function( elem ) {
  1799. var item = this.getItem( elem );
  1800. if ( item ) {
  1801. items.push( item );
  1802. }
  1803. }, this );
  1804. return items;
  1805. };
  1806. /**
  1807. * remove element(s) from instance and DOM
  1808. * @param {Array or NodeList or Element} elems
  1809. */
  1810. proto.remove = function( elems ) {
  1811. var removeItems = this.getItems( elems );
  1812. this._emitCompleteOnItems( 'remove', removeItems );
  1813. // bail if no items to remove
  1814. if ( !removeItems || !removeItems.length ) {
  1815. return;
  1816. }
  1817. removeItems.forEach( function( item ) {
  1818. item.remove();
  1819. // remove item from collection
  1820. utils.removeFrom( this.items, item );
  1821. }, this );
  1822. };
  1823. // ----- destroy ----- //
  1824. // remove and disable Outlayer instance
  1825. proto.destroy = function() {
  1826. // clean up dynamic styles
  1827. var style = this.element.style;
  1828. style.height = '';
  1829. style.position = '';
  1830. style.width = '';
  1831. // destroy items
  1832. this.items.forEach( function( item ) {
  1833. item.destroy();
  1834. });
  1835. this.unbindResize();
  1836. var id = this.element.outlayerGUID;
  1837. delete instances[ id ]; // remove reference to instance by id
  1838. delete this.element.outlayerGUID;
  1839. // remove data for jQuery
  1840. if ( jQuery ) {
  1841. jQuery.removeData( this.element, this.constructor.namespace );
  1842. }
  1843. };
  1844. // -------------------------- data -------------------------- //
  1845. /**
  1846. * get Outlayer instance from element
  1847. * @param {Element} elem
  1848. * @returns {Outlayer}
  1849. */
  1850. Outlayer.data = function( elem ) {
  1851. elem = utils.getQueryElement( elem );
  1852. var id = elem && elem.outlayerGUID;
  1853. return id && instances[ id ];
  1854. };
  1855. // -------------------------- create Outlayer class -------------------------- //
  1856. /**
  1857. * create a layout class
  1858. * @param {String} namespace
  1859. */
  1860. Outlayer.create = function( namespace, options ) {
  1861. // sub-class Outlayer
  1862. var Layout = subclass( Outlayer );
  1863. // apply new options and compatOptions
  1864. Layout.defaults = utils.extend( {}, Outlayer.defaults );
  1865. utils.extend( Layout.defaults, options );
  1866. Layout.compatOptions = utils.extend( {}, Outlayer.compatOptions );
  1867. Layout.namespace = namespace;
  1868. Layout.data = Outlayer.data;
  1869. // sub-class Item
  1870. Layout.Item = subclass( Item );
  1871. // -------------------------- declarative -------------------------- //
  1872. utils.htmlInit( Layout, namespace );
  1873. // -------------------------- jQuery bridge -------------------------- //
  1874. // make into jQuery plugin
  1875. if ( jQuery && jQuery.bridget ) {
  1876. jQuery.bridget( namespace, Layout );
  1877. }
  1878. return Layout;
  1879. };
  1880. function subclass( Parent ) {
  1881. function SubClass() {
  1882. Parent.apply( this, arguments );
  1883. }
  1884. SubClass.prototype = Object.create( Parent.prototype );
  1885. SubClass.prototype.constructor = SubClass;
  1886. return SubClass;
  1887. }
  1888. // ----- helpers ----- //
  1889. // how many milliseconds are in each unit
  1890. var msUnits = {
  1891. ms: 1,
  1892. s: 1000
  1893. };
  1894. // munge time-like parameter into millisecond number
  1895. // '0.4s' -> 40
  1896. function getMilliseconds( time ) {
  1897. if ( typeof time == 'number' ) {
  1898. return time;
  1899. }
  1900. var matches = time.match( /(^\d*\.?\d*)(\w*)/ );
  1901. var num = matches && matches[1];
  1902. var unit = matches && matches[2];
  1903. if ( !num.length ) {
  1904. return 0;
  1905. }
  1906. num = parseFloat( num );
  1907. var mult = msUnits[ unit ] || 1;
  1908. return num * mult;
  1909. }
  1910. // ----- fin ----- //
  1911. // back in global
  1912. Outlayer.Item = Item;
  1913. return Outlayer;
  1914. }));
  1915. /**
  1916. * Isotope Item
  1917. **/
  1918. ( function( window, factory ) {
  1919. // universal module definition
  1920. /* jshint strict: false */ /*globals define, module, require */
  1921. if ( typeof define == 'function' && define.amd ) {
  1922. // AMD
  1923. define( 'isotope-layout/js/item',[
  1924. 'outlayer/outlayer'
  1925. ],
  1926. factory );
  1927. } else if ( typeof module == 'object' && module.exports ) {
  1928. // CommonJS
  1929. module.exports = factory(
  1930. require('outlayer')
  1931. );
  1932. } else {
  1933. // browser global
  1934. window.Isotope = window.Isotope || {};
  1935. window.Isotope.Item = factory(
  1936. window.Outlayer
  1937. );
  1938. }
  1939. }( window, function factory( Outlayer ) {
  1940. 'use strict';
  1941. // -------------------------- Item -------------------------- //
  1942. // sub-class Outlayer Item
  1943. function Item() {
  1944. Outlayer.Item.apply( this, arguments );
  1945. }
  1946. var proto = Item.prototype = Object.create( Outlayer.Item.prototype );
  1947. var _create = proto._create;
  1948. proto._create = function() {
  1949. // assign id, used for original-order sorting
  1950. this.id = this.layout.itemGUID++;
  1951. _create.call( this );
  1952. this.sortData = {};
  1953. };
  1954. proto.updateSortData = function() {
  1955. if ( this.isIgnored ) {
  1956. return;
  1957. }
  1958. // default sorters
  1959. this.sortData.id = this.id;
  1960. // for backward compatibility
  1961. this.sortData['original-order'] = this.id;
  1962. this.sortData.random = Math.random();
  1963. // go thru getSortData obj and apply the sorters
  1964. var getSortData = this.layout.options.getSortData;
  1965. var sorters = this.layout._sorters;
  1966. for ( var key in getSortData ) {
  1967. var sorter = sorters[ key ];
  1968. this.sortData[ key ] = sorter( this.element, this );
  1969. }
  1970. };
  1971. var _destroy = proto.destroy;
  1972. proto.destroy = function() {
  1973. // call super
  1974. _destroy.apply( this, arguments );
  1975. // reset display, #741
  1976. this.css({
  1977. display: ''
  1978. });
  1979. };
  1980. return Item;
  1981. }));
  1982. /**
  1983. * Isotope LayoutMode
  1984. */
  1985. ( function( window, factory ) {
  1986. // universal module definition
  1987. /* jshint strict: false */ /*globals define, module, require */
  1988. if ( typeof define == 'function' && define.amd ) {
  1989. // AMD
  1990. define( 'isotope-layout/js/layout-mode',[
  1991. 'get-size/get-size',
  1992. 'outlayer/outlayer'
  1993. ],
  1994. factory );
  1995. } else if ( typeof module == 'object' && module.exports ) {
  1996. // CommonJS
  1997. module.exports = factory(
  1998. require('get-size'),
  1999. require('outlayer')
  2000. );
  2001. } else {
  2002. // browser global
  2003. window.Isotope = window.Isotope || {};
  2004. window.Isotope.LayoutMode = factory(
  2005. window.getSize,
  2006. window.Outlayer
  2007. );
  2008. }
  2009. }( window, function factory( getSize, Outlayer ) {
  2010. 'use strict';
  2011. // layout mode class
  2012. function LayoutMode( isotope ) {
  2013. this.isotope = isotope;
  2014. // link properties
  2015. if ( isotope ) {
  2016. this.options = isotope.options[ this.namespace ];
  2017. this.element = isotope.element;
  2018. this.items = isotope.filteredItems;
  2019. this.size = isotope.size;
  2020. }
  2021. }
  2022. var proto = LayoutMode.prototype;
  2023. /**
  2024. * some methods should just defer to default Outlayer method
  2025. * and reference the Isotope instance as `this`
  2026. **/
  2027. var facadeMethods = [
  2028. '_resetLayout',
  2029. '_getItemLayoutPosition',
  2030. '_manageStamp',
  2031. '_getContainerSize',
  2032. '_getElementOffset',
  2033. 'needsResizeLayout',
  2034. '_getOption'
  2035. ];
  2036. facadeMethods.forEach( function( methodName ) {
  2037. proto[ methodName ] = function() {
  2038. return Outlayer.prototype[ methodName ].apply( this.isotope, arguments );
  2039. };
  2040. });
  2041. // ----- ----- //
  2042. // for horizontal layout modes, check vertical size
  2043. proto.needsVerticalResizeLayout = function() {
  2044. // don't trigger if size did not change
  2045. var size = getSize( this.isotope.element );
  2046. // check that this.size and size are there
  2047. // IE8 triggers resize on body size change, so they might not be
  2048. var hasSizes = this.isotope.size && size;
  2049. return hasSizes && size.innerHeight != this.isotope.size.innerHeight;
  2050. };
  2051. // ----- measurements ----- //
  2052. proto._getMeasurement = function() {
  2053. this.isotope._getMeasurement.apply( this, arguments );
  2054. };
  2055. proto.getColumnWidth = function() {
  2056. this.getSegmentSize( 'column', 'Width' );
  2057. };
  2058. proto.getRowHeight = function() {
  2059. this.getSegmentSize( 'row', 'Height' );
  2060. };
  2061. /**
  2062. * get columnWidth or rowHeight
  2063. * segment: 'column' or 'row'
  2064. * size 'Width' or 'Height'
  2065. **/
  2066. proto.getSegmentSize = function( segment, size ) {
  2067. var segmentName = segment + size;
  2068. var outerSize = 'outer' + size;
  2069. // columnWidth / outerWidth // rowHeight / outerHeight
  2070. this._getMeasurement( segmentName, outerSize );
  2071. // got rowHeight or columnWidth, we can chill
  2072. if ( this[ segmentName ] ) {
  2073. return;
  2074. }
  2075. // fall back to item of first element
  2076. var firstItemSize = this.getFirstItemSize();
  2077. this[ segmentName ] = firstItemSize && firstItemSize[ outerSize ] ||
  2078. // or size of container
  2079. this.isotope.size[ 'inner' + size ];
  2080. };
  2081. proto.getFirstItemSize = function() {
  2082. var firstItem = this.isotope.filteredItems[0];
  2083. return firstItem && firstItem.element && getSize( firstItem.element );
  2084. };
  2085. // ----- methods that should reference isotope ----- //
  2086. proto.layout = function() {
  2087. this.isotope.layout.apply( this.isotope, arguments );
  2088. };
  2089. proto.getSize = function() {
  2090. this.isotope.getSize();
  2091. this.size = this.isotope.size;
  2092. };
  2093. // -------------------------- create -------------------------- //
  2094. LayoutMode.modes = {};
  2095. LayoutMode.create = function( namespace, options ) {
  2096. function Mode() {
  2097. LayoutMode.apply( this, arguments );
  2098. }
  2099. Mode.prototype = Object.create( proto );
  2100. Mode.prototype.constructor = Mode;
  2101. // default options
  2102. if ( options ) {
  2103. Mode.options = options;
  2104. }
  2105. Mode.prototype.namespace = namespace;
  2106. // register in Isotope
  2107. LayoutMode.modes[ namespace ] = Mode;
  2108. return Mode;
  2109. };
  2110. return LayoutMode;
  2111. }));
  2112. /*!
  2113. * Masonry v4.2.1
  2114. * Cascading grid layout library
  2115. * https://masonry.desandro.com
  2116. * MIT License
  2117. * by David DeSandro
  2118. */
  2119. ( function( window, factory ) {
  2120. // universal module definition
  2121. /* jshint strict: false */ /*globals define, module, require */
  2122. if ( typeof define == 'function' && define.amd ) {
  2123. // AMD
  2124. define( 'masonry-layout/masonry',[
  2125. 'outlayer/outlayer',
  2126. 'get-size/get-size'
  2127. ],
  2128. factory );
  2129. } else if ( typeof module == 'object' && module.exports ) {
  2130. // CommonJS
  2131. module.exports = factory(
  2132. require('outlayer'),
  2133. require('get-size')
  2134. );
  2135. } else {
  2136. // browser global
  2137. window.Masonry = factory(
  2138. window.Outlayer,
  2139. window.getSize
  2140. );
  2141. }
  2142. }( window, function factory( Outlayer, getSize ) {
  2143. // -------------------------- masonryDefinition -------------------------- //
  2144. // create an Outlayer layout class
  2145. var Masonry = Outlayer.create('masonry');
  2146. // isFitWidth -> fitWidth
  2147. Masonry.compatOptions.fitWidth = 'isFitWidth';
  2148. var proto = Masonry.prototype;
  2149. proto._resetLayout = function() {
  2150. this.getSize();
  2151. this._getMeasurement( 'columnWidth', 'outerWidth' );
  2152. this._getMeasurement( 'gutter', 'outerWidth' );
  2153. this.measureColumns();
  2154. // reset column Y
  2155. this.colYs = [];
  2156. for ( var i=0; i < this.cols; i++ ) {
  2157. this.colYs.push( 0 );
  2158. }
  2159. this.maxY = 0;
  2160. this.horizontalColIndex = 0;
  2161. };
  2162. proto.measureColumns = function() {
  2163. this.getContainerWidth();
  2164. // if columnWidth is 0, default to outerWidth of first item
  2165. if ( !this.columnWidth ) {
  2166. var firstItem = this.items[0];
  2167. var firstItemElem = firstItem && firstItem.element;
  2168. // columnWidth fall back to item of first element
  2169. this.columnWidth = firstItemElem && getSize( firstItemElem ).outerWidth ||
  2170. // if first elem has no width, default to size of container
  2171. this.containerWidth;
  2172. }
  2173. var columnWidth = this.columnWidth += this.gutter;
  2174. // calculate columns
  2175. var containerWidth = this.containerWidth + this.gutter;
  2176. var cols = containerWidth / columnWidth;
  2177. // fix rounding errors, typically with gutters
  2178. var excess = columnWidth - containerWidth % columnWidth;
  2179. // if overshoot is less than a pixel, round up, otherwise floor it
  2180. var mathMethod = excess && excess < 1 ? 'round' : 'floor';
  2181. cols = Math[ mathMethod ]( cols );
  2182. this.cols = Math.max( cols, 1 );
  2183. };
  2184. proto.getContainerWidth = function() {
  2185. // container is parent if fit width
  2186. var isFitWidth = this._getOption('fitWidth');
  2187. var container = isFitWidth ? this.element.parentNode : this.element;
  2188. // check that this.size and size are there
  2189. // IE8 triggers resize on body size change, so they might not be
  2190. var size = getSize( container );
  2191. this.containerWidth = size && size.innerWidth;
  2192. };
  2193. proto._getItemLayoutPosition = function( item ) {
  2194. item.getSize();
  2195. // how many columns does this brick span
  2196. var remainder = item.size.outerWidth % this.columnWidth;
  2197. var mathMethod = remainder && remainder < 1 ? 'round' : 'ceil';
  2198. // round if off by 1 pixel, otherwise use ceil
  2199. var colSpan = Math[ mathMethod ]( item.size.outerWidth / this.columnWidth );
  2200. colSpan = Math.min( colSpan, this.cols );
  2201. // use horizontal or top column position
  2202. var colPosMethod = this.options.horizontalOrder ?
  2203. '_getHorizontalColPosition' : '_getTopColPosition';
  2204. var colPosition = this[ colPosMethod ]( colSpan, item );
  2205. // position the brick
  2206. var position = {
  2207. x: this.columnWidth * colPosition.col,
  2208. y: colPosition.y
  2209. };
  2210. // apply setHeight to necessary columns
  2211. var setHeight = colPosition.y + item.size.outerHeight;
  2212. var setMax = colSpan + colPosition.col;
  2213. for ( var i = colPosition.col; i < setMax; i++ ) {
  2214. this.colYs[i] = setHeight;
  2215. }
  2216. return position;
  2217. };
  2218. proto._getTopColPosition = function( colSpan ) {
  2219. var colGroup = this._getTopColGroup( colSpan );
  2220. // get the minimum Y value from the columns
  2221. var minimumY = Math.min.apply( Math, colGroup );
  2222. return {
  2223. col: colGroup.indexOf( minimumY ),
  2224. y: minimumY,
  2225. };
  2226. };
  2227. /**
  2228. * @param {Number} colSpan - number of columns the element spans
  2229. * @returns {Array} colGroup
  2230. */
  2231. proto._getTopColGroup = function( colSpan ) {
  2232. if ( colSpan < 2 ) {
  2233. // if brick spans only one column, use all the column Ys
  2234. return this.colYs;
  2235. }
  2236. var colGroup = [];
  2237. // how many different places could this brick fit horizontally
  2238. var groupCount = this.cols + 1 - colSpan;
  2239. // for each group potential horizontal position
  2240. for ( var i = 0; i < groupCount; i++ ) {
  2241. colGroup[i] = this._getColGroupY( i, colSpan );
  2242. }
  2243. return colGroup;
  2244. };
  2245. proto._getColGroupY = function( col, colSpan ) {
  2246. if ( colSpan < 2 ) {
  2247. return this.colYs[ col ];
  2248. }
  2249. // make an array of colY values for that one group
  2250. var groupColYs = this.colYs.slice( col, col + colSpan );
  2251. // and get the max value of the array
  2252. return Math.max.apply( Math, groupColYs );
  2253. };
  2254. // get column position based on horizontal index. #873
  2255. proto._getHorizontalColPosition = function( colSpan, item ) {
  2256. var col = this.horizontalColIndex % this.cols;
  2257. var isOver = colSpan > 1 && col + colSpan > this.cols;
  2258. // shift to next row if item can't fit on current row
  2259. col = isOver ? 0 : col;
  2260. // don't let zero-size items take up space
  2261. var hasSize = item.size.outerWidth && item.size.outerHeight;
  2262. this.horizontalColIndex = hasSize ? col + colSpan : this.horizontalColIndex;
  2263. return {
  2264. col: col,
  2265. y: this._getColGroupY( col, colSpan ),
  2266. };
  2267. };
  2268. proto._manageStamp = function( stamp ) {
  2269. var stampSize = getSize( stamp );
  2270. var offset = this._getElementOffset( stamp );
  2271. // get the columns that this stamp affects
  2272. var isOriginLeft = this._getOption('originLeft');
  2273. var firstX = isOriginLeft ? offset.left : offset.right;
  2274. var lastX = firstX + stampSize.outerWidth;
  2275. var firstCol = Math.floor( firstX / this.columnWidth );
  2276. firstCol = Math.max( 0, firstCol );
  2277. var lastCol = Math.floor( lastX / this.columnWidth );
  2278. // lastCol should not go over if multiple of columnWidth #425
  2279. lastCol -= lastX % this.columnWidth ? 0 : 1;
  2280. lastCol = Math.min( this.cols - 1, lastCol );
  2281. // set colYs to bottom of the stamp
  2282. var isOriginTop = this._getOption('originTop');
  2283. var stampMaxY = ( isOriginTop ? offset.top : offset.bottom ) +
  2284. stampSize.outerHeight;
  2285. for ( var i = firstCol; i <= lastCol; i++ ) {
  2286. this.colYs[i] = Math.max( stampMaxY, this.colYs[i] );
  2287. }
  2288. };
  2289. proto._getContainerSize = function() {
  2290. this.maxY = Math.max.apply( Math, this.colYs );
  2291. var size = {
  2292. height: this.maxY
  2293. };
  2294. if ( this._getOption('fitWidth') ) {
  2295. size.width = this._getContainerFitWidth();
  2296. }
  2297. return size;
  2298. };
  2299. proto._getContainerFitWidth = function() {
  2300. var unusedCols = 0;
  2301. // count unused columns
  2302. var i = this.cols;
  2303. while ( --i ) {
  2304. if ( this.colYs[i] !== 0 ) {
  2305. break;
  2306. }
  2307. unusedCols++;
  2308. }
  2309. // fit container to columns that have been used
  2310. return ( this.cols - unusedCols ) * this.columnWidth - this.gutter;
  2311. };
  2312. proto.needsResizeLayout = function() {
  2313. var previousWidth = this.containerWidth;
  2314. this.getContainerWidth();
  2315. return previousWidth != this.containerWidth;
  2316. };
  2317. return Masonry;
  2318. }));
  2319. /*!
  2320. * Masonry layout mode
  2321. * sub-classes Masonry
  2322. * https://masonry.desandro.com
  2323. */
  2324. ( function( window, factory ) {
  2325. // universal module definition
  2326. /* jshint strict: false */ /*globals define, module, require */
  2327. if ( typeof define == 'function' && define.amd ) {
  2328. // AMD
  2329. define( 'isotope-layout/js/layout-modes/masonry',[
  2330. '../layout-mode',
  2331. 'masonry-layout/masonry'
  2332. ],
  2333. factory );
  2334. } else if ( typeof module == 'object' && module.exports ) {
  2335. // CommonJS
  2336. module.exports = factory(
  2337. require('../layout-mode'),
  2338. require('masonry-layout')
  2339. );
  2340. } else {
  2341. // browser global
  2342. factory(
  2343. window.Isotope.LayoutMode,
  2344. window.Masonry
  2345. );
  2346. }
  2347. }( window, function factory( LayoutMode, Masonry ) {
  2348. 'use strict';
  2349. // -------------------------- masonryDefinition -------------------------- //
  2350. // create an Outlayer layout class
  2351. var MasonryMode = LayoutMode.create('masonry');
  2352. var proto = MasonryMode.prototype;
  2353. var keepModeMethods = {
  2354. _getElementOffset: true,
  2355. layout: true,
  2356. _getMeasurement: true
  2357. };
  2358. // inherit Masonry prototype
  2359. for ( var method in Masonry.prototype ) {
  2360. // do not inherit mode methods
  2361. if ( !keepModeMethods[ method ] ) {
  2362. proto[ method ] = Masonry.prototype[ method ];
  2363. }
  2364. }
  2365. var measureColumns = proto.measureColumns;
  2366. proto.measureColumns = function() {
  2367. // set items, used if measuring first item
  2368. this.items = this.isotope.filteredItems;
  2369. measureColumns.call( this );
  2370. };
  2371. // point to mode options for fitWidth
  2372. var _getOption = proto._getOption;
  2373. proto._getOption = function( option ) {
  2374. if ( option == 'fitWidth' ) {
  2375. return this.options.isFitWidth !== undefined ?
  2376. this.options.isFitWidth : this.options.fitWidth;
  2377. }
  2378. return _getOption.apply( this.isotope, arguments );
  2379. };
  2380. return MasonryMode;
  2381. }));
  2382. /**
  2383. * fitRows layout mode
  2384. */
  2385. ( function( window, factory ) {
  2386. // universal module definition
  2387. /* jshint strict: false */ /*globals define, module, require */
  2388. if ( typeof define == 'function' && define.amd ) {
  2389. // AMD
  2390. define( 'isotope-layout/js/layout-modes/fit-rows',[
  2391. '../layout-mode'
  2392. ],
  2393. factory );
  2394. } else if ( typeof exports == 'object' ) {
  2395. // CommonJS
  2396. module.exports = factory(
  2397. require('../layout-mode')
  2398. );
  2399. } else {
  2400. // browser global
  2401. factory(
  2402. window.Isotope.LayoutMode
  2403. );
  2404. }
  2405. }( window, function factory( LayoutMode ) {
  2406. 'use strict';
  2407. var FitRows = LayoutMode.create('fitRows');
  2408. var proto = FitRows.prototype;
  2409. proto._resetLayout = function() {
  2410. this.x = 0;
  2411. this.y = 0;
  2412. this.maxY = 0;
  2413. this._getMeasurement( 'gutter', 'outerWidth' );
  2414. };
  2415. proto._getItemLayoutPosition = function( item ) {
  2416. item.getSize();
  2417. var itemWidth = item.size.outerWidth + this.gutter;
  2418. // if this element cannot fit in the current row
  2419. var containerWidth = this.isotope.size.innerWidth + this.gutter;
  2420. if ( this.x !== 0 && itemWidth + this.x > containerWidth ) {
  2421. this.x = 0;
  2422. this.y = this.maxY;
  2423. }
  2424. var position = {
  2425. x: this.x,
  2426. y: this.y
  2427. };
  2428. this.maxY = Math.max( this.maxY, this.y + item.size.outerHeight );
  2429. this.x += itemWidth;
  2430. return position;
  2431. };
  2432. proto._getContainerSize = function() {
  2433. return { height: this.maxY };
  2434. };
  2435. return FitRows;
  2436. }));
  2437. /**
  2438. * vertical layout mode
  2439. */
  2440. ( function( window, factory ) {
  2441. // universal module definition
  2442. /* jshint strict: false */ /*globals define, module, require */
  2443. if ( typeof define == 'function' && define.amd ) {
  2444. // AMD
  2445. define( 'isotope-layout/js/layout-modes/vertical',[
  2446. '../layout-mode'
  2447. ],
  2448. factory );
  2449. } else if ( typeof module == 'object' && module.exports ) {
  2450. // CommonJS
  2451. module.exports = factory(
  2452. require('../layout-mode')
  2453. );
  2454. } else {
  2455. // browser global
  2456. factory(
  2457. window.Isotope.LayoutMode
  2458. );
  2459. }
  2460. }( window, function factory( LayoutMode ) {
  2461. 'use strict';
  2462. var Vertical = LayoutMode.create( 'vertical', {
  2463. horizontalAlignment: 0
  2464. });
  2465. var proto = Vertical.prototype;
  2466. proto._resetLayout = function() {
  2467. this.y = 0;
  2468. };
  2469. proto._getItemLayoutPosition = function( item ) {
  2470. item.getSize();
  2471. var x = ( this.isotope.size.innerWidth - item.size.outerWidth ) *
  2472. this.options.horizontalAlignment;
  2473. var y = this.y;
  2474. this.y += item.size.outerHeight;
  2475. return { x: x, y: y };
  2476. };
  2477. proto._getContainerSize = function() {
  2478. return { height: this.y };
  2479. };
  2480. return Vertical;
  2481. }));
  2482. /*!
  2483. * Isotope v3.0.6
  2484. *
  2485. * Licensed GPLv3 for open source use
  2486. * or Isotope Commercial License for commercial use
  2487. *
  2488. * https://isotope.metafizzy.co
  2489. * Copyright 2010-2018 Metafizzy
  2490. */
  2491. ( function( window, factory ) {
  2492. // universal module definition
  2493. /* jshint strict: false */ /*globals define, module, require */
  2494. if ( typeof define == 'function' && define.amd ) {
  2495. // AMD
  2496. define( [
  2497. 'outlayer/outlayer',
  2498. 'get-size/get-size',
  2499. 'desandro-matches-selector/matches-selector',
  2500. 'fizzy-ui-utils/utils',
  2501. 'isotope-layout/js/item',
  2502. 'isotope-layout/js/layout-mode',
  2503. // include default layout modes
  2504. 'isotope-layout/js/layout-modes/masonry',
  2505. 'isotope-layout/js/layout-modes/fit-rows',
  2506. 'isotope-layout/js/layout-modes/vertical'
  2507. ],
  2508. function( Outlayer, getSize, matchesSelector, utils, Item, LayoutMode ) {
  2509. return factory( window, Outlayer, getSize, matchesSelector, utils, Item, LayoutMode );
  2510. });
  2511. } else if ( typeof module == 'object' && module.exports ) {
  2512. // CommonJS
  2513. module.exports = factory(
  2514. window,
  2515. require('outlayer'),
  2516. require('get-size'),
  2517. require('desandro-matches-selector'),
  2518. require('fizzy-ui-utils'),
  2519. require('isotope-layout/js/item'),
  2520. require('isotope-layout/js/layout-mode'),
  2521. // include default layout modes
  2522. require('isotope-layout/js/layout-modes/masonry'),
  2523. require('isotope-layout/js/layout-modes/fit-rows'),
  2524. require('isotope-layout/js/layout-modes/vertical')
  2525. );
  2526. } else {
  2527. // browser global
  2528. window.Isotope = factory(
  2529. window,
  2530. window.Outlayer,
  2531. window.getSize,
  2532. window.matchesSelector,
  2533. window.fizzyUIUtils,
  2534. window.Isotope.Item,
  2535. window.Isotope.LayoutMode
  2536. );
  2537. }
  2538. }( window, function factory( window, Outlayer, getSize, matchesSelector, utils,
  2539. Item, LayoutMode ) {
  2540. // -------------------------- vars -------------------------- //
  2541. var jQuery = window.jQuery;
  2542. // -------------------------- helpers -------------------------- //
  2543. var trim = String.prototype.trim ?
  2544. function( str ) {
  2545. return str.trim();
  2546. } :
  2547. function( str ) {
  2548. return str.replace( /^\s+|\s+$/g, '' );
  2549. };
  2550. // -------------------------- isotopeDefinition -------------------------- //
  2551. // create an Outlayer layout class
  2552. var Isotope = Outlayer.create( 'isotope', {
  2553. layoutMode: 'masonry',
  2554. isJQueryFiltering: true,
  2555. sortAscending: true
  2556. });
  2557. Isotope.Item = Item;
  2558. Isotope.LayoutMode = LayoutMode;
  2559. var proto = Isotope.prototype;
  2560. proto._create = function() {
  2561. this.itemGUID = 0;
  2562. // functions that sort items
  2563. this._sorters = {};
  2564. this._getSorters();
  2565. // call super
  2566. Outlayer.prototype._create.call( this );
  2567. // create layout modes
  2568. this.modes = {};
  2569. // start filteredItems with all items
  2570. this.filteredItems = this.items;
  2571. // keep of track of sortBys
  2572. this.sortHistory = [ 'original-order' ];
  2573. // create from registered layout modes
  2574. for ( var name in LayoutMode.modes ) {
  2575. this._initLayoutMode( name );
  2576. }
  2577. };
  2578. proto.reloadItems = function() {
  2579. // reset item ID counter
  2580. this.itemGUID = 0;
  2581. // call super
  2582. Outlayer.prototype.reloadItems.call( this );
  2583. };
  2584. proto._itemize = function() {
  2585. var items = Outlayer.prototype._itemize.apply( this, arguments );
  2586. // assign ID for original-order
  2587. for ( var i=0; i < items.length; i++ ) {
  2588. var item = items[i];
  2589. item.id = this.itemGUID++;
  2590. }
  2591. this._updateItemsSortData( items );
  2592. return items;
  2593. };
  2594. // -------------------------- layout -------------------------- //
  2595. proto._initLayoutMode = function( name ) {
  2596. var Mode = LayoutMode.modes[ name ];
  2597. // set mode options
  2598. // HACK extend initial options, back-fill in default options
  2599. var initialOpts = this.options[ name ] || {};
  2600. this.options[ name ] = Mode.options ?
  2601. utils.extend( Mode.options, initialOpts ) : initialOpts;
  2602. // init layout mode instance
  2603. this.modes[ name ] = new Mode( this );
  2604. };
  2605. proto.layout = function() {
  2606. // if first time doing layout, do all magic
  2607. if ( !this._isLayoutInited && this._getOption('initLayout') ) {
  2608. this.arrange();
  2609. return;
  2610. }
  2611. this._layout();
  2612. };
  2613. // private method to be used in layout() & magic()
  2614. proto._layout = function() {
  2615. // don't animate first layout
  2616. var isInstant = this._getIsInstant();
  2617. // layout flow
  2618. this._resetLayout();
  2619. this._manageStamps();
  2620. this.layoutItems( this.filteredItems, isInstant );
  2621. // flag for initalized
  2622. this._isLayoutInited = true;
  2623. };
  2624. // filter + sort + layout
  2625. proto.arrange = function( opts ) {
  2626. // set any options pass
  2627. this.option( opts );
  2628. this._getIsInstant();
  2629. // filter, sort, and layout
  2630. // filter
  2631. var filtered = this._filter( this.items );
  2632. this.filteredItems = filtered.matches;
  2633. this._bindArrangeComplete();
  2634. if ( this._isInstant ) {
  2635. this._noTransition( this._hideReveal, [ filtered ] );
  2636. } else {
  2637. this._hideReveal( filtered );
  2638. }
  2639. this._sort();
  2640. this._layout();
  2641. };
  2642. // alias to _init for main plugin method
  2643. proto._init = proto.arrange;
  2644. proto._hideReveal = function( filtered ) {
  2645. this.reveal( filtered.needReveal );
  2646. this.hide( filtered.needHide );
  2647. };
  2648. // HACK
  2649. // Don't animate/transition first layout
  2650. // Or don't animate/transition other layouts
  2651. proto._getIsInstant = function() {
  2652. var isLayoutInstant = this._getOption('layoutInstant');
  2653. var isInstant = isLayoutInstant !== undefined ? isLayoutInstant :
  2654. !this._isLayoutInited;
  2655. this._isInstant = isInstant;
  2656. return isInstant;
  2657. };
  2658. // listen for layoutComplete, hideComplete and revealComplete
  2659. // to trigger arrangeComplete
  2660. proto._bindArrangeComplete = function() {
  2661. // listen for 3 events to trigger arrangeComplete
  2662. var isLayoutComplete, isHideComplete, isRevealComplete;
  2663. var _this = this;
  2664. function arrangeParallelCallback() {
  2665. if ( isLayoutComplete && isHideComplete && isRevealComplete ) {
  2666. _this.dispatchEvent( 'arrangeComplete', null, [ _this.filteredItems ] );
  2667. }
  2668. }
  2669. this.once( 'layoutComplete', function() {
  2670. isLayoutComplete = true;
  2671. arrangeParallelCallback();
  2672. });
  2673. this.once( 'hideComplete', function() {
  2674. isHideComplete = true;
  2675. arrangeParallelCallback();
  2676. });
  2677. this.once( 'revealComplete', function() {
  2678. isRevealComplete = true;
  2679. arrangeParallelCallback();
  2680. });
  2681. };
  2682. // -------------------------- filter -------------------------- //
  2683. proto._filter = function( items ) {
  2684. var filter = this.options.filter;
  2685. filter = filter || '*';
  2686. var matches = [];
  2687. var hiddenMatched = [];
  2688. var visibleUnmatched = [];
  2689. var test = this._getFilterTest( filter );
  2690. // test each item
  2691. for ( var i=0; i < items.length; i++ ) {
  2692. var item = items[i];
  2693. if ( item.isIgnored ) {
  2694. continue;
  2695. }
  2696. // add item to either matched or unmatched group
  2697. var isMatched = test( item );
  2698. // item.isFilterMatched = isMatched;
  2699. // add to matches if its a match
  2700. if ( isMatched ) {
  2701. matches.push( item );
  2702. }
  2703. // add to additional group if item needs to be hidden or revealed
  2704. if ( isMatched && item.isHidden ) {
  2705. hiddenMatched.push( item );
  2706. } else if ( !isMatched && !item.isHidden ) {
  2707. visibleUnmatched.push( item );
  2708. }
  2709. }
  2710. // return collections of items to be manipulated
  2711. return {
  2712. matches: matches,
  2713. needReveal: hiddenMatched,
  2714. needHide: visibleUnmatched
  2715. };
  2716. };
  2717. // get a jQuery, function, or a matchesSelector test given the filter
  2718. proto._getFilterTest = function( filter ) {
  2719. if ( jQuery && this.options.isJQueryFiltering ) {
  2720. // use jQuery
  2721. return function( item ) {
  2722. return jQuery( item.element ).is( filter );
  2723. };
  2724. }
  2725. if ( typeof filter == 'function' ) {
  2726. // use filter as function
  2727. return function( item ) {
  2728. return filter( item.element );
  2729. };
  2730. }
  2731. // default, use filter as selector string
  2732. return function( item ) {
  2733. return matchesSelector( item.element, filter );
  2734. };
  2735. };
  2736. // -------------------------- sorting -------------------------- //
  2737. /**
  2738. * @params {Array} elems
  2739. * @public
  2740. */
  2741. proto.updateSortData = function( elems ) {
  2742. // get items
  2743. var items;
  2744. if ( elems ) {
  2745. elems = utils.makeArray( elems );
  2746. items = this.getItems( elems );
  2747. } else {
  2748. // update all items if no elems provided
  2749. items = this.items;
  2750. }
  2751. this._getSorters();
  2752. this._updateItemsSortData( items );
  2753. };
  2754. proto._getSorters = function() {
  2755. var getSortData = this.options.getSortData;
  2756. for ( var key in getSortData ) {
  2757. var sorter = getSortData[ key ];
  2758. this._sorters[ key ] = mungeSorter( sorter );
  2759. }
  2760. };
  2761. /**
  2762. * @params {Array} items - of Isotope.Items
  2763. * @private
  2764. */
  2765. proto._updateItemsSortData = function( items ) {
  2766. // do not update if no items
  2767. var len = items && items.length;
  2768. for ( var i=0; len && i < len; i++ ) {
  2769. var item = items[i];
  2770. item.updateSortData();
  2771. }
  2772. };
  2773. // ----- munge sorter ----- //
  2774. // encapsulate this, as we just need mungeSorter
  2775. // other functions in here are just for munging
  2776. var mungeSorter = ( function() {
  2777. // add a magic layer to sorters for convienent shorthands
  2778. // `.foo-bar` will use the text of .foo-bar querySelector
  2779. // `[foo-bar]` will use attribute
  2780. // you can also add parser
  2781. // `.foo-bar parseInt` will parse that as a number
  2782. function mungeSorter( sorter ) {
  2783. // if not a string, return function or whatever it is
  2784. if ( typeof sorter != 'string' ) {
  2785. return sorter;
  2786. }
  2787. // parse the sorter string
  2788. var args = trim( sorter ).split(' ');
  2789. var query = args[0];
  2790. // check if query looks like [an-attribute]
  2791. var attrMatch = query.match( /^\[(.+)\]$/ );
  2792. var attr = attrMatch && attrMatch[1];
  2793. var getValue = getValueGetter( attr, query );
  2794. // use second argument as a parser
  2795. var parser = Isotope.sortDataParsers[ args[1] ];
  2796. // parse the value, if there was a parser
  2797. sorter = parser ? function( elem ) {
  2798. return elem && parser( getValue( elem ) );
  2799. } :
  2800. // otherwise just return value
  2801. function( elem ) {
  2802. return elem && getValue( elem );
  2803. };
  2804. return sorter;
  2805. }
  2806. // get an attribute getter, or get text of the querySelector
  2807. function getValueGetter( attr, query ) {
  2808. // if query looks like [foo-bar], get attribute
  2809. if ( attr ) {
  2810. return function getAttribute( elem ) {
  2811. return elem.getAttribute( attr );
  2812. };
  2813. }
  2814. // otherwise, assume its a querySelector, and get its text
  2815. return function getChildText( elem ) {
  2816. var child = elem.querySelector( query );
  2817. return child && child.textContent;
  2818. };
  2819. }
  2820. return mungeSorter;
  2821. })();
  2822. // parsers used in getSortData shortcut strings
  2823. Isotope.sortDataParsers = {
  2824. 'parseInt': function( val ) {
  2825. return parseInt( val, 10 );
  2826. },
  2827. 'parseFloat': function( val ) {
  2828. return parseFloat( val );
  2829. }
  2830. };
  2831. // ----- sort method ----- //
  2832. // sort filteredItem order
  2833. proto._sort = function() {
  2834. if ( !this.options.sortBy ) {
  2835. return;
  2836. }
  2837. // keep track of sortBy History
  2838. var sortBys = utils.makeArray( this.options.sortBy );
  2839. if ( !this._getIsSameSortBy( sortBys ) ) {
  2840. // concat all sortBy and sortHistory, add to front, oldest goes in last
  2841. this.sortHistory = sortBys.concat( this.sortHistory );
  2842. }
  2843. // sort magic
  2844. var itemSorter = getItemSorter( this.sortHistory, this.options.sortAscending );
  2845. this.filteredItems.sort( itemSorter );
  2846. };
  2847. // check if sortBys is same as start of sortHistory
  2848. proto._getIsSameSortBy = function( sortBys ) {
  2849. for ( var i=0; i < sortBys.length; i++ ) {
  2850. if ( sortBys[i] != this.sortHistory[i] ) {
  2851. return false;
  2852. }
  2853. }
  2854. return true;
  2855. };
  2856. // returns a function used for sorting
  2857. function getItemSorter( sortBys, sortAsc ) {
  2858. return function sorter( itemA, itemB ) {
  2859. // cycle through all sortKeys
  2860. for ( var i = 0; i < sortBys.length; i++ ) {
  2861. var sortBy = sortBys[i];
  2862. var a = itemA.sortData[ sortBy ];
  2863. var b = itemB.sortData[ sortBy ];
  2864. if ( a > b || a < b ) {
  2865. // if sortAsc is an object, use the value given the sortBy key
  2866. var isAscending = sortAsc[ sortBy ] !== undefined ? sortAsc[ sortBy ] : sortAsc;
  2867. var direction = isAscending ? 1 : -1;
  2868. return ( a > b ? 1 : -1 ) * direction;
  2869. }
  2870. }
  2871. return 0;
  2872. };
  2873. }
  2874. // -------------------------- methods -------------------------- //
  2875. // get layout mode
  2876. proto._mode = function() {
  2877. var layoutMode = this.options.layoutMode;
  2878. var mode = this.modes[ layoutMode ];
  2879. if ( !mode ) {
  2880. // TODO console.error
  2881. throw new Error( 'No layout mode: ' + layoutMode );
  2882. }
  2883. // HACK sync mode's options
  2884. // any options set after init for layout mode need to be synced
  2885. mode.options = this.options[ layoutMode ];
  2886. return mode;
  2887. };
  2888. proto._resetLayout = function() {
  2889. // trigger original reset layout
  2890. Outlayer.prototype._resetLayout.call( this );
  2891. this._mode()._resetLayout();
  2892. };
  2893. proto._getItemLayoutPosition = function( item ) {
  2894. return this._mode()._getItemLayoutPosition( item );
  2895. };
  2896. proto._manageStamp = function( stamp ) {
  2897. this._mode()._manageStamp( stamp );
  2898. };
  2899. proto._getContainerSize = function() {
  2900. return this._mode()._getContainerSize();
  2901. };
  2902. proto.needsResizeLayout = function() {
  2903. return this._mode().needsResizeLayout();
  2904. };
  2905. // -------------------------- adding & removing -------------------------- //
  2906. // HEADS UP overwrites default Outlayer appended
  2907. proto.appended = function( elems ) {
  2908. var items = this.addItems( elems );
  2909. if ( !items.length ) {
  2910. return;
  2911. }
  2912. // filter, layout, reveal new items
  2913. var filteredItems = this._filterRevealAdded( items );
  2914. // add to filteredItems
  2915. this.filteredItems = this.filteredItems.concat( filteredItems );
  2916. };
  2917. // HEADS UP overwrites default Outlayer prepended
  2918. proto.prepended = function( elems ) {
  2919. var items = this._itemize( elems );
  2920. if ( !items.length ) {
  2921. return;
  2922. }
  2923. // start new layout
  2924. this._resetLayout();
  2925. this._manageStamps();
  2926. // filter, layout, reveal new items
  2927. var filteredItems = this._filterRevealAdded( items );
  2928. // layout previous items
  2929. this.layoutItems( this.filteredItems );
  2930. // add to items and filteredItems
  2931. this.filteredItems = filteredItems.concat( this.filteredItems );
  2932. this.items = items.concat( this.items );
  2933. };
  2934. proto._filterRevealAdded = function( items ) {
  2935. var filtered = this._filter( items );
  2936. this.hide( filtered.needHide );
  2937. // reveal all new items
  2938. this.reveal( filtered.matches );
  2939. // layout new items, no transition
  2940. this.layoutItems( filtered.matches, true );
  2941. return filtered.matches;
  2942. };
  2943. /**
  2944. * Filter, sort, and layout newly-appended item elements
  2945. * @param {Array or NodeList or Element} elems
  2946. */
  2947. proto.insert = function( elems ) {
  2948. var items = this.addItems( elems );
  2949. if ( !items.length ) {
  2950. return;
  2951. }
  2952. // append item elements
  2953. var i, item;
  2954. var len = items.length;
  2955. for ( i=0; i < len; i++ ) {
  2956. item = items[i];
  2957. this.element.appendChild( item.element );
  2958. }
  2959. // filter new stuff
  2960. var filteredInsertItems = this._filter( items ).matches;
  2961. // set flag
  2962. for ( i=0; i < len; i++ ) {
  2963. items[i].isLayoutInstant = true;
  2964. }
  2965. this.arrange();
  2966. // reset flag
  2967. for ( i=0; i < len; i++ ) {
  2968. delete items[i].isLayoutInstant;
  2969. }
  2970. this.reveal( filteredInsertItems );
  2971. };
  2972. var _remove = proto.remove;
  2973. proto.remove = function( elems ) {
  2974. elems = utils.makeArray( elems );
  2975. var removeItems = this.getItems( elems );
  2976. // do regular thing
  2977. _remove.call( this, elems );
  2978. // bail if no items to remove
  2979. var len = removeItems && removeItems.length;
  2980. // remove elems from filteredItems
  2981. for ( var i=0; len && i < len; i++ ) {
  2982. var item = removeItems[i];
  2983. // remove item from collection
  2984. utils.removeFrom( this.filteredItems, item );
  2985. }
  2986. };
  2987. proto.shuffle = function() {
  2988. // update random sortData
  2989. for ( var i=0; i < this.items.length; i++ ) {
  2990. var item = this.items[i];
  2991. item.sortData.random = Math.random();
  2992. }
  2993. this.options.sortBy = 'random';
  2994. this._sort();
  2995. this._layout();
  2996. };
  2997. /**
  2998. * trigger fn without transition
  2999. * kind of hacky to have this in the first place
  3000. * @param {Function} fn
  3001. * @param {Array} args
  3002. * @returns ret
  3003. * @private
  3004. */
  3005. proto._noTransition = function( fn, args ) {
  3006. // save transitionDuration before disabling
  3007. var transitionDuration = this.options.transitionDuration;
  3008. // disable transition
  3009. this.options.transitionDuration = 0;
  3010. // do it
  3011. var returnValue = fn.apply( this, args );
  3012. // re-enable transition for reveal
  3013. this.options.transitionDuration = transitionDuration;
  3014. return returnValue;
  3015. };
  3016. // ----- helper methods ----- //
  3017. /**
  3018. * getter method for getting filtered item elements
  3019. * @returns {Array} elems - collection of item elements
  3020. */
  3021. proto.getFilteredItemElements = function() {
  3022. return this.filteredItems.map( function( item ) {
  3023. return item.element;
  3024. });
  3025. };
  3026. // ----- ----- //
  3027. return Isotope;
  3028. }));