33 Mega Menu for Squarespace 7.1 Websites
44 This Code is licensed by Will-Myers.com
55===================*/
6-
76function MegaMenu ( link , menu , menuClone , headerLinkTrigger , clickthrough , animation , action , showClose , mobileMenuType ) {
87 let thisObj = this ,
98 $header = $ ( '#header' ) ,
@@ -87,7 +86,7 @@ function MegaMenu(link, menu, menuClone, headerLinkTrigger, clickthrough, animat
8786 } ) ;
8887
8988 /*Function to hide All Menus*/
90- function hideAllMenus ( ) {
89+ function hideAllMenus ( ) {
9190 $ ( '.show-mega-menu' ) . removeClass ( 'show-mega-menu' ) ;
9291 $deactivateTriggers . off ( 'mouseenter mouseleave' ) ;
9392 $ ( '#header .header-announcement-bar-wrapper' ) . removeClass ( 'mega-menu-on' ) ;
@@ -97,7 +96,7 @@ function MegaMenu(link, menu, menuClone, headerLinkTrigger, clickthrough, animat
9796 let openTimer ;
9897 /*Show on Hover*/
9998
100- $ ( thisObj . trigger ) . on ( thisObj . action , function ( e ) {
99+ $ ( thisObj . trigger ) . on ( thisObj . action , function ( e ) {
101100 e . preventDefault ( ) ;
102101 e . stopPropagation ( ) ;
103102 setHeight ( ) ;
@@ -230,8 +229,7 @@ $('[data-mega-menu]').each(function(){
230229
231230/*First Present At All*/
232231if ( $ ( '[data-mega-menu]' ) . length ) {
233- $ ( 'head' ) . prepend ( '<link href="https://cdn.jsdelivr.net/gh/willmyethewebsiteguy/MegaMenu@1.9/styles.css" rel="stylesheet">' ) ;
234-
232+ $ ( 'head' ) . prepend ( '<link href="https://cdn.jsdelivr.net/gh/willmyethewebsiteguy/MegaMenu@1/styles.css" rel="stylesheet">' ) ;
235233
236234 /*Add active Menu link Class on ClickThrough Items*/
237235 $ ( function ( ) {
@@ -246,32 +244,8 @@ if($('[data-mega-menu]').length) {
246244 } )
247245
248246 $ ( function ( ) {
249- function loadPluginImages ( ) {
250- var images = document . querySelectorAll ( '.wm-mega-menu-item img[data-src]' ) ;
251- for ( var i = 0 ; i < images . length ; i ++ ) {
252- ImageLoader . load ( images [ i ] , { load : true } ) ;
253- }
254- }
255- function loadImageMasks ( ) {
256- let imageMaskContainer = document . createElement ( 'div' ) ;
257- let imageMasksInMega = document . querySelectorAll ( '.footer-mega-menu [data-image-mask-id]' ) ;
258-
259- imageMasksInMega . forEach ( mask => {
260- imageMaskContainer . append ( mask ) ;
261- } )
262- imageMaskContainer . dataset . description = "This element is meant for the Mega Menu Plugin to show image masks in the menu" ;
263- imageMaskContainer . classList . add ( 'wm-image-mask-container-mega-menu' ) ;
264- imageMaskContainer . style . cssText = 'position:absolute;z-index:-1;opacity:0;height:0;overflow:hidden;'
265-
266- document . body . append ( imageMaskContainer )
267- }
268- loadPluginImages ( ) ;
269- window . addEventListener ( 'load' , function ( ) {
270- loadPluginImages ( ) ;
271- loadImageMasks ( ) ;
272- } ) ;
273-
274247 /*If in the Backend Editor*/
248+
275249 if ( window . self !== window . top ) {
276250 let observer ;
277251
@@ -295,5 +269,29 @@ if($('[data-mega-menu]').length) {
295269 observer . observe ( document . body , observerConfig ) ;
296270 }
297271 }
272+ function loadPluginImages ( ) {
273+ var images = document . querySelectorAll ( '.wm-mega-menu-item img[data-src]' ) ;
274+ for ( var i = 0 ; i < images . length ; i ++ ) {
275+ ImageLoader . load ( images [ i ] , { load : true } ) ;
276+ }
277+ }
278+ function loadImageMasks ( ) {
279+ let imageMaskContainer = document . createElement ( 'div' ) ;
280+ let imageMasksInMega = document . querySelectorAll ( '.footer-mega-menu [data-image-mask-id]' ) ;
281+
282+ imageMasksInMega . forEach ( mask => {
283+ imageMaskContainer . append ( mask ) ;
284+ } )
285+ imageMaskContainer . dataset . description = "This element is meant for the Mega Menu Plugin to show image masks in the menu" ;
286+ imageMaskContainer . classList . add ( 'wm-image-mask-container-mega-menu' ) ;
287+ imageMaskContainer . style . cssText = 'position:absolute;z-index:-1;opacity:0;height:0;overflow:hidden;'
288+
289+ document . body . append ( imageMaskContainer )
290+ }
291+ loadPluginImages ( ) ;
292+ window . addEventListener ( 'load' , function ( ) {
293+ loadPluginImages ( ) ;
294+ loadImageMasks ( ) ;
295+ } ) ;
298296 } )
299297}
0 commit comments