linaro-jekyll-theme 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -4
  3. data/_data/authors.yml +7 -0
  4. data/_data/company.yml +2 -1
  5. data/_data/sub-nav.yml +15 -0
  6. data/_includes/_theme-includes/_head/head.html +1 -1
  7. data/_includes/_theme-includes/_navigation/tabbed-nav.html +32 -0
  8. data/_includes/_theme-includes/_page-structure/home-hero.html +6 -6
  9. data/_includes/_theme-includes/_script-includes/javascript.html +14 -2
  10. data/{assets/vendor.js → _layouts/about.html} +0 -0
  11. data/_layouts/blog.html +3 -2
  12. data/_layouts/default-no-sub-nav.html +2 -2
  13. data/_layouts/default.html +3 -3
  14. data/_layouts/fluid-no-sub-nav.html +11 -0
  15. data/_layouts/fluid.html +15 -0
  16. data/_layouts/home.html +2 -2
  17. data/_layouts/post.html +130 -144
  18. data/_sass/core/nav.scss +5 -1
  19. data/_sass/core/theme.scss +9 -6
  20. data/assets/css/blog-pages.scss +1 -2
  21. data/assets/css/main.scss +0 -1
  22. data/assets/images/avatar-placeholder.png +0 -0
  23. data/assets/images/css3.png +0 -0
  24. data/assets/images/favicon.ico +0 -0
  25. data/assets/images/favicon.png +0 -0
  26. data/assets/images/html5.png +0 -0
  27. data/assets/images/jekyll.svg +1 -0
  28. data/assets/images/js.jpeg +0 -0
  29. data/assets/js/app/{96boards.js → main.js} +0 -29
  30. data/assets/js/app/{search-page.js → search.js} +0 -0
  31. data/assets/js/app/{sticky-navbar.js → sticky.js} +0 -0
  32. data/assets/js/vendor/flipclock.min.js +33 -0
  33. data/assets/js/vendor/lightbox.min.js +14 -0
  34. metadata +19 -23
  35. data/_includes/_theme-includes/_footer/backup.html +0 -71
  36. data/_includes/_theme-includes/_head/ascii-art.html +0 -11
  37. data/_includes/_theme-includes/_navigation/_sub-navigation/tabbed-nav.html +0 -26
  38. data/_includes/_theme-includes/_page-structure/old-breadcrumb.html +0 -139
  39. data/_sass/blog-pages.scss +0 -5
  40. data/assets/js/app.js +0 -2
  41. data/assets/js/app/app.js +0 -5
  42. data/assets/js/app/mixitup.js +0 -23
  43. data/assets/js/sticky-navbar.js +0 -65
  44. data/assets/js/vendor.js +0 -7
  45. data/assets/js/vendor/filtrify.js +0 -11
  46. data/assets/js/vendor/lightbox.js +0 -519
  47. data/assets/js/vendor/loadCSS.js +0 -35
  48. data/assets/js/vendor/loadCSS.min.js +0 -2
  49. data/assets/js/vendor/picturefill.min.js +0 -5
  50. data/assets/js/vendor/shuffle.js +0 -2004
  51. data/assets/js/vendor/vendor.js +0 -6
