masonry.pkgd.min.js 92 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911
  1. /*!
  2. * Masonry PACKAGED v3.1.4
  3. * Cascading grid layout library
  4. * http://masonry.desandro.com
  5. * MIT License
  6. * by David DeSandro
  7. */
  8. /**
  9. * Mike Davis - Added "getItems" method
  10. * - Fixed bug in "measureColumns" method which didn't take into
  11. * account hidden items.
  12. * 2/28/2014
  13. */
  14. /**
  15. * Bridget makes jQuery widgets
  16. * v1.0.1
  17. */
  18. (function (window) {
  19. // -------------------------- utils -------------------------- //
  20. var slice = Array.prototype.slice;
  21. function noop() { }
  22. // -------------------------- definition -------------------------- //
  23. function defineBridget($) {
  24. // bail if no jQuery
  25. if (!$) {
  26. return;
  27. }
  28. // -------------------------- addOptionMethod -------------------------- //
  29. /**
  30. * adds option method -> $().plugin('option', {...})
  31. * @param {Function} PluginClass - constructor class
  32. */
  33. function addOptionMethod(PluginClass) {
  34. // don't overwrite original option method
  35. if (PluginClass.prototype.option) {
  36. return;
  37. }
  38. // option setter
  39. PluginClass.prototype.option = function (opts) {
  40. // bail out if not an object
  41. if (!$.isPlainObject(opts)) {
  42. return;
  43. }
  44. this.options = $.extend(true, this.options, opts);
  45. };
  46. }
  47. // -------------------------- plugin bridge -------------------------- //
  48. // helper function for logging errors
  49. // $.error breaks jQuery chaining
  50. var logError = typeof console === 'undefined' ? noop :
  51. function (message) {
  52. console.error(message);
  53. };
  54. /**
  55. * jQuery plugin bridge, access methods like $elem.plugin('method')
  56. * @param {String} namespace - plugin name
  57. * @param {Function} PluginClass - constructor class
  58. */
  59. function bridge(namespace, PluginClass) {
  60. // add to jQuery fn namespace
  61. $.fn[namespace] = function (options) {
  62. if (typeof options === 'string') {
  63. // call plugin method when first argument is a string
  64. // get arguments for method
  65. var args = slice.call(arguments, 1);
  66. for (var i = 0, len = this.length; i < len; i++) {
  67. var elem = this[i];
  68. var instance = $.data(elem, namespace);
  69. if (!instance) {
  70. logError("cannot call methods on " + namespace + " prior to initialization; " +
  71. "attempted to call '" + options + "'");
  72. continue;
  73. }
  74. if (!$.isFunction(instance[options]) || options.charAt(0) === '_') {
  75. logError("no such method '" + options + "' for " + namespace + " instance");
  76. continue;
  77. }
  78. // trigger method with arguments
  79. var returnValue = instance[options].apply(instance, args);
  80. // break look and return first value if provided
  81. if (returnValue !== undefined) {
  82. return returnValue;
  83. }
  84. }
  85. // return this if no return value
  86. return this;
  87. } else {
  88. return this.each(function () {
  89. var instance = $.data(this, namespace);
  90. if (instance) {
  91. // apply options & init
  92. instance.option(options);
  93. instance._init();
  94. } else {
  95. // initialize new instance
  96. instance = new PluginClass(this, options);
  97. $.data(this, namespace, instance);
  98. }
  99. });
  100. }
  101. };
  102. }
  103. // -------------------------- bridget -------------------------- //
  104. /**
  105. * converts a Prototypical class into a proper jQuery plugin
  106. * the class must have a ._init method
  107. * @param {String} namespace - plugin name, used in $().pluginName
  108. * @param {Function} PluginClass - constructor class
  109. */
  110. $.bridget = function (namespace, PluginClass) {
  111. addOptionMethod(PluginClass);
  112. bridge(namespace, PluginClass);
  113. };
  114. return $.bridget;
  115. }
  116. // transport
  117. if (typeof define === 'function' && define.amd) {
  118. // AMD
  119. define('jquery-bridget/jquery.bridget', ['jquery'], defineBridget);
  120. } else {
  121. // get jquery from browser global
  122. defineBridget(window.jQuery);
  123. }
  124. })(window);
  125. /*!
  126. * eventie v1.0.5
  127. * event binding helper
  128. * eventie.bind( elem, 'click', myFn )
  129. * eventie.unbind( elem, 'click', myFn )
  130. * MIT license
  131. */
  132. /*jshint browser: true, undef: true, unused: true */
  133. /*global define: false, module: false */
  134. (function (window) {
  135. var docElem = document.documentElement;
  136. var bind = function () { };
  137. function getIEEvent(obj) {
  138. var event = window.event;
  139. // add event.target
  140. event.target = event.target || event.srcElement || obj;
  141. return event;
  142. }
  143. if (docElem.addEventListener) {
  144. bind = function (obj, type, fn) {
  145. obj.addEventListener(type, fn, false);
  146. };
  147. } else if (docElem.attachEvent) {
  148. bind = function (obj, type, fn) {
  149. obj[type + fn] = fn.handleEvent ?
  150. function () {
  151. var event = getIEEvent(obj);
  152. fn.handleEvent.call(fn, event);
  153. } :
  154. function () {
  155. var event = getIEEvent(obj);
  156. fn.call(obj, event);
  157. };
  158. obj.attachEvent("on" + type, obj[type + fn]);
  159. };
  160. }
  161. var unbind = function () { };
  162. if (docElem.removeEventListener) {
  163. unbind = function (obj, type, fn) {
  164. obj.removeEventListener(type, fn, false);
  165. };
  166. } else if (docElem.detachEvent) {
  167. unbind = function (obj, type, fn) {
  168. obj.detachEvent("on" + type, obj[type + fn]);
  169. try {
  170. delete obj[type + fn];
  171. } catch (err) {
  172. // can't delete window object properties
  173. obj[type + fn] = undefined;
  174. }
  175. };
  176. }
  177. var eventie = {
  178. bind: bind,
  179. unbind: unbind
  180. };
  181. // ----- module definition ----- //
  182. if (typeof define === 'function' && define.amd) {
  183. // AMD
  184. define('eventie/eventie', eventie);
  185. } else if (typeof exports === 'object') {
  186. // CommonJS
  187. module.exports = eventie;
  188. } else {
  189. // browser global
  190. window.eventie = eventie;
  191. }
  192. })(this);
  193. /*!
  194. * docReady
  195. * Cross browser DOMContentLoaded event emitter
  196. */
  197. /*jshint browser: true, strict: true, undef: true, unused: true*/
  198. /*global define: false */
  199. (function (window) {
  200. var document = window.document;
  201. // collection of functions to be triggered on ready
  202. var queue = [];
  203. function docReady(fn) {
  204. // throw out non-functions
  205. if (typeof fn !== 'function') {
  206. return;
  207. }
  208. if (docReady.isReady) {
  209. // ready now, hit it
  210. fn();
  211. } else {
  212. // queue function when ready
  213. queue.push(fn);
  214. }
  215. }
  216. docReady.isReady = false;
  217. // triggered on various doc ready events
  218. function init(event) {
  219. // bail if IE8 document is not ready just yet
  220. var isIE8NotReady = event.type === 'readystatechange' && document.readyState !== 'complete';
  221. if (docReady.isReady || isIE8NotReady) {
  222. return;
  223. }
  224. docReady.isReady = true;
  225. // process queue
  226. for (var i = 0, len = queue.length; i < len; i++) {
  227. var fn = queue[i];
  228. fn();
  229. }
  230. }
  231. function defineDocReady(eventie) {
  232. eventie.bind(document, 'DOMContentLoaded', init);
  233. eventie.bind(document, 'readystatechange', init);
  234. eventie.bind(window, 'load', init);
  235. return docReady;
  236. }
  237. // transport
  238. if (typeof define === 'function' && define.amd) {
  239. // AMD
  240. // if RequireJS, then doc is already ready
  241. docReady.isReady = typeof requirejs === 'function';
  242. define('doc-ready/doc-ready', ['eventie/eventie'], defineDocReady);
  243. } else {
  244. // browser global
  245. window.docReady = defineDocReady(window.eventie);
  246. }
  247. })(this);
  248. /*!
  249. * EventEmitter v4.2.7 - git.io/ee
  250. * Oliver Caldwell
  251. * MIT license
  252. * @preserve
  253. */
  254. (function () {
  255. /**
  256. * Class for managing events.
  257. * Can be extended to provide event functionality in other classes.
  258. *
  259. * @class EventEmitter Manages event registering and emitting.
  260. */
  261. function EventEmitter() { }
  262. // Shortcuts to improve speed and size
  263. var proto = EventEmitter.prototype;
  264. var exports = this;
  265. var originalGlobalValue = exports.EventEmitter;
  266. /**
  267. * Finds the index of the listener for the event in it's storage array.
  268. *
  269. * @param {Function[]} listeners Array of listeners to search through.
  270. * @param {Function} listener Method to look for.
  271. * @return {Number} Index of the specified listener, -1 if not found
  272. * @api private
  273. */
  274. function indexOfListener(listeners, listener) {
  275. var i = listeners.length;
  276. while (i--) {
  277. if (listeners[i].listener === listener) {
  278. return i;
  279. }
  280. }
  281. return -1;
  282. }
  283. /**
  284. * Alias a method while keeping the context correct, to allow for overwriting of target method.
  285. *
  286. * @param {String} name The name of the target method.
  287. * @return {Function} The aliased method
  288. * @api private
  289. */
  290. function alias(name) {
  291. return function aliasClosure() {
  292. return this[name].apply(this, arguments);
  293. };
  294. }
  295. /**
  296. * Returns the listener array for the specified event.
  297. * Will initialise the event object and listener arrays if required.
  298. * Will return an object if you use a regex search. The object contains keys for each matched event. So /ba[rz]/ might return an object containing bar and baz. But only if you have either defined them with defineEvent or added some listeners to them.
  299. * Each property in the object response is an array of listener functions.
  300. *
  301. * @param {String|RegExp} evt Name of the event to return the listeners from.
  302. * @return {Function[]|Object} All listener functions for the event.
  303. */
  304. proto.getListeners = function getListeners(evt) {
  305. var events = this._getEvents();
  306. var response;
  307. var key;
  308. // Return a concatenated array of all matching events if
  309. // the selector is a regular expression.
  310. if (evt instanceof RegExp) {
  311. response = {};
  312. for (key in events) {
  313. if (events.hasOwnProperty(key) && evt.test(key)) {
  314. response[key] = events[key];
  315. }
  316. }
  317. }
  318. else {
  319. response = events[evt] || (events[evt] = []);
  320. }
  321. return response;
  322. };
  323. /**
  324. * Takes a list of listener objects and flattens it into a list of listener functions.
  325. *
  326. * @param {Object[]} listeners Raw listener objects.
  327. * @return {Function[]} Just the listener functions.
  328. */
  329. proto.flattenListeners = function flattenListeners(listeners) {
  330. var flatListeners = [];
  331. var i;
  332. for (i = 0; i < listeners.length; i += 1) {
  333. flatListeners.push(listeners[i].listener);
  334. }
  335. return flatListeners;
  336. };
  337. /**
  338. * Fetches the requested listeners via getListeners but will always return the results inside an object. This is mainly for internal use but others may find it useful.
  339. *
  340. * @param {String|RegExp} evt Name of the event to return the listeners from.
  341. * @return {Object} All listener functions for an event in an object.
  342. */
  343. proto.getListenersAsObject = function getListenersAsObject(evt) {
  344. var listeners = this.getListeners(evt);
  345. var response;
  346. if (listeners instanceof Array) {
  347. response = {};
  348. response[evt] = listeners;
  349. }
  350. return response || listeners;
  351. };
  352. /**
  353. * Adds a listener function to the specified event.
  354. * The listener will not be added if it is a duplicate.
  355. * If the listener returns true then it will be removed after it is called.
  356. * If you pass a regular expression as the event name then the listener will be added to all events that match it.
  357. *
  358. * @param {String|RegExp} evt Name of the event to attach the listener to.
  359. * @param {Function} listener Method to be called when the event is emitted. If the function returns true then it will be removed after calling.
  360. * @return {Object} Current instance of EventEmitter for chaining.
  361. */
  362. proto.addListener = function addListener(evt, listener) {
  363. var listeners = this.getListenersAsObject(evt);
  364. var listenerIsWrapped = typeof listener === 'object';
  365. var key;
  366. for (key in listeners) {
  367. if (listeners.hasOwnProperty(key) && indexOfListener(listeners[key], listener) === -1) {
  368. listeners[key].push(listenerIsWrapped ? listener : {
  369. listener: listener,
  370. once: false
  371. });
  372. }
  373. }
  374. return this;
  375. };
  376. /**
  377. * Alias of addListener
  378. */
  379. proto.on = alias('addListener');
  380. /**
  381. * Semi-alias of addListener. It will add a listener that will be
  382. * automatically removed after it's first execution.
  383. *
  384. * @param {String|RegExp} evt Name of the event to attach the listener to.
  385. * @param {Function} listener Method to be called when the event is emitted. If the function returns true then it will be removed after calling.
  386. * @return {Object} Current instance of EventEmitter for chaining.
  387. */
  388. proto.addOnceListener = function addOnceListener(evt, listener) {
  389. return this.addListener(evt, {
  390. listener: listener,
  391. once: true
  392. });
  393. };
  394. /**
  395. * Alias of addOnceListener.
  396. */
  397. proto.once = alias('addOnceListener');
  398. /**
  399. * Defines an event name. This is required if you want to use a regex to add a listener to multiple events at once. If you don't do this then how do you expect it to know what event to add to? Should it just add to every possible match for a regex? No. That is scary and bad.
  400. * You need to tell it what event names should be matched by a regex.
  401. *
  402. * @param {String} evt Name of the event to create.
  403. * @return {Object} Current instance of EventEmitter for chaining.
  404. */
  405. proto.defineEvent = function defineEvent(evt) {
  406. this.getListeners(evt);
  407. return this;
  408. };
  409. /**
  410. * Uses defineEvent to define multiple events.
  411. *
  412. * @param {String[]} evts An array of event names to define.
  413. * @return {Object} Current instance of EventEmitter for chaining.
  414. */
  415. proto.defineEvents = function defineEvents(evts) {
  416. for (var i = 0; i < evts.length; i += 1) {
  417. this.defineEvent(evts[i]);
  418. }
  419. return this;
  420. };
  421. /**
  422. * Removes a listener function from the specified event.
  423. * When passed a regular expression as the event name, it will remove the listener from all events that match it.
  424. *
  425. * @param {String|RegExp} evt Name of the event to remove the listener from.
  426. * @param {Function} listener Method to remove from the event.
  427. * @return {Object} Current instance of EventEmitter for chaining.
  428. */
  429. proto.removeListener = function removeListener(evt, listener) {
  430. var listeners = this.getListenersAsObject(evt);
  431. var index;
  432. var key;
  433. for (key in listeners) {
  434. if (listeners.hasOwnProperty(key)) {
  435. index = indexOfListener(listeners[key], listener);
  436. if (index !== -1) {
  437. listeners[key].splice(index, 1);
  438. }
  439. }
  440. }
  441. return this;
  442. };
  443. /**
  444. * Alias of removeListener
  445. */
  446. proto.off = alias('removeListener');
  447. /**
  448. * Adds listeners in bulk using the manipulateListeners method.
  449. * If you pass an object as the second argument you can add to multiple events at once. The object should contain key value pairs of events and listeners or listener arrays. You can also pass it an event name and an array of listeners to be added.
  450. * You can also pass it a regular expression to add the array of listeners to all events that match it.
  451. * Yeah, this function does quite a bit. That's probably a bad thing.
  452. *
  453. * @param {String|Object|RegExp} evt An event name if you will pass an array of listeners next. An object if you wish to add to multiple events at once.
  454. * @param {Function[]} [listeners] An optional array of listener functions to add.
  455. * @return {Object} Current instance of EventEmitter for chaining.
  456. */
  457. proto.addListeners = function addListeners(evt, listeners) {
  458. // Pass through to manipulateListeners
  459. return this.manipulateListeners(false, evt, listeners);
  460. };
  461. /**
  462. * Removes listeners in bulk using the manipulateListeners method.
  463. * If you pass an object as the second argument you can remove from multiple events at once. The object should contain key value pairs of events and listeners or listener arrays.
  464. * You can also pass it an event name and an array of listeners to be removed.
  465. * You can also pass it a regular expression to remove the listeners from all events that match it.
  466. *
  467. * @param {String|Object|RegExp} evt An event name if you will pass an array of listeners next. An object if you wish to remove from multiple events at once.
  468. * @param {Function[]} [listeners] An optional array of listener functions to remove.
  469. * @return {Object} Current instance of EventEmitter for chaining.
  470. */
  471. proto.removeListeners = function removeListeners(evt, listeners) {
  472. // Pass through to manipulateListeners
  473. return this.manipulateListeners(true, evt, listeners);
  474. };
  475. /**
  476. * Edits listeners in bulk. The addListeners and removeListeners methods both use this to do their job. You should really use those instead, this is a little lower level.
  477. * The first argument will determine if the listeners are removed (true) or added (false).
  478. * If you pass an object as the second argument you can add/remove from multiple events at once. The object should contain key value pairs of events and listeners or listener arrays.
  479. * You can also pass it an event name and an array of listeners to be added/removed.
  480. * You can also pass it a regular expression to manipulate the listeners of all events that match it.
  481. *
  482. * @param {Boolean} remove True if you want to remove listeners, false if you want to add.
  483. * @param {String|Object|RegExp} evt An event name if you will pass an array of listeners next. An object if you wish to add/remove from multiple events at once.
  484. * @param {Function[]} [listeners] An optional array of listener functions to add/remove.
  485. * @return {Object} Current instance of EventEmitter for chaining.
  486. */
  487. proto.manipulateListeners = function manipulateListeners(remove, evt, listeners) {
  488. var i;
  489. var value;
  490. var single = remove ? this.removeListener : this.addListener;
  491. var multiple = remove ? this.removeListeners : this.addListeners;
  492. // If evt is an object then pass each of it's properties to this method
  493. if (typeof evt === 'object' && !(evt instanceof RegExp)) {
  494. for (i in evt) {
  495. if (evt.hasOwnProperty(i) && (value = evt[i])) {
  496. // Pass the single listener straight through to the singular method
  497. if (typeof value === 'function') {
  498. single.call(this, i, value);
  499. }
  500. else {
  501. // Otherwise pass back to the multiple function
  502. multiple.call(this, i, value);
  503. }
  504. }
  505. }
  506. }
  507. else {
  508. // So evt must be a string
  509. // And listeners must be an array of listeners
  510. // Loop over it and pass each one to the multiple method
  511. i = listeners.length;
  512. while (i--) {
  513. single.call(this, evt, listeners[i]);
  514. }
  515. }
  516. return this;
  517. };
  518. /**
  519. * Removes all listeners from a specified event.
  520. * If you do not specify an event then all listeners will be removed.
  521. * That means every event will be emptied.
  522. * You can also pass a regex to remove all events that match it.
  523. *
  524. * @param {String|RegExp} [evt] Optional name of the event to remove all listeners for. Will remove from every event if not passed.
  525. * @return {Object} Current instance of EventEmitter for chaining.
  526. */
  527. proto.removeEvent = function removeEvent(evt) {
  528. var type = typeof evt;
  529. var events = this._getEvents();
  530. var key;
  531. // Remove different things depending on the state of evt
  532. if (type === 'string') {
  533. // Remove all listeners for the specified event
  534. delete events[evt];
  535. }
  536. else if (evt instanceof RegExp) {
  537. // Remove all events matching the regex.
  538. for (key in events) {
  539. if (events.hasOwnProperty(key) && evt.test(key)) {
  540. delete events[key];
  541. }
  542. }
  543. }
  544. else {
  545. // Remove all listeners in all events
  546. delete this._events;
  547. }
  548. return this;
  549. };
  550. /**
  551. * Alias of removeEvent.
  552. *
  553. * Added to mirror the node API.
  554. */
  555. proto.removeAllListeners = alias('removeEvent');
  556. /**
  557. * Emits an event of your choice.
  558. * When emitted, every listener attached to that event will be executed.
  559. * If you pass the optional argument array then those arguments will be passed to every listener upon execution.
  560. * Because it uses `apply`, your array of arguments will be passed as if you wrote them out separately.
  561. * So they will not arrive within the array on the other side, they will be separate.
  562. * You can also pass a regular expression to emit to all events that match it.
  563. *
  564. * @param {String|RegExp} evt Name of the event to emit and execute listeners for.
  565. * @param {Array} [args] Optional array of arguments to be passed to each listener.
  566. * @return {Object} Current instance of EventEmitter for chaining.
  567. */
  568. proto.emitEvent = function emitEvent(evt, args) {
  569. var listeners = this.getListenersAsObject(evt);
  570. var listener;
  571. var i;
  572. var key;
  573. var response;
  574. for (key in listeners) {
  575. if (listeners.hasOwnProperty(key)) {
  576. i = listeners[key].length;
  577. while (i--) {
  578. // If the listener returns true then it shall be removed from the event
  579. // The function is executed either with a basic call or an apply if there is an args array
  580. listener = listeners[key][i];
  581. if (listener.once === true) {
  582. this.removeListener(evt, listener.listener);
  583. }
  584. response = listener.listener.apply(this, args || []);
  585. if (response === this._getOnceReturnValue()) {
  586. this.removeListener(evt, listener.listener);
  587. }
  588. }
  589. }
  590. }
  591. return this;
  592. };
  593. /**
  594. * Alias of emitEvent
  595. */
  596. proto.trigger = alias('emitEvent');
  597. /**
  598. * Subtly different from emitEvent in that it will pass its arguments on to the listeners, as opposed to taking a single array of arguments to pass on.
  599. * As with emitEvent, you can pass a regex in place of the event name to emit to all events that match it.
  600. *
  601. * @param {String|RegExp} evt Name of the event to emit and execute listeners for.
  602. * @param {...*} Optional additional arguments to be passed to each listener.
  603. * @return {Object} Current instance of EventEmitter for chaining.
  604. */
  605. proto.emit = function emit(evt) {
  606. var args = Array.prototype.slice.call(arguments, 1);
  607. return this.emitEvent(evt, args);
  608. };
  609. /**
  610. * Sets the current value to check against when executing listeners. If a
  611. * listeners return value matches the one set here then it will be removed
  612. * after execution. This value defaults to true.
  613. *
  614. * @param {*} value The new value to check for when executing listeners.
  615. * @return {Object} Current instance of EventEmitter for chaining.
  616. */
  617. proto.setOnceReturnValue = function setOnceReturnValue(value) {
  618. this._onceReturnValue = value;
  619. return this;
  620. };
  621. /**
  622. * Fetches the current value to check against when executing listeners. If
  623. * the listeners return value matches this one then it should be removed
  624. * automatically. It will return true by default.
  625. *
  626. * @return {*|Boolean} The current value to check for or the default, true.
  627. * @api private
  628. */
  629. proto._getOnceReturnValue = function _getOnceReturnValue() {
  630. if (this.hasOwnProperty('_onceReturnValue')) {
  631. return this._onceReturnValue;
  632. }
  633. else {
  634. return true;
  635. }
  636. };
  637. /**
  638. * Fetches the events object and creates one if required.
  639. *
  640. * @return {Object} The events storage object.
  641. * @api private
  642. */
  643. proto._getEvents = function _getEvents() {
  644. return this._events || (this._events = {});
  645. };
  646. /**
  647. * Reverts the global {@link EventEmitter} to its previous value and returns a reference to this version.
  648. *
  649. * @return {Function} Non conflicting EventEmitter class.
  650. */
  651. EventEmitter.noConflict = function noConflict() {
  652. exports.EventEmitter = originalGlobalValue;
  653. return EventEmitter;
  654. };
  655. // Expose the class either via AMD, CommonJS or the global object
  656. if (typeof define === 'function' && define.amd) {
  657. define('eventEmitter/EventEmitter', [], function () {
  658. return EventEmitter;
  659. });
  660. }
  661. else if (typeof module === 'object' && module.exports) {
  662. module.exports = EventEmitter;
  663. }
  664. else {
  665. this.EventEmitter = EventEmitter;
  666. }
  667. }.call(this));
  668. /*!
  669. * getStyleProperty v1.0.3
  670. * original by kangax
  671. * http://perfectionkills.com/feature-testing-css-properties/
  672. */
  673. /*jshint browser: true, strict: true, undef: true */
  674. /*global define: false, exports: false, module: false */
  675. (function (window) {
  676. var prefixes = 'Webkit Moz ms Ms O'.split(' ');
  677. var docElemStyle = document.documentElement.style;
  678. function getStyleProperty(propName) {
  679. if (!propName) {
  680. return;
  681. }
  682. // test standard property first
  683. if (typeof docElemStyle[propName] === 'string') {
  684. return propName;
  685. }
  686. // capitalize
  687. propName = propName.charAt(0).toUpperCase() + propName.slice(1);
  688. // test vendor specific properties
  689. var prefixed;
  690. for (var i = 0, len = prefixes.length; i < len; i++) {
  691. prefixed = prefixes[i] + propName;
  692. if (typeof docElemStyle[prefixed] === 'string') {
  693. return prefixed;
  694. }
  695. }
  696. }
  697. // transport
  698. if (typeof define === 'function' && define.amd) {
  699. // AMD
  700. define('get-style-property/get-style-property', [], function () {
  701. return getStyleProperty;
  702. });
  703. } else if (typeof exports === 'object') {
  704. // CommonJS for Component
  705. module.exports = getStyleProperty;
  706. } else {
  707. // browser global
  708. window.getStyleProperty = getStyleProperty;
  709. }
  710. })(window);
  711. /**
  712. * getSize v1.1.7
  713. * measure size of elements
  714. */
  715. /*jshint browser: true, strict: true, undef: true, unused: true */
  716. /*global define: false, exports: false, require: false, module: false */
  717. (function (window, undefined) {
  718. // -------------------------- helpers -------------------------- //
  719. var getComputedStyle = window.getComputedStyle;
  720. var getStyle = getComputedStyle ?
  721. function (elem) {
  722. return getComputedStyle(elem, null);
  723. } :
  724. function (elem) {
  725. return elem.currentStyle;
  726. };
  727. // get a number from a string, not a percentage
  728. function getStyleSize(value) {
  729. var num = parseFloat(value);
  730. // not a percent like '100%', and a number
  731. var isValid = value.indexOf('%') === -1 && !isNaN(num);
  732. return isValid && num;
  733. }
  734. // -------------------------- measurements -------------------------- //
  735. var measurements = [
  736. 'paddingLeft',
  737. 'paddingRight',
  738. 'paddingTop',
  739. 'paddingBottom',
  740. 'marginLeft',
  741. 'marginRight',
  742. 'marginTop',
  743. 'marginBottom',
  744. 'borderLeftWidth',
  745. 'borderRightWidth',
  746. 'borderTopWidth',
  747. 'borderBottomWidth'
  748. ];
  749. function getZeroSize() {
  750. var size = {
  751. width: 0,
  752. height: 0,
  753. innerWidth: 0,
  754. innerHeight: 0,
  755. outerWidth: 0,
  756. outerHeight: 0
  757. };
  758. for (var i = 0, len = measurements.length; i < len; i++) {
  759. var measurement = measurements[i];
  760. size[measurement] = 0;
  761. }
  762. return size;
  763. }
  764. function defineGetSize(getStyleProperty) {
  765. // -------------------------- box sizing -------------------------- //
  766. var boxSizingProp = getStyleProperty('boxSizing');
  767. var isBoxSizeOuter;
  768. /**
  769. * WebKit measures the outer-width on style.width on border-box elems
  770. * IE & Firefox measures the inner-width
  771. */
  772. (function () {
  773. if (!boxSizingProp) {
  774. return;
  775. }
  776. var div = document.createElement('div');
  777. div.style.width = '200px';
  778. div.style.padding = '1px 2px 3px 4px';
  779. div.style.borderStyle = 'solid';
  780. div.style.borderWidth = '1px 2px 3px 4px';
  781. div.style[boxSizingProp] = 'border-box';
  782. var body = document.body || document.documentElement;
  783. body.appendChild(div);
  784. var style = getStyle(div);
  785. isBoxSizeOuter = getStyleSize(style.width) === 200;
  786. body.removeChild(div);
  787. })();
  788. // -------------------------- getSize -------------------------- //
  789. function getSize(elem) {
  790. // use querySeletor if elem is string
  791. if (typeof elem === 'string') {
  792. elem = document.querySelector(elem);
  793. }
  794. // do not proceed on non-objects
  795. if (!elem || typeof elem !== 'object' || !elem.nodeType) {
  796. return;
  797. }
  798. var style = getStyle(elem);
  799. // if hidden, everything is 0
  800. if (style.display === 'none') {
  801. return getZeroSize();
  802. }
  803. var size = {};
  804. size.width = elem.offsetWidth;
  805. size.height = elem.offsetHeight;
  806. var isBorderBox = size.isBorderBox = !!(boxSizingProp &&
  807. style[boxSizingProp] && style[boxSizingProp] === 'border-box');
  808. // get all measurements
  809. for (var i = 0, len = measurements.length; i < len; i++) {
  810. var measurement = measurements[i];
  811. var value = style[measurement];
  812. value = mungeNonPixel(elem, value);
  813. var num = parseFloat(value);
  814. // any 'auto', 'medium' value will be 0
  815. size[measurement] = !isNaN(num) ? num : 0;
  816. }
  817. var paddingWidth = size.paddingLeft + size.paddingRight;
  818. var paddingHeight = size.paddingTop + size.paddingBottom;
  819. var marginWidth = size.marginLeft + size.marginRight;
  820. var marginHeight = size.marginTop + size.marginBottom;
  821. var borderWidth = size.borderLeftWidth + size.borderRightWidth;
  822. var borderHeight = size.borderTopWidth + size.borderBottomWidth;
  823. var isBorderBoxSizeOuter = isBorderBox && isBoxSizeOuter;
  824. // overwrite width and height if we can get it from style
  825. var styleWidth = getStyleSize(style.width);
  826. if (styleWidth !== false) {
  827. size.width = styleWidth +
  828. // add padding and border unless it's already including it
  829. (isBorderBoxSizeOuter ? 0 : paddingWidth + borderWidth);
  830. }
  831. var styleHeight = getStyleSize(style.height);
  832. if (styleHeight !== false) {
  833. size.height = styleHeight +
  834. // add padding and border unless it's already including it
  835. (isBorderBoxSizeOuter ? 0 : paddingHeight + borderHeight);
  836. }
  837. size.innerWidth = size.width - (paddingWidth + borderWidth);
  838. size.innerHeight = size.height - (paddingHeight + borderHeight);
  839. size.outerWidth = size.width + marginWidth;
  840. size.outerHeight = size.height + marginHeight;
  841. return size;
  842. }
  843. // IE8 returns percent values, not pixels
  844. // taken from jQuery's curCSS
  845. function mungeNonPixel(elem, value) {
  846. // IE8 and has percent value
  847. if (getComputedStyle || value.indexOf('%') === -1) {
  848. return value;
  849. }
  850. var style = elem.style;
  851. // Remember the original values
  852. var left = style.left;
  853. var rs = elem.runtimeStyle;
  854. var rsLeft = rs && rs.left;
  855. // Put in the new values to get a computed value out
  856. if (rsLeft) {
  857. rs.left = elem.currentStyle.left;
  858. }
  859. style.left = value;
  860. value = style.pixelLeft;
  861. // Revert the changed values
  862. style.left = left;
  863. if (rsLeft) {
  864. rs.left = rsLeft;
  865. }
  866. return value;
  867. }
  868. return getSize;
  869. }
  870. // transport
  871. if (typeof define === 'function' && define.amd) {
  872. // AMD for RequireJS
  873. define('get-size/get-size', ['get-style-property/get-style-property'], defineGetSize);
  874. } else if (typeof exports === 'object') {
  875. // CommonJS for Component
  876. module.exports = defineGetSize(require('get-style-property'));
  877. } else {
  878. // browser global
  879. window.getSize = defineGetSize(window.getStyleProperty);
  880. }
  881. })(window);
  882. /**
  883. * matchesSelector helper v1.0.1
  884. *
  885. * @name matchesSelector
  886. * @param {Element} elem
  887. * @param {String} selector
  888. */
  889. /*jshint browser: true, strict: true, undef: true, unused: true */
  890. /*global define: false */
  891. (function (global, ElemProto) {
  892. var matchesMethod = (function () {
  893. // check un-prefixed
  894. if (ElemProto.matchesSelector) {
  895. return 'matchesSelector';
  896. }
  897. // check vendor prefixes
  898. var prefixes = ['webkit', 'moz', 'ms', 'o'];
  899. for (var i = 0, len = prefixes.length; i < len; i++) {
  900. var prefix = prefixes[i];
  901. var method = prefix + 'MatchesSelector';
  902. if (ElemProto[method]) {
  903. return method;
  904. }
  905. }
  906. })();
  907. // ----- match ----- //
  908. function match(elem, selector) {
  909. return elem[matchesMethod](selector);
  910. }
  911. // ----- appendToFragment ----- //
  912. function checkParent(elem) {
  913. // not needed if already has parent
  914. if (elem.parentNode) {
  915. return;
  916. }
  917. var fragment = document.createDocumentFragment();
  918. fragment.appendChild(elem);
  919. }
  920. // ----- query ----- //
  921. // fall back to using QSA
  922. // thx @jonathantneal https://gist.github.com/3062955
  923. function query(elem, selector) {
  924. // append to fragment if no parent
  925. checkParent(elem);
  926. // match elem with all selected elems of parent
  927. var elems = elem.parentNode.querySelectorAll(selector);
  928. for (var i = 0, len = elems.length; i < len; i++) {
  929. // return true if match
  930. if (elems[i] === elem) {
  931. return true;
  932. }
  933. }
  934. // otherwise return false
  935. return false;
  936. }
  937. // ----- matchChild ----- //
  938. function matchChild(elem, selector) {
  939. checkParent(elem);
  940. return match(elem, selector);
  941. }
  942. // ----- matchesSelector ----- //
  943. var matchesSelector;
  944. if (matchesMethod) {
  945. // IE9 supports matchesSelector, but doesn't work on orphaned elems
  946. // check for that
  947. var div = document.createElement('div');
  948. var supportsOrphans = match(div, 'div');
  949. matchesSelector = supportsOrphans ? match : matchChild;
  950. } else {
  951. matchesSelector = query;
  952. }
  953. // transport
  954. if (typeof define === 'function' && define.amd) {
  955. // AMD
  956. define('matches-selector/matches-selector', [], function () {
  957. return matchesSelector;
  958. });
  959. } else {
  960. // browser global
  961. window.matchesSelector = matchesSelector;
  962. }
  963. })(this, Element.prototype);
  964. /**
  965. * Outlayer Item
  966. */
  967. (function (window) {
  968. // ----- get style ----- //
  969. var defView = document.defaultView;
  970. var getStyle = defView && defView.getComputedStyle ?
  971. function (elem) {
  972. return defView.getComputedStyle(elem, null);
  973. } :
  974. function (elem) {
  975. return elem.currentStyle;
  976. };
  977. // extend objects
  978. function extend(a, b) {
  979. for (var prop in b) {
  980. a[prop] = b[prop];
  981. }
  982. return a;
  983. }
  984. function isEmptyObj(obj) {
  985. for (var prop in obj) {
  986. return false;
  987. }
  988. prop = null;
  989. return true;
  990. }
  991. // http://jamesroberts.name/blog/2010/02/22/string-functions-for-javascript-trim-to-camel-case-to-dashed-and-to-underscore/
  992. function toDash(str) {
  993. return str.replace(/([A-Z])/g, function ($1) {
  994. return '-' + $1.toLowerCase();
  995. });
  996. }
  997. // -------------------------- Outlayer definition -------------------------- //
  998. function outlayerItemDefinition(EventEmitter, getSize, getStyleProperty) {
  999. // -------------------------- CSS3 support -------------------------- //
  1000. var transitionProperty = getStyleProperty('transition');
  1001. var transformProperty = getStyleProperty('transform');
  1002. var supportsCSS3 = transitionProperty && transformProperty;
  1003. var is3d = !!getStyleProperty('perspective');
  1004. var transitionEndEvent = {
  1005. WebkitTransition: 'webkitTransitionEnd',
  1006. MozTransition: 'transitionend',
  1007. OTransition: 'otransitionend',
  1008. transition: 'transitionend'
  1009. }[transitionProperty];
  1010. // properties that could have vendor prefix
  1011. var prefixableProperties = [
  1012. 'transform',
  1013. 'transition',
  1014. 'transitionDuration',
  1015. 'transitionProperty'
  1016. ];
  1017. // cache all vendor properties
  1018. var vendorProperties = (function () {
  1019. var cache = {};
  1020. for (var i = 0, len = prefixableProperties.length; i < len; i++) {
  1021. var prop = prefixableProperties[i];
  1022. var supportedProp = getStyleProperty(prop);
  1023. if (supportedProp && supportedProp !== prop) {
  1024. cache[prop] = supportedProp;
  1025. }
  1026. }
  1027. return cache;
  1028. })();
  1029. // -------------------------- Item -------------------------- //
  1030. function Item(element, layout) {
  1031. if (!element) {
  1032. return;
  1033. }
  1034. this.element = element;
  1035. // parent layout class, i.e. Masonry, Isotope, or Packery
  1036. this.layout = layout;
  1037. this.position = {
  1038. x: 0,
  1039. y: 0
  1040. };
  1041. this._create();
  1042. }
  1043. // inherit EventEmitter
  1044. extend(Item.prototype, EventEmitter.prototype);
  1045. Item.prototype._create = function () {
  1046. // transition objects
  1047. this._transn = {
  1048. ingProperties: {},
  1049. clean: {},
  1050. onEnd: {}
  1051. };
  1052. this.css({
  1053. position: 'absolute'
  1054. });
  1055. };
  1056. // trigger specified handler for event type
  1057. Item.prototype.handleEvent = function (event) {
  1058. var method = 'on' + event.type;
  1059. if (this[method]) {
  1060. this[method](event);
  1061. }
  1062. };
  1063. Item.prototype.getSize = function () {
  1064. this.size = getSize(this.element);
  1065. };
  1066. /**
  1067. * apply CSS styles to element
  1068. * @param {Object} style
  1069. */
  1070. Item.prototype.css = function (style) {
  1071. var elemStyle = this.element.style;
  1072. for (var prop in style) {
  1073. // use vendor property if available
  1074. var supportedProp = vendorProperties[prop] || prop;
  1075. elemStyle[supportedProp] = style[prop];
  1076. }
  1077. };
  1078. // measure position, and sets it
  1079. Item.prototype.getPosition = function () {
  1080. var style = getStyle(this.element);
  1081. var layoutOptions = this.layout.options;
  1082. var isOriginLeft = layoutOptions.isOriginLeft;
  1083. var isOriginTop = layoutOptions.isOriginTop;
  1084. var x = parseInt(style[isOriginLeft ? 'left' : 'right'], 10);
  1085. var y = parseInt(style[isOriginTop ? 'top' : 'bottom'], 10);
  1086. // clean up 'auto' or other non-integer values
  1087. x = isNaN(x) ? 0 : x;
  1088. y = isNaN(y) ? 0 : y;
  1089. // remove padding from measurement
  1090. var layoutSize = this.layout.size;
  1091. x -= isOriginLeft ? layoutSize.paddingLeft : layoutSize.paddingRight;
  1092. y -= isOriginTop ? layoutSize.paddingTop : layoutSize.paddingBottom;
  1093. this.position.x = x;
  1094. this.position.y = y;
  1095. };
  1096. // set settled position, apply padding
  1097. Item.prototype.layoutPosition = function () {
  1098. var layoutSize = this.layout.size;
  1099. var layoutOptions = this.layout.options;
  1100. var style = {};
  1101. if (layoutOptions.isOriginLeft) {
  1102. style.left = (this.position.x + layoutSize.paddingLeft) + 'px';
  1103. // reset other property
  1104. style.right = '';
  1105. } else {
  1106. style.right = (this.position.x + layoutSize.paddingRight) + 'px';
  1107. style.left = '';
  1108. }
  1109. if (layoutOptions.isOriginTop) {
  1110. style.top = (this.position.y + layoutSize.paddingTop) + 'px';
  1111. style.bottom = '';
  1112. } else {
  1113. style.bottom = (this.position.y + layoutSize.paddingBottom) + 'px';
  1114. style.top = '';
  1115. }
  1116. this.css(style);
  1117. this.emitEvent('layout', [this]);
  1118. };
  1119. // transform translate function
  1120. var translate = is3d ?
  1121. function (x, y) {
  1122. return 'translate3d(' + x + 'px, ' + y + 'px, 0)';
  1123. } :
  1124. function (x, y) {
  1125. return 'translate(' + x + 'px, ' + y + 'px)';
  1126. };
  1127. Item.prototype._transitionTo = function (x, y) {
  1128. this.getPosition();
  1129. // get current x & y from top/left
  1130. var curX = this.position.x;
  1131. var curY = this.position.y;
  1132. var compareX = parseInt(x, 10);
  1133. var compareY = parseInt(y, 10);
  1134. var didNotMove = compareX === this.position.x && compareY === this.position.y;
  1135. // save end position
  1136. this.setPosition(x, y);
  1137. // if did not move and not transitioning, just go to layout
  1138. if (didNotMove && !this.isTransitioning) {
  1139. this.layoutPosition();
  1140. return;
  1141. }
  1142. var transX = x - curX;
  1143. var transY = y - curY;
  1144. var transitionStyle = {};
  1145. // flip cooridinates if origin on right or bottom
  1146. var layoutOptions = this.layout.options;
  1147. transX = layoutOptions.isOriginLeft ? transX : -transX;
  1148. transY = layoutOptions.isOriginTop ? transY : -transY;
  1149. transitionStyle.transform = translate(transX, transY);
  1150. this.transition({
  1151. to: transitionStyle,
  1152. onTransitionEnd: {
  1153. transform: this.layoutPosition
  1154. },
  1155. isCleaning: true
  1156. });
  1157. };
  1158. // non transition + transform support
  1159. Item.prototype.goTo = function (x, y) {
  1160. this.setPosition(x, y);
  1161. this.layoutPosition();
  1162. };
  1163. // use transition and transforms if supported
  1164. Item.prototype.moveTo = supportsCSS3 ?
  1165. Item.prototype._transitionTo : Item.prototype.goTo;
  1166. Item.prototype.setPosition = function (x, y) {
  1167. this.position.x = parseInt(x, 10);
  1168. this.position.y = parseInt(y, 10);
  1169. };
  1170. // ----- transition ----- //
  1171. /**
  1172. * @param {Object} style - CSS
  1173. * @param {Function} onTransitionEnd
  1174. */
  1175. // non transition, just trigger callback
  1176. Item.prototype._nonTransition = function (args) {
  1177. this.css(args.to);
  1178. if (args.isCleaning) {
  1179. this._removeStyles(args.to);
  1180. }
  1181. for (var prop in args.onTransitionEnd) {
  1182. args.onTransitionEnd[prop].call(this);
  1183. }
  1184. };
  1185. /**
  1186. * proper transition
  1187. * @param {Object} args - arguments
  1188. * @param {Object} to - style to transition to
  1189. * @param {Object} from - style to start transition from
  1190. * @param {Boolean} isCleaning - removes transition styles after transition
  1191. * @param {Function} onTransitionEnd - callback
  1192. */
  1193. Item.prototype._transition = function (args) {
  1194. // redirect to nonTransition if no transition duration
  1195. if (!parseFloat(this.layout.options.transitionDuration)) {
  1196. this._nonTransition(args);
  1197. return;
  1198. }
  1199. var _transition = this._transn;
  1200. // keep track of onTransitionEnd callback by css property
  1201. for (var prop in args.onTransitionEnd) {
  1202. _transition.onEnd[prop] = args.onTransitionEnd[prop];
  1203. }
  1204. // keep track of properties that are transitioning
  1205. for (prop in args.to) {
  1206. _transition.ingProperties[prop] = true;
  1207. // keep track of properties to clean up when transition is done
  1208. if (args.isCleaning) {
  1209. _transition.clean[prop] = true;
  1210. }
  1211. }
  1212. // set from styles
  1213. if (args.from) {
  1214. this.css(args.from);
  1215. // force redraw. http://blog.alexmaccaw.com/css-transitions
  1216. var h = this.element.offsetHeight;
  1217. // hack for JSHint to hush about unused var
  1218. h = null;
  1219. }
  1220. // enable transition
  1221. this.enableTransition(args.to);
  1222. // set styles that are transitioning
  1223. this.css(args.to);
  1224. this.isTransitioning = true;
  1225. };
  1226. var itemTransitionProperties = transformProperty && (toDash(transformProperty) +
  1227. ',opacity');
  1228. Item.prototype.enableTransition = function (/* style */) {
  1229. // only enable if not already transitioning
  1230. // bug in IE10 were re-setting transition style will prevent
  1231. // transitionend event from triggering
  1232. if (this.isTransitioning) {
  1233. return;
  1234. }
  1235. // make transition: foo, bar, baz from style object
  1236. // TODO uncomment this bit when IE10 bug is resolved
  1237. // var transitionValue = [];
  1238. // for ( var prop in style ) {
  1239. // // dash-ify camelCased properties like WebkitTransition
  1240. // transitionValue.push( toDash( prop ) );
  1241. // }
  1242. // enable transition styles
  1243. // HACK always enable transform,opacity for IE10
  1244. this.css({
  1245. transitionProperty: itemTransitionProperties,
  1246. transitionDuration: this.layout.options.transitionDuration
  1247. });
  1248. // listen for transition end event
  1249. this.element.addEventListener(transitionEndEvent, this, false);
  1250. };
  1251. Item.prototype.transition = Item.prototype[transitionProperty ? '_transition' : '_nonTransition'];
  1252. // ----- events ----- //
  1253. Item.prototype.onwebkitTransitionEnd = function (event) {
  1254. this.ontransitionend(event);
  1255. };
  1256. Item.prototype.onotransitionend = function (event) {
  1257. this.ontransitionend(event);
  1258. };
  1259. // properties that I munge to make my life easier
  1260. var dashedVendorProperties = {
  1261. '-webkit-transform': 'transform',
  1262. '-moz-transform': 'transform',
  1263. '-o-transform': 'transform'
  1264. };
  1265. Item.prototype.ontransitionend = function (event) {
  1266. // disregard bubbled events from children
  1267. if (event.target !== this.element) {
  1268. return;
  1269. }
  1270. var _transition = this._transn;
  1271. // get property name of transitioned property, convert to prefix-free
  1272. var propertyName = dashedVendorProperties[event.propertyName] || event.propertyName;
  1273. // remove property that has completed transitioning
  1274. delete _transition.ingProperties[propertyName];
  1275. // check if any properties are still transitioning
  1276. if (isEmptyObj(_transition.ingProperties)) {
  1277. // all properties have completed transitioning
  1278. this.disableTransition();
  1279. }
  1280. // clean style
  1281. if (propertyName in _transition.clean) {
  1282. // clean up style
  1283. this.element.style[event.propertyName] = '';
  1284. delete _transition.clean[propertyName];
  1285. }
  1286. // trigger onTransitionEnd callback
  1287. if (propertyName in _transition.onEnd) {
  1288. var onTransitionEnd = _transition.onEnd[propertyName];
  1289. onTransitionEnd.call(this);
  1290. delete _transition.onEnd[propertyName];
  1291. }
  1292. this.emitEvent('transitionEnd', [this]);
  1293. };
  1294. Item.prototype.disableTransition = function () {
  1295. this.removeTransitionStyles();
  1296. this.element.removeEventListener(transitionEndEvent, this, false);
  1297. this.isTransitioning = false;
  1298. };
  1299. /**
  1300. * removes style property from element
  1301. * @param {Object} style
  1302. **/
  1303. Item.prototype._removeStyles = function (style) {
  1304. // clean up transition styles
  1305. var cleanStyle = {};
  1306. for (var prop in style) {
  1307. cleanStyle[prop] = '';
  1308. }
  1309. this.css(cleanStyle);
  1310. };
  1311. var cleanTransitionStyle = {
  1312. transitionProperty: '',
  1313. transitionDuration: ''
  1314. };
  1315. Item.prototype.removeTransitionStyles = function () {
  1316. // remove transition
  1317. this.css(cleanTransitionStyle);
  1318. };
  1319. // ----- show/hide/remove ----- //
  1320. // remove element from DOM
  1321. Item.prototype.removeElem = function () {
  1322. this.element.parentNode.removeChild(this.element);
  1323. this.emitEvent('remove', [this]);
  1324. };
  1325. Item.prototype.remove = function () {
  1326. // just remove element if no transition support or no transition
  1327. if (!transitionProperty || !parseFloat(this.layout.options.transitionDuration)) {
  1328. this.removeElem();
  1329. return;
  1330. }
  1331. // start transition
  1332. var _this = this;
  1333. this.on('transitionEnd', function () {
  1334. _this.removeElem();
  1335. return true; // bind once
  1336. });
  1337. this.hide();
  1338. };
  1339. Item.prototype.reveal = function () {
  1340. delete this.isHidden;
  1341. // remove display: none
  1342. this.css({ display: '' });
  1343. var options = this.layout.options;
  1344. this.transition({
  1345. from: options.hiddenStyle,
  1346. to: options.visibleStyle,
  1347. isCleaning: true
  1348. });
  1349. };
  1350. Item.prototype.hide = function () {
  1351. // set flag
  1352. this.isHidden = true;
  1353. // remove display: none
  1354. this.css({ display: '' });
  1355. var options = this.layout.options;
  1356. this.transition({
  1357. from: options.visibleStyle,
  1358. to: options.hiddenStyle,
  1359. // keep hidden stuff hidden
  1360. isCleaning: true,
  1361. onTransitionEnd: {
  1362. opacity: function () {
  1363. // check if still hidden
  1364. // during transition, item may have been un-hidden
  1365. if (this.isHidden) {
  1366. this.css({ display: 'none' });
  1367. }
  1368. }
  1369. }
  1370. });
  1371. };
  1372. Item.prototype.destroy = function () {
  1373. this.css({
  1374. position: '',
  1375. left: '',
  1376. right: '',
  1377. top: '',
  1378. bottom: '',
  1379. transition: '',
  1380. transform: ''
  1381. });
  1382. };
  1383. return Item;
  1384. }
  1385. // -------------------------- transport -------------------------- //
  1386. if (typeof define === 'function' && define.amd) {
  1387. // AMD
  1388. define('outlayer/item', [
  1389. 'eventEmitter/EventEmitter',
  1390. 'get-size/get-size',
  1391. 'get-style-property/get-style-property'
  1392. ],
  1393. outlayerItemDefinition);
  1394. } else {
  1395. // browser global
  1396. window.Outlayer = {};
  1397. window.Outlayer.Item = outlayerItemDefinition(
  1398. window.EventEmitter,
  1399. window.getSize,
  1400. window.getStyleProperty
  1401. );
  1402. }
  1403. })(window);
  1404. /*!
  1405. * Outlayer v1.1.10
  1406. * the brains and guts of a layout library
  1407. * MIT license
  1408. */
  1409. (function (window) {
  1410. // ----- vars ----- //
  1411. var document = window.document;
  1412. var console = window.console;
  1413. var jQuery = window.jQuery;
  1414. var noop = function () { };
  1415. // -------------------------- helpers -------------------------- //
  1416. // extend objects
  1417. function extend(a, b) {
  1418. for (var prop in b) {
  1419. a[prop] = b[prop];
  1420. }
  1421. return a;
  1422. }
  1423. var objToString = Object.prototype.toString;
  1424. function isArray(obj) {
  1425. return objToString.call(obj) === '[object Array]';
  1426. }
  1427. // turn element or nodeList into an array
  1428. function makeArray(obj) {
  1429. var ary = [];
  1430. if (isArray(obj)) {
  1431. // use object if already an array
  1432. ary = obj;
  1433. } else if (obj && typeof obj.length === 'number') {
  1434. // convert nodeList to array
  1435. for (var i = 0, len = obj.length; i < len; i++) {
  1436. ary.push(obj[i]);
  1437. }
  1438. } else {
  1439. // array of single index
  1440. ary.push(obj);
  1441. }
  1442. return ary;
  1443. }
  1444. // http://stackoverflow.com/a/384380/182183
  1445. var isElement = (typeof HTMLElement === 'object') ?
  1446. function isElementDOM2(obj) {
  1447. return obj instanceof HTMLElement;
  1448. } :
  1449. function isElementQuirky(obj) {
  1450. return obj && typeof obj === 'object' &&
  1451. obj.nodeType === 1 && typeof obj.nodeName === 'string';
  1452. };
  1453. // index of helper cause IE8
  1454. var indexOf = Array.prototype.indexOf ? function (ary, obj) {
  1455. return ary.indexOf(obj);
  1456. } : function (ary, obj) {
  1457. for (var i = 0, len = ary.length; i < len; i++) {
  1458. if (ary[i] === obj) {
  1459. return i;
  1460. }
  1461. }
  1462. return -1;
  1463. };
  1464. function removeFrom(obj, ary) {
  1465. var index = indexOf(ary, obj);
  1466. if (index !== -1) {
  1467. ary.splice(index, 1);
  1468. }
  1469. }
  1470. // http://jamesroberts.name/blog/2010/02/22/string-functions-for-javascript-trim-to-camel-case-to-dashed-and-to-underscore/
  1471. function toDashed(str) {
  1472. return str.replace(/(.)([A-Z])/g, function (match, $1, $2) {
  1473. return $1 + '-' + $2;
  1474. }).toLowerCase();
  1475. }
  1476. function outlayerDefinition(eventie, docReady, EventEmitter, getSize, matchesSelector, Item) {
  1477. // -------------------------- Outlayer -------------------------- //
  1478. // globally unique identifiers
  1479. var GUID = 0;
  1480. // internal store of all Outlayer intances
  1481. var instances = {};
  1482. /**
  1483. * @param {Element, String} element
  1484. * @param {Object} options
  1485. * @constructor
  1486. */
  1487. function Outlayer(element, options) {
  1488. // use element as selector string
  1489. if (typeof element === 'string') {
  1490. element = document.querySelector(element);
  1491. }
  1492. // bail out if not proper element
  1493. if (!element || !isElement(element)) {
  1494. if (console) {
  1495. console.error('Bad ' + this.constructor.namespace + ' element: ' + element);
  1496. }
  1497. return;
  1498. }
  1499. this.element = element;
  1500. // options
  1501. this.options = extend({}, this.options);
  1502. this.option(options);
  1503. // add id for Outlayer.getFromElement
  1504. var id = ++GUID;
  1505. this.element.outlayerGUID = id; // expando
  1506. instances[id] = this; // associate via id
  1507. // kick it off
  1508. this._create();
  1509. if (this.options.isInitLayout) {
  1510. this.layout();
  1511. }
  1512. }
  1513. // settings are for internal use only
  1514. Outlayer.namespace = 'outlayer';
  1515. Outlayer.Item = Item;
  1516. // default options
  1517. Outlayer.prototype.options = {
  1518. containerStyle: {
  1519. position: 'relative'
  1520. },
  1521. isInitLayout: true,
  1522. isOriginLeft: true,
  1523. isOriginTop: true,
  1524. isResizeBound: true,
  1525. // item options
  1526. transitionDuration: '0.4s',
  1527. hiddenStyle: {
  1528. opacity: 0,
  1529. transform: 'scale(0.001)'
  1530. },
  1531. visibleStyle: {
  1532. opacity: 1,
  1533. transform: 'scale(1)'
  1534. }
  1535. };
  1536. // inherit EventEmitter
  1537. extend(Outlayer.prototype, EventEmitter.prototype);
  1538. /**
  1539. * set options
  1540. * @param {Object} opts
  1541. */
  1542. Outlayer.prototype.option = function (opts) {
  1543. extend(this.options, opts);
  1544. };
  1545. Outlayer.prototype._create = function () {
  1546. // get items from children
  1547. this.reloadItems();
  1548. // elements that affect layout, but are not laid out
  1549. this.stamps = [];
  1550. this.stamp(this.options.stamp);
  1551. // set container style
  1552. extend(this.element.style, this.options.containerStyle);
  1553. // bind resize method
  1554. if (this.options.isResizeBound) {
  1555. this.bindResize();
  1556. }
  1557. };
  1558. // goes through all children again and gets bricks in proper order
  1559. Outlayer.prototype.reloadItems = function () {
  1560. // collection of item elements
  1561. this.items = this._itemize(this.element.children);
  1562. };
  1563. /**
  1564. * turn elements into Outlayer.Items to be used in layout
  1565. * @param {Array or NodeList or HTMLElement} elems
  1566. * @returns {Array} items - collection of new Outlayer Items
  1567. */
  1568. Outlayer.prototype._itemize = function (elems) {
  1569. var itemElems = this._filterFindItemElements(elems);
  1570. var Item = this.constructor.Item;
  1571. // create new Outlayer Items for collection
  1572. var items = [];
  1573. for (var i = 0, len = itemElems.length; i < len; i++) {
  1574. var elem = itemElems[i];
  1575. var item = new Item(elem, this);
  1576. items.push(item);
  1577. }
  1578. return items;
  1579. };
  1580. /**
  1581. * get item elements to be used in layout
  1582. * @param {Array or NodeList or HTMLElement} elems
  1583. * @returns {Array} items - item elements
  1584. */
  1585. Outlayer.prototype._filterFindItemElements = function (elems) {
  1586. // make array of elems
  1587. elems = makeArray(elems);
  1588. var itemSelector = this.options.itemSelector;
  1589. var itemElems = [];
  1590. for (var i = 0, len = elems.length; i < len; i++) {
  1591. var elem = elems[i];
  1592. // check that elem is an actual element
  1593. if (!isElement(elem)) {
  1594. continue;
  1595. }
  1596. // filter & find items if we have an item selector
  1597. if (itemSelector) {
  1598. // filter siblings
  1599. if (matchesSelector(elem, itemSelector)) {
  1600. itemElems.push(elem);
  1601. }
  1602. // find children
  1603. var childElems = elem.querySelectorAll(itemSelector);
  1604. // concat childElems to filterFound array
  1605. for (var j = 0, jLen = childElems.length; j < jLen; j++) {
  1606. itemElems.push(childElems[j]);
  1607. }
  1608. } else {
  1609. itemElems.push(elem);
  1610. }
  1611. }
  1612. return itemElems;
  1613. };
  1614. /**
  1615. * getter method for getting items
  1616. * @returns {Array} elems - collection of items
  1617. */
  1618. Outlayer.prototype.getAllItems = function () {
  1619. var elems = [];
  1620. for (var i = 0, len = this.items.length; i < len; i++) {
  1621. elems.push(this.items[i]);
  1622. }
  1623. return elems;
  1624. };
  1625. /**
  1626. * getter method for getting item elements
  1627. * @returns {Array} elems - collection of item elements
  1628. */
  1629. Outlayer.prototype.getItemElements = function () {
  1630. var elems = [];
  1631. for (var i = 0, len = this.items.length; i < len; i++) {
  1632. elems.push(this.items[i].element);
  1633. }
  1634. return elems;
  1635. };
  1636. // ----- init & layout ----- //
  1637. /**
  1638. * lays out all items
  1639. */
  1640. Outlayer.prototype.layout = function () {
  1641. this._resetLayout();
  1642. this._manageStamps();
  1643. // don't animate first layout
  1644. var isInstant = this.options.isLayoutInstant !== undefined ?
  1645. this.options.isLayoutInstant : !this._isLayoutInited;
  1646. this.layoutItems(this.items, isInstant);
  1647. // flag for initalized
  1648. this._isLayoutInited = true;
  1649. };
  1650. // _init is alias for layout
  1651. Outlayer.prototype._init = Outlayer.prototype.layout;
  1652. /**
  1653. * logic before any new layout
  1654. */
  1655. Outlayer.prototype._resetLayout = function () {
  1656. this.getSize();
  1657. };
  1658. Outlayer.prototype.getSize = function () {
  1659. this.size = getSize(this.element);
  1660. };
  1661. /**
  1662. * get measurement from option, for columnWidth, rowHeight, gutter
  1663. * if option is String -> get element from selector string, & get size of element
  1664. * if option is Element -> get size of element
  1665. * else use option as a number
  1666. *
  1667. * @param {String} measurement
  1668. * @param {String} size - width or height
  1669. * @private
  1670. */
  1671. Outlayer.prototype._getMeasurement = function (measurement, size) {
  1672. var option = this.options[measurement];
  1673. var elem;
  1674. if (!option) {
  1675. // default to 0
  1676. this[measurement] = 0;
  1677. } else {
  1678. // use option as an element
  1679. if (typeof option === 'string') {
  1680. elem = this.element.querySelector(option);
  1681. } else if (isElement(option)) {
  1682. elem = option;
  1683. }
  1684. // use size of element, if element
  1685. this[measurement] = elem ? getSize(elem)[size] : option;
  1686. }
  1687. };
  1688. /**
  1689. * layout a collection of item elements
  1690. * @api public
  1691. */
  1692. Outlayer.prototype.layoutItems = function (items, isInstant) {
  1693. items = this._getItemsForLayout(items);
  1694. this._layoutItems(items, isInstant);
  1695. this._postLayout();
  1696. };
  1697. /**
  1698. * get the items to be laid out
  1699. * you may want to skip over some items
  1700. * @param {Array} items
  1701. * @returns {Array} items
  1702. */
  1703. Outlayer.prototype._getItemsForLayout = function (items) {
  1704. var layoutItems = [];
  1705. for (var i = 0, len = items.length; i < len; i++) {
  1706. var item = items[i];
  1707. if (!item.isIgnored) {
  1708. layoutItems.push(item);
  1709. }
  1710. }
  1711. return layoutItems;
  1712. };
  1713. /**
  1714. * layout items
  1715. * @param {Array} items
  1716. * @param {Boolean} isInstant
  1717. */
  1718. Outlayer.prototype._layoutItems = function (items, isInstant) {
  1719. var _this = this;
  1720. function onItemsLayout() {
  1721. _this.emitEvent('layoutComplete', [_this, items]);
  1722. }
  1723. if (!items || !items.length) {
  1724. // no items, emit event with empty array
  1725. onItemsLayout();
  1726. return;
  1727. }
  1728. // emit layoutComplete when done
  1729. this._itemsOn(items, 'layout', onItemsLayout);
  1730. var queue = [];
  1731. for (var i = 0, len = items.length; i < len; i++) {
  1732. var item = items[i];
  1733. // get x/y object from method
  1734. var position = this._getItemLayoutPosition(item);
  1735. // enqueue
  1736. position.item = item;
  1737. position.isInstant = isInstant || item.isLayoutInstant;
  1738. queue.push(position);
  1739. }
  1740. this._processLayoutQueue(queue);
  1741. };
  1742. /**
  1743. * get item layout position
  1744. * @param {Outlayer.Item} item
  1745. * @returns {Object} x and y position
  1746. */
  1747. Outlayer.prototype._getItemLayoutPosition = function ( /* item */) {
  1748. return {
  1749. x: 0,
  1750. y: 0
  1751. };
  1752. };
  1753. /**
  1754. * iterate over array and position each item
  1755. * Reason being - separating this logic prevents 'layout invalidation'
  1756. * thx @paul_irish
  1757. * @param {Array} queue
  1758. */
  1759. Outlayer.prototype._processLayoutQueue = function (queue) {
  1760. for (var i = 0, len = queue.length; i < len; i++) {
  1761. var obj = queue[i];
  1762. this._positionItem(obj.item, obj.x, obj.y, obj.isInstant);
  1763. }
  1764. };
  1765. /**
  1766. * Sets position of item in DOM
  1767. * @param {Outlayer.Item} item
  1768. * @param {Number} x - horizontal position
  1769. * @param {Number} y - vertical position
  1770. * @param {Boolean} isInstant - disables transitions
  1771. */
  1772. Outlayer.prototype._positionItem = function (item, x, y, isInstant) {
  1773. if (isInstant) {
  1774. // if not transition, just set CSS
  1775. item.goTo(x, y);
  1776. } else {
  1777. item.moveTo(x, y);
  1778. }
  1779. };
  1780. /**
  1781. * Any logic you want to do after each layout,
  1782. * i.e. size the container
  1783. */
  1784. Outlayer.prototype._postLayout = function () {
  1785. var size = this._getContainerSize();
  1786. if (size) {
  1787. this._setContainerMeasure(size.width, true);
  1788. this._setContainerMeasure(size.height, false);
  1789. }
  1790. };
  1791. /**
  1792. * @returns {Object} size
  1793. * @param {Number} width
  1794. * @param {Number} height
  1795. */
  1796. Outlayer.prototype._getContainerSize = noop;
  1797. /**
  1798. * @param {Number} measure - size of width or height
  1799. * @param {Boolean} isWidth
  1800. */
  1801. Outlayer.prototype._setContainerMeasure = function (measure, isWidth) {
  1802. if (measure === undefined) {
  1803. return;
  1804. }
  1805. var elemSize = this.size;
  1806. // add padding and border width if border box
  1807. if (elemSize.isBorderBox) {
  1808. measure += isWidth ? elemSize.paddingLeft + elemSize.paddingRight +
  1809. elemSize.borderLeftWidth + elemSize.borderRightWidth :
  1810. elemSize.paddingBottom + elemSize.paddingTop +
  1811. elemSize.borderTopWidth + elemSize.borderBottomWidth;
  1812. }
  1813. measure = Math.max(measure, 0);
  1814. this.element.style[isWidth ? 'width' : 'height'] = measure + 'px';
  1815. };
  1816. /**
  1817. * trigger a callback for a collection of items events
  1818. * @param {Array} items - Outlayer.Items
  1819. * @param {String} eventName
  1820. * @param {Function} callback
  1821. */
  1822. Outlayer.prototype._itemsOn = function (items, eventName, callback) {
  1823. var doneCount = 0;
  1824. var count = items.length;
  1825. // event callback
  1826. var _this = this;
  1827. function tick() {
  1828. doneCount++;
  1829. if (doneCount === count) {
  1830. callback.call(_this);
  1831. }
  1832. return true; // bind once
  1833. }
  1834. // bind callback
  1835. for (var i = 0, len = items.length; i < len; i++) {
  1836. var item = items[i];
  1837. item.on(eventName, tick);
  1838. }
  1839. };
  1840. // -------------------------- ignore & stamps -------------------------- //
  1841. /**
  1842. * keep item in collection, but do not lay it out
  1843. * ignored items do not get skipped in layout
  1844. * @param {Element} elem
  1845. */
  1846. Outlayer.prototype.ignore = function (elem) {
  1847. var item = this.getItem(elem);
  1848. if (item) {
  1849. item.isIgnored = true;
  1850. }
  1851. };
  1852. /**
  1853. * return item to layout collection
  1854. * @param {Element} elem
  1855. */
  1856. Outlayer.prototype.unignore = function (elem) {
  1857. var item = this.getItem(elem);
  1858. if (item) {
  1859. delete item.isIgnored;
  1860. }
  1861. };
  1862. /**
  1863. * adds elements to stamps
  1864. * @param {NodeList, Array, Element, or String} elems
  1865. */
  1866. Outlayer.prototype.stamp = function (elems) {
  1867. elems = this._find(elems);
  1868. if (!elems) {
  1869. return;
  1870. }
  1871. this.stamps = this.stamps.concat(elems);
  1872. // ignore
  1873. for (var i = 0, len = elems.length; i < len; i++) {
  1874. var elem = elems[i];
  1875. this.ignore(elem);
  1876. }
  1877. };
  1878. /**
  1879. * removes elements to stamps
  1880. * @param {NodeList, Array, or Element} elems
  1881. */
  1882. Outlayer.prototype.unstamp = function (elems) {
  1883. elems = this._find(elems);
  1884. if (!elems) {
  1885. return;
  1886. }
  1887. for (var i = 0, len = elems.length; i < len; i++) {
  1888. var elem = elems[i];
  1889. // filter out removed stamp elements
  1890. removeFrom(elem, this.stamps);
  1891. this.unignore(elem);
  1892. }
  1893. };
  1894. /**
  1895. * finds child elements
  1896. * @param {NodeList, Array, Element, or String} elems
  1897. * @returns {Array} elems
  1898. */
  1899. Outlayer.prototype._find = function (elems) {
  1900. if (!elems) {
  1901. return;
  1902. }
  1903. // if string, use argument as selector string
  1904. if (typeof elems === 'string') {
  1905. elems = this.element.querySelectorAll(elems);
  1906. }
  1907. elems = makeArray(elems);
  1908. return elems;
  1909. };
  1910. Outlayer.prototype._manageStamps = function () {
  1911. if (!this.stamps || !this.stamps.length) {
  1912. return;
  1913. }
  1914. this._getBoundingRect();
  1915. for (var i = 0, len = this.stamps.length; i < len; i++) {
  1916. var stamp = this.stamps[i];
  1917. this._manageStamp(stamp);
  1918. }
  1919. };
  1920. // update boundingLeft / Top
  1921. Outlayer.prototype._getBoundingRect = function () {
  1922. // get bounding rect for container element
  1923. var boundingRect = this.element.getBoundingClientRect();
  1924. var size = this.size;
  1925. this._boundingRect = {
  1926. left: boundingRect.left + size.paddingLeft + size.borderLeftWidth,
  1927. top: boundingRect.top + size.paddingTop + size.borderTopWidth,
  1928. right: boundingRect.right - (size.paddingRight + size.borderRightWidth),
  1929. bottom: boundingRect.bottom - (size.paddingBottom + size.borderBottomWidth)
  1930. };
  1931. };
  1932. /**
  1933. * @param {Element} stamp
  1934. **/
  1935. Outlayer.prototype._manageStamp = noop;
  1936. /**
  1937. * get x/y position of element relative to container element
  1938. * @param {Element} elem
  1939. * @returns {Object} offset - has left, top, right, bottom
  1940. */
  1941. Outlayer.prototype._getElementOffset = function (elem) {
  1942. var boundingRect = elem.getBoundingClientRect();
  1943. var thisRect = this._boundingRect;
  1944. var size = getSize(elem);
  1945. var offset = {
  1946. left: boundingRect.left - thisRect.left - size.marginLeft,
  1947. top: boundingRect.top - thisRect.top - size.marginTop,
  1948. right: thisRect.right - boundingRect.right - size.marginRight,
  1949. bottom: thisRect.bottom - boundingRect.bottom - size.marginBottom
  1950. };
  1951. return offset;
  1952. };
  1953. // -------------------------- resize -------------------------- //
  1954. // enable event handlers for listeners
  1955. // i.e. resize -> onresize
  1956. Outlayer.prototype.handleEvent = function (event) {
  1957. var method = 'on' + event.type;
  1958. if (this[method]) {
  1959. this[method](event);
  1960. }
  1961. };
  1962. /**
  1963. * Bind layout to window resizing
  1964. */
  1965. Outlayer.prototype.bindResize = function () {
  1966. // bind just one listener
  1967. if (this.isResizeBound) {
  1968. return;
  1969. }
  1970. eventie.bind(window, 'resize', this);
  1971. this.isResizeBound = true;
  1972. };
  1973. /**
  1974. * Unbind layout to window resizing
  1975. */
  1976. Outlayer.prototype.unbindResize = function () {
  1977. eventie.unbind(window, 'resize', this);
  1978. this.isResizeBound = false;
  1979. };
  1980. // original debounce by John Hann
  1981. // http://unscriptable.com/index.php/2009/03/20/debouncing-javascript-methods/
  1982. // this fires every resize
  1983. Outlayer.prototype.onresize = function () {
  1984. if (this.resizeTimeout) {
  1985. clearTimeout(this.resizeTimeout);
  1986. }
  1987. var _this = this;
  1988. function delayed() {
  1989. _this.resize();
  1990. delete _this.resizeTimeout;
  1991. }
  1992. this.resizeTimeout = setTimeout(delayed, 100);
  1993. };
  1994. // debounced, layout on resize
  1995. Outlayer.prototype.resize = function () {
  1996. // don't trigger if size did not change
  1997. var size = getSize(this.element);
  1998. // check that this.size and size are there
  1999. // IE8 triggers resize on body size change, so they might not be
  2000. var hasSizes = this.size && size;
  2001. if (hasSizes && size.innerWidth === this.size.innerWidth) {
  2002. return;
  2003. }
  2004. this.layout();
  2005. };
  2006. // -------------------------- methods -------------------------- //
  2007. /**
  2008. * add items to Outlayer instance
  2009. * @param {Array or NodeList or Element} elems
  2010. * @returns {Array} items - Outlayer.Items
  2011. **/
  2012. Outlayer.prototype.addItems = function (elems) {
  2013. var items = this._itemize(elems);
  2014. // add items to collection
  2015. if (items.length) {
  2016. this.items = this.items.concat(items);
  2017. }
  2018. return items;
  2019. };
  2020. /**
  2021. * Layout newly-appended item elements
  2022. * @param {Array or NodeList or Element} elems
  2023. */
  2024. Outlayer.prototype.appended = function (elems) {
  2025. var items = this.addItems(elems);
  2026. if (!items.length) {
  2027. return;
  2028. }
  2029. // layout and reveal just the new items
  2030. this.layoutItems(items, true);
  2031. this.reveal(items);
  2032. };
  2033. /**
  2034. * Layout prepended elements
  2035. * @param {Array or NodeList or Element} elems
  2036. */
  2037. Outlayer.prototype.prepended = function (elems) {
  2038. var items = this._itemize(elems);
  2039. if (!items.length) {
  2040. return;
  2041. }
  2042. // add items to beginning of collection
  2043. var previousItems = this.items.slice(0);
  2044. this.items = items.concat(previousItems);
  2045. // start new layout
  2046. this._resetLayout();
  2047. this._manageStamps();
  2048. // layout new stuff without transition
  2049. this.layoutItems(items, true);
  2050. this.reveal(items);
  2051. // layout previous items
  2052. this.layoutItems(previousItems);
  2053. };
  2054. /**
  2055. * reveal a collection of items
  2056. * @param {Array of Outlayer.Items} items
  2057. */
  2058. Outlayer.prototype.reveal = function (items) {
  2059. var len = items && items.length;
  2060. if (!len) {
  2061. return;
  2062. }
  2063. for (var i = 0; i < len; i++) {
  2064. var item = items[i];
  2065. item.reveal();
  2066. }
  2067. };
  2068. /**
  2069. * hide a collection of items
  2070. * @param {Array of Outlayer.Items} items
  2071. */
  2072. Outlayer.prototype.hide = function (items) {
  2073. var len = items && items.length;
  2074. if (!len) {
  2075. return;
  2076. }
  2077. for (var i = 0; i < len; i++) {
  2078. var item = items[i];
  2079. item.hide();
  2080. }
  2081. };
  2082. /**
  2083. * get Outlayer.Item, given an Element
  2084. * @param {Element} elem
  2085. * @param {Function} callback
  2086. * @returns {Outlayer.Item} item
  2087. */
  2088. Outlayer.prototype.getItem = function (elem) {
  2089. // loop through items to get the one that matches
  2090. for (var i = 0, len = this.items.length; i < len; i++) {
  2091. var item = this.items[i];
  2092. if (item.element === elem) {
  2093. // return item
  2094. return item;
  2095. }
  2096. }
  2097. };
  2098. /**
  2099. * get collection of Outlayer.Items, given Elements
  2100. * @param {Array} elems
  2101. * @returns {Array} items - Outlayer.Items
  2102. */
  2103. Outlayer.prototype.getItems = function (elems) {
  2104. if (!elems || !elems.length) {
  2105. return;
  2106. }
  2107. var items = [];
  2108. for (var i = 0, len = elems.length; i < len; i++) {
  2109. var elem = elems[i];
  2110. var item = this.getItem(elem);
  2111. if (item) {
  2112. items.push(item);
  2113. }
  2114. }
  2115. return items;
  2116. };
  2117. /**
  2118. * remove element(s) from instance and DOM
  2119. * @param {Array or NodeList or Element} elems
  2120. */
  2121. Outlayer.prototype.remove = function (elems) {
  2122. elems = makeArray(elems);
  2123. var removeItems = this.getItems(elems);
  2124. // bail if no items to remove
  2125. if (!removeItems || !removeItems.length) {
  2126. return;
  2127. }
  2128. this._itemsOn(removeItems, 'remove', function () {
  2129. this.emitEvent('removeComplete', [this, removeItems]);
  2130. });
  2131. for (var i = 0, len = removeItems.length; i < len; i++) {
  2132. var item = removeItems[i];
  2133. item.remove();
  2134. // remove item from collection
  2135. removeFrom(item, this.items);
  2136. }
  2137. };
  2138. // ----- destroy ----- //
  2139. // remove and disable Outlayer instance
  2140. Outlayer.prototype.destroy = function () {
  2141. // clean up dynamic styles
  2142. var style = this.element.style;
  2143. style.height = '';
  2144. style.position = '';
  2145. style.width = '';
  2146. // destroy items
  2147. for (var i = 0, len = this.items.length; i < len; i++) {
  2148. var item = this.items[i];
  2149. item.destroy();
  2150. }
  2151. this.unbindResize();
  2152. delete this.element.outlayerGUID;
  2153. // remove data for jQuery
  2154. if (jQuery) {
  2155. jQuery.removeData(this.element, this.constructor.namespace);
  2156. }
  2157. };
  2158. // -------------------------- data -------------------------- //
  2159. /**
  2160. * get Outlayer instance from element
  2161. * @param {Element} elem
  2162. * @returns {Outlayer}
  2163. */
  2164. Outlayer.data = function (elem) {
  2165. var id = elem && elem.outlayerGUID;
  2166. return id && instances[id];
  2167. };
  2168. // -------------------------- -------------------------- //
  2169. // copy an object on the Outlayer prototype to new object
  2170. function copyOutlayerProto(obj, property) {
  2171. obj.prototype[property] = extend({}, Outlayer.prototype[property]);
  2172. }
  2173. // -------------------------- create Outlayer class -------------------------- //
  2174. /**
  2175. * create a layout class
  2176. * @param {String} namespace
  2177. */
  2178. Outlayer.create = function (namespace, options) {
  2179. // sub-class Outlayer
  2180. function Layout() {
  2181. Outlayer.apply(this, arguments);
  2182. }
  2183. // inherit Outlayer prototype, use Object.create if there
  2184. if (Object.create) {
  2185. Layout.prototype = Object.create(Outlayer.prototype);
  2186. } else {
  2187. extend(Layout.prototype, Outlayer.prototype);
  2188. }
  2189. // set contructor, used for namespace and Item
  2190. Layout.prototype.constructor = Layout;
  2191. // copy default options so Outlayer.options don't get touched
  2192. copyOutlayerProto(Layout, 'options');
  2193. // apply new options
  2194. extend(Layout.prototype.options, options);
  2195. Layout.namespace = namespace;
  2196. Layout.data = Outlayer.data;
  2197. // sub-class Item
  2198. Layout.Item = function LayoutItem() {
  2199. Item.apply(this, arguments);
  2200. };
  2201. Layout.Item.prototype = new Item();
  2202. // -------------------------- declarative -------------------------- //
  2203. /**
  2204. * allow user to initialize Outlayer via .js-namespace class
  2205. * options are parsed from data-namespace-option attribute
  2206. */
  2207. docReady(function () {
  2208. var dashedNamespace = toDashed(namespace);
  2209. var elems = document.querySelectorAll('.js-' + dashedNamespace);
  2210. var dataAttr = 'data-' + dashedNamespace + '-options';
  2211. for (var i = 0, len = elems.length; i < len; i++) {
  2212. var elem = elems[i];
  2213. var attr = elem.getAttribute(dataAttr);
  2214. var options;
  2215. try {
  2216. options = attr && JSON.parse(attr);
  2217. } catch (error) {
  2218. // log error, do not initialize
  2219. if (console) {
  2220. console.error('Error parsing ' + dataAttr + ' on ' +
  2221. elem.nodeName.toLowerCase() + (elem.id ? '#' + elem.id : '') + ': ' +
  2222. error);
  2223. }
  2224. continue;
  2225. }
  2226. // initialize
  2227. var instance = new Layout(elem, options);
  2228. // make available via $().data('layoutname')
  2229. if (jQuery) {
  2230. jQuery.data(elem, namespace, instance);
  2231. }
  2232. }
  2233. });
  2234. // -------------------------- jQuery bridge -------------------------- //
  2235. // make into jQuery plugin
  2236. if (jQuery && jQuery.bridget) {
  2237. jQuery.bridget(namespace, Layout);
  2238. }
  2239. return Layout;
  2240. };
  2241. // ----- fin ----- //
  2242. // back in global
  2243. Outlayer.Item = Item;
  2244. return Outlayer;
  2245. }
  2246. // -------------------------- transport -------------------------- //
  2247. if (typeof define === 'function' && define.amd) {
  2248. // AMD
  2249. define('outlayer/outlayer', [
  2250. 'eventie/eventie',
  2251. 'doc-ready/doc-ready',
  2252. 'eventEmitter/EventEmitter',
  2253. 'get-size/get-size',
  2254. 'matches-selector/matches-selector',
  2255. './item'
  2256. ],
  2257. outlayerDefinition);
  2258. } else {
  2259. // browser global
  2260. window.Outlayer = outlayerDefinition(
  2261. window.eventie,
  2262. window.docReady,
  2263. window.EventEmitter,
  2264. window.getSize,
  2265. window.matchesSelector,
  2266. window.Outlayer.Item
  2267. );
  2268. }
  2269. })(window);
  2270. /*!
  2271. * Masonry v3.1.4
  2272. * Cascading grid layout library
  2273. * http://masonry.desandro.com
  2274. * MIT License
  2275. * by David DeSandro
  2276. */
  2277. (function (window) {
  2278. // -------------------------- helpers -------------------------- //
  2279. var indexOf = Array.prototype.indexOf ?
  2280. function (items, value) {
  2281. return items.indexOf(value);
  2282. } :
  2283. function (items, value) {
  2284. for (var i = 0, len = items.length; i < len; i++) {
  2285. var item = items[i];
  2286. if (item === value) {
  2287. return i;
  2288. }
  2289. }
  2290. return -1;
  2291. };
  2292. // -------------------------- masonryDefinition -------------------------- //
  2293. // used for AMD definition and requires
  2294. function masonryDefinition(Outlayer, getSize) {
  2295. // create an Outlayer layout class
  2296. var Masonry = Outlayer.create('masonry');
  2297. Masonry.prototype._resetLayout = function () {
  2298. this.getSize();
  2299. this._getMeasurement('columnWidth', 'outerWidth');
  2300. this._getMeasurement('gutter', 'outerWidth');
  2301. this.measureColumns();
  2302. // reset column Y
  2303. var i = this.cols;
  2304. this.colYs = [];
  2305. while (i--) {
  2306. this.colYs.push(0);
  2307. }
  2308. this.maxY = 0;
  2309. };
  2310. Masonry.prototype.measureColumns = function () {
  2311. this.getContainerWidth();
  2312. // if columnWidth is 0, default to outerWidth of first item
  2313. if (!this.columnWidth) {
  2314. var firstItem;
  2315. for (var i = 0, len = this.items.length; i < len; i++) {
  2316. if (!this.items[i].isIgnored) {
  2317. firstItem = this.items[i];
  2318. break;
  2319. }
  2320. }
  2321. if (!firstItem) {
  2322. firstItem = this.items[0];
  2323. }
  2324. var firstItemElem = firstItem && firstItem.element;
  2325. // columnWidth fall back to item of first element
  2326. this.columnWidth = firstItemElem && getSize(firstItemElem).outerWidth ||
  2327. // if first elem has no width, default to size of container
  2328. this.containerWidth;
  2329. }
  2330. this.columnWidth += this.gutter;
  2331. this.cols = Math.floor((this.containerWidth + this.gutter) / this.columnWidth);
  2332. this.cols = Math.max(this.cols, 1);
  2333. };
  2334. Masonry.prototype.getContainerWidth = function () {
  2335. // container is parent if fit width
  2336. var container = this.options.isFitWidth ? this.element.parentNode : this.element;
  2337. // check that this.size and size are there
  2338. // IE8 triggers resize on body size change, so they might not be
  2339. var size = getSize(container);
  2340. this.containerWidth = size && size.innerWidth;
  2341. };
  2342. Masonry.prototype._getItemLayoutPosition = function (item) {
  2343. item.getSize();
  2344. // how many columns does this brick span
  2345. var remainder = item.size.outerWidth % this.columnWidth;
  2346. var mathMethod = remainder && remainder < 1 ? 'round' : 'ceil';
  2347. // round if off by 1 pixel, otherwise use ceil
  2348. var colSpan = Math[mathMethod](item.size.outerWidth / this.columnWidth);
  2349. colSpan = Math.min(colSpan, this.cols);
  2350. var colGroup = this._getColGroup(colSpan);
  2351. // get the minimum Y value from the columns
  2352. var minimumY = Math.min.apply(Math, colGroup);
  2353. var shortColIndex = indexOf(colGroup, minimumY);
  2354. // position the brick
  2355. var position = {
  2356. x: this.columnWidth * shortColIndex,
  2357. y: minimumY
  2358. };
  2359. // apply setHeight to necessary columns
  2360. var setHeight = minimumY + item.size.outerHeight;
  2361. var setSpan = this.cols + 1 - colGroup.length;
  2362. for (var i = 0; i < setSpan; i++) {
  2363. this.colYs[shortColIndex + i] = setHeight;
  2364. }
  2365. return position;
  2366. };
  2367. /**
  2368. * @param {Number} colSpan - number of columns the element spans
  2369. * @returns {Array} colGroup
  2370. */
  2371. Masonry.prototype._getColGroup = function (colSpan) {
  2372. if (colSpan < 2) {
  2373. // if brick spans only one column, use all the column Ys
  2374. return this.colYs;
  2375. }
  2376. var colGroup = [];
  2377. // how many different places could this brick fit horizontally
  2378. var groupCount = this.cols + 1 - colSpan;
  2379. // for each group potential horizontal position
  2380. for (var i = 0; i < groupCount; i++) {
  2381. // make an array of colY values for that one group
  2382. var groupColYs = this.colYs.slice(i, i + colSpan);
  2383. // and get the max value of the array
  2384. colGroup[i] = Math.max.apply(Math, groupColYs);
  2385. }
  2386. return colGroup;
  2387. };
  2388. Masonry.prototype._manageStamp = function (stamp) {
  2389. var stampSize = getSize(stamp);
  2390. var offset = this._getElementOffset(stamp);
  2391. // get the columns that this stamp affects
  2392. var firstX = this.options.isOriginLeft ? offset.left : offset.right;
  2393. var lastX = firstX + stampSize.outerWidth;
  2394. var firstCol = Math.floor(firstX / this.columnWidth);
  2395. firstCol = Math.max(0, firstCol);
  2396. var lastCol = Math.floor(lastX / this.columnWidth);
  2397. // lastCol should not go over if multiple of columnWidth #425
  2398. lastCol -= lastX % this.columnWidth ? 0 : 1;
  2399. lastCol = Math.min(this.cols - 1, lastCol);
  2400. // set colYs to bottom of the stamp
  2401. var stampMaxY = (this.options.isOriginTop ? offset.top : offset.bottom) +
  2402. stampSize.outerHeight;
  2403. for (var i = firstCol; i <= lastCol; i++) {
  2404. this.colYs[i] = Math.max(stampMaxY, this.colYs[i]);
  2405. }
  2406. };
  2407. Masonry.prototype._getContainerSize = function () {
  2408. this.maxY = Math.max.apply(Math, this.colYs);
  2409. var size = {
  2410. height: this.maxY
  2411. };
  2412. if (this.options.isFitWidth) {
  2413. size.width = this._getContainerFitWidth();
  2414. }
  2415. return size;
  2416. };
  2417. Masonry.prototype._getContainerFitWidth = function () {
  2418. var unusedCols = 0;
  2419. // count unused columns
  2420. var i = this.cols;
  2421. while (--i) {
  2422. if (this.colYs[i] !== 0) {
  2423. break;
  2424. }
  2425. unusedCols++;
  2426. }
  2427. // fit container to columns that have been used
  2428. return (this.cols - unusedCols) * this.columnWidth - this.gutter;
  2429. };
  2430. // debounced, layout on resize
  2431. // HEADS UP this overwrites Outlayer.resize
  2432. // Any changes in Outlayer.resize need to be manually added here
  2433. Masonry.prototype.resize = function () {
  2434. // don't trigger if size did not change
  2435. var previousWidth = this.containerWidth;
  2436. this.getContainerWidth();
  2437. if (previousWidth === this.containerWidth) {
  2438. return;
  2439. }
  2440. this.layout();
  2441. };
  2442. return Masonry;
  2443. }
  2444. // -------------------------- transport -------------------------- //
  2445. if (typeof define === 'function' && define.amd) {
  2446. // AMD
  2447. define([
  2448. 'outlayer/outlayer',
  2449. 'get-size/get-size'
  2450. ],
  2451. masonryDefinition);
  2452. } else {
  2453. // browser global
  2454. window.Masonry = masonryDefinition(
  2455. window.Outlayer,
  2456. window.getSize
  2457. );
  2458. }
  2459. })(window);