-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflickity-responsive.min.js
14 lines (14 loc) · 8.08 KB
/
flickity-responsive.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/**!
* Flickity Responsive v2.1.1
* @author phucbm
* @homepage https://github.com/phucbm/flickity-responsive
* @license MIT 2021-2025
*/
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var n=t();for(var r in n)("object"==typeof exports?exports:e)[r]=n[r]}}(this,(()=>(()=>{"use strict";var e={d:(t,n)=>{for(var r in n)e.o(n,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:n[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{FlickityExtend:()=>O,FlickityResponsive:()=>A,_attr:()=>g});
/**!
* Match Media Screen v0.0.3
* @author phucbm
* @homepage https://github.com/phucbm/match-media-screen
* @license MIT 2022
*/
var n={d:(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},r={};function o(e,t=!0){const n=[...e];return t?n.sort(((e,t)=>e.breakpoint<t.breakpoint?1:-1)):n.sort(((e,t)=>e.breakpoint>t.breakpoint?1:-1)),n}function i(e,t=150){let n;return(...r)=>{clearTimeout(n),n=setTimeout((()=>{e.apply(this,r)}),t)}}n.d(r,{o:()=>s});class s{constructor(e){if(this.dev=!0===e.dev,this.object=e.object||void 0,this.object){if(this.onMatched=e.onMatched,this.onUpdate=e.onUpdate,window.addEventListener("resize",i((()=>{"function"==typeof this.onUpdate&&this.onUpdate(this.currentObject)}),this.debounce)),!this.object.responsive)return this.currentObject={type:"no-responsive",lastBreakpoint:void 0,breakpoint:-1,object:this.mergeObject(-1,this.object)},"function"==typeof this.onMatched&&this.onMatched(this.currentObject),this.dev&&console.warn("Property object must have responsive array."),!1;this.isInherit=void 0===e.isInherit||e.isInherit,this.debounce=e.debounce||100,this.currentObject={breakpoint:void 0,object:{}},this.object.responsive=o(this.object.responsive),this.match(),window.addEventListener("resize",i((()=>this.match()),this.debounce))}else console.error("Property object:{} must be provided.")}match(){let e=!1;for(let t=0;t<this.object.responsive.length;t++){const n=this.object.responsive[t];if(e=matchMedia(this.getQuery(t)).matches,e){this.currentObject.breakpoint!==n.breakpoint&&(this.currentObject={type:"responsive",lastBreakpoint:this.currentObject.breakpoint,breakpoint:n.breakpoint,object:this.mergeObject(n.breakpoint,n.settings)},"function"==typeof this.onMatched&&this.onMatched(this.currentObject));break}}e||-1===this.currentObject.breakpoint||(this.currentObject={type:"default",lastBreakpoint:this.currentObject.breakpoint,breakpoint:-1,object:this.mergeObject(-1,this.object)},"function"==typeof this.onMatched&&this.onMatched(this.currentObject))}getQuery(e){let t=`screen and (max-width:${this.object.responsive[e].breakpoint}px)`;const n=this.object.responsive[e+1];return n&&(t+=` and (min-width:${n.breakpoint+1}px)`),t}mergeObject(e,t){let n={...t};if(this.isInherit&&-1!==e){const t=o(this.object.responsive,!1);for(let r=0;r<t.length;r++)t[r].breakpoint>e&&(n={...t[r].settings,...n})}return n={...this.object,...n},delete n.responsive,n}}var c=r.o;function a(e){return"undefined"!=typeof jQuery&&e instanceof jQuery}function d(e){let t={};if(!function(e){try{return JSON.parse(e)&&!!e}catch(e){return!1}}(e))return t;t=JSON.parse(e);for(const[e,n]of Object.entries(t))"false"===n&&(t[e]=!1),"true"===n&&(t[e]=!0);return t}function u(e,t){if("string"==typeof e){let n=document;if(t){n=t;const e=t.closest(`div:has([${g.init}]), div:has(.flickity-enabled)`);if(e){1===e.querySelectorAll(`[${g.init}], .flickity-enabled`).length&&(n=e)}}return n.querySelectorAll(e)}let n=a(e)?e.get():e;return n instanceof NodeList||Array.isArray(n)||(n=[n]),n}function l(e,t){if(t.isInfinite)return;const n=e.options.customArrows.prevArrow.el,r=e.options.customArrows.nextArrow.el,o=function(e){const{selectedIndex:t,slides:n}=e;return 0===t?0:t===n.length-1?1:-1}(e),i=(e,t)=>{t?e.forEach((e=>e?.setAttribute("disabled","disabled"))):e.forEach((e=>e?.removeAttribute("disabled")))};0===o?(i(n,!0),i(r,!1)):1===o?(i(n,!1),i(r,!0)):(i(r,!1),i(n,!1))}function p(e,t){const n=!0===t.indicatorZeroPad;let r=u(t.indicatorTotal,e.element),o=u(t.indicatorCurrent,e.element);const i=e.slides.length;if(r&&r.length&&r.forEach((e=>e.innerText=n?h(i):i)),o&&o.length){let t=e.selectedIndex;o.forEach((e=>e.innerText=n?h(t+1):t+1)),e.on("change",(t=>{const r=e.selectedIndex+1;o.forEach((e=>e.innerText=n?h(r):r))}))}}function h(e=0){return e.toString().padStart(2,"0")}function f(e,t){if(!0!==t.forceMove)return;e.element.classList.add(t._class.isForceMove);let n=e.selectedSlide;e.on("change",(()=>{const t=e.selectedSlide,r=y(n,t);if(0===r)return;let o=b(e.slides,t,1===r);t.target===n.target&&(o+=r),n=e.selectedSlide,e.select(o)}))}const b=(e,t,n=!0)=>n?e.findLastIndex((e=>e.target===t.target)):e.findIndex((e=>e.target===t.target)),y=(e,t)=>t.x>e.x?1:t.x<e.x?-1:0;function v(e,t){let n=Flickity.data(e);const r=void 0!==n;r&&n.destroy(),t.destroy?r&&n.destroy():(n=new Flickity(e,t),t.wrapAround&&(n.options.wrapAround=m(n)),t.isInfinite=t.hasOwnProperty("wrapAround")&&n.options.wrapAround,function(e,t){const n={prevArrow:{func:()=>e.previous(),el:[]},nextArrow:{func:()=>e.next(),el:[]}};let r=!1;Object.entries(n).forEach((([o,i])=>{if(!t.hasOwnProperty(o))return;const s=t[o];if(!s)return;const c=u(s);c&&"object"==typeof c&&(Array.isArray(c)&&c.every((e=>void 0===e))||(c.forEach((e=>{e&&e.addEventListener("click",(()=>i.func()))})),n[o].el=c,e.element.classList.add(`has-custom-${o}`),r=!0))})),e.options.customArrows=n,e.options.hasCustomArrow=r,r&&(l(e,t),e.on("change",(()=>l(e,t))))}(n,t),p(n,t),f(n,t),n.resize())}function j(e,t){if(!0!==t.responsiveNavigation)return;const n=[];e.pageDots&&n.push(e.pageDots.holder),e.prevButton&&n.push(e.prevButton.element),e.nextButton&&n.push(e.nextButton.element),e.options.hasCustomArrow&&(n.push(...e.options.customArrows.prevArrow.el),n.push(...e.options.customArrows.nextArrow.el));const r=Math.round(e.slideableWidth)>Math.round(e.size.innerWidth);n.forEach((e=>{e&&"object"==typeof e&&(r?(e.classList.remove(t._class.isFreeze),e.style.display=""):(e.classList.add(t._class.isFreeze),e.style.display="none"))})),r?e.element.classList.remove(t._class.isCannotSlide):e.element.classList.add(t._class.isCannotSlide),e.options.draggable=r,e.updateDraggable()}function w(e,t,n){return"undefined"==typeof Flickity?(console.warn("Flickity is undefined!"),!1):(new c({object:t,onMatched:t=>v(e,{...n,...t.object}),onUpdate:t=>function(e,t){let n=Flickity.data(e);n&&(j(n,t),t.wrapAround&&(n.options.wrapAround=m(n)))}(e,{...n,...t.object})}),function(e,t){let n=Flickity.data(e);n&&(t.object?.wrapAround&&(t.object.wrapAround=m(n)),j(n,t),p(n,t),f(n,t),function(e,t){t.ariaHiddenFocus&&e.element.querySelectorAll('[aria-hidden="true"] a, [aria-hidden="true"] button').forEach((e=>{e.setAttribute("tabindex","-1"),e.classList.add("is-focus-disabled")}))}(n,t))}(e,{...n,...t}),!0)}function m(e){const t=e.cells.reduce(((e,t)=>e+t.size.width),0);return Math.round(e.size.width)<Math.round(t)}const g={init:"data-flickity-responsive",indicatorCurrent:"data-indicator-current",indicatorTotal:"data-indicator-total",prevArrow:"data-prev-arrow",nextArrow:"data-next-arrow"},k={contain:!0,destroy:!1,prevArrow:`[${g.prevArrow}]`,nextArrow:`[${g.nextArrow}]`,responsiveNavigation:!0,indicatorZeroPad:!1,indicatorCurrent:`[${g.indicatorCurrent}]`,indicatorTotal:`[${g.indicatorTotal}]`,forceMove:!0,ariaHiddenFocus:!0,_class:{isFreeze:"is-freeze",isForceMove:"is-force-move",isCannotSlide:"is-cannot-slide"}};class A{constructor(e,t){if(w(e,t,k))return this.flickity=Flickity.data(e),this.flickity}}var x;"undefined"!=typeof jQuery&&((x=jQuery).fn.flickityResponsive=function(e){x(this).get().forEach((t=>new A(t,e)))}),document.querySelectorAll(`[${g.init}]`).forEach((e=>{const t=d(e.getAttribute(g.init));new A(e,t)}));class O{constructor(e,t){new A(e,t)}}return"undefined"!=typeof jQuery&&function(e){e.fn.flickityExtend=function(t){e(this).get().forEach((e=>new A(e,t)))}}(jQuery),t})()));