{"version":3,"sources":["webpack:///./cartridges/app_accelerator_core/cartridge/client/default/js/modules/module.window-scroll.js"],"names":["WindowScroll","query","_classCallCheck","callbackOnElements","setupWindowScroll","bind","breakpoints","breakpointRanges","_createClass","key","value","isEnabled","breakpointName","matchedBreakpoint","min","document","body","offsetWidth","max","getOffsetValue","offsetMatch","HTMLElement","getBoundingClientRect","height","bindEvents","el","settings","JSON","parse","getAttribute","addEventListener","enabled","hasOwnProperty","call","delay","window","setTimeout","disabled","classList","contains","setupScroll","target","duration","offset","scrollContainer","removeAttribute","destination","arguments","length","undefined","manualOffset","callback","containerEl","querySelector","scrollOptions","easings","easeOutCubic","t","startPosition","getScrollPosition","startTime","performance","now","Date","getTime","destinationPosition","scrollToPosition","scroll","easeScroll","scrollTop","pageYOffset","elapsedTime","time","Math","timeFunction","currentScrollPos","ceil","requestAnimationFrame"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEiF;AACzB;AAAA,IAEnCA,YAAY;EAC7B,SAAAA,aAAaC,KAAK,EAAG;IAAAC,eAAA,OAAAF,YAAA;IACjBG,oFAAkB,CAACF,KAAK,EAAE,IAAI,CAACG,iBAAiB,CAACC,IAAI,CAAC,IAAI,CAAC,CAAC;IAE5D,IAAI,CAACC,WAAW,GAAGC,mEAAgB;EACvC;EAAC,OAAAC,YAAA,CAAAR,YAAA;IAAAS,GAAA;IAAAC,KAAA,EA0DD,SAAAC,SAASA,CAACC,cAAc,EAAE;MACtB,IAAIC,iBAAiB,GAAG,IAAI,CAACP,WAAW,CAACM,cAAc,CAAC;MAExD,OAAOC,iBAAiB,KAAK,CAACA,iBAAiB,CAACC,GAAG,IAAIC,QAAQ,CAACC,IAAI,CAACC,WAAW,IAAIJ,iBAAiB,CAACC,GAAG,CAAC,KAAK,CAACD,iBAAiB,CAACK,GAAG,IAAIH,QAAQ,CAACC,IAAI,CAACC,WAAW,IAAIJ,i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QAExB;MACJ;MAEAhB,MAAM,CAAC0C,qBAAqB,CAAC7E,YAAY,CAACoE,UAAU,CAAC/D,IAAI,CAAC,IAAI,EAAEuC,eAAe,EAAEU,aAAa,CAAC,CAAC;IACpG;EAAC;AAAA","file":"module-window-scroll.js","sourcesContent":["/**\n * WINDOW SCROLL MODULE\n *\n * This module scrolls the window to a target via a click on an element with a [data-window-scroll] property.\n *\n * @param {[Object]} data-window-scroll\n * [\n * target: [Required] HTML Element. Element to scroll to.\n * offset: [Optional] Number | HTML Element. If parameter is a number, then the number will used for offset. If it is a HTML Element, than the offsetHeight of the element will be used.\n * duration: [Optional] Number. Duration of the scroll.\n * callback: [Optional] Function. This is called once the scroll is complete.\n * ]\n */\n\nimport { callbackOnElements, scrollToPosition } from '@borngroup/born-utilities';\nimport { breakpointRanges } from '../helpers/utilities';\n\nexport default class WindowScroll {\n constructor( query ) {\n callbackOnElements(query, this.setupWindowScroll.bind(this));\n\n this.breakpoints = breakpointRanges;\n }\n\n static setupScroll(destination, duration = 350, manualOffset = 0, callback, containerEl) {\n let scrollContainer = typeof containerEl === 'string' ? document.querySelector(containerEl) : containerEl,\n scrollOptions = {\n easings: {\n easeOutCubic(t) {\n return (--t) * t * t + 1;\n }\n },\n startPosition: WindowScroll.getScrollPosition(scrollContainer),\n startTime: 'now' in window.performance ? performance.now() : new Date().getTime(),\n duration: duration,\n destinationPosition: scrollToPosition(destination, manualOffset, scrollContainer),\n callback: callback || function() {\n return true;\n }\n };\n\n if ('requestAnimationFrame' in window === false) {\n (scrollContainer || window).scroll(0, scrollOptions.destinationPosition);\n\n if (typeof callback === 'function') {\n callback(scrollOptions);\n }\n\n return;\n }\n\n WindowScroll.easeScroll(scrollContainer, scrollOptions);\n }\n\n static getScrollPosition(scrollContainer) {\n return scrollContainer ? scrollContainer.scrollTop : window.pageYOffset;\n }\n\n static easeScroll(scrollContainer, scrollOptions) {\n let now = 'now' in window.performance ? performance.now() : new Date().getTime(),\n elapsedTime = now - scrollOptions.startTime,\n time = Math.min(1, (elapsedTime / scrollOptions.duration)),\n timeFunction = scrollOptions.easings['easeOutCubic'](time),\n currentScrollPos;\n\n (scrollContainer || window).scroll(0, Math.ceil((timeFunction * (scrollOptions.destinationPosition - scrollOptions.startPosition)) + scrollOptions.startPosition));\n\n currentScrollPos = WindowScroll.getScrollPosition(scrollContainer);\n\n //Check for both the elapsed time and the current position.\n //If either matches, stop the scrolling function.\n if (currentScrollPos === scrollOptions.destinationPosition || elapsedTime >= scrollOptions.duration) {\n scrollOptions.callback();\n\n return;\n }\n\n window.requestAnimationFrame(WindowScroll.easeScroll.bind(this, scrollContainer, scrollOptions));\n }\n\n isEnabled(breakpointName) {\n let matchedBreakpoint = this.breakpoints[breakpointName];\n\n return matchedBreakpoint && (!matchedBreakpoint.min || document.body.offsetWidth >= matchedBreakpoint.min) && (!matchedBreakpoint.max || document.body.offsetWidth <= matchedBreakpoint.max);\n }\n\n getOffsetValue(offsetMatch) {\n return offsetMatch instanceof HTMLElement ? offsetMatch.getBoundingClientRect().height : (offsetMatch || 0);\n }\n\n bindEvents(el) {\n let settings = JSON.parse( el.getAttribute( 'data-window-scroll' ) );\n\n el.addEventListener('click', function() {\n let enabled = settings.hasOwnProperty('enabled') ? this.isEnabled.call(this, settings.enabled) : true,\n delay = settings.delay || 0;\n\n window.setTimeout(function() {\n if (enabled && !(el.disabled || el.classList.contains('disabled'))) {\n WindowScroll.setupScroll(settings.target, settings.duration, settings.offset, null, settings.scrollContainer);\n }\n }, delay);\n }.bind(this));\n\n el.removeAttribute('data-window-scroll');\n }\n\n setupWindowScroll(el) {\n this.bindEvents(el);\n }\n}\n"],"sourceRoot":""}