/
SoRusV
/
src_xendil
Обзор
Документация
Войти
/
SoRusV
/
src_xendil
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
html/src/menu.js
287 строк
10 KB
ruslan
Initial commit
29 окт 2024, 11:18
29 окт 2024, 11:18
5c4dcf5
Код
Авторство
О чём код?
// TwoByOne('MMain0.htm', 'CMain0.htm'); //++ parent.parent.FrameTop.location.href='top.htm'; // parent.parent.FrameDown.location.href='down.htm'; // ++ parent.parent.FrameMain.location.href='MAbout.htm'; //parent.parent.FrameComment.location.href = 'CAbout.htm'; // console.log(JSON.stringify(parent.JNetUdpDShow)); // if (CheckTab("{\"LPWMChanelLED\":{\"ShowTab\":0}}")) { // document.getElementById("idLLight").style.display = "block"; // } // else { // document.getElementById("idLLight").style.display = "none"; // } // if(CheckTab("{\"LPWMChanelTimer\":{\"ShowTab\":0}}")) // document.getElementById("idLTimer").style.display = "block"; // else // document.getElementById("idLTimer").style.display = "none"; //let JShowHideTab={}; // ShowHideTab(); function myhref(Link) { if(parent) parent.document.location.href = Link; //"http://google.com";//Link; else document.location.href = Link; //"http://google.com";//Link; } function MakeMenuMainTab(E) { /// file:///C:/Oleg/Scord/html/src/MAbout.htm?param=val&data=ololo function AddItem(E, Link, Value, FuncOnClick){ let A = document.createElement('a'); // A.href="javascript:TwoByOne('"+Link+"?&ShowAqua="+ShowAqua+"&ShowName="+ShowName+"', '')"; A.href="javascript:TwoByOne('"+Link+"', '')"; // A.href="javascript:TwoByOne('MLight.htm', '')"; A.id="id"+Value; A.innerHTML=Value; A.onclick=function (){ return ClickItem(A.textContent);};//"return ClickItem(A.textContent)";//FuncOnClick; // A.class = "current"; E.appendChild(A); }; ClearElement(E); let D, S; D = document.createElement('div'); S = document.createElement('span'); S.innerHTML="Main"; D.appendChild(S); AddItem(D, "MLight.htm", "Light"); AddItem(D, "MTimer.htm", "Timer"); AddItem(D, "MTemperature.htm", "Temperature"); E.appendChild(D); D = document.createElement('div'); S = document.createElement('span'); S.innerHTML="Settings"; D.appendChild(S); AddItem(D, "MWiFi.htm", "WiFi"); AddItem(D, "MTime.htm", "Time"); AddItem(D, "MGPIO.htm", "General"); AddItem(D, "MPWMChanel.htm", "PWM"); AddItem(D, "MNet.htm", "Net"); E.appendChild(D); D = document.createElement('div'); S = document.createElement('span'); S.innerHTML="Tools"; D.appendChild(S); AddItem(D, "edit.htm", "FileSystem"); AddItem(D, "MReboot.htm", "Reboot"); AddItem(D, "MInfo.htm", "Info"); AddItem(D, "MAbout.htm", "About"); E.appendChild(D); E.style.height = E.scrollHeight + 'px' myMenu = new SDMenu(E); myMenu.init(); // ShowHideTab(); //<a className = "current" href="javascript:TwoByOne('MLight.htm', '')" id="idLLight" onclick="myFunction(textContent)">Light</a> }; function ShowHideTab() { if (CheckTab("TabLight") > 0) document.getElementById("idLight").style.display = "block"; else document.getElementById("idLight").style.display = "none"; if (CheckTab("TabTimer") > 0) document.getElementById("idTimer").style.display = "block"; else document.getElementById("idTimer").style.display = "none"; if(CheckTab("TabTemperature")>0) document.getElementById("idTemperature").style.display = "block"; else document.getElementById("idTemperature").style.display = "none"; } function CheckTab(Name) { return JNetUdpDShow["Data"]["0"][Name]; // SetCookie("TabLight", JNetUdpDShow["Data"]["0"]["TabLight"]); // SetCookie("TabTimer", JNetUdpDShow["Data"]["0"]["TabTimer"]); // SetCookie("TabTemperature", JNetUdpDShow["Data"]["0"]["TabTemperature"]); // function FuncRetGetJNetUdp(J){ // ShowHideTab(); // }; // if(JShowHideTab[Name]) // return JShowHideTab[Name]; // let v=GetCookie(Name); // if(v)//!=undefined) // return v; // // GetJNetUdp({}, FuncRetGetJNetUdp); // return 1; // var JsonR = get_rest("Json=" + sJson, _ip); // JsonE = JSON.parse(sJson); // return JsonGet(JsonR, JsonE) } function TwoByOne(Link1, Link2, textContent) { // location.href = Link1; // document.location.href=Link1; if(Link1!="") { if(parent.parent.FrameMain) { let a=parent.parent.FrameMain.GetShowAqua(); a=Link1 + "?&AquaName=" + a.ShowAqua + "&Name=" + a.ShowName + "&IP=" + a._ip; parent.parent.FrameMain.location.href = a; a=a; } else parent.location.href = Link1+"?&AquaName="+ShowAqua+"&Name="+ShowName+"&IP="+_ip;; // document.location.href = Link1; } // if(Link2!="") // parent.parent.FrameComment.location.href=Link2; var tags=document.getElementsByTagName("a"); // for(i in tags) // { // var pp=tags[i].firstChild; // if(pp) // { // if(pp.textContent==textContent) // tags[i].className = "current"; // else // tags[i].className="deactive"; // } // } } function ClickItem(textContent) { // document.getElementById("demo").style.color = "red"; // document.getElementById(e).style.color = "red"; // console.log("++++") // console.log(textContent); // console.log("++++") // return; var tags=document.getElementsByTagName("a"); for(let i in tags) if(tags[i].className == "current") tags[i].className="deactive"; for(let i in tags) { var pp=tags[i].firstChild; if(pp && pp.textContent==textContent) tags[i].className = "current"; } } function SDMenu(E) { // if (!document.getElementById || !document.getElementsByTagName) // return false; this.menu = E;//document.getElementById(id); this.submenus = this.menu.getElementsByTagName("div"); this.remember = true; this.speed = 3; this.markCurrent = true; this.oneSmOnly = false; this.submenus[1].className="collapsed"; this.submenus[2].className="collapsed"; } SDMenu.prototype.init = function() { var mainInstance = this; for (var i = 0; i < this.submenus.length; i++) this.submenus[i].getElementsByTagName("span")[0].onclick = function() { mainInstance.toggleMenu(this.parentNode); }; // if (this.remember) { // var regex = new RegExp("ScorbMenu_" + encodeURIComponent(this.menu.id) + "=([01]+)"); // var match = regex.exec(document.cookie); // if (match) { // var states = match[1].split(""); // for (var i = 0; i < states.length; i++) // this.submenus[i].className = (states[i] == 1 ? "" : "collapsed"); // // this.submenus[i].className = (states[i] == 0 ? "collapsed" : ""); // } // else // { // for (var i = 0; i < this.submenus.length; i++) // this.submenus[i].className ="collapsed"; // } // } }; SDMenu.prototype.toggleMenu = function(submenu) { if (submenu.className == "collapsed") this.expandMenu(submenu); else this.collapseMenu(submenu); }; SDMenu.prototype.expandMenu = function(submenu) { var fullHeight = submenu.getElementsByTagName("span")[0].offsetHeight; var links = submenu.getElementsByTagName("a"); for (var i = 0; i < links.length; i++) fullHeight += links[i].offsetHeight; var moveBy = Math.round(this.speed * links.length); var mainInstance = this; var intId = setInterval(function() { var curHeight = submenu.offsetHeight; var newHeight = curHeight + moveBy; if (newHeight < fullHeight) submenu.style.height = newHeight + "px"; else { clearInterval(intId); submenu.style.height = ""; submenu.className = ""; // mainInstance.memorize(); } }, 30); this.collapseOthers(submenu); }; SDMenu.prototype.collapseMenu = function(submenu) { var minHeight = submenu.getElementsByTagName("span")[0].offsetHeight; var moveBy = Math.round(this.speed * submenu.getElementsByTagName("a").length); var mainInstance = this; var intId = setInterval(function() { var curHeight = submenu.offsetHeight; var newHeight = curHeight - moveBy; if (newHeight > minHeight) submenu.style.height = newHeight + "px"; else { clearInterval(intId); submenu.style.height = ""; submenu.className = "collapsed"; // mainInstance.memorize(); } }, 30); }; SDMenu.prototype.collapseOthers = function(submenu) { if (this.oneSmOnly) { for (var i = 0; i < this.submenus.length; i++) if (this.submenus[i] != submenu && this.submenus[i].className != "collapsed") this.collapseMenu(this.submenus[i]); } }; SDMenu.prototype.expandAll = function() { var oldOneSmOnly = this.oneSmOnly; this.oneSmOnly = false; for (var i = 0; i < this.submenus.length; i++) if (this.submenus[i].className == "collapsed") this.expandMenu(this.submenus[i]); this.oneSmOnly = oldOneSmOnly; }; SDMenu.prototype.collapseAll = function() { for (var i = 0; i < this.submenus.length; i++) if (this.submenus[i].className != "collapsed") this.collapseMenu(this.submenus[i]); }; // SDMenu.prototype.memorize = function() { // if (this.remember) { // var states = []; // for (var i = 0; i < this.submenus.length; i++) // states.push(this.submenus[i].className == "collapsed" ? 0 : 1); // var d = new Date(); // d.setTime(d.getTime() + (30 * 24 * 60 * 60 * 1000)); // document.cookie = "ScorbMenu_" + encodeURIComponent(this.menu.id) + "=" + states.join("") + "; expires=" + d.toGMTString() + "; path=/"; // // let tt="ScorbMenu_" + encodeURIComponent(this.menu.id) + "=" + states.join("") + "; expires=" + d.toGMTString() + "; path=/"; // } // };