1class AOSResponsive { 2 /** 3 * Initializes AOSResponsive with jQuery and AOS. 4 * @param {jQuery} $ - jQuery instance. 5 * @param {Object} AOS - AOS library instance. 6 */ 7 constructor($, AOS) { 8 this.$ = $; 9 this.AOS = AOS; 10 11 // Breakpoints copied from Tailwind CSS (https://tailwindcss.com/docs/breakpoints) 12 this.breakpoints = [ 13 { name: 'sm', minWidth: 640 }, 14 { name: 'md', minWidth: 768 }, 15 { name: 'lg', minWidth: 1024 }, 16 { name: 'xl', minWidth: 1280 }, 17 { name: '2xl', minWidth: 1536 }, 18 ]; 19 20 // List of supported AOS data-aos-* attributes 21 this.attributes = [ 22 'aos', 23 'aos-offset', 24 'aos-delay', 25 'aos-duration', 26 'aos-easing', 27 'aos-mirror', 28 'aos-once', 29 'aos-anchor-placement', 30 ]; 31 } 32 33 /** 34 * Updates the AOS attributes based on viewport size. 35 */ 36 updateAOSAttributes() { 37 const viewportWidth = window.innerWidth; 38 39 for (const breakpoint of this.breakpoints) { 40 if (viewportWidth < breakpoint.minWidth) break; 41 42 for (const attribute of this.attributes) { 43 const $elements = this.$(`[data-${breakpoint.name}-${attribute}]`); 44 45 $elements.each((_, element) => { 46 const value = this.$(element).data(`${breakpoint.name}-${attribute}`); 47 this.$(element).attr(`data-${attribute}`, value); 48 }); 49 } 50 } 51 } 52 53 /** 54 * Sets and sorts breakpoints. 55 * @param {Object} conf - Configuration object for breakpoints. 56 */ 57 setBreakpoints(conf) { 58 this.breakpoints = Object.keys(conf).map(key => ({ 59 name: key, 60 minWidth: conf[key], 61 })); 62 63 this.breakpoints.sort((a, b) => a.minWidth - b.minWidth); 64 } 65 66 /** 67 * Initializes AOSResponsive with given options. 68 * @param {Object} conf - Configuration object. 69 */ 70 init(conf = {}) { 71 if (conf.screen) { 72 this.setBreakpoints(conf.screen); 73 delete conf.screen; 74 } 75 76 if (conf.attributes) { 77 this.attributes = conf.attributes; 78 delete conf.attributes; 79 } 80 81 this.updateAOSAttributes(); 82 83 setTimeout(() => { 84 this.AOS.init(conf); 85 }, 1); 86 } 87} 88 89/** 90 * Waits for dependencies before initializing AOSResponsive. 91 */ 92 93(async function waitForDependencies() { 94 while (typeof AOS === "undefined" || typeof jQuery === "undefined") { 95 await new Promise(resolve => setTimeout(resolve, 100)); 96 } 97 98 const aosResponsive = new AOSResponsive(jQuery, AOS); 99 aosResponsive.init({ 100 mirror: false, 101 once: true, 102 duration: 500, 103 offset: -100, 104 }); 105 106})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.