isotope.pkgd.js 88 KB

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