treemenu.js
来自「视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.」· JavaScript 代码 · 共 641 行 · 第 1/2 页
JS
641 行
/*** Can the browser handle the dynamic menu?*/ TreeMenu.prototype.doesMenu = function () { return (is_ie4up || is_nav6up || is_gecko); }/*** Can the browser handle save the branch status*/ TreeMenu.prototype.doesPersistence = function () { return (is_ie4up || is_gecko || is_nav6up); }/*** Returns the appropriate layer accessor*/ TreeMenu.prototype.getLayer = function (layerID) { if (is_ie4) { return document.all(layerID); } else if (document.getElementById(layerID)) { return document.getElementById(layerID); } else if (document.all(layerID)) { return document.all(layerID); } }/*** Save the status of the layer*/ TreeMenu.prototype.setExpandedStatusForCookie = function (layerID, expanded) { this.cookieStatuses[layerID] = expanded; this.saveCookie(); }/*** Load the status of the layer*/ TreeMenu.prototype.getExpandedStatusFromCookie = function (layerID) { if (this.cookieStatuses[layerID]) { return this.cookieStatuses[layerID]; } return false; }/*** Saves the cookie that holds which branches are expanded.* Only saves the details of the branches which are expanded.*/ TreeMenu.prototype.saveCookie = function () { var cookieString = new Array(); for (var i in this.cookieStatuses) { if (this.cookieStatuses[i] == true) { cookieString[cookieString.length] = i; } } document.cookie = 'TreeMenuBranchStatus=' + cookieString.join(':'); }/*** Reads cookie parses it for status info and* stores that info in the class member.*/ TreeMenu.prototype.loadCookie = function () { var cookie = document.cookie.split('; '); for (var i=0; i < cookie.length; i++) { var crumb = cookie[i].split('='); if ('TreeMenuBranchStatus' == crumb[0] && crumb[1]) { var expandedBranches = crumb[1].split(':'); for (var j=0; j<expandedBranches.length; j++) { this.cookieStatuses[expandedBranches[j]] = true; } } } }/*** Reset branch status*/ TreeMenu.prototype.resetBranches = function () { if (!this.doesPersistence()) { return false; } this.loadCookie(); for (var i=0; i<this.branches.length; i++) { var status = this.getExpandedStatusFromCookie(this.branches[i]); // Only update if it's supposed to be expanded and it's not already if (status == true && this.branchStatus[this.branches[i]] != true) { if (this.checkParentVisibility(this.branches[i])) { this.toggleBranch(this.branches[i], true, false); } else { this.branchStatus[this.branches[i]] = true; this.swapImage(this.branches[i]); } } } }/*** Checks whether a branch should be open * or not based on its parents' status*/ TreeMenu.prototype.checkParentVisibility = function (layerID) { if (this.in_array(this.childParents[layerID], this.branches) && this.branchStatus[this.childParents[layerID]] && this.checkParentVisibility(this.childParents[layerID]) ) { return true; } else if (this.childParents[layerID] == null) { return true; } return false; }/*** New C# style string formatter*/ TreeMenu.prototype.stringFormat = function (strInput) { var idx = 0; for (var i=1; i<arguments.length; i++) { while ((idx = strInput.indexOf('{' + (i - 1) + '}', idx)) != -1) { strInput = strInput.substring(0, idx) + arguments[i] + strInput.substr(idx + 3); } } return strInput; }/*** Also much adored, the PHP implode() function*/ TreeMenu.prototype.implode = function (seperator, input) { var output = ''; for (var i=0; i<input.length; i++) { if (i == 0) { output += input[i]; } else { output += seperator + input[i]; } } return output; }/*** Aah, all the old favourites are coming out...*/ TreeMenu.prototype.in_array = function (item, arr) { for (var i=0; i<arr.length; i++) { if (arr[i] == item) { return true; } } return false; }/*** TreeNode Class*/ function TreeNode(title, icon, link, expanded, isDynamic, cssClass) { this.title = title; this.icon = icon; this.link = link; this.expanded = expanded; this.isDynamic = isDynamic; this.cssClass = cssClass; this.n = new Array(); this.events = new Array(); this.handlers = null; this.oncollapse = null; this.onexpand = null; this.ontoggle = null; }/*** Adds a node to an already existing node*/ TreeNode.prototype.addItem = function (newNode) { newIndex = this.n.length; this.n[newIndex] = newNode; return this.n[newIndex]; }/*** Sets an event for this particular node*/ TreeNode.prototype.setEvent = function (eventName, eventHandler) { switch (eventName.toLowerCase()) { case 'onexpand': this.onexpand = eventHandler; break; case 'oncollapse': this.oncollapse = eventHandler; break; case 'ontoggle': this.ontoggle = eventHandler; break; default: this.events[eventName] = eventHandler; } }/*** That's the end of the tree classes. What follows is* the browser detection code.*/ //<!--// Ultimate client-side JavaScript client sniff. Version 3.03// (C) Netscape Communications 1999-2001. Permission granted to reuse and distribute.// Revised 17 May 99 to add is_nav5up and is_ie5up (see below).// Revised 20 Dec 00 to add is_gecko and change is_nav5up to is_nav6up// also added support for IE5.5 Opera4&5 HotJava3 AOLTV// Revised 22 Feb 01 to correct Javascript Detection for IE 5.x, Opera 4, // correct Opera 5 detection// add support for winME and win2k// synch with browser-type-oo.js// Revised 26 Mar 01 to correct Opera detection// Revised 02 Oct 01 to add IE6 detection// Everything you always wanted to know about your JavaScript client// but were afraid to ask. Creates "is_" variables indicating:// (1) browser vendor:// is_nav, is_ie, is_opera, is_hotjava, is_webtv, is_TVNavigator, is_AOLTV// (2) browser version number:// is_major (integer indicating major version number: 2, 3, 4 ...)// is_minor (float indicating full version number: 2.02, 3.01, 4.04 ...)// (3) browser vendor AND major version number// is_nav2, is_nav3, is_nav4, is_nav4up, is_nav6, is_nav6up, is_gecko, is_ie3,// is_ie4, is_ie4up, is_ie5, is_ie5up, is_ie5_5, is_ie5_5up, is_ie6, is_ie6up, is_hotjava3, is_hotjava3up,// is_opera2, is_opera3, is_opera4, is_opera5, is_opera5up// (4) JavaScript version number:// is_js (float indicating full JavaScript version number: 1, 1.1, 1.2 ...)// (5) OS platform and version:// is_win, is_win16, is_win32, is_win31, is_win95, is_winnt, is_win98, is_winme, is_win2k// is_os2// is_mac, is_mac68k, is_macppc// is_unix// is_sun, is_sun4, is_sun5, is_suni86// is_irix, is_irix5, is_irix6// is_hpux, is_hpux9, is_hpux10// is_aix, is_aix1, is_aix2, is_aix3, is_aix4// is_linux, is_sco, is_unixware, is_mpras, is_reliant// is_dec, is_sinix, is_freebsd, is_bsd// is_vms//// See http://www.it97.de/JavaScript/JS_tutorial/bstat/navobj.html and// http://www.it97.de/JavaScript/JS_tutorial/bstat/Browseraol.html// for detailed lists of userAgent strings.//// Note: you don't want your Nav4 or IE4 code to "turn off" or// stop working when new versions of browsers are released, so// in conditional code forks, use is_ie5up ("IE 5.0 or greater") // is_opera5up ("Opera 5.0 or greater") instead of is_ie5 or is_opera5// to check version in code which you want to work on future// versions./*** Severly curtailed all this as only certain elements* are required by TreeMenu, specifically:* o is_ie4up* o is_nav6up* o is_gecko*/ // convert all characters to lowercase to simplify testing var agt=navigator.userAgent.toLowerCase(); // *** BROWSER VERSION *** // Note: On IE5, these return 4, so use is_ie5up to detect IE5. var is_major = parseInt(navigator.appVersion); var is_minor = parseFloat(navigator.appVersion); // Note: Opera and WebTV spoof Navigator. We do strict client detection. // If you want to allow spoofing, take out the tests for opera and webtv. var is_nav = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1)); var is_nav6up = (is_nav && (is_major >= 5)); var is_gecko = (agt.indexOf('gecko') != -1); var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1)); var is_ie4 = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) ); var is_ie4up = (is_ie && (is_major >= 4));//--> end hide JavaScript
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?