From 23d47e427e6ca01e31e7028d9a3732c65779d003 Mon Sep 17 00:00:00 2001 From: KrzysztofPajak Date: Sun, 12 Sep 2021 20:25:23 +0200 Subject: [PATCH] Menu JS - Move script to common file --- src/Web/Grand.Web/Views/Shared/Head.cshtml | 1 - .../Grand.Web/wwwroot/theme/script/menu.js | 51 ----------------- .../wwwroot/theme/script/public.common.js | 57 ++++++++++++++++++- 3 files changed, 56 insertions(+), 53 deletions(-) delete mode 100644 src/Web/Grand.Web/wwwroot/theme/script/menu.js diff --git a/src/Web/Grand.Web/Views/Shared/Head.cshtml b/src/Web/Grand.Web/Views/Shared/Head.cshtml index ef8306eb7..a82314221 100644 --- a/src/Web/Grand.Web/Views/Shared/Head.cshtml +++ b/src/Web/Grand.Web/Views/Shared/Head.cshtml @@ -45,7 +45,6 @@ - diff --git a/src/Web/Grand.Web/wwwroot/theme/script/menu.js b/src/Web/Grand.Web/wwwroot/theme/script/menu.js deleted file mode 100644 index 5bd080b27..000000000 --- a/src/Web/Grand.Web/wwwroot/theme/script/menu.js +++ /dev/null @@ -1,51 +0,0 @@ -(function(){ - function $(selector, context){ - context = context || document; - return context["querySelectorAll"](selector); - } - - function forEach(collection, iterator){ - for(var key in Object.keys(collection)){ - iterator(collection[key]); - } - } - - function showMenu(menu){ - var menu = this; - var ul = $("ul", menu)[0]; - - if(!ul || ul.classList.contains("-visible")) return; - - ul.classList.add("-visible"); - } - - function hideMenu(menu){ - var menu = this; - var ul = menu.parentElement; - - if(!ul || !ul.classList.contains("-visible")) return; - - setTimeout(function(){ - ul.classList.remove("-visible"); - }, 300); - } - - window.addEventListener("load", function(){ - forEach($(".Menu li.-hasSubmenu"), function(e){ - e.showMenu = showMenu; - e.hideMenu = hideMenu; - }); - - forEach($(".Menu > li.-hasSubmenu"), function(e){ - e.addEventListener("click", showMenu); - }); - - forEach($(".Menu li .back"), function(e){ - e.addEventListener("click", hideMenu); - }); - - forEach($(".Menu > li.-hasSubmenu li.-hasSubmenu"), function(e){ - e.addEventListener("click", showMenu); - }); - }); -})(); diff --git a/src/Web/Grand.Web/wwwroot/theme/script/public.common.js b/src/Web/Grand.Web/wwwroot/theme/script/public.common.js index 4eda50b5a..e28ff4d5f 100644 --- a/src/Web/Grand.Web/wwwroot/theme/script/public.common.js +++ b/src/Web/Grand.Web/wwwroot/theme/script/public.common.js @@ -531,4 +531,59 @@ document.addEventListener("DOMContentLoaded", function () { newsletterBox(); CloseSearchBox(); backToTop(); -}); \ No newline at end of file +}); + +/* MENU */ +(function () { + function $(selector, context) { + context = context || document; + return context["querySelectorAll"](selector); + } + + function forEach(collection, iterator) { + for (var key in Object.keys(collection)) { + iterator(collection[key]); + } + } + + function showMenu(menu) { + var menu = this; + var ul = $("ul", menu)[0]; + + if (!ul || ul.classList.contains("-visible")) return; + + ul.classList.add("-visible"); + } + + function hideMenu(menu) { + var menu = this; + var ul = menu.parentElement; + + if (!ul || !ul.classList.contains("-visible")) return; + + setTimeout(function () { + ul.classList.remove("-visible"); + }, 300); + } + + window.addEventListener("load", function () { + forEach($(".Menu li.-hasSubmenu"), function (e) { + e.showMenu = showMenu; + e.hideMenu = hideMenu; + }); + + forEach($(".Menu > li.-hasSubmenu"), function (e) { + e.addEventListener("click", showMenu); + }); + + forEach($(".Menu li .back"), function (e) { + e.addEventListener("click", hideMenu); + }); + + forEach($(".Menu > li.-hasSubmenu li.-hasSubmenu"), function (e) { + e.addEventListener("click", showMenu); + }); + }); +})(); + +/* ENDMENU */ \ No newline at end of file