https://www.coheedandcambria.com/wp-content/plugins/umg-grand-roya…/js/modules/deeplink.js?ver=3.5.8
1(function($) { 2 3 /** 4 * Set scroll restoration (browser scroll function for anchors) to manual so we can scroll smoother using TweenMax 5 * @type {"manual"} 6 */ 7 history.scrollRestoration = 'manual'; 8 9 $(document).ready(function() { 10 11 //fire only when body has finished loading (i.e. loader is hidden) 12 $('body').on('umggr-body-loaded', function() { 13 UMGGR_Deeplink_Module.onLoad(); 14 }); 15 }); 16 17 /** 18 * Allow deeplink automatic scrolling to be disabled if other libraries are handling it 19 * 20 * @type {boolean} 21 */ 22 UMGGR_Deeplink_Module.deeplinkScrollEnabled = true; 23 24 /** 25 * Set which type of URL to use for sections. Either hash '#' or path '/' 26 * 27 * @type {boolean} 28 */ 29 UMGGR_Deeplink_Module.urlType = '#'; 30 31 /** 32 * Current Hash or URL path value 33 * @type {string|null} 34 */ 35 UMGGR_Deeplink_Module.currentLink = null 36 37 /** 38 * Define which element we use for scrolling. By default it's window but some layouts use a container and scroll inside 39 * of the container instead. 40 * @type {mixed} 41 */ 42 UMGGR_Deeplink_Module.scrollParent = window; 43 44 /** 45 * Define scroll offset - this usually depends on top bar height and device 46 * @type {number} 47 */ 48 UMGGR_Deeplink_Module.scrollOffset = 0; 49 50 /** 51 * Define admin bar height if logged in as admin 52 * @type {number} 53 */ 54 UMGGR_Deeplink_Module.adminBarHeight = 0; 55 56 57 /** 58 * Function ran onLoan of DOM. This will navigate scroll to element if hash value is present 59 * Also checks if data-deeplink attributes are present for anchors so it can open them (i.e. news modals) 60 */ 61 UMGGR_Deeplink_Module.onLoad = function() { 62 63 //set admin bar height if exists 64 if($('#wpadminbar').length) { 65 UMGGR_Deeplink_Module.adminBarHeight = $('#wpadminbar').height(); 66 } 67 68 //check if deeplink scrolling is enabled 69 if(UMGGR_Deeplink_Module.deeplinkScrollEnabled) { 70 //handle onClick events for anchors that are for on page elements 71 $('.scroll-menu-link').click(function (e) { 72 73 //get menu item url 74 var address = $(this).find('a').attr("href").toLowerCase(); 75 76 //get item to which we are navigating 77 var navigateTo = $('[data-deeplink="' + address.replace(UMGGR_Deeplink_Module.urlType, '') + '"]'); 78 79 //ensure body has overflow visible & hide mobile menus if open 80 $('#umggr-nav-overlay').hide(); 81 $('body').removeClass('-no-overflow'); 82 83 if (navigateTo.length) { 84 85 UMGGR_Deeplink_Module.singlePagerNavigate(address, navigateTo, UMGGR_Deeplink_Module.scrollOffset); 86 } else { 87 //element not found so navigate to top of page 88 UMGGR_Deeplink_Module.singlePagerNavigate(null, null, 0); 89 } 90 91 return false; 92 }); 93 94 /** 95 * Scroll to elements on page when browser history back/forward is clicked 96 */ 97 window.onpopstate = function(event) { 98 if(typeof location.hash !== 'undefined') { 99 var hashValue = location.hash.replace(UMGGR_Deeplink_Module.urlType, ''); 100 if(hashValue.length) { 101 //navigate to deeplink element if found 102 var deeplinkElement = $('[data-deeplink="'+hashValue+'"]'); 103 if(deeplinkElement.length) { 104 105 UMGGR_Deeplink_Module.currentLink = hashValue 106 107 UMGGR_Deeplink_Module.updateScroller(deeplinkElement, UMGGR_Deeplink_Module.scrollOffset); 108 } 109 } else { 110 if(typeof location.pathname !== 'undefined' && location.pathname === '/') { 111 UMGGR_Deeplink_Module.currentLink = null 112 113 //navigate to top of page if value is blank or only '/' 114 UMGGR_Deeplink_Module.updateScroller(0, 0); 115 } 116 } 117 } 118 }; 119 120 //get URL hash if present 121 var navigationHash = location.hash; 122 if(navigationHash.length) { 123 124 let cleanHash 125 126 //remove hash prefix added by react HashRouter 127 if (navigationHash.startsWith('#/')) { 128 cleanHash = navigationHash.replace('#/', '') 129 } else { 130 cleanHash = navigationHash.replace(UMGGR_Deeplink_Module.urlType, '') 131 } 132 133 //get item to which we are navigating 134 var navigateTo = $('[data-deeplink="' + cleanHash + '"]'); 135 136 //trigger event so external scripts can handle their own actions 137 UMGGR_Deeplink_Module.triggerEvent('navigation','hash', navigationHash); 138 139 if(navigateTo.length) { 140 UMGGR_Deeplink_Module.currentLink = cleanHash 141 142 UMGGR_Deeplink_Module.singlePagerNavigate(navigationHash, navigateTo, UMGGR_Deeplink_Module.scrollOffset); 143 } 144 } 145 } 146 147 var href = location.href; 148 if(href.length) { 149 150 //remove hash from URL if any is set 151 if(href.includes('#')) { 152 href = href.substr(0, href.indexOf('#')); 153 } 154 155 //remove any query parts 156 if(href.includes('?')) { 157 href = href.substr(0, href.indexOf('?')); 158 } 159 160 //find anchor with attribute of deep-link and href same as one in the URL 161 var deeplinkAnchor = $('a[data-deeplink][href="'+href+'"]'); 162 if(deeplinkAnchor.length) { 163 164 UMGGR_Deeplink_Module.currentLink = href 165 166 //trigger event so external scripts can handle their own actions 167 UMGGR_Deeplink_Module.triggerEvent('navigation', 'path', deeplinkAnchor); 168 169 var parentAnchor = $(deeplinkAnchor).parents('[data-deeplink]'); 170 171 if(parentAnchor.length) { 172 //scroll to element 173 UMGGR_Deeplink_Module.updateScroller(parentAnchor, UMGGR_Deeplink_Module.scrollOffset); 174 } else { 175 //scroll to element 176 UMGGR_Deeplink_Module.updateScroller(deeplinkAnchor, UMGGR_Deeplink_Module.scrollOffset); 177 } 178 179 UMGGR_Deeplink_Module.openModal(deeplinkAnchor); 180 } 181 } 182 183 UMGGR_Deeplink_Module.triggerEvent('loaded'); 184 }; 185 186 /** 187 * List of callback functions 188 * 189 * @type {Array} 190 */ 191 UMGGR_Deeplink_Module.onEventCallbacks = []; 192 193 /** 194 * Add callback for event so external scripts can handle their own functions 195 * 196 * @param callback 197 */ 198 UMGGR_Deeplink_Module.onEvent = function(eventName, callback) { 199 UMGGR_Deeplink_Module.onEventCallbacks.push({ 200 eventName: eventName, 201 callback, 202 }); 203 } 204 205 /** 206 * Run registered deeplink callbacks 207 * 208 * @param string type 209 * @param string url 210 */ 211 UMGGR_Deeplink_Module.triggerEvent = function(eventName, args) { 212 if(UMGGR_Deeplink_Module.onEventCallbacks.length) { 213 for(var i in UMGGR_Deeplink_Module.onEventCallbacks) { 214 if(eventName === UMGGR_Deeplink_Module.onEventCallbacks[i].eventName) { 215 UMGGR_Deeplink_Module.onEventCallbacks[i].callback.apply([].slice.call(arguments, 1)); 216 } 217 } 218 } 219 } 220 221 222 /**
223 * Navigate single page site to element via TweenMax + Update URL address bar with menu navigation 224 * 225 * @param string anchorUrl 226 * @param jQueryElement navigateTo 227 * @param number offset 228 */ 229 UMGGR_Deeplink_Module.singlePagerNavigate = function(anchorUrl, navigateTo, offset ) { 230 231 //if navigateTo is null then set Y = 0 (top of page) 232 if(navigateTo === null) { 233 navigateTo = 0; 234 } 235 236 //if anchorURL is null then we are navigating to top of page 237 if(anchorUrl === null) { 238 anchorUrl = '/'; 239 } 240 241 //scroll to element 242 UMGGR_Deeplink_Module.updateScroller(navigateTo, offset); 243 244 //update browser url bar 245 UMGGR_Deeplink_Module.updateNavigation(anchorUrl); 246 }; 247 248 /** 249 * Set scroll browser position to specific element and offset 250 * @param jQueryElement element 251 * @param number offset 252 */ 253 UMGGR_Deeplink_Module.updateScroller = function(element, offset) { 254 element = element ? element : $('body'); 255 var offset = offset - UMGGR_Deeplink_Module.adminBarHeight; 256 $('html, body').animate({ 257 scrollTop: $(element).offset().top - offset, 258 259 }, 150, 'linear'); 260 }; 261 262 /** 263 * Set browser URL bar hash value 264 * Also adds to history navigation 265 * 266 * @param url 267 */ 268 UMGGR_Deeplink_Module.updateNavigation = function(url, parentWindow) { 269 270 //allow parent window URL to be changed 271 var win = window; 272 if(typeof parentWindow !== 'undefined' && parentWindow) { 273 win = window.parent; 274 } 275 if(history.pushState) { 276 277 win.history.pushState(null, null, url); 278 } 279 else { 280 win.location.hash = url; 281 } 282 283 }; 284 285 /** 286 * Open FancyBox modal for given URL (iframe) 287 * 288 * @param url 289 */ 290 UMGGR_Deeplink_Module.openModal = function(anchor, type='') { 291 var url = $(anchor).attr('href'); 292 var inCustomizer = false; 293 294 if(type==='news') { 295 url = $(anchor).data('link'); 296 } 297 var modalUrl = url + '?modal=1'; 298 299 //Check to see if the modal is being opened inside the grand royal wizard 300 if(window.location.href.includes("customize_messenger_channel")){ 301 inCustomizer = true; 302 } 303 304 $.fancybox.open({ 305 type:'iframe', 306 src: modalUrl, 307 baseClass:'fancy-news', 308 preload:true, 309 margin: [0, 0, 0, 0], 310 opts: { 311 beforeShow: function( instance, current ) { 312 if(!inCustomizer){ 313 UMGGR_Deeplink_Module.updateNavigation(url, UMGGR_Deeplink_Module.inIframe()); 314 } 315 }, 316 afterClose: function () { 317 if(!inCustomizer){ 318 var parentAnchor = $(anchor).parents('[data-deeplink]'); 319 320 if(parentAnchor.length) { 321 322 var urlPrefix = UMGGR_Deeplink_Module.urlType === '#' ? '/#' : '/'; 323 var urlPostfix = UMGGR_Deeplink_Module.urlType === '#' ? '' : '/'; 324 325 UMGGR_Deeplink_Module.updateNavigation(urlPrefix + parentAnchor.attr('data-deeplink') + urlPostfix, UMGGR_Deeplink_Module.inIframe()); 326 } else { 327 UMGGR_Deeplink_Module.updateNavigation('/', UMGGR_Deeplink_Module.inIframe()); 328 } 329 } 330 331 } 332 } 333 }); 334 } 335 336 /** 337 * Determine if current window is inside an iFrame 338 * 339 * @returns {boolean} 340 */ 341 UMGGR_Deeplink_Module.inIframe = function() { 342 try { 343 return window.self !== window.top; 344 } catch (e) { 345 return true; 346 } 347 } 348})(jQuery);
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.