-
Notifications
You must be signed in to change notification settings - Fork 1
/
equalizer.min.js
1 lines (1 loc) · 3.03 KB
/
equalizer.min.js
1
var Equalizer=function(){"use strict";function e(){for(var e=l.breakpoints,t=window.innerWidth,n=0;n<e.length;n++){var i=e[n].minWidth,r="(min-width: "+i+"px)",a=r,o,u;if("maxWidth"in e[n]&&(o=e[n].maxWidth,u=" and (max-width: "+o+"px)",a+=u),matchMedia(a).matches)return e[n].name}}function t(){for(var e=document.querySelectorAll("[data-equalizer-row]"),t=0;t<e.length;t++){var r=e[t],o=r.getAttribute("data-equalizer-row"),l=r.querySelectorAll("[data-equalizer]"),u=r.getAttribute("data-equalizer-on");if(null==u||""===u?u="all":u&&(u=u.replace(/ /g,"").split(",")),o&&(l=r.querySelectorAll('[data-equalizer="'+o+'"]')),l.length){var d=a.currentBreakpoint();if(i(l),Array.isArray(u))for(var c=0;c<u.length;c++)u[c]==d&&n(l);else n(l)}}}function n(e){for(var t=0,n=0;n<e.length;n++){var i=e[n].clientHeight;i>t&&(t=i)}for(var r=0;r<e.length;r++)e[r].style.height=t+"px"}function i(e){for(var t=0;t<e.length;t++)e[t].style.height="auto"}function r(e){e=e||{};var t=[];for(var n in e){var i=parseInt(e[n],10);if(isNaN(i))break;t.push({name:n,minWidth:i})}t=t.sort(function(e,t){return e.minWidth<t.minWidth?-1:1});for(var r=0;r<t.length;r++){var a=9999;void 0!==t[r+1]&&(a=t[r+1].minWidth-1),t[r].maxWidth=a}return t}var a={},o=[],l,u={breakpoints:{small:480,medium:640,large:1024,xlarge:1200}};!function(){function e(e,t){t=t||{bubbles:!1,cancelable:!1,detail:void 0};var n=document.createEvent("CustomEvent");return n.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),n}"function"===window.CustomEvent&&(e.prototype=window.Event.prototype,window.CustomEvent=e)}(),function(){!function(e,t,n){n=n||window;var i=!1,r=function(){i||(i=!0,requestAnimationFrame(function(){n.dispatchEvent(new CustomEvent(t)),i=!1}))};n.addEventListener(e,r)}("resize","optimizedResize")}(),window.matchMedia||(window.matchMedia=function(){var e=window.styleMedia||window.media;if(!e){var t=document.createElement("style"),n=document.getElementsByTagName("script")[0],i=null;t.type="text/css",t.id="matchmediajs-test",n?n.parentNode.insertBefore(t,n):document.head.appendChild(t),i="getComputedStyle"in window&&window.getComputedStyle(t,null)||t.currentStyle,e={matchMedium:function(e){var n="@media "+e+"{ #matchmediajs-test { width: 1px; } }";return t.styleSheet?t.styleSheet.cssText=n:t.textContent=n,"1px"===i.width}}}return function(t){return{matches:e.matchMedium(t||"all"),media:t||"all"}}}());var d=function(){var e={},t=!1,n=0;"[object Boolean]"===Object.prototype.toString.call(arguments[0])&&(t=arguments[0],n++);for(var i=function(n){for(var i in n)n.hasOwnProperty(i)&&(t&&"[object Object]"===Object.prototype.toString.call(n[i])?e[i]=d(e[i],n[i]):e[i]=n[i])};n<arguments.length;n++){i(arguments[n])}return e};return a.init=function(e){l=d(u,e||{}),document.documentElement.classList.add("equalizer-active"),l.breakpoints=r(l.breakpoints),t(),window.addEventListener("optimizedResize",t)},a.destroy=function(){document.documentElement.classList.remove("equalizer-active"),i(document.querySelectorAll("[data-equalizer]"))},a.currentBreakpoint=e,a.equalizeHeight=n,a.resetHeight=i,a.parseBreakpoints=r,a}();