@@ -1,35 +0,0 @@
1
- /*! loadCSS: load a CSS file asynchronously. [c]2016 @scottjehl, Filament Group, Inc. Licensed MIT */
2
- ! function(e) {
3
- "use strict";
4
- var n = function(n, t, o) {
5
- function i(e) {
6
- return a.body ? e() : void setTimeout(function() {
7
- i(e)
8
- })
9
- }
10
-
11
- function r() {
12
- l.addEventListener && l.removeEventListener("load", r), l.media = o || "all"
13
- }
14
- var d, a = e.document,
15
- l = a.createElement("link");
16
- if (t) d = t;
17
- else {
18
- var s = (a.body || a.getElementsByTagName("head")[0]).childNodes;
19
- d = s[s.length - 1]
20
- }
21
- var f = a.styleSheets;
22
- l.rel = "stylesheet", l.href = n, l.media = "only x", i(function() {
23
- d.parentNode.insertBefore(l, t ? d : d.nextSibling)
24
- });
25
- var u = function(e) {
26
- for (var n = l.href, t = f.length; t--;)
27
- if (f[t].href === n) return e();
28
- setTimeout(function() {
29
- u(e)
30
- })
31
- };
32
- return l.addEventListener && l.addEventListener("load", r), l.onloadcssdefined = u, u(r), l
33
- };
34
- "undefined" != typeof exports ? exports.loadCSS = n : e.loadCSS = n
35
- }("undefined" != typeof global ? global : this);
@@ -1,2 +0,0 @@
1
- /*! loadCSS. [c]2017 Filament Group, Inc. MIT License */
2
- !function(a){"use strict";var b=function(b,c,d){function e(a){return h.body?a():void setTimeout(function(){e(a)})}function f(){i.addEventListener&&i.removeEventListener("load",f),i.media=d||"all"}var g,h=a.document,i=h.createElement("link");if(c)g=c;else{var j=(h.body||h.getElementsByTagName("head")[0]).childNodes;g=j[j.length-1]}var k=h.styleSheets;i.rel="stylesheet",i.href=b,i.media="only x",e(function(){g.parentNode.insertBefore(i,c?g:g.nextSibling)});var l=function(a){for(var b=i.href,c=k.length;c--;)if(k[c].href===b)return a();setTimeout(function(){l(a)})};return i.addEventListener&&i.addEventListener("load",f),i.onloadcssdefined=l,l(f),i};"undefined"!=typeof exports?exports.loadCSS=b:a.loadCSS=b}("undefined"!=typeof global?global:this);
@@ -1,5 +0,0 @@
1
- /*! picturefill - v3.0.2 - 2016-02-12
2
- * https://scottjehl.github.io/picturefill/
3
- * Copyright (c) 2016 https://github.com/scottjehl/picturefill/blob/master/Authors.txt; Licensed MIT
4
- */
5
- !function(a){var b=navigator.userAgent;a.HTMLPictureElement&&/ecko/.test(b)&&b.match(/rv\:(\d+)/)&&RegExp.$1<45&&addEventListener("resize",function(){var b,c=document.createElement("source"),d=function(a){var b,d,e=a.parentNode;"PICTURE"===e.nodeName.toUpperCase()?(b=c.cloneNode(),e.insertBefore(b,e.firstElementChild),setTimeout(function(){e.removeChild(b)})):(!a._pfLastSize||a.offsetWidth>a._pfLastSize)&&(a._pfLastSize=a.offsetWidth,d=a.sizes,a.sizes+=",100vw",setTimeout(function(){a.sizes=d}))},e=function(){var a,b=document.querySelectorAll("picture > img, img[srcset][sizes]");for(a=0;a<b.length;a++)d(b[a])},f=function(){clearTimeout(b),b=setTimeout(e,99)},g=a.matchMedia&&matchMedia("(orientation: landscape)"),h=function(){f(),g&&g.addListener&&g.addListener(f)};return c.srcset="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==",/^[c|i]|d$/.test(document.readyState||"")?h():document.addEventListener("DOMContentLoaded",h),f}())}(window),function(a,b,c){"use strict";function d(a){return" "===a||" "===a||"\n"===a||"\f"===a||"\r"===a}function e(b,c){var d=new a.Image;return d.onerror=function(){A[b]=!1,ba()},d.onload=function(){A[b]=1===d.width,ba()},d.src=c,"pending"}function f(){M=!1,P=a.devicePixelRatio,N={},O={},s.DPR=P||1,Q.width=Math.max(a.innerWidth||0,z.clientWidth),Q.height=Math.max(a.innerHeight||0,z.clientHeight),Q.vw=Q.width/100,Q.vh=Q.height/100,r=[Q.height,Q.width,P].join("-"),Q.em=s.getEmValue(),Q.rem=Q.em}function g(a,b,c,d){var e,f,g,h;return"saveData"===B.algorithm?a>2.7?h=c+1:(f=b-c,e=Math.pow(a-.6,1.5),g=f*e,d&&(g+=.1*e),h=a+g):h=c>1?Math.sqrt(a*b):a,h>c}function h(a){var b,c=s.getSet(a),d=!1;"pending"!==c&&(d=r,c&&(b=s.setRes(c),s.applySetCandidate(b,a))),a[s.ns].evaled=d}function i(a,b){return a.res-b.res}function j(a,b,c){var d;return!c&&b&&(c=a[s.ns].sets,c=c&&c[c.length-1]),d=k(b,c),d&&(b=s.makeUrl(b),a[s.ns].curSrc=b,a[s.ns].curCan=d,d.res||aa(d,d.set.sizes)),d}function k(a,b){var c,d,e;if(a&&b)for(e=s.parseSet(b),a=s.makeUrl(a),c=0;c<e.length;c++)if(a===s.makeUrl(e[c].url)){d=e[c];break}return d}function l(a,b){var c,d,e,f,g=a.getElementsByTagName("source");for(c=0,d=g.length;d>c;c++)e=g[c],e[s.ns]=!0,f=e.getAttribute("srcset"),f&&b.push({srcset:f,media:e.getAttribute("media"),type:e.getAttribute("type"),sizes:e.getAttribute("sizes")})}function m(a,b){function c(b){var c,d=b.exec(a.substring(m));return d?(c=d[0],m+=c.length,c):void 0}function e(){var a,c,d,e,f,i,j,k,l,m=!1,o={};for(e=0;e<h.length;e++)f=h[e],i=f[f.length-1],j=f.substring(0,f.length-1),k=parseInt(j,10),l=parseFloat(j),X.test(j)&&"w"===i?((a||c)&&(m=!0),0===k?m=!0:a=k):Y.test(j)&&"x"===i?((a||c||d)&&(m=!0),0>l?m=!0:c=l):X.test(j)&&"h"===i?((d||c)&&(m=!0),0===k?m=!0:d=k):m=!0;m||(o.url=g,a&&(o.w=a),c&&(o.d=c),d&&(o.h=d),d||c||a||(o.d=1),1===o.d&&(b.has1x=!0),o.set=b,n.push(o))}function f(){for(c(T),i="",j="in descriptor";;){if(k=a.charAt(m),"in descriptor"===j)if(d(k))i&&(h.push(i),i="",j="after descriptor");else{if(","===k)return m+=1,i&&h.push(i),void e();if("("===k)i+=k,j="in parens";else{if(""===k)return i&&h.push(i),void e();i+=k}}else if("in parens"===j)if(")"===k)i+=k,j="in descriptor";else{if(""===k)return h.push(i),void e();i+=k}else if("after descriptor"===j)if(d(k));else{if(""===k)return void e();j="in descriptor",m-=1}m+=1}}for(var g,h,i,j,k,l=a.length,m=0,n=[];;){if(c(U),m>=l)return n;g=c(V),h=[],","===g.slice(-1)?(g=g.replace(W,""),e()):f()}}function n(a){function b(a){function b(){f&&(g.push(f),f="")}function c(){g[0]&&(h.push(g),g=[])}for(var e,f="",g=[],h=[],i=0,j=0,k=!1;;){if(e=a.charAt(j),""===e)return b(),c(),h;if(k){if("*"===e&&"/"===a[j+1]){k=!1,j+=2,b();continue}j+=1}else{if(d(e)){if(a.charAt(j-1)&&d(a.charAt(j-1))||!f){j+=1;continue}if(0===i){b(),j+=1;continue}e=" "}else if("("===e)i+=1;else if(")"===e)i-=1;else{if(","===e){b(),c(),j+=1;continue}if("/"===e&&"*"===a.charAt(j+1)){k=!0,j+=2;continue}}f+=e,j+=1}}}function c(a){return k.test(a)&&parseFloat(a)>=0?!0:l.test(a)?!0:"0"===a||"-0"===a||"+0"===a?!0:!1}var e,f,g,h,i,j,k=/^(?:[+-]?[0-9]+|[0-9]*\.[0-9]+)(?:[eE][+-]?[0-9]+)?(?:ch|cm|em|ex|in|mm|pc|pt|px|rem|vh|vmin|vmax|vw)$/i,l=/^calc\((?:[0-9a-z \.\+\-\*\/\(\)]+)\)$/i;for(f=b(a),g=f.length,e=0;g>e;e++)if(h=f[e],i=h[h.length-1],c(i)){if(j=i,h.pop(),0===h.length)return j;if(h=h.join(" "),s.matchesMedia(h))return j}return"100vw"}b.createElement("picture");var o,p,q,r,s={},t=!1,u=function(){},v=b.createElement("img"),w=v.getAttribute,x=v.setAttribute,y=v.removeAttribute,z=b.documentElement,A={},B={algorithm:""},C="data-pfsrc",D=C+"set",E=navigator.userAgent,F=/rident/.test(E)||/ecko/.test(E)&&E.match(/rv\:(\d+)/)&&RegExp.$1>35,G="currentSrc",H=/\s+\+?\d+(e\d+)?w/,I=/(\([^)]+\))?\s*(.+)/,J=a.picturefillCFG,K="position:absolute;left:0;visibility:hidden;display:block;padding:0;border:none;font-size:1em;width:1em;overflow:hidden;clip:rect(0px, 0px, 0px, 0px)",L="font-size:100%!important;",M=!0,N={},O={},P=a.devicePixelRatio,Q={px:1,"in":96},R=b.createElement("a"),S=!1,T=/^[ \t\n\r\u000c]+/,U=/^[, \t\n\r\u000c]+/,V=/^[^ \t\n\r\u000c]+/,W=/[,]+$/,X=/^\d+$/,Y=/^-?(?:[0-9]+|[0-9]*\.[0-9]+)(?:[eE][+-]?[0-9]+)?$/,Z=function(a,b,c,d){a.addEventListener?a.addEventListener(b,c,d||!1):a.attachEvent&&a.attachEvent("on"+b,c)},$=function(a){var b={};return function(c){return c in b||(b[c]=a(c)),b[c]}},_=function(){var a=/^([\d\.]+)(em|vw|px)$/,b=function(){for(var a=arguments,b=0,c=a[0];++b in a;)c=c.replace(a[b],a[++b]);return c},c=$(function(a){return"return "+b((a||"").toLowerCase(),/\band\b/g,"&&",/,/g,"||",/min-([a-z-\s]+):/g,"e.$1>=",/max-([a-z-\s]+):/g,"e.$1<=",/calc([^)]+)/g,"($1)",/(\d+[\.]*[\d]*)([a-z]+)/g,"($1 * e.$2)",/^(?!(e.[a-z]|[0-9\.&=|><\+\-\*\(\)\/])).*/gi,"")+";"});return function(b,d){var e;if(!(b in N))if(N[b]=!1,d&&(e=b.match(a)))N[b]=e[1]*Q[e[2]];else try{N[b]=new Function("e",c(b))(Q)}catch(f){}return N[b]}}(),aa=function(a,b){return a.w?(a.cWidth=s.calcListLength(b||"100vw"),a.res=a.w/a.cWidth):a.res=a.d,a},ba=function(a){if(t){var c,d,e,f=a||{};if(f.elements&&1===f.elements.nodeType&&("IMG"===f.elements.nodeName.toUpperCase()?f.elements=[f.elements]:(f.context=f.elements,f.elements=null)),c=f.elements||s.qsa(f.context||b,f.reevaluate||f.reselect?s.sel:s.selShort),e=c.length){for(s.setupRun(f),S=!0,d=0;e>d;d++)s.fillImg(c[d],f);s.teardownRun(f)}}};o=a.console&&console.warn?function(a){console.warn(a)}:u,G in v||(G="src"),A["image/jpeg"]=!0,A["image/gif"]=!0,A["image/png"]=!0,A["image/svg+xml"]=b.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#Image","1.1"),s.ns=("pf"+(new Date).getTime()).substr(0,9),s.supSrcset="srcset"in v,s.supSizes="sizes"in v,s.supPicture=!!a.HTMLPictureElement,s.supSrcset&&s.supPicture&&!s.supSizes&&!function(a){v.srcset="data:,a",a.src="data:,a",s.supSrcset=v.complete===a.complete,s.supPicture=s.supSrcset&&s.supPicture}(b.createElement("img")),s.supSrcset&&!s.supSizes?!function(){var a="data:image/gif;base64,R0lGODlhAgABAPAAAP///wAAACH5BAAAAAAALAAAAAACAAEAAAICBAoAOw==",c="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==",d=b.createElement("img"),e=function(){var a=d.width;2===a&&(s.supSizes=!0),q=s.supSrcset&&!s.supSizes,t=!0,setTimeout(ba)};d.onload=e,d.onerror=e,d.setAttribute("sizes","9px"),d.srcset=c+" 1w,"+a+" 9w",d.src=c}():t=!0,s.selShort="picture>img,img[srcset]",s.sel=s.selShort,s.cfg=B,s.DPR=P||1,s.u=Q,s.types=A,s.setSize=u,s.makeUrl=$(function(a){return R.href=a,R.href}),s.qsa=function(a,b){return"querySelector"in a?a.querySelectorAll(b):[]},s.matchesMedia=function(){return a.matchMedia&&(matchMedia("(min-width: 0.1em)")||{}).matches?s.matchesMedia=function(a){return!a||matchMedia(a).matches}:s.matchesMedia=s.mMQ,s.matchesMedia.apply(this,arguments)},s.mMQ=function(a){return a?_(a):!0},s.calcLength=function(a){var b=_(a,!0)||!1;return 0>b&&(b=!1),b},s.supportsType=function(a){return a?A[a]:!0},s.parseSize=$(function(a){var b=(a||"").match(I);return{media:b&&b[1],length:b&&b[2]}}),s.parseSet=function(a){return a.cands||(a.cands=m(a.srcset,a)),a.cands},s.getEmValue=function(){var a;if(!p&&(a=b.body)){var c=b.createElement("div"),d=z.style.cssText,e=a.style.cssText;c.style.cssText=K,z.style.cssText=L,a.style.cssText=L,a.appendChild(c),p=c.offsetWidth,a.removeChild(c),p=parseFloat(p,10),z.style.cssText=d,a.style.cssText=e}return p||16},s.calcListLength=function(a){if(!(a in O)||B.uT){var b=s.calcLength(n(a));O[a]=b?b:Q.width}return O[a]},s.setRes=function(a){var b;if(a){b=s.parseSet(a);for(var c=0,d=b.length;d>c;c++)aa(b[c],a.sizes)}return b},s.setRes.res=aa,s.applySetCandidate=function(a,b){if(a.length){var c,d,e,f,h,k,l,m,n,o=b[s.ns],p=s.DPR;if(k=o.curSrc||b[G],l=o.curCan||j(b,k,a[0].set),l&&l.set===a[0].set&&(n=F&&!b.complete&&l.res-.1>p,n||(l.cached=!0,l.res>=p&&(h=l))),!h)for(a.sort(i),f=a.length,h=a[f-1],d=0;f>d;d++)if(c=a[d],c.res>=p){e=d-1,h=a[e]&&(n||k!==s.makeUrl(c.url))&&g(a[e].res,c.res,p,a[e].cached)?a[e]:c;break}h&&(m=s.makeUrl(h.url),o.curSrc=m,o.curCan=h,m!==k&&s.setSrc(b,h),s.setSize(b))}},s.setSrc=function(a,b){var c;a.src=b.url,"image/svg+xml"===b.set.type&&(c=a.style.width,a.style.width=a.offsetWidth+1+"px",a.offsetWidth+1&&(a.style.width=c))},s.getSet=function(a){var b,c,d,e=!1,f=a[s.ns].sets;for(b=0;b<f.length&&!e;b++)if(c=f[b],c.srcset&&s.matchesMedia(c.media)&&(d=s.supportsType(c.type))){"pending"===d&&(c=d),e=c;break}return e},s.parseSets=function(a,b,d){var e,f,g,h,i=b&&"PICTURE"===b.nodeName.toUpperCase(),j=a[s.ns];(j.src===c||d.src)&&(j.src=w.call(a,"src"),j.src?x.call(a,C,j.src):y.call(a,C)),(j.srcset===c||d.srcset||!s.supSrcset||a.srcset)&&(e=w.call(a,"srcset"),j.srcset=e,h=!0),j.sets=[],i&&(j.pic=!0,l(b,j.sets)),j.srcset?(f={srcset:j.srcset,sizes:w.call(a,"sizes")},j.sets.push(f),g=(q||j.src)&&H.test(j.srcset||""),g||!j.src||k(j.src,f)||f.has1x||(f.srcset+=", "+j.src,f.cands.push({url:j.src,d:1,set:f}))):j.src&&j.sets.push({srcset:j.src,sizes:null}),j.curCan=null,j.curSrc=c,j.supported=!(i||f&&!s.supSrcset||g&&!s.supSizes),h&&s.supSrcset&&!j.supported&&(e?(x.call(a,D,e),a.srcset=""):y.call(a,D)),j.supported&&!j.srcset&&(!j.src&&a.src||a.src!==s.makeUrl(j.src))&&(null===j.src?a.removeAttribute("src"):a.src=j.src),j.parsed=!0},s.fillImg=function(a,b){var c,d=b.reselect||b.reevaluate;a[s.ns]||(a[s.ns]={}),c=a[s.ns],(d||c.evaled!==r)&&((!c.parsed||b.reevaluate)&&s.parseSets(a,a.parentNode,b),c.supported?c.evaled=r:h(a))},s.setupRun=function(){(!S||M||P!==a.devicePixelRatio)&&f()},s.supPicture?(ba=u,s.fillImg=u):!function(){var c,d=a.attachEvent?/d$|^c/:/d$|^c|^i/,e=function(){var a=b.readyState||"";f=setTimeout(e,"loading"===a?200:999),b.body&&(s.fillImgs(),c=c||d.test(a),c&&clearTimeout(f))},f=setTimeout(e,b.body?9:99),g=function(a,b){var c,d,e=function(){var f=new Date-d;b>f?c=setTimeout(e,b-f):(c=null,a())};return function(){d=new Date,c||(c=setTimeout(e,b))}},h=z.clientHeight,i=function(){M=Math.max(a.innerWidth||0,z.clientWidth)!==Q.width||z.clientHeight!==h,h=z.clientHeight,M&&s.fillImgs()};Z(a,"resize",g(i,99)),Z(b,"readystatechange",e)}(),s.picturefill=ba,s.fillImgs=ba,s.teardownRun=u,ba._=s,a.picturefillCFG={pf:s,push:function(a){var b=a.shift();"function"==typeof s[b]?s[b].apply(s,a):(B[b]=a[0],S&&s.fillImgs({reselect:!0}))}};for(;J&&J.length;)a.picturefillCFG.push(J.shift());a.picturefill=ba,"object"==typeof module&&"object"==typeof module.exports?module.exports=ba:"function"==typeof define&&define.amd&&define("picturefill",function(){return ba}),s.supPicture||(A["image/webp"]=e("image/webp","data:image/webp;base64,UklGRkoAAABXRUJQVlA4WAoAAAAQAAAAAAAAAAAAQUxQSAwAAAABBxAR/Q9ERP8DAABWUDggGAAAADABAJ0BKgEAAQADADQlpAADcAD++/1QAA=="))}(window,document);
@@ -1,2004 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
3
- typeof define === 'function' && define.amd ? define(factory) :
4
- (global.shuffle = factory());
5
- }(this, (function () { 'use strict';
6
-
7
- // Polyfill for creating CustomEvents on IE9/10/11
8
-
9
- // code pulled from:
10
- // https://github.com/d4tocchini/customevent-polyfill
11
- // https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent#Polyfill
12
-
13
- try {
14
- var ce = new window.CustomEvent('test');
15
- ce.preventDefault();
16
- if (ce.defaultPrevented !== true) {
17
- // IE has problems with .preventDefault() on custom events
18
- // http://stackoverflow.com/questions/23349191
19
- throw new Error('Could not prevent default');
20
- }
21
- } catch(e) {
22
- var CustomEvent$1 = function(event, params) {
23
- var evt, origPrevent;
24
- params = params || {
25
- bubbles: false,
26
- cancelable: false,
27
- detail: undefined
28
- };
29
-
30
- evt = document.createEvent("CustomEvent");
31
- evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
32
- origPrevent = evt.preventDefault;
33
- evt.preventDefault = function () {
34
- origPrevent.call(this);
35
- try {
36
- Object.defineProperty(this, 'defaultPrevented', {
37
- get: function () {
38
- return true;
39
- }
40
- });
41
- } catch(e) {
42
- this.defaultPrevented = true;
43
- }
44
- };
45
- return evt;
46
- };
47
-
48
- CustomEvent$1.prototype = window.Event.prototype;
49
- window.CustomEvent = CustomEvent$1; // expose definition to window
50
- }
51
-
52
- var proto = Element.prototype;
53
- var vendor = proto.matches
54
- || proto.matchesSelector
55
- || proto.webkitMatchesSelector
56
- || proto.mozMatchesSelector
57
- || proto.msMatchesSelector
58
- || proto.oMatchesSelector;
59
-
60
- var index = match;
61
-
62
- /**
63
- * Match `el` to `selector`.
64
- *
65
- * @param {Element} el
66
- * @param {String} selector
67
- * @return {Boolean}
68
- * @api public
69
- */
70
-
71
- function match(el, selector) {
72
- if (vendor) return vendor.call(el, selector);
73
- var nodes = el.parentNode.querySelectorAll(selector);
74
- for (var i = 0; i < nodes.length; i++) {
75
- if (nodes[i] == el) return true;
76
- }
77
- return false;
78
- }
79
-
80
- var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
81
-
82
-
83
-
84
-
85
-
86
- function createCommonjsModule(fn, module) {
87
- return module = { exports: {} }, fn(module, module.exports), module.exports;
88
- }
89
-
90
- var index$1 = createCommonjsModule(function (module) {
91
- 'use strict';
92
-
93
- // there's 3 implementations written in increasing order of efficiency
94
-
95
- // 1 - no Set type is defined
96
- function uniqNoSet(arr) {
97
- var ret = [];
98
-
99
- for (var i = 0; i < arr.length; i++) {
100
- if (ret.indexOf(arr[i]) === -1) {
101
- ret.push(arr[i]);
102
- }
103
- }
104
-
105
- return ret;
106
- }
107
-
108
- // 2 - a simple Set type is defined
109
- function uniqSet(arr) {
110
- var seen = new Set();
111
- return arr.filter(function (el) {
112
- if (!seen.has(el)) {
113
- seen.add(el);
114
- return true;
115
- }
116
-
117
- return false;
118
- });
119
- }
120
-
121
- // 3 - a standard Set type is defined and it has a forEach method
122
- function uniqSetWithForEach(arr) {
123
- var ret = [];
124
-
125
- (new Set(arr)).forEach(function (el) {
126
- ret.push(el);
127
- });
128
-
129
- return ret;
130
- }
131
-
132
- // V8 currently has a broken implementation
133
- // https://github.com/joyent/node/issues/8449
134
- function doesForEachActuallyWork() {
135
- var ret = false;
136
-
137
- (new Set([true])).forEach(function (el) {
138
- ret = el;
139
- });
140
-
141
- return ret === true;
142
- }
143
-
144
- if ('Set' in commonjsGlobal) {
145
- if (typeof Set.prototype.forEach === 'function' && doesForEachActuallyWork()) {
146
- module.exports = uniqSetWithForEach;
147
- } else {
148
- module.exports = uniqSet;
149
- }
150
- } else {
151
- module.exports = uniqNoSet;
152
- }
153
- });
154
-
155
- var immutable = extend;
156
-
157
- var hasOwnProperty = Object.prototype.hasOwnProperty;
158
-
159
- function extend() {
160
- var target = {};
161
-
162
- for (var i = 0; i < arguments.length; i++) {
163
- var source = arguments[i];
164
-
165
- for (var key in source) {
166
- if (hasOwnProperty.call(source, key)) {
167
- target[key] = source[key];
168
- }
169
- }
170
- }
171
-
172
- return target
173
- }
174
-
175
- var index$2 = throttle;
176
-
177
- /**
178
- * Returns a new function that, when invoked, invokes `func` at most once per `wait` milliseconds.
179
- *
180
- * @param {Function} func Function to wrap.
181
- * @param {Number} wait Number of milliseconds that must elapse between `func` invocations.
182
- * @return {Function} A new function that wraps the `func` function passed in.
183
- */
184
-
185
- function throttle (func, wait) {
186
- var ctx, args, rtn, timeoutID; // caching
187
- var last = 0;
188
-
189
- return function throttled () {
190
- ctx = this;
191
- args = arguments;
192
- var delta = new Date() - last;
193
- if (!timeoutID)
194
- if (delta >= wait) call();
195
- else timeoutID = setTimeout(call, wait - delta);
196
- return rtn;
197
- };
198
-
199
- function call () {
200
- timeoutID = 0;
201
- last = +new Date();
202
- rtn = func.apply(ctx, args);
203
- ctx = null;
204
- args = null;
205
- }
206
- }
207
-
208
- var index$3 = function parallel(fns, context, callback) {
209
- if (!callback) {
210
- if (typeof context === 'function') {
211
- callback = context;
212
- context = null;
213
- } else {
214
- callback = noop;
215
- }
216
- }
217
-
218
- var pending = fns && fns.length;
219
- if (!pending) return callback(null, []);
220
-
221
- var finished = false;
222
- var results = new Array(pending);
223
-
224
- fns.forEach(context ? function (fn, i) {
225
- fn.call(context, maybeDone(i));
226
- } : function (fn, i) {
227
- fn(maybeDone(i));
228
- });
229
-
230
- function maybeDone(i) {
231
- return function (err, result) {
232
- if (finished) return;
233
-
234
- if (err) {
235
- callback(err, results);
236
- finished = true;
237
- return
238
- }
239
-
240
- results[i] = result;
241
-
242
- if (!--pending) callback(null, results);
243
- }
244
- }
245
- };
246
-
247
- function noop() {}
248
-
249
- /**
250
- * Always returns a numeric value, given a value. Logic from jQuery's `isNumeric`.
251
- * @param {*} value Possibly numeric value.
252
- * @return {number} `value` or zero if `value` isn't numeric.
253
- */
254
- function getNumber(value) {
255
- return parseFloat(value) || 0;
256
- }
257
-
258
- var classCallCheck = function (instance, Constructor) {
259
- if (!(instance instanceof Constructor)) {
260
- throw new TypeError("Cannot call a class as a function");
261
- }
262
- };
263
-
264
- var createClass = function () {
265
- function defineProperties(target, props) {
266
- for (var i = 0; i < props.length; i++) {
267
- var descriptor = props[i];
268
- descriptor.enumerable = descriptor.enumerable || false;
269
- descriptor.configurable = true;
270
- if ("value" in descriptor) descriptor.writable = true;
271
- Object.defineProperty(target, descriptor.key, descriptor);
272
- }
273
- }
274
-
275
- return function (Constructor, protoProps, staticProps) {
276
- if (protoProps) defineProperties(Constructor.prototype, protoProps);
277
- if (staticProps) defineProperties(Constructor, staticProps);
278
- return Constructor;
279
- };
280
- }();
281
-
282
- var Point = function () {
283
-
284
- /**
285
- * Represents a coordinate pair.
286
- * @param {number} [x=0] X.
287
- * @param {number} [y=0] Y.
288
- */
289
- function Point(x, y) {
290
- classCallCheck(this, Point);
291
-
292
- this.x = getNumber(x);
293
- this.y = getNumber(y);
294
- }
295
-
296
- /**
297
- * Whether two points are equal.
298
- * @param {Point} a Point A.
299
- * @param {Point} b Point B.
300
- * @return {boolean}
301
- */
302
-
303
-
304
- createClass(Point, null, [{
305
- key: 'equals',
306
- value: function equals(a, b) {
307
- return a.x === b.x && a.y === b.y;
308
- }
309
- }]);
310
- return Point;
311
- }();
312
-
313
- var Classes = {
314
- BASE: 'shuffle',
315
- SHUFFLE_ITEM: 'shuffle-item',
316
- VISIBLE: 'shuffle-item--visible',
317
- HIDDEN: 'shuffle-item--hidden'
318
- };
319
-
320
- var id$1 = 0;
321
-
322
- var ShuffleItem = function () {
323
- function ShuffleItem(element) {
324
- classCallCheck(this, ShuffleItem);
325
-
326
- id$1 += 1;
327
- this.id = id$1;
328
- this.element = element;
329
- this.isVisible = true;
330
- }
331
-
332
- createClass(ShuffleItem, [{
333
- key: 'show',
334
- value: function show() {
335
- this.isVisible = true;
336
- this.element.classList.remove(Classes.HIDDEN);
337
- this.element.classList.add(Classes.VISIBLE);
338
- }
339
- }, {
340
- key: 'hide',
341
- value: function hide() {
342
- this.isVisible = false;
343
- this.element.classList.remove(Classes.VISIBLE);
344
- this.element.classList.add(Classes.HIDDEN);
345
- }
346
- }, {
347
- key: 'init',
348
- value: function init() {
349
- this.addClasses([Classes.SHUFFLE_ITEM, Classes.VISIBLE]);
350
- this.applyCss(ShuffleItem.Css.INITIAL);
351
- this.scale = ShuffleItem.Scale.VISIBLE;
352
- this.point = new Point();
353
- }
354
- }, {
355
- key: 'addClasses',
356
- value: function addClasses(classes) {
357
- var _this = this;
358
-
359
- classes.forEach(function (className) {
360
- _this.element.classList.add(className);
361
- });
362
- }
363
- }, {
364
- key: 'removeClasses',
365
- value: function removeClasses(classes) {
366
- var _this2 = this;
367
-
368
- classes.forEach(function (className) {
369
- _this2.element.classList.remove(className);
370
- });
371
- }
372
- }, {
373
- key: 'applyCss',
374
- value: function applyCss(obj) {
375
- var _this3 = this;
376
-
377
- Object.keys(obj).forEach(function (key) {
378
- _this3.element.style[key] = obj[key];
379
- });
380
- }
381
- }, {
382
- key: 'dispose',
383
- value: function dispose() {
384
- this.removeClasses([Classes.HIDDEN, Classes.VISIBLE, Classes.SHUFFLE_ITEM]);
385
-
386
- this.element.removeAttribute('style');
387
- this.element = null;
388
- }
389
- }]);
390
- return ShuffleItem;
391
- }();
392
-
393
- ShuffleItem.Css = {
394
- INITIAL: {
395
- position: 'absolute',
396
- top: 0,
397
- left: 0,
398
- visibility: 'visible',
399
- 'will-change': 'transform'
400
- },
401
- VISIBLE: {
402
- before: {
403
- opacity: 1,
404
- visibility: 'visible'
405
- },
406
- after: {}
407
- },
408
- HIDDEN: {
409
- before: {
410
- opacity: 0
411
- },
412
- after: {
413
- visibility: 'hidden'
414
- }
415
- }
416
- };
417
-
418
- ShuffleItem.Scale = {
419
- VISIBLE: 1,
420
- HIDDEN: 0.001
421
- };
422
-
423
- var element = document.body || document.documentElement;
424
- var e$1 = document.createElement('div');
425
- e$1.style.cssText = 'width:10px;padding:2px;box-sizing:border-box;';
426
- element.appendChild(e$1);
427
-
428
- var width = window.getComputedStyle(e$1, null).width;
429
- var ret = width === '10px';
430
-
431
- element.removeChild(e$1);
432
-
433
- /**
434
- * Retrieve the computed style for an element, parsed as a float.
435
- * @param {Element} element Element to get style for.
436
- * @param {string} style Style property.
437
- * @param {CSSStyleDeclaration} [styles] Optionally include clean styles to
438
- * use instead of asking for them again.
439
- * @return {number} The parsed computed value or zero if that fails because IE
440
- * will return 'auto' when the element doesn't have margins instead of
441
- * the computed style.
442
- */
443
- function getNumberStyle(element, style) {
444
- var styles = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : window.getComputedStyle(element, null);
445
-
446
- var value = getNumber(styles[style]);
447
-
448
- // Support IE<=11 and W3C spec.
449
- if (!ret && style === 'width') {
450
- value += getNumber(styles.paddingLeft) + getNumber(styles.paddingRight) + getNumber(styles.borderLeftWidth) + getNumber(styles.borderRightWidth);
451
- } else if (!ret && style === 'height') {
452
- value += getNumber(styles.paddingTop) + getNumber(styles.paddingBottom) + getNumber(styles.borderTopWidth) + getNumber(styles.borderBottomWidth);
453
- }
454
-
455
- return value;
456
- }
457
-
458
- /**
459
- * Fisher-Yates shuffle.
460
- * http://stackoverflow.com/a/962890/373422
461
- * https://bost.ocks.org/mike/shuffle/
462
- * @param {Array} array Array to shuffle.
463
- * @return {Array} Randomly sorted array.
464
- */
465
- function randomize(array) {
466
- var n = array.length;
467
-
468
- while (n) {
469
- n -= 1;
470
- var i = Math.floor(Math.random() * (n + 1));
471
- var temp = array[i];
472
- array[i] = array[n];
473
- array[n] = temp;
474
- }
475
-
476
- return array;
477
- }
478
-
479
- var defaults$1 = {
480
- // Use array.reverse() to reverse the results
481
- reverse: false,
482
-
483
- // Sorting function
484
- by: null,
485
-
486
- // If true, this will skip the sorting and return a randomized order in the array
487
- randomize: false,
488
-
489
- // Determines which property of each item in the array is passed to the
490
- // sorting method.
491
- key: 'element'
492
- };
493
-
494
- // You can return `undefined` from the `by` function to revert to DOM order.
495
- function sorter(arr, options) {
496
- var opts = immutable(defaults$1, options);
497
- var original = [].slice.call(arr);
498
- var revert = false;
499
-
500
- if (!arr.length) {
501
- return [];
502
- }
503
-
504
- if (opts.randomize) {
505
- return randomize(arr);
506
- }
507
-
508
- // Sort the elements by the opts.by function.
509
- // If we don't have opts.by, default to DOM order
510
- if (typeof opts.by === 'function') {
511
- arr.sort(function (a, b) {
512
- // Exit early if we already know we want to revert
513
- if (revert) {
514
- return 0;
515
- }
516
-
517
- var valA = opts.by(a[opts.key]);
518
- var valB = opts.by(b[opts.key]);
519
-
520
- // If both values are undefined, use the DOM order
521
- if (valA === undefined && valB === undefined) {
522
- revert = true;
523
- return 0;
524
- }
525
-
526
- if (valA < valB || valA === 'sortFirst' || valB === 'sortLast') {
527
- return -1;
528
- }
529
-
530
- if (valA > valB || valA === 'sortLast' || valB === 'sortFirst') {
531
- return 1;
532
- }
533
-
534
- return 0;
535
- });
536
- }
537
-
538
- // Revert to the original array if necessary
539
- if (revert) {
540
- return original;
541
- }
542
-
543
- if (opts.reverse) {
544
- arr.reverse();
545
- }
546
-
547
- return arr;
548
- }
549
-
550
- var transitions = {};
551
- var eventName = 'transitionend';
552
- var count = 0;
553
-
554
- function uniqueId() {
555
- count += 1;
556
- return eventName + count;
557
- }
558
-
559
- function cancelTransitionEnd(id) {
560
- if (transitions[id]) {
561
- transitions[id].element.removeEventListener(eventName, transitions[id].listener);
562
- transitions[id] = null;
563
- return true;
564
- }
565
-
566
- return false;
567
- }
568
-
569
- function onTransitionEnd(element, callback) {
570
- var id = uniqueId();
571
- var listener = function listener(evt) {
572
- if (evt.currentTarget === evt.target) {
573
- cancelTransitionEnd(id);
574
- callback(evt);
575
- }
576
- };
577
-
578
- element.addEventListener(eventName, listener);
579
-
580
- transitions[id] = { element: element, listener: listener };
581
-
582
- return id;
583
- }
584
-
585
- function arrayMax(array) {
586
- return Math.max.apply(Math, array); // eslint-disable-line prefer-spread
587
- }
588
-
589
- function arrayMin(array) {
590
- return Math.min.apply(Math, array); // eslint-disable-line prefer-spread
591
- }
592
-
593
- /**
594
- * Determine the number of columns an items spans.
595
- * @param {number} itemWidth Width of the item.
596
- * @param {number} columnWidth Width of the column (includes gutter).
597
- * @param {number} columns Total number of columns
598
- * @param {number} threshold A buffer value for the size of the column to fit.
599
- * @return {number}
600
- */
601
- function getColumnSpan(itemWidth, columnWidth, columns, threshold) {
602
- var columnSpan = itemWidth / columnWidth;
603
-
604
- // If the difference between the rounded column span number and the
605
- // calculated column span number is really small, round the number to
606
- // make it fit.
607
- if (Math.abs(Math.round(columnSpan) - columnSpan) < threshold) {
608
- // e.g. columnSpan = 4.0089945390298745
609
- columnSpan = Math.round(columnSpan);
610
- }
611
-
612
- // Ensure the column span is not more than the amount of columns in the whole layout.
613
- return Math.min(Math.ceil(columnSpan), columns);
614
- }
615
-
616
- /**
617
- * Retrieves the column set to use for placement.
618
- * @param {number} columnSpan The number of columns this current item spans.
619
- * @param {number} columns The total columns in the grid.
620
- * @return {Array.<number>} An array of numbers represeting the column set.
621
- */
622
- function getAvailablePositions(positions, columnSpan, columns) {
623
- // The item spans only one column.
624
- if (columnSpan === 1) {
625
- return positions;
626
- }
627
-
628
- // The item spans more than one column, figure out how many different
629
- // places it could fit horizontally.
630
- // The group count is the number of places within the positions this block
631
- // could fit, ignoring the current positions of items.
632
- // Imagine a 2 column brick as the second item in a 4 column grid with
633
- // 10px height each. Find the places it would fit:
634
- // [20, 10, 10, 0]
635
- // | | |
636
- // * * *
637
- //
638
- // Then take the places which fit and get the bigger of the two:
639
- // max([20, 10]), max([10, 10]), max([10, 0]) = [20, 10, 0]
640
- //
641
- // Next, find the first smallest number (the short column).
642
- // [20, 10, 0]
643
- // |
644
- // *
645
- //
646
- // And that's where it should be placed!
647
- //
648
- // Another example where the second column's item extends past the first:
649
- // [10, 20, 10, 0] => [20, 20, 10] => 10
650
- var available = [];
651
-
652
- // For how many possible positions for this item there are.
653
- for (var i = 0; i <= columns - columnSpan; i++) {
654
- // Find the bigger value for each place it could fit.
655
- available.push(arrayMax(positions.slice(i, i + columnSpan)));
656
- }
657
-
658
- return available;
659
- }
660
-
661
- /**
662
- * Find index of short column, the first from the left where this item will go.
663
- *
664
- * @param {Array.<number>} positions The array to search for the smallest number.
665
- * @param {number} buffer Optional buffer which is very useful when the height
666
- * is a percentage of the width.
667
- * @return {number} Index of the short column.
668
- */
669
- function getShortColumn(positions, buffer) {
670
- var minPosition = arrayMin(positions);
671
- for (var i = 0, len = positions.length; i < len; i++) {
672
- if (positions[i] >= minPosition - buffer && positions[i] <= minPosition + buffer) {
673
- return i;
674
- }
675
- }
676
-
677
- return 0;
678
- }
679
-
680
- /**
681
- * Determine the location of the next item, based on its size.
682
- * @param {Object} itemSize Object with width and height.
683
- * @param {Array.<number>} positions Positions of the other current items.
684
- * @param {number} gridSize The column width or row height.
685
- * @param {number} total The total number of columns or rows.
686
- * @param {number} threshold Buffer value for the column to fit.
687
- * @param {number} buffer Vertical buffer for the height of items.
688
- * @return {Point}
689
- */
690
- function getItemPosition(_ref) {
691
- var itemSize = _ref.itemSize,
692
- positions = _ref.positions,
693
- gridSize = _ref.gridSize,
694
- total = _ref.total,
695
- threshold = _ref.threshold,
696
- buffer = _ref.buffer;
697
-
698
- var span = getColumnSpan(itemSize.width, gridSize, total, threshold);
699
- var setY = getAvailablePositions(positions, span, total);
700
- var shortColumnIndex = getShortColumn(setY, buffer);
701
-
702
- // Position the item
703
- var point = new Point(Math.round(gridSize * shortColumnIndex), Math.round(setY[shortColumnIndex]));
704
-
705
- // Update the columns array with the new values for each column.
706
- // e.g. before the update the columns could be [250, 0, 0, 0] for an item
707
- // which spans 2 columns. After it would be [250, itemHeight, itemHeight, 0].
708
- var setHeight = setY[shortColumnIndex] + itemSize.height;
709
- for (var i = 0; i < span; i++) {
710
- positions[shortColumnIndex + i] = setHeight;
711
- }
712
-
713
- return point;
714
- }
715
-
716
- function toArray(arrayLike) {
717
- return Array.prototype.slice.call(arrayLike);
718
- }
719
-
720
- function arrayIncludes(array, obj) {
721
- return array.indexOf(obj) > -1;
722
- }
723
-
724
- // Used for unique instance variables
725
- var id = 0;
726
-
727
- var Shuffle = function () {
728
-
729
- /**
730
- * Categorize, sort, and filter a responsive grid of items.
731
- *
732
- * @param {Element} element An element which is the parent container for the grid items.
733
- * @param {Object} [options=Shuffle.options] Options object.
734
- * @constructor
735
- */
736
- function Shuffle(element) {
737
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
738
- classCallCheck(this, Shuffle);
739
-
740
- this.options = immutable(Shuffle.options, options);
741
-
742
- this.useSizer = false;
743
- this.lastSort = {};
744
- this.group = Shuffle.ALL_ITEMS;
745
- this.lastFilter = Shuffle.ALL_ITEMS;
746
- this.isEnabled = true;
747
- this.isDestroyed = false;
748
- this.isInitialized = false;
749
- this._transitions = [];
750
- this.isTransitioning = false;
751
- this._queue = [];
752
-
753
- var el = this._getElementOption(element);
754
-
755
- if (!el) {
756
- throw new TypeError('Shuffle needs to be initialized with an element.');
757
- }
758
-
759
- this.element = el;
760
- this.id = 'shuffle_' + id;
761
- id += 1;
762
-
763
- this._init();
764
- this.isInitialized = true;
765
- }
766
-
767
- createClass(Shuffle, [{
768
- key: '_init',
769
- value: function _init() {
770
- this.items = this._getItems();
771
-
772
- this.options.sizer = this._getElementOption(this.options.sizer);
773
-
774
- if (this.options.sizer) {
775
- this.useSizer = true;
776
- }
777
-
778
- // Add class and invalidate styles
779
- this.element.classList.add(Shuffle.Classes.BASE);
780
-
781
- // Set initial css for each item
782
- this._initItems();
783
-
784
- // Bind resize events
785
- this._onResize = this._getResizeFunction();
786
- window.addEventListener('resize', this._onResize);
787
-
788
- // Get container css all in one request. Causes reflow
789
- var containerCss = window.getComputedStyle(this.element, null);
790
- var containerWidth = Shuffle.getSize(this.element).width;
791
-
792
- // Add styles to the container if it doesn't have them.
793
- this._validateStyles(containerCss);
794
-
795
- // We already got the container's width above, no need to cause another
796
- // reflow getting it again... Calculate the number of columns there will be
797
- this._setColumns(containerWidth);
798
-
799
- // Kick off!
800
- this.filter(this.options.group, this.options.initialSort);
801
-
802
- // The shuffle items haven't had transitions set on them yet so the user
803
- // doesn't see the first layout. Set them now that the first layout is done.
804
- // First, however, a synchronous layout must be caused for the previous
805
- // styles to be applied without transitions.
806
- this.element.offsetWidth; // eslint-disable-line no-unused-expressions
807
- this._setTransitions();
808
- this.element.style.transition = 'height ' + this.options.speed + 'ms ' + this.options.easing;
809
- }
810
-
811
- /**
812
- * Returns a throttled and proxied function for the resize handler.
813
- * @return {Function}
814
- * @private
815
- */
816
-
817
- }, {
818
- key: '_getResizeFunction',
819
- value: function _getResizeFunction() {
820
- var resizeFunction = this._handleResize.bind(this);
821
- return this.options.throttle ? this.options.throttle(resizeFunction, this.options.throttleTime) : resizeFunction;
822
- }
823
-
824
- /**
825
- * Retrieve an element from an option.
826
- * @param {string|jQuery|Element} option The option to check.
827
- * @return {?Element} The plain element or null.
828
- * @private
829
- */
830
-
831
- }, {
832
- key: '_getElementOption',
833
- value: function _getElementOption(option) {
834
- // If column width is a string, treat is as a selector and search for the
835
- // sizer element within the outermost container
836
- if (typeof option === 'string') {
837
- return this.element.querySelector(option);
838
-
839
- // Check for an element
840
- } else if (option && option.nodeType && option.nodeType === 1) {
841
- return option;
842
-
843
- // Check for jQuery object
844
- } else if (option && option.jquery) {
845
- return option[0];
846
- }
847
-
848
- return null;
849
- }
850
-
851
- /**
852
- * Ensures the shuffle container has the css styles it needs applied to it.
853
- * @param {Object} styles Key value pairs for position and overflow.
854
- * @private
855
- */
856
-
857
- }, {
858
- key: '_validateStyles',
859
- value: function _validateStyles(styles) {
860
- // Position cannot be static.
861
- if (styles.position === 'static') {
862
- this.element.style.position = 'relative';
863
- }
864
-
865
- // Overflow has to be hidden.
866
- if (styles.overflow !== 'hidden') {
867
- this.element.style.overflow = 'hidden';
868
- }
869
- }
870
-
871
- /**
872
- * Filter the elements by a category.
873
- * @param {string} [category] Category to filter by. If it's given, the last
874
- * category will be used to filter the items.
875
- * @param {Array} [collection] Optionally filter a collection. Defaults to
876
- * all the items.
877
- * @return {!{visible: Array, hidden: Array}}
878
- * @private
879
- */
880
-
881
- }, {
882
- key: '_filter',
883
- value: function _filter() {
884
- var category = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.lastFilter;
885
- var collection = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.items;
886
-
887
- var set$$1 = this._getFilteredSets(category, collection);
888
-
889
- // Individually add/remove hidden/visible classes
890
- this._toggleFilterClasses(set$$1);
891
-
892
- // Save the last filter in case elements are appended.
893
- this.lastFilter = category;
894
-
895
- // This is saved mainly because providing a filter function (like searching)
896
- // will overwrite the `lastFilter` property every time its called.
897
- if (typeof category === 'string') {
898
- this.group = category;
899
- }
900
-
901
- return set$$1;
902
- }
903
-
904
- /**
905
- * Returns an object containing the visible and hidden elements.
906
- * @param {string|Function} category Category or function to filter by.
907
- * @param {Array.<Element>} items A collection of items to filter.
908
- * @return {!{visible: Array, hidden: Array}}
909
- * @private
910
- */
911
-
912
- }, {
913
- key: '_getFilteredSets',
914
- value: function _getFilteredSets(category, items) {
915
- var _this = this;
916
-
917
- var visible = [];
918
- var hidden = [];
919
-
920
- // category === 'all', add visible class to everything
921
- if (category === Shuffle.ALL_ITEMS) {
922
- visible = items;
923
-
924
- // Loop through each item and use provided function to determine
925
- // whether to hide it or not.
926
- } else {
927
- items.forEach(function (item) {
928
- if (_this._doesPassFilter(category, item.element)) {
929
- visible.push(item);
930
- } else {
931
- hidden.push(item);
932
- }
933
- });
934
- }
935
-
936
- return {
937
- visible: visible,
938
- hidden: hidden
939
- };
940
- }
941
-
942
- /**
943
- * Test an item to see if it passes a category.
944
- * @param {string|Function} category Category or function to filter by.
945
- * @param {Element} element An element to test.
946
- * @return {boolean} Whether it passes the category/filter.
947
- * @private
948
- */
949
-
950
- }, {
951
- key: '_doesPassFilter',
952
- value: function _doesPassFilter(category, element) {
953
- if (typeof category === 'function') {
954
- return category.call(element, element, this);
955
- }
956
-
957
- // Check each element's data-groups attribute against the given category.
958
- var attr = element.getAttribute('data-' + Shuffle.FILTER_ATTRIBUTE_KEY);
959
- var keys = this.options.delimeter ? attr.split(this.options.delimeter) : JSON.parse(attr);
960
-
961
- function testCategory(category) {
962
- return arrayIncludes(keys, category);
963
- }
964
-
965
- if (Array.isArray(category)) {
966
- if (this.options.filterMode === Shuffle.FilterMode.ANY) {
967
- return category.some(testCategory);
968
- }
969
- return category.every(testCategory);
970
- }
971
-
972
- return arrayIncludes(keys, category);
973
- }
974
-
975
- /**
976
- * Toggles the visible and hidden class names.
977
- * @param {{visible, hidden}} Object with visible and hidden arrays.
978
- * @private
979
- */
980
-
981
- }, {
982
- key: '_toggleFilterClasses',
983
- value: function _toggleFilterClasses(_ref) {
984
- var visible = _ref.visible,
985
- hidden = _ref.hidden;
986
-
987
- visible.forEach(function (item) {
988
- item.show();
989
- });
990
-
991
- hidden.forEach(function (item) {
992
- item.hide();
993
- });
994
- }
995
-
996
- /**
997
- * Set the initial css for each item
998
- * @param {Array.<ShuffleItem>} [items] Optionally specifiy at set to initialize.
999
- * @private
1000
- */
1001
-
1002
- }, {
1003
- key: '_initItems',
1004
- value: function _initItems() {
1005
- var items = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.items;
1006
-
1007
- items.forEach(function (item) {
1008
- item.init();
1009
- });
1010
- }
1011
-
1012
- /**
1013
- * Remove element reference and styles.
1014
- * @private
1015
- */
1016
-
1017
- }, {
1018
- key: '_disposeItems',
1019
- value: function _disposeItems() {
1020
- var items = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.items;
1021
-
1022
- items.forEach(function (item) {
1023
- item.dispose();
1024
- });
1025
- }
1026
-
1027
- /**
1028
- * Updates the visible item count.
1029
- * @private
1030
- */
1031
-
1032
- }, {
1033
- key: '_updateItemCount',
1034
- value: function _updateItemCount() {
1035
- this.visibleItems = this._getFilteredItems().length;
1036
- }
1037
-
1038
- /**
1039
- * Sets css transform transition on a group of elements. This is not executed
1040
- * at the same time as `item.init` so that transitions don't occur upon
1041
- * initialization of Shuffle.
1042
- * @param {Array.<ShuffleItem>} items Shuffle items to set transitions on.
1043
- * @private
1044
- */
1045
-
1046
- }, {
1047
- key: '_setTransitions',
1048
- value: function _setTransitions() {
1049
- var items = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.items;
1050
-
1051
- var speed = this.options.speed;
1052
- var easing = this.options.easing;
1053
-
1054
- var str = this.options.useTransforms ? 'transform ' + speed + 'ms ' + easing + ', opacity ' + speed + 'ms ' + easing : 'top ' + speed + 'ms ' + easing + ', left ' + speed + 'ms ' + easing + ', opacity ' + speed + 'ms ' + easing;
1055
-
1056
- items.forEach(function (item) {
1057
- item.element.style.transition = str;
1058
- });
1059
- }
1060
- }, {
1061
- key: '_getItems',
1062
- value: function _getItems() {
1063
- var _this2 = this;
1064
-
1065
- return toArray(this.element.children).filter(function (el) {
1066
- return index(el, _this2.options.itemSelector);
1067
- }).map(function (el) {
1068
- return new ShuffleItem(el);
1069
- });
1070
- }
1071
-
1072
- /**
1073
- * When new elements are added to the shuffle container, update the array of
1074
- * items because that is the order `_layout` calls them.
1075
- */
1076
-
1077
- }, {
1078
- key: '_updateItemsOrder',
1079
- value: function _updateItemsOrder() {
1080
- var children = this.element.children;
1081
- this.items = sorter(this.items, {
1082
- by: function by(element) {
1083
- return Array.prototype.indexOf.call(children, element);
1084
- }
1085
- });
1086
- }
1087
- }, {
1088
- key: '_getFilteredItems',
1089
- value: function _getFilteredItems() {
1090
- return this.items.filter(function (item) {
1091
- return item.isVisible;
1092
- });
1093
- }
1094
- }, {
1095
- key: '_getConcealedItems',
1096
- value: function _getConcealedItems() {
1097
- return this.items.filter(function (item) {
1098
- return !item.isVisible;
1099
- });
1100
- }
1101
-
1102
- /**
1103
- * Returns the column size, based on column width and sizer options.
1104
- * @param {number} containerWidth Size of the parent container.
1105
- * @param {number} gutterSize Size of the gutters.
1106
- * @return {number}
1107
- * @private
1108
- */
1109
-
1110
- }, {
1111
- key: '_getColumnSize',
1112
- value: function _getColumnSize(containerWidth, gutterSize) {
1113
- var size = void 0;
1114
-
1115
- // If the columnWidth property is a function, then the grid is fluid
1116
- if (typeof this.options.columnWidth === 'function') {
1117
- size = this.options.columnWidth(containerWidth);
1118
-
1119
- // columnWidth option isn't a function, are they using a sizing element?
1120
- } else if (this.useSizer) {
1121
- size = Shuffle.getSize(this.options.sizer).width;
1122
-
1123
- // if not, how about the explicitly set option?
1124
- } else if (this.options.columnWidth) {
1125
- size = this.options.columnWidth;
1126
-
1127
- // or use the size of the first item
1128
- } else if (this.items.length > 0) {
1129
- size = Shuffle.getSize(this.items[0].element, true).width;
1130
-
1131
- // if there's no items, use size of container
1132
- } else {
1133
- size = containerWidth;
1134
- }
1135
-
1136
- // Don't let them set a column width of zero.
1137
- if (size === 0) {
1138
- size = containerWidth;
1139
- }
1140
-
1141
- return size + gutterSize;
1142
- }
1143
-
1144
- /**
1145
- * Returns the gutter size, based on gutter width and sizer options.
1146
- * @param {number} containerWidth Size of the parent container.
1147
- * @return {number}
1148
- * @private
1149
- */
1150
-
1151
- }, {
1152
- key: '_getGutterSize',
1153
- value: function _getGutterSize(containerWidth) {
1154
- var size = void 0;
1155
- if (typeof this.options.gutterWidth === 'function') {
1156
- size = this.options.gutterWidth(containerWidth);
1157
- } else if (this.useSizer) {
1158
- size = getNumberStyle(this.options.sizer, 'marginLeft');
1159
- } else {
1160
- size = this.options.gutterWidth;
1161
- }
1162
-
1163
- return size;
1164
- }
1165
-
1166
- /**
1167
- * Calculate the number of columns to be used. Gets css if using sizer element.
1168
- * @param {number} [containerWidth] Optionally specify a container width if
1169
- * it's already available.
1170
- */
1171
-
1172
- }, {
1173
- key: '_setColumns',
1174
- value: function _setColumns() {
1175
- var containerWidth = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : Shuffle.getSize(this.element).width;
1176
-
1177
- var gutter = this._getGutterSize(containerWidth);
1178
- var columnWidth = this._getColumnSize(containerWidth, gutter);
1179
- var calculatedColumns = (containerWidth + gutter) / columnWidth;
1180
-
1181
- // Widths given from getStyles are not precise enough...
1182
- if (Math.abs(Math.round(calculatedColumns) - calculatedColumns) < this.options.columnThreshold) {
1183
- // e.g. calculatedColumns = 11.998876
1184
- calculatedColumns = Math.round(calculatedColumns);
1185
- }
1186
-
1187
- this.cols = Math.max(Math.floor(calculatedColumns), 1);
1188
- this.containerWidth = containerWidth;
1189
- this.colWidth = columnWidth;
1190
- }
1191
-
1192
- /**
1193
- * Adjust the height of the grid
1194
- */
1195
-
1196
- }, {
1197
- key: '_setContainerSize',
1198
- value: function _setContainerSize() {
1199
- this.element.style.height = this._getContainerSize() + 'px';
1200
- }
1201
-
1202
- /**
1203
- * Based on the column heights, it returns the biggest one.
1204
- * @return {number}
1205
- * @private
1206
- */
1207
-
1208
- }, {
1209
- key: '_getContainerSize',
1210
- value: function _getContainerSize() {
1211
- return arrayMax(this.positions);
1212
- }
1213
-
1214
- /**
1215
- * Get the clamped stagger amount.
1216
- * @param {number} index Index of the item to be staggered.
1217
- * @return {number}
1218
- */
1219
-
1220
- }, {
1221
- key: '_getStaggerAmount',
1222
- value: function _getStaggerAmount(index$$1) {
1223
- return Math.min(index$$1 * this.options.staggerAmount, this.options.staggerAmountMax);
1224
- }
1225
-
1226
- /**
1227
- * @return {boolean} Whether the event was prevented or not.
1228
- */
1229
-
1230
- }, {
1231
- key: '_dispatch',
1232
- value: function _dispatch(name) {
1233
- var details = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1234
-
1235
- if (this.isDestroyed) {
1236
- return false;
1237
- }
1238
-
1239
- details.shuffle = this;
1240
- return !this.element.dispatchEvent(new CustomEvent(name, {
1241
- bubbles: true,
1242
- cancelable: false,
1243
- detail: details
1244
- }));
1245
- }
1246
-
1247
- /**
1248
- * Zeros out the y columns array, which is used to determine item placement.
1249
- * @private
1250
- */
1251
-
1252
- }, {
1253
- key: '_resetCols',
1254
- value: function _resetCols() {
1255
- var i = this.cols;
1256
- this.positions = [];
1257
- while (i) {
1258
- i -= 1;
1259
- this.positions.push(0);
1260
- }
1261
- }
1262
-
1263
- /**
1264
- * Loops through each item that should be shown and calculates the x, y position.
1265
- * @param {Array.<ShuffleItem>} items Array of items that will be shown/layed
1266
- * out in order in their array.
1267
- */
1268
-
1269
- }, {
1270
- key: '_layout',
1271
- value: function _layout(items) {
1272
- var _this3 = this;
1273
-
1274
- var count = 0;
1275
- items.forEach(function (item) {
1276
- var currPos = item.point;
1277
- var currScale = item.scale;
1278
- var itemSize = Shuffle.getSize(item.element, true);
1279
- var pos = _this3._getItemPosition(itemSize);
1280
-
1281
- function callback() {
1282
- item.element.style.transitionDelay = '';
1283
- item.applyCss(ShuffleItem.Css.VISIBLE.after);
1284
- }
1285
-
1286
- // If the item will not change its position, do not add it to the render
1287
- // queue. Transitions don't fire when setting a property to the same value.
1288
- if (Point.equals(currPos, pos) && currScale === ShuffleItem.Scale.VISIBLE) {
1289
- item.applyCss(ShuffleItem.Css.VISIBLE.before);
1290
- callback();
1291
- return;
1292
- }
1293
-
1294
- item.point = pos;
1295
- item.scale = ShuffleItem.Scale.VISIBLE;
1296
-
1297
- // Use xtend here to clone the object so that the `before` object isn't
1298
- // modified when the transition delay is added.
1299
- var styles = immutable(ShuffleItem.Css.VISIBLE.before);
1300
- styles.transitionDelay = _this3._getStaggerAmount(count) + 'ms';
1301
-
1302
- _this3._queue.push({
1303
- item: item,
1304
- styles: styles,
1305
- callback: callback
1306
- });
1307
-
1308
- count += 1;
1309
- });
1310
- }
1311
-
1312
- /**
1313
- * Determine the location of the next item, based on its size.
1314
- * @param {{width: number, height: number}} itemSize Object with width and height.
1315
- * @return {Point}
1316
- * @private
1317
- */
1318
-
1319
- }, {
1320
- key: '_getItemPosition',
1321
- value: function _getItemPosition(itemSize) {
1322
- return getItemPosition({
1323
- itemSize: itemSize,
1324
- positions: this.positions,
1325
- gridSize: this.colWidth,
1326
- total: this.cols,
1327
- threshold: this.options.columnThreshold,
1328
- buffer: this.options.buffer
1329
- });
1330
- }
1331
-
1332
- /**
1333
- * Hides the elements that don't match our filter.
1334
- * @param {Array.<ShuffleItem>} collection Collection to shrink.
1335
- * @private
1336
- */
1337
-
1338
- }, {
1339
- key: '_shrink',
1340
- value: function _shrink() {
1341
- var _this4 = this;
1342
-
1343
- var collection = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this._getConcealedItems();
1344
-
1345
- var count = 0;
1346
- collection.forEach(function (item) {
1347
- function callback() {
1348
- item.applyCss(ShuffleItem.Css.HIDDEN.after);
1349
- }
1350
-
1351
- // Continuing would add a transitionend event listener to the element, but
1352
- // that listener would not execute because the transform and opacity would
1353
- // stay the same.
1354
- // The callback is executed here because it is not guaranteed to be called
1355
- // after the transitionend event because the transitionend could be
1356
- // canceled if another animation starts.
1357
- if (item.scale === ShuffleItem.Scale.HIDDEN) {
1358
- item.applyCss(ShuffleItem.Css.HIDDEN.before);
1359
- callback();
1360
- return;
1361
- }
1362
-
1363
- item.scale = ShuffleItem.Scale.HIDDEN;
1364
-
1365
- var styles = immutable(ShuffleItem.Css.HIDDEN.before);
1366
- styles.transitionDelay = _this4._getStaggerAmount(count) + 'ms';
1367
-
1368
- _this4._queue.push({
1369
- item: item,
1370
- styles: styles,
1371
- callback: callback
1372
- });
1373
-
1374
- count += 1;
1375
- });
1376
- }
1377
-
1378
- /**
1379
- * Resize handler.
1380
- * @private
1381
- */
1382
-
1383
- }, {
1384
- key: '_handleResize',
1385
- value: function _handleResize() {
1386
- // If shuffle is disabled, destroyed, don't do anything
1387
- if (!this.isEnabled || this.isDestroyed) {
1388
- return;
1389
- }
1390
-
1391
- // Will need to check height in the future if it's layed out horizontaly
1392
- var containerWidth = Shuffle.getSize(this.element).width;
1393
-
1394
- // containerWidth hasn't changed, don't do anything
1395
- if (containerWidth === this.containerWidth) {
1396
- return;
1397
- }
1398
-
1399
- this.update();
1400
- }
1401
-
1402
- /**
1403
- * Returns styles which will be applied to the an item for a transition.
1404
- * @param {Object} obj Transition options.
1405
- * @return {!Object} Transforms for transitions, left/top for animate.
1406
- * @private
1407
- */
1408
-
1409
- }, {
1410
- key: '_getStylesForTransition',
1411
- value: function _getStylesForTransition(_ref2) {
1412
- var item = _ref2.item,
1413
- styles = _ref2.styles;
1414
-
1415
- if (!styles.transitionDelay) {
1416
- styles.transitionDelay = '0ms';
1417
- }
1418
-
1419
- var x = item.point.x;
1420
- var y = item.point.y;
1421
-
1422
- if (this.options.useTransforms) {
1423
- styles.transform = 'translate(' + x + 'px, ' + y + 'px) scale(' + item.scale + ')';
1424
- } else {
1425
- styles.left = x + 'px';
1426
- styles.top = y + 'px';
1427
- }
1428
-
1429
- return styles;
1430
- }
1431
-
1432
- /**
1433
- * Listen for the transition end on an element and execute the itemCallback
1434
- * when it finishes.
1435
- * @param {Element} element Element to listen on.
1436
- * @param {Function} itemCallback Callback for the item.
1437
- * @param {Function} done Callback to notify `parallel` that this one is done.
1438
- */
1439
-
1440
- }, {
1441
- key: '_whenTransitionDone',
1442
- value: function _whenTransitionDone(element, itemCallback, done) {
1443
- var id = onTransitionEnd(element, function (evt) {
1444
- itemCallback();
1445
- done(null, evt);
1446
- });
1447
-
1448
- this._transitions.push(id);
1449
- }
1450
-
1451
- /**
1452
- * Return a function which will set CSS styles and call the `done` function
1453
- * when (if) the transition finishes.
1454
- * @param {Object} opts Transition object.
1455
- * @return {Function} A function to be called with a `done` function.
1456
- */
1457
-
1458
- }, {
1459
- key: '_getTransitionFunction',
1460
- value: function _getTransitionFunction(opts) {
1461
- var _this5 = this;
1462
-
1463
- return function (done) {
1464
- opts.item.applyCss(_this5._getStylesForTransition(opts));
1465
- _this5._whenTransitionDone(opts.item.element, opts.callback, done);
1466
- };
1467
- }
1468
-
1469
- /**
1470
- * Execute the styles gathered in the style queue. This applies styles to elements,
1471
- * triggering transitions.
1472
- * @private
1473
- */
1474
-
1475
- }, {
1476
- key: '_processQueue',
1477
- value: function _processQueue() {
1478
- if (this.isTransitioning) {
1479
- this._cancelMovement();
1480
- }
1481
-
1482
- var hasSpeed = this.options.speed > 0;
1483
- var hasQueue = this._queue.length > 0;
1484
-
1485
- if (hasQueue && hasSpeed && this.isInitialized) {
1486
- this._startTransitions(this._queue);
1487
- } else if (hasQueue) {
1488
- this._styleImmediately(this._queue);
1489
- this._dispatchLayout();
1490
-
1491
- // A call to layout happened, but none of the newly visible items will
1492
- // change position or the transition duration is zero, which will not trigger
1493
- // the transitionend event.
1494
- } else {
1495
- this._dispatchLayout();
1496
- }
1497
-
1498
- // Remove everything in the style queue
1499
- this._queue.length = 0;
1500
- }
1501
-
1502
- /**
1503
- * Wait for each transition to finish, the emit the layout event.
1504
- * @param {Array.<Object>} transitions Array of transition objects.
1505
- */
1506
-
1507
- }, {
1508
- key: '_startTransitions',
1509
- value: function _startTransitions(transitions) {
1510
- var _this6 = this;
1511
-
1512
- // Set flag that shuffle is currently in motion.
1513
- this.isTransitioning = true;
1514
-
1515
- // Create an array of functions to be called.
1516
- var callbacks = transitions.map(function (obj) {
1517
- return _this6._getTransitionFunction(obj);
1518
- });
1519
-
1520
- index$3(callbacks, this._movementFinished.bind(this));
1521
- }
1522
- }, {
1523
- key: '_cancelMovement',
1524
- value: function _cancelMovement() {
1525
- // Remove the transition end event for each listener.
1526
- this._transitions.forEach(cancelTransitionEnd);
1527
-
1528
- // Reset the array.
1529
- this._transitions.length = 0;
1530
-
1531
- // Show it's no longer active.
1532
- this.isTransitioning = false;
1533
- }
1534
-
1535
- /**
1536
- * Apply styles without a transition.
1537
- * @param {Array.<Object>} objects Array of transition objects.
1538
- * @private
1539
- */
1540
-
1541
- }, {
1542
- key: '_styleImmediately',
1543
- value: function _styleImmediately(objects) {
1544
- var _this7 = this;
1545
-
1546
- if (objects.length) {
1547
- var elements = objects.map(function (obj) {
1548
- return obj.item.element;
1549
- });
1550
-
1551
- Shuffle._skipTransitions(elements, function () {
1552
- objects.forEach(function (obj) {
1553
- obj.item.applyCss(_this7._getStylesForTransition(obj));
1554
- obj.callback();
1555
- });
1556
- });
1557
- }
1558
- }
1559
- }, {
1560
- key: '_movementFinished',
1561
- value: function _movementFinished() {
1562
- this._transitions.length = 0;
1563
- this.isTransitioning = false;
1564
- this._dispatchLayout();
1565
- }
1566
- }, {
1567
- key: '_dispatchLayout',
1568
- value: function _dispatchLayout() {
1569
- this._dispatch(Shuffle.EventType.LAYOUT);
1570
- }
1571
-
1572
- /**
1573
- * The magic. This is what makes the plugin 'shuffle'
1574
- * @param {string|Function|Array.<string>} [category] Category to filter by.
1575
- * Can be a function, string, or array of strings.
1576
- * @param {Object} [sortObj] A sort object which can sort the visible set
1577
- */
1578
-
1579
- }, {
1580
- key: 'filter',
1581
- value: function filter(category, sortObj) {
1582
- if (!this.isEnabled) {
1583
- return;
1584
- }
1585
-
1586
- if (!category || category && category.length === 0) {
1587
- category = Shuffle.ALL_ITEMS; // eslint-disable-line no-param-reassign
1588
- }
1589
-
1590
- this._filter(category);
1591
-
1592
- // Shrink each hidden item
1593
- this._shrink();
1594
-
1595
- // How many visible elements?
1596
- this._updateItemCount();
1597
-
1598
- // Update transforms on visible elements so they will animate to their new positions.
1599
- this.sort(sortObj);
1600
- }
1601
-
1602
- /**
1603
- * Gets the visible elements, sorts them, and passes them to layout.
1604
- * @param {Object} opts the options object for the sorted plugin
1605
- */
1606
-
1607
- }, {
1608
- key: 'sort',
1609
- value: function sort() {
1610
- var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.lastSort;
1611
-
1612
- if (!this.isEnabled) {
1613
- return;
1614
- }
1615
-
1616
- this._resetCols();
1617
-
1618
- var items = this._getFilteredItems();
1619
- items = sorter(items, opts);
1620
-
1621
- this._layout(items);
1622
-
1623
- // `_layout` always happens after `_shrink`, so it's safe to process the style
1624
- // queue here with styles from the shrink method.
1625
- this._processQueue();
1626
-
1627
- // Adjust the height of the container.
1628
- this._setContainerSize();
1629
-
1630
- this.lastSort = opts;
1631
- }
1632
-
1633
- /**
1634
- * Reposition everything.
1635
- * @param {boolean} isOnlyLayout If true, column and gutter widths won't be
1636
- * recalculated.
1637
- */
1638
-
1639
- }, {
1640
- key: 'update',
1641
- value: function update(isOnlyLayout) {
1642
- if (this.isEnabled) {
1643
- if (!isOnlyLayout) {
1644
- // Get updated colCount
1645
- this._setColumns();
1646
- }
1647
-
1648
- // Layout items
1649
- this.sort();
1650
- }
1651
- }
1652
-
1653
- /**
1654
- * Use this instead of `update()` if you don't need the columns and gutters updated
1655
- * Maybe an image inside `shuffle` loaded (and now has a height), which means calculations
1656
- * could be off.
1657
- */
1658
-
1659
- }, {
1660
- key: 'layout',
1661
- value: function layout() {
1662
- this.update(true);
1663
- }
1664
-
1665
- /**
1666
- * New items have been appended to shuffle. Mix them in with the current
1667
- * filter or sort status.
1668
- * @param {Array.<Element>} newItems Collection of new items.
1669
- */
1670
-
1671
- }, {
1672
- key: 'add',
1673
- value: function add(newItems) {
1674
- var items = index$1(newItems).map(function (el) {
1675
- return new ShuffleItem(el);
1676
- });
1677
-
1678
- // Add classes and set initial positions.
1679
- this._initItems(items);
1680
-
1681
- // Add transition to each item.
1682
- this._setTransitions(items);
1683
-
1684
- // Update the list of items.
1685
- this.items = this.items.concat(items);
1686
- this._updateItemsOrder();
1687
- this.filter(this.lastFilter);
1688
- }
1689
-
1690
- /**
1691
- * Disables shuffle from updating dimensions and layout on resize
1692
- */
1693
-
1694
- }, {
1695
- key: 'disable',
1696
- value: function disable() {
1697
- this.isEnabled = false;
1698
- }
1699
-
1700
- /**
1701
- * Enables shuffle again
1702
- * @param {boolean} [isUpdateLayout=true] if undefined, shuffle will update columns and gutters
1703
- */
1704
-
1705
- }, {
1706
- key: 'enable',
1707
- value: function enable(isUpdateLayout) {
1708
- this.isEnabled = true;
1709
- if (isUpdateLayout !== false) {
1710
- this.update();
1711
- }
1712
- }
1713
-
1714
- /**
1715
- * Remove 1 or more shuffle items
1716
- * @param {Array.<Element>} elements An array containing one or more
1717
- * elements in shuffle
1718
- * @return {Shuffle} The shuffle object
1719
- */
1720
-
1721
- }, {
1722
- key: 'remove',
1723
- value: function remove(elements) {
1724
- var _this8 = this;
1725
-
1726
- if (!elements.length) {
1727
- return;
1728
- }
1729
-
1730
- var collection = index$1(elements);
1731
-
1732
- var oldItems = collection.map(function (element) {
1733
- return _this8.getItemByElement(element);
1734
- }).filter(function (item) {
1735
- return !!item;
1736
- });
1737
-
1738
- var handleLayout = function handleLayout() {
1739
- _this8.element.removeEventListener(Shuffle.EventType.LAYOUT, handleLayout);
1740
- _this8._disposeItems(oldItems);
1741
-
1742
- // Remove the collection in the callback
1743
- collection.forEach(function (element) {
1744
- element.parentNode.removeChild(element);
1745
- });
1746
-
1747
- _this8._dispatch(Shuffle.EventType.REMOVED, { collection: collection });
1748
- };
1749
-
1750
- // Hide collection first.
1751
- this._toggleFilterClasses({
1752
- visible: [],
1753
- hidden: oldItems
1754
- });
1755
-
1756
- this._shrink(oldItems);
1757
-
1758
- this.sort();
1759
-
1760
- // Update the list of items here because `remove` could be called again
1761
- // with an item that is in the process of being removed.
1762
- this.items = this.items.filter(function (item) {
1763
- return !arrayIncludes(oldItems, item);
1764
- });
1765
- this._updateItemCount();
1766
-
1767
- this.element.addEventListener(Shuffle.EventType.LAYOUT, handleLayout);
1768
- }
1769
-
1770
- /**
1771
- * Retrieve a shuffle item by its element.
1772
- * @param {Element} element Element to look for.
1773
- * @return {?ShuffleItem} A shuffle item or null if it's not found.
1774
- */
1775
-
1776
- }, {
1777
- key: 'getItemByElement',
1778
- value: function getItemByElement(element) {
1779
- for (var i = this.items.length - 1; i >= 0; i--) {
1780
- if (this.items[i].element === element) {
1781
- return this.items[i];
1782
- }
1783
- }
1784
-
1785
- return null;
1786
- }
1787
-
1788
- /**
1789
- * Destroys shuffle, removes events, styles, and classes
1790
- */
1791
-
1792
- }, {
1793
- key: 'destroy',
1794
- value: function destroy() {
1795
- this._cancelMovement();
1796
- window.removeEventListener('resize', this._onResize);
1797
-
1798
- // Reset container styles
1799
- this.element.classList.remove('shuffle');
1800
- this.element.removeAttribute('style');
1801
-
1802
- // Reset individual item styles
1803
- this._disposeItems();
1804
-
1805
- // Null DOM references
1806
- this.items = null;
1807
- this.options.sizer = null;
1808
- this.element = null;
1809
- this._transitions = null;
1810
-
1811
- // Set a flag so if a debounced resize has been triggered,
1812
- // it can first check if it is actually isDestroyed and not doing anything
1813
- this.isDestroyed = true;
1814
- }
1815
-
1816
- /**
1817
- * Returns the outer width of an element, optionally including its margins.
1818
- *
1819
- * There are a few different methods for getting the width of an element, none of
1820
- * which work perfectly for all Shuffle's use cases.
1821
- *
1822
- * 1. getBoundingClientRect() `left` and `right` properties.
1823
- * - Accounts for transform scaled elements, making it useless for Shuffle
1824
- * elements which have shrunk.
1825
- * 2. The `offsetWidth` property.
1826
- * - This value stays the same regardless of the elements transform property,
1827
- * however, it does not return subpixel values.
1828
- * 3. getComputedStyle()
1829
- * - This works great Chrome, Firefox, Safari, but IE<=11 does not include
1830
- * padding and border when box-sizing: border-box is set, requiring a feature
1831
- * test and extra work to add the padding back for IE and other browsers which
1832
- * follow the W3C spec here.
1833
- *
1834
- * @param {Element} element The element.
1835
- * @param {boolean} [includeMargins] Whether to include margins. Default is false.
1836
- * @return {{width: number, height: number}} The width and height.
1837
- */
1838
-
1839
- }], [{
1840
- key: 'getSize',
1841
- value: function getSize(element, includeMargins) {
1842
- // Store the styles so that they can be used by others without asking for it again.
1843
- var styles = window.getComputedStyle(element, null);
1844
- var width = getNumberStyle(element, 'width', styles);
1845
- var height = getNumberStyle(element, 'height', styles);
1846
-
1847
- if (includeMargins) {
1848
- var marginLeft = getNumberStyle(element, 'marginLeft', styles);
1849
- var marginRight = getNumberStyle(element, 'marginRight', styles);
1850
- var marginTop = getNumberStyle(element, 'marginTop', styles);
1851
- var marginBottom = getNumberStyle(element, 'marginBottom', styles);
1852
- width += marginLeft + marginRight;
1853
- height += marginTop + marginBottom;
1854
- }
1855
-
1856
- return {
1857
- width: width,
1858
- height: height
1859
- };
1860
- }
1861
-
1862
- /**
1863
- * Change a property or execute a function which will not have a transition
1864
- * @param {Array.<Element>} elements DOM elements that won't be transitioned.
1865
- * @param {Function} callback A function which will be called while transition
1866
- * is set to 0ms.
1867
- * @private
1868
- */
1869
-
1870
- }, {
1871
- key: '_skipTransitions',
1872
- value: function _skipTransitions(elements, callback) {
1873
- var zero = '0ms';
1874
-
1875
- // Save current duration and delay.
1876
- var data = elements.map(function (element) {
1877
- var style = element.style;
1878
- var duration = style.transitionDuration;
1879
- var delay = style.transitionDelay;
1880
-
1881
- // Set the duration to zero so it happens immediately
1882
- style.transitionDuration = zero;
1883
- style.transitionDelay = zero;
1884
-
1885
- return {
1886
- duration: duration,
1887
- delay: delay
1888
- };
1889
- });
1890
-
1891
- callback();
1892
-
1893
- // Cause reflow.
1894
- elements[0].offsetWidth; // eslint-disable-line no-unused-expressions
1895
-
1896
- // Put the duration back
1897
- elements.forEach(function (element, i) {
1898
- element.style.transitionDuration = data[i].duration;
1899
- element.style.transitionDelay = data[i].delay;
1900
- });
1901
- }
1902
- }]);
1903
- return Shuffle;
1904
- }();
1905
-
1906
- Shuffle.ShuffleItem = ShuffleItem;
1907
-
1908
- Shuffle.ALL_ITEMS = 'all';
1909
- Shuffle.FILTER_ATTRIBUTE_KEY = 'groups';
1910
-
1911
- /**
1912
- * @enum {string}
1913
- */
1914
- Shuffle.EventType = {
1915
- LAYOUT: 'shuffle:layout',
1916
- REMOVED: 'shuffle:removed'
1917
- };
1918
-
1919
- /** @enum {string} */
1920
- Shuffle.Classes = Classes;
1921
-
1922
- /**
1923
- * @enum {string}
1924
- */
1925
- Shuffle.FilterMode = {
1926
- ANY: 'any',
1927
- ALL: 'all'
1928
- };
1929
-
1930
- // Overrideable options
1931
- Shuffle.options = {
1932
- // Initial filter group.
1933
- group: Shuffle.ALL_ITEMS,
1934
-
1935
- // Transition/animation speed (milliseconds).
1936
- speed: 250,
1937
-
1938
- // CSS easing function to use.
1939
- easing: 'ease',
1940
-
1941
- // e.g. '.picture-item'.
1942
- itemSelector: '*',
1943
-
1944
- // Element or selector string. Use an element to determine the size of columns
1945
- // and gutters.
1946
- sizer: null,
1947
-
1948
- // A static number or function that tells the plugin how wide the gutters
1949
- // between columns are (in pixels).
1950
- gutterWidth: 0,
1951
-
1952
- // A static number or function that returns a number which tells the plugin
1953
- // how wide the columns are (in pixels).
1954
- columnWidth: 0,
1955
-
1956
- // If your group is not json, and is comma delimeted, you could set delimeter
1957
- // to ','.
1958
- delimeter: null,
1959
-
1960
- // Useful for percentage based heights when they might not always be exactly
1961
- // the same (in pixels).
1962
- buffer: 0,
1963
-
1964
- // Reading the width of elements isn't precise enough and can cause columns to
1965
- // jump between values.
1966
- columnThreshold: 0.01,
1967
-
1968
- // Shuffle can be isInitialized with a sort object. It is the same object
1969
- // given to the sort method.
1970
- initialSort: null,
1971
-
1972
- // By default, shuffle will throttle resize events. This can be changed or
1973
- // removed.
1974
- throttle: index$2,
1975
-
1976
- // How often shuffle can be called on resize (in milliseconds).
1977
- throttleTime: 300,
1978
-
1979
- // Transition delay offset for each item in milliseconds.
1980
- staggerAmount: 15,
1981
-
1982
- // Maximum stagger delay in milliseconds.
1983
- staggerAmountMax: 250,
1984
-
1985
- // Whether to use transforms or absolute positioning.
1986
- useTransforms: true,
1987
-
1988
- // Affects using an array with filter. e.g. `filter(['one', 'two'])`. With "any",
1989
- // the element passes the test if any of its groups are in the array. With "all",
1990
- // the element only passes if all groups are in the array.
1991
- filterMode: Shuffle.FilterMode.ANY
1992
- };
1993
-
1994
- // Expose for testing. Hack at your own risk.
1995
- Shuffle.__Point = Point;
1996
- Shuffle.__sorter = sorter;
1997
- Shuffle.__getColumnSpan = getColumnSpan;
1998
- Shuffle.__getAvailablePositions = getAvailablePositions;
1999
- Shuffle.__getShortColumn = getShortColumn;
2000
-
2001
- return Shuffle;
2002
-
2003
- })));
2004
- //# sourceMappingURL=shuffle.js.map