github.com/Azareal/Gosora@v0.0.0-20210729070923-553e66b59003/themes/nox/public/misc.js (about) 1 "use strict"; 2 3 function noxMenuBind() { 4 $(".more_menu").remove(); 5 $("#main_menu li:not(.menu_hamburger").removeClass("menu_hide"); 6 7 let mWidth = $("#main_menu").width(); 8 let iWidth = 0; 9 let lastElem = null; 10 $("#main_menu > li:not(.menu_hamburger)").each(function(){ 11 iWidth += $(this).outerWidth(); 12 if(iWidth > (mWidth - 100) && (mWidth - 100) > 0) { 13 this.classList.add("menu_hide"); 14 if(lastElem!==null) lastElem.classList.add("menu_hide"); 15 } 16 lastElem = this; 17 }); 18 if(iWidth > (mWidth - 100) && (mWidth - 100) > 0) $(".menu_hamburger").show(); 19 else $(".menu_hamburger").hide(); 20 21 let div = document.createElement('div'); 22 div.className = "more_menu"; 23 $("#main_menu > li:not(.menu_hamburger):not(#menu_overview)").each(function(){ 24 if(!this.classList.contains("menu_hide")) return; 25 let cop = this.cloneNode(true); 26 cop.classList.remove("menu_hide"); 27 div.appendChild(cop); 28 }); 29 document.getElementsByClassName("menu_hamburger")[0].appendChild(div); 30 } 31 32 (() => { 33 if(window.location.pathname.startsWith("/panel/")) { 34 addInitHook("pre_global", () => noAlerts = true); 35 } 36 37 function moveAlerts() { 38 // Move the alerts above the first header 39 let cSel = $(".colstack_right .colstack_head:first"); 40 let cSelAlt = $(".colstack_right .colstack_item:first"); 41 let cSelAltAlt = $(".colstack_right .coldyn_block:first"); 42 if(cSel.length > 0) $('.alert').insertBefore(cSel); 43 else if (cSelAlt.length > 0) $('.alert').insertBefore(cSelAlt); 44 else if (cSelAltAlt.length > 0) $('.alert').insertBefore(cSelAltAlt); 45 else $('.alert').insertAfter(".rowhead:first"); 46 } 47 48 addInitHook("after_update_alert_list", count => { 49 log("misc.js"); 50 log("count",count); 51 if(count==0) { 52 $(".alerts").html(phraseBox["alerts"]["alerts.no_alerts_short"]); 53 $(".user_box").removeClass("has_alerts"); 54 } else { 55 // TODO: Localise this 56 $(".alerts").html(count+" new alerts"); 57 $(".user_box").addClass("has_alerts"); 58 } 59 }); 60 addHook("open_edit", () => $('.topic_block').addClass("edithead")); 61 addHook("close_edit", () => $('.topic_block').removeClass("edithead")); 62 63 addInitHook("end_init", () => { 64 $(".alerts").click(ev => { 65 ev.stopPropagation(); 66 let alerts = $(".menu_alerts")[0]; 67 if($(alerts).hasClass("selectedAlert")) return; 68 if(!conn) loadAlerts(alerts); 69 alerts.className += " selectedAlert"; 70 document.getElementById("back").className += " alertActive" 71 }); 72 73 $(window).resize(() => noxMenuBind()); 74 noxMenuBind(); 75 moveAlerts(); 76 77 $(".menu_hamburger").click(function() { 78 event.stopPropagation(); 79 let mm = document.getElementsByClassName("more_menu")[0]; 80 mm.classList.add("more_menu_selected"); 81 let calc = $(this).offset().left - (mm.offsetWidth / 4); 82 mm.style.left = calc+"px"; 83 }); 84 85 $(document).click(() => $(".more_menu").removeClass("more_menu_selected")); 86 }); 87 88 addInitHook("after_notice", moveAlerts); 89 })();