1let CossetteRouter = (function ($, Drupal) { 2 let self = {}; 3 4 let routes = [ 5 { filter: 'header', cls: 'OtqNavigation', method: 'init', onPageLoad: false }, 6 { filter: '[data-dismiss]', cls: 'OtqAlerts', method: 'init', onPageLoad: false }, 7 { filter: '.map-sticky', cls: 'OtqMap', method: 'initStickyMap', onPageLoad: false }, 8 { filter: '.btn-map', cls: 'OtqMap', method: 'init', onPageLoad: false }, 9 { filter: '.audio-player', cls: 'OtqAudioPlayer', method: 'init', onPageLoad: false }, 10 { filter: '.content-slider', cls: 'OtqSlider', method: 'init', onPageLoad: false }, 11 { filter: '.content-overlay', cls: 'OtqOverlay', method: 'init', onPageLoad: false }, 12 { filter: '.side-content-overlay', cls: 'OtqSideOverlay', method: 'init', onPageLoad: false }, 13 { filter: '.map-overlay', cls: 'OtqOverlay', method: 'initMapOverlay', onPageLoad: false }, 14 { filter: 'form.filters', cls: 'OtqFilters', method: 'init', onPageLoad: false }, 15 { filter: '.pagination-container', cls: 'OtqPager', method: 'init', onPageLoad: false }, 16 { filter: 'form.validated', cls: 'OtqForm', method: 'init', onPageLoad: false }, 17 { filter: '[data-modal]', cls: 'OtqModal', method: 'init', onPageLoad: false }, 18 { filter: '.tabs-nav', cls: 'OtqTab', method: 'init', onPageLoad: false }, 19 { filter: '[data-emergence]', cls: 'OtqReveal', method: 'init', onPageLoad: false }, 20 { filter: '.media-video', cls: 'OtqVideo', method: 'init', onPageLoad: false }, 21 { filter: '.page-module.shorts', cls: 'OtqVideo', method: 'init', onPageLoad: false }, 22 { filter: 'video', cls: 'OtqVideo', method: 'initNative', onPageLoad: false }, 23 { filter: '.dimension-tools', cls: 'OtqTool', method: 'initDimensionToggle', onPageLoad: false }, 24 { filter: '[data-toggle]', cls: 'OtqTool', method: 'initToggle', onPageLoad: false }, 25 { filter: '.datepicker', cls: 'OtqTool', method: 'initDatePicker', onPageLoad: false }, 26 { filter: '#members-list', cls: 'OtqTool', method: 'initMemberChanger', onPageLoad: false }, 27 { filter: '.active-campaign', cls: 'OtqForm', method: 'initAciveCampaign', onPageLoad: false }, 28 { filter: '.paragraph--type--neighbourhoods-map', cls: 'OtqNeighbourhoodsMap', method: 'init', onPageLoad: false }, 29 { filter: '.paragraph--view-mode--newsletter', cls: 'OtqForm', method: 'initNewsletterTwoStep', onPageLoad: false }, 30 { filter: 'body', cls: 'OtqPrint', method: 'init', onPageLoad: false } 31 ]; 32 33 self.currentPage = null; 34 self.currentController = null; 35 self.initiliazed = []; 36 self.initiliazedClasses = {}; 37 38 /** ------------------------------ 39 * Constructor 40 --------------------------------- */ 41 42 self.construct = (function () {})(); 43 44 /** ------------------------------ 45 * Public methods 46 --------------------------------- */ 47 48 self.init = function () { 49 // if (self.currentController && typeof self.currentController['destruct'] != 'undefined') { 50 // self.currentController.destruct(); 51 // self.currentController = null; 52 // } 53 54 // Loop through routes to call initializer 55 for (let i = 0; i < routes.length; i++) { 56 let route = routes[i]; 57 58 if (route.onPageLoad === false) { 59 createController(route); 60 } 61 } 62 }; 63 64 self.initAppLoaded = function () { 65 for (let i = 0; i < routes.length; i++) { 66 let route = routes[i]; 67 68 if (route.onPageLoad === true) { 69 createController(route); 70 } 71 } 72 }; 73 74 /** 75 * Get a class reference object, initilize it if not done yet 76 * @param name 77 * @returns {*} 78 */ 79 self.getClassReference = function (name) { 80 let _class; 81 82 if (self.initiliazedClasses[name] !== undefined) { 83 _class = self.initiliazedClasses[name]; 84 } else { 85 _class = new window[name]($, Drupal); 86 self.initiliazedClasses[name] = _class; 87 self.initiliazed.push(name); 88 } 89 90 return _class; 91 }; 92 93 let createController = function (route) { 94 const elements = document.querySelectorAll(route.filter); 95 if (!elements.length) return; 96 97 // Critical modules load immediately 98 const criticalModules = ['OtqNavigation', 'OtqAlerts']; 99 100 if (criticalModules.includes(route.cls)) { 101 initializeModule(route); 102 } else { 103 // Lazy load non-critical modules 104 const observer = new IntersectionObserver( 105 (entries) => {
106 entries.forEach((entry) => { 107 if (entry.isIntersecting) { 108 initializeModule(route); 109 observer.disconnect(); 110 } 111 }); 112 }, 113 { rootMargin: '50px' } 114 ); 115 116 elements.forEach((element) => observer.observe(element)); 117 } 118 }; 119 120 let initializeModule = function (route) { 121 if (typeof window[route.cls] !== 'undefined') { 122 if (self.initiliazed.indexOf(route.cls) === -1) { 123 self.currentController = new window[route.cls]($, Drupal); 124 self.initiliazedClasses[route.cls] = self.currentController; 125 self.initiliazed.push(route.cls); 126 } else { 127 self.currentController = self.initiliazedClasses[route.cls]; 128 } 129 130 if (typeof self.currentController[route.method] !== 'undefined') { 131 self.currentController[route.method](); 132 } 133 } 134 }; 135 136 return self; 137})(jQuery, Drupal);
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.