📄 common.js.svn-base
字号:
return g;}// 03/03/06 : Botho - New progress bar implementation//// BEGIN xp_progressbar// Copyright 2004 Brian Gosselin of ScriptAsylum.com//// v1.0 - Initial release// v1.1 - Added ability to pause the scrolling action (requires you to assign// the bar to a unique arbitrary variable).// - Added ability to specify an action to perform after a x amount of// - bar scrolls. This requires two added arguments.// v1.2 - Added ability to hide/show each bar (requires you to assign the bar// to a unique arbitrary variable).// v.13 - Botho 03/03/06 : incorporate DD-WRT styles// var xyz = createBar(// total_width,// total_height,// background_color, Botho 03/03/06 : incorporate DD-WRT styles// border_width, Botho 03/03/06 : incorporate DD-WRT styles// border_color, Botho 03/03/06 : incorporate DD-WRT styles// block_color, Botho 03/03/06 : incorporate DD-WRT styles// scroll_speed,// block_count,// scroll_count,// action_to_perform_after_scrolled_n_times// )var w3c=(document.getElementById)?true:false;var ie=(document.all)?true:false;var N=-1;function createBar(w,h,speed,blocks,count,action) { if(ie||w3c){ var t='<div class="progressbar" id="_xpbar'+(++N)+'" style="width:'+w+'px; height:'+h+'px;">'; t+='<span class="progressbarblock" id="blocks'+N+'" style="left:-'+(h*2+1)+'px;">'; for(i=0;i<blocks;i++){ t+='<span class="progressbarblock" style="left:-'+((h*i)+i)+'px; width:'+h+'px; height:'+h+'px; ' t+=(ie)?'filter:alpha(opacity='+(100-i*(100/blocks))+')':'-Moz-opacity:'+((100-i*(100/blocks))/100); t+='"></span>'; } t+='</span></div>'; document.write(t); var bA=(ie)?document.all['blocks'+N]:document.getElementById('blocks'+N); bA.bar=(ie)?document.all['_xpbar'+N]:document.getElementById('_xpbar'+N); bA.blocks=blocks; bA.N=N; bA.w=w; bA.h=h; bA.speed=speed; bA.ctr=0; bA.count=count; bA.action=action; bA.togglePause=togglePause; bA.showBar=function(){ this.bar.style.visibility="visible"; } bA.hideBar=function(){ this.bar.style.visibility="hidden"; } bA.tid=setInterval('startBar('+N+')',speed); return bA; }}function startBar(bn){ var t=(ie)?document.all['blocks'+bn]:document.getElementById('blocks'+bn); if(parseInt(t.style.left)+t.h+1-(t.blocks*t.h+t.blocks)>t.w){ t.style.left=-(t.h*2+1)+'px'; t.ctr++; if(t.ctr>=t.count){ eval(t.action); t.ctr=0; } } else t.style.left=(parseInt(t.style.left)+t.h+1)+'px';}function togglePause(){ if(this.tid==0){ this.tid=setInterval('startBar('+this.N+')',this.speed); }else{ clearInterval(this.tid); this.tid=0; }}// END xp_progressbar// 03/03/06 : Botho - Change style of the element in paramfunction change_style(id, newClass) { identity=document.getElementById(id); identity.className=newClass;}// 14/03/06 : Botho - New way for translation. (Linksys one)function Capture(obj){ document.write(obj); } function defined(val) { return (typeof val != "undefined");}function cleanTable(table) { for(var i = table.rows.length - 1; i > 0; i--) table.deleteRow(i);}// Opens the help window at the right side of the screen.function openHelpWindow(url) { var top = 30; var left = Math.floor(screen.availWidth * .66) - 10; var width = Math.floor(screen.availWidth * .33); var height = Math.floor(screen.availHeight * .9) - 30; var win = window.open("help/" + url, 'DDWRT_Help', 'top=' + top + ',left=' + left + ',width=' + width + ',height=' + height + ",resizable=yes,scrollbars=yes,statusbar=no"); win.focus();}function openHelpWindowExt(url) { var top = 30; var left = Math.floor(screen.availWidth * .66) - 10; var width = Math.floor(screen.availWidth * .33); var height = Math.floor(screen.availHeight * .9) - 30; var win = window.open("http://www.dd-wrt.com/help/english/" + url, 'DDWRT_Help', 'top=' + top + ',left=' + left + ',width=' + width + ',height=' + height + ",resizable=yes,scrollbars=yes,statusbar=no"); win.focus();}function openAboutWindow() { var width = 500; var height = 650; var top = Math.floor((screen.availHeight - height - 10) / 2); var left = Math.floor((screen.availWidth - width) / 2); var win = window.open("About.htm", 'DDWRT_About', 'top=' + top + ',left=' + left + ',width=' + width + ',height=' + height + ",resizable=no,scrollbars=no,statusbar=no"); win.focus();}// Opens a new window in the center of the screen and closes it, if the parent window is unloadedfunction openWindow(url, width, height, title) { if (!title) title=url.replace(/\.asp/, ""); var top = Math.floor((screen.availHeight - height - 10) / 2); var left = Math.floor((screen.availWidth - width) / 2); var win = window.open(url, 'DDWRT_' + title, 'top=' + top + ',left=' + left + ',width=' + width + ',height=' + height + ",resizable=yes,scrollbars=yes,statusbar=no"); addEvent(window, "unload", function() { if(!win.closed) win.close(); }); win.focus();}// Renders a nice meter with the percentage valuefunction setMeterBar(id, fraq, text) { if(isNaN(fraq)) fraq = 0; fraq = Math.max(0, Math.min(100, Math.round(fraq))) + "%"; var node = (typeof id == "string" ? document.getElementById(id) : id); if(node.firstChild) { node.firstChild.childNodes[0].style.width = fraq; node.firstChild.childNodes[1].firstChild.data = fraq; if(defined(text)) node.lastChild.data = text; } else { node.innerHTML = '<div class="meter"><div class="bar" style="width:' + fraq + ';"></div>' + '<div class="text">' + fraq + '</div></div>' + (defined(text) ? text : ""); }}//function setTableContent(id, data, sortBy) {//}// Sets the content inside the tag given by its idfunction setElementContent(id, content) { if(!document.getElementById(id)) return; document.getElementById(id).innerHTML = content;}// Shows or hides element given by its idfunction setElementVisible(id, state) { if(!document.getElementById(id)) return; document.getElementById(id).style.display = (state ? "" : "none");}// Disables or enables a form element given by its name// (Might replace choose_enable and choose_disable in future)function setElementActive(name, state) { var elements = document.getElementsByName(name); if(!elements) return; for(var i = 0; i < elements.length; i++) { elements[i].disabled = !state; }}// Disables or enables several elements given by name of the first and the last elementfunction setElementsActive(firstName, lastName, state) { if(!document.forms[0].elements[firstName] || !document.forms[0].elements[lastName]) return; var go = false; for(var i = 0; i < document.forms[0].elements.length; i++) { var currentName = document.forms[0].elements[i].name; if(!document.forms[0].elements[i].type || (currentName != firstName && !go)) continue; go = true; document.forms[0].elements[i].disabled = !state; if(currentName == lastName) break; }}// Adds an eventlistner to objectfunction addEvent(object, type, func) { if(object.addEventListener) object.addEventListener(type, func, false); else if (object.attachEvent) object.attachEvent("on" + type, func);}// Removes an eventlistner from objectfunction removeEvent(object, type, func) { if(object.removeEventListener) object.removeEventListener(type, func, false); else if (object.detachEvent) object.detachEvent("on" + type, func);}// Class for requesting updates periodically using ajaxfunction StatusUpdate(_url, _frequency) { var request; var timer; var url = _url; var frequency = _frequency * 1000; var me = this; var callbacks = new Object(); var updates = new Object(); this.start = function() { if((!window.XMLHttpRequest && !window.ActiveXObject) || frequency == 0) return false; if(document.getElementsByName("refresh_button")) { document.getElementsByName("refresh_button")[0].disabled = true; document.getElementsByName("refresh_button")[0].style.background = '#DADADA'; document.getElementsByName("refresh_button")[0].style.cursor = "default"; } timer = setTimeout(me.doUpdate, frequency); } this.stop = function() { clearTimeout(timer); if(document.getElementsByName("refresh_button")) document.getElementsByName("refresh_button")[0].disabled = false; request = null; } this.onUpdate = function(id, func) { callbacks[id] = func; } this.doUpdate = function() { if(request && request.readyState < 4) return; if(window.XMLHttpRequest) request = new XMLHttpRequest(); if(window.ActiveXObject) request = new ActiveXObject("Microsoft.XMLHTTP"); request.open("GET", url, true); request.onreadystatechange = function() { if(request.readyState < 4 || request.status != 200) return; var activeCallbacks = new Array(); var regex = /\{(\w+)::([^\}]*)\}/g; while(result = regex.exec(request.responseText)) { var key = result[1]; var value = result[2]; if(defined(updates[key]) && updates[key] == value) continue; updates[key] = value; if(defined(callbacks[key])) activeCallbacks.push(callbacks[key]); setElementContent(key, value); } for(var i = 0; i < activeCallbacks.length; i++) { (activeCallbacks[i])(updates); } timer = setTimeout(me.doUpdate, frequency); } request.send(""); } this.forceUpdate = function() { this.stop(); this.doUpdate(); }}// Gray all form when submittingfunction apply(form, text) { if(!text) text=errmsg.err100; Dialog.info(text, {windowParameters: {className: "ddwrt", width:250, height:100}, showProgress: true}); setTimeout(function(){form.submit();}, 2000);}// Class for sending a request using ajax// This is work in progress, plz do not use yet./* function Request(_url) { var url = _url; var values = new Array(); var callback = new Array(); this.addAllElements = function() { for(var i = 0; i < document.forms[0].elements.length; i++) this.addElement(document.forms[0].elements[i].name); } this.addElement = function(name) { if(!document.forms[0].elements[name]) return; this.addValue(name, document.forms[0].elements[name].value); } this.addValue = function(name, value) { if(name.match(/[^\w]/)) return; values.push(name + "=" + encodeURIComponent(value)); } this.onRequest = function(func) { callback.push(func); } this.send = function() { // some function to disable page if(window.XMLHttpRequest) request = new XMLHttpRequest(); if(window.ActiveXObject) request = new ActiveXObject("Microsoft.XMLHTTP"); request.open("POST", url, false); request.send(values.join("&")); if(request.readyState < 4 || request.status != 200) alert("Error while processing this request: " + values.join("&")); var updates = new Object(); while(result = /\{(\w+)::([^\}]*)\}/g.exec(request.responseText)) { updates[result[1]] = result[2]; } for(var i = 0; i < callback.length; i++) { (callback[i])(updates); } // enable page }} */// Botho 06/04/2006 : Function to resolve OUI namesfunction getOUIFromMAC(mac) { var top = 30; var left = Math.floor(screen.availWidth * .66) - 10; var width = 700 var height = 400 var tab = new Array(); tab = mac.split(mac.substr(2,1)); var win = window.open("http://standards.ieee.org/cgi-bin/ouisearch?" + tab[0] + '-' + tab[1] + '-' + tab[2], 'DDWRT_OUI_Search', 'top=' + top + ',left=' + left + ',width=' + width + ',height=' + height + ",resizable=yes,scrollbars=yes,statusbar=no"); addEvent(window, "unload", function() { if(!win.closed) win.close(); }); win.focus();}/* Added by Botho 25.April.06 *//* write in asp file dynamicaly wait_time and scroll_count dipending of the CPU frequency *//* reference values (125 Mhz cpu): 60 sec for a reboot or restore config file, 90 for a reset nvram + reboot */ function getTimeOut(clk, rest_default, flags) { var wait_time = 60; // 60 seconds without rest to factory default ==> need to be tested var scroll_count = (wait_time / 5) - 3; // a scroll is during about 5 seconds var coef = 1.1; // +10% to be on a safe side if many services need to be restarted, Eko if (rest_default == 1) { // if restore default is ask (in upgrade process or restore default process) then timeout is doubled coef = 1.5; } if (flags==1) { coef = coef * 3; } if (flags==2) { coef = coef * 1.8; } this.wait_time = coef * wait_time * (125 / clk); this.scroll_count = this.wait_time / 5 - 3;}/* Added by Botho 06.May.06 */// Unmask or Mask an input type (for password or key)function setElementMask(id, state) { var OldInput = document.getElementById(id); if(!OldInput) return; var val = OldInput.value; var val_maxlength = OldInput.maxlength; var val_size = OldInput.size; var val_onblur = OldInput.onblur; var parent = OldInput.parentNode; var sibling = OldInput.nextSibling; var newInput = document.createElement('input'); newInput.setAttribute('value', val); newInput.setAttribute('name', id); newInput.setAttribute('id', id); newInput.setAttribute('maxlength', val_maxlength); newInput.setAttribute('size', val_size); newInput.setAttribute('onblur', val_onblur); if (state == true) newInput.setAttribute('type', 'text'); else newInput.setAttribute('type', 'password'); parent.removeChild(OldInput); parent.insertBefore(newInput, sibling); newInput.focus(); }var windo = { getWindoSize: function() { if (window.innerHeight) return {height: window.innerHeight, width: window.innerWidth}; else if (document.documentElement && document.documentElement.clientHeight) return {height: document.documentElement.clientHeight, width: document.documentElement.clientWidth}; return {Height: document.body.clientHeight, width: document.body.clientWidth}; }};function show_layer_ext(obj, id, state){ if(!obj) return; if(state){ visibility_style='visible'; display_style='block'; } else { visibility_style='hidden'; display_style='none'; } // Show/hide the layer if(ie4) { eval("document.all." + id + ".style.visibility='" + visibility_style + "'"); eval("document.all." + id + ".style.display='" + display_style + "'"); } if(ns4) { eval("document." + id + ".visibility='" + visibility_style + "'"); eval("document." + id + ".display='" + display_style + "'"); } if(ns6 || op) { eval("document.getElementById('" + id + "').style.visibility='" + visibility_style + "'"); eval("document.getElementById('" + id + "').style.display='" + display_style + "'"); }}function lgout() { document.forms[0].action.value = "Logout"; document.forms[0].submit();}function comma(n){ n = '' + n; var p = n; while ((n = n.replace(/(\d+)(\d{3})/g, '$1,$2')) != p) p = n; return n;}function scaleSize(num){ if (isNaN(num *= 1)) return '-'; if (num <= 9999) return '' + num; var s = -1; do { num /= 1024; ++s; } while ((num > 9999) && (s < 2)); return comma(num.toFixed(2)) + '<small> ' + (['KB', 'MB', 'GB'])[s] + '</small>';}function DisplayDiv(current,evt,h,w,text){ var height = h; var width = w; text = text.replace(/</gi,'<'); text = text.replace(/>/gi,'>'); if(document.all) { if(document.readyState == 'complete') { document.all.bulle.innerHTML = '<table class="bulle" cellspacing="0"><tr><td class="bulle">' + text + '</td></tr></table>'; document.all.bulle.style.pixelLeft = event.clientX + document.body.scrollLeft + width; document.all.bulle.style.pixelTop = event.clientY + document.body.scrollTop + height; document.all.bulle.style.visibility = 'visible'; } } else if(document.getElementById) { document.getElementById('bulle').innerHTML = '<table class="bulle" cellspacing="0"><tr><td class="bulle">' + text + '</td></tr></table>'; document.getElementById('bulle').style.left = evt.pageX + width + 'px'; document.getElementById('bulle').style.top = evt.pageY + height + 'px'; document.getElementById('bulle').style.visibility = 'visible'; }}function unDisplayDiv(){ if(document.all) { document.all.bulle.style.visibility = 'hidden'; } else if(document.layers) { document.bulle.visibility = 'hidden'; } else if(document.getElementById) { document.getElementById('bulle').style.visibility = 'hidden'; }}function submitFooterButton(sub, res, reb, autoref, ref, clo) { if(sub) document.write("<input class=\"button\" type=\"button\" name=\"save_button\" value=\"" + sbutton.save + "\" onclick=\"to_submit(this.form);\" />"); if(res) document.write("<input class=\"button\" type=\"button\" name=\"reset_button\" value=\"" + sbutton.cancel + "\" onclick=\"window.location.reload();\" />"); if(reb) document.write("<input class=\"button\" type=\"button\" name=\"reboot_button\" value=\"" + sbutton.reboot + "\" onclick=\"to_reboot(this.form);\" />"); if(autoref) document.write("<input class=\"button\" type=\"button\" name=\"refresh_button\" value=\"" + autoref + "\" onclick=\"window.location.reload();\">"); if(ref) document.write("<input class=\"button\" type=\"button\" name=\"refresh_button\" value=\"" + sbutton.refres + "\" onclick=\"window.location.reload();\" />"); if(clo) document.write("<input class=\"button\" type=\"button\" name=\"close_button\" value=\"" + sbutton.clos + "\" onclick=\"self.close();\" />");}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -