/* * Salvattore 1.0.5 by @rnmp and @ppold * https://github.com/rnmp/salvattore */ !function(a,b){"object"==typeof exports?module.exports=b():"function"==typeof define&&define.amd?define("salvattore",[],b):a.salvattore=b()}(this,function(){window.matchMedia||(window.matchMedia=function(){"use strict";var a=window.styleMedia||window.media;if(!a){var b=document.createElement("style"),c=document.getElementsByTagName("script")[0],d=null;b.type="text/css",b.id="matchmediajs-test",c.parentNode.insertBefore(b,c),d="getComputedStyle"in window&&window.getComputedStyle(b,null)||b.currentStyle,a={matchMedium:function(a){var c="@media "+a+"{ #matchmediajs-test { width: 1px; } }";return b.styleSheet?b.styleSheet.cssText=c:b.textContent=c,"1px"===d.width}}}return function(b){return{matches:a.matchMedium(b||"all"),media:b||"all"}}}()),function(){if(window.matchMedia&&window.matchMedia("all").addListener)return!1;var a=window.matchMedia,b=a("only all").matches,c=!1,d=0,e=[],f=function(){clearTimeout(d),d=setTimeout(function(){for(var b=0,c=e.length;c>b;b++){var d=e[b].mql,f=e[b].listeners||[],g=a(d.media).matches;if(g!==d.matches){d.matches=g;for(var h=0,i=f.length;i>h;h++)f[h].call(window,d)}}},30)};window.matchMedia=function(d){var g=a(d),h=[],i=0;return g.addListener=function(a){b&&(c||(c=!0,window.addEventListener("resize",f,!0)),0===i&&(i=e.push({mql:g,listeners:h})),h.push(a))},g.removeListener=function(a){for(var b=0,c=h.length;c>b;b++)h[b]===a&&h.splice(b,1)},g}}(),function(){for(var a=0,b=["ms","moz","webkit","o"],c=0;c *:nth-child("+h+"n-"+l+")",j.push(d.querySelectorAll(f));j.forEach(function(a){var c=b.createElement("div"),d=b.createDocumentFragment();c.className=i.join(" "),Array.prototype.forEach.call(a,function(a){d.appendChild(a)}),c.appendChild(d),k.appendChild(c)}),a.appendChild(k),e(a,"columns",h)},c.removeColumns=function(c){var d=b.createRange();d.selectNodeContents(c);var f=Array.prototype.filter.call(d.extractContents().childNodes,function(b){return b instanceof a.HTMLElement}),g=f.length,h=f[0].childNodes.length,i=new Array(h*g);Array.prototype.forEach.call(f,function(a,b){Array.prototype.forEach.call(a.children,function(a,c){i[c*g+b]=a})});var j=b.createElement("div");return e(j,"columns",0),i.filter(function(a){return!!a}).forEach(function(a){j.appendChild(a)}),j},c.recreateColumns=function(b){a.requestAnimationFrame(function(){c.addColumns(b,c.removeColumns(b));var a=new CustomEvent("columnsChange");b.dispatchEvent(a)})},c.mediaQueryChange=function(a){a.matches&&Array.prototype.forEach.call(d,c.recreateColumns)},c.getCSSRules=function(a){var b;try{b=a.sheet.cssRules||a.sheet.rules}catch(c){return[]}return b||[]},c.getStylesheets=function(){return Array.prototype.concat.call(Array.prototype.slice.call(b.querySelectorAll("style[type='text/css']")),Array.prototype.slice.call(b.querySelectorAll("link[rel='stylesheet']")))},c.mediaRuleHasColumnsSelector=function(a){var b,c;try{b=a.length}catch(d){b=0}for(;b--;)if(c=a[b],c.selectorText&&c.selectorText.match(/\[data-columns\](.*)::?before$/))return!0;return!1},c.scanMediaQueries=function(){var b=[];a.matchMedia&&(c.getStylesheets().forEach(function(d){Array.prototype.forEach.call(c.getCSSRules(d),function(d){d.media&&d.cssRules&&c.mediaRuleHasColumnsSelector(d.cssRules)&&b.push(a.matchMedia(d.media.mediaText))})}),b.forEach(function(a){a.addListener(c.mediaQueryChange)}))},c.nextElementColumnIndex=function(a,b){var c,d,e,f=a.children,g=f.length,h=0,i=0;for(e=0;g>e;e++)c=f[e],d=c.children.length+(b[e].children||b[e].childNodes).length,0===h&&(h=d),h>d&&(i=e,h=d);return i},c.createFragmentsList=function(a){for(var c=new Array(a),d=0;d!==a;)c[d]=b.createDocumentFragment(),d++;return c},c.appendElements=function(a,b){var d=a.children,e=d.length,f=c.createFragmentsList(e);Array.prototype.forEach.call(b,function(b){var d=c.next_element_column_index(a,f);f[d].appendChild(b)}),Array.prototype.forEach.call(d,function(a,b){a.appendChild(f[b])})},c.prependElements=function(a,d){var e=a.children,f=e.length,g=c.createFragmentsList(f),h=f-1;d.forEach(function(a){var b=g[h];b.insertBefore(a,b.firstChild),0===h?h=f-1:h--}),Array.prototype.forEach.call(e,function(a,b){a.insertBefore(g[b],a.firstChild)});for(var i=b.createDocumentFragment(),j=d.length%f;0!==j--;)i.appendChild(a.lastChild);a.insertBefore(i,a.firstChild)},c.registerGrid=function(f){if("none"!==a.getComputedStyle(f).display){var g=b.createRange();g.selectNodeContents(f);var h=b.createElement("div");h.appendChild(g.extractContents()),e(h,"columns",0),c.addColumns(f,h),d.push(f)}},c.init=function(){var a=b.createElement("style");a.innerHTML="[data-columns]::before{visibility:hidden;position:absolute;font-size:1px;}",b.head.appendChild(a);var d=b.querySelectorAll("[data-columns]");Array.prototype.forEach.call(d,c.registerGrid),c.scanMediaQueries()},c.init(),{appendElements:c.appendElements,prependElements:c.prependElements,registerGrid:c.registerGrid,recreateColumns:c.recreateColumns,append_elements:c.appendElements,prepend_elements:c.prependElements,register_grid:c.registerGrid,recreate_columns:c.recreateColumns}}(window,window.document);return a});