From 469d17e7d448ec1833abb72add88d1d1f61c4a06 Mon Sep 17 00:00:00 2001 From: artem Date: Wed, 20 Aug 2008 14:46:11 +0000 Subject: - [DEV-199] performance improvements of js scripts in hosts screen (Artem) - [DEV-137] many small fixes (Artem) git-svn-id: svn://svn.zabbix.com/trunk@5932 97f52cf1-0a1b-0410-bd0e-c28be96e8082 --- frontends/php/js/common.js | 559 +++++++++++++++++---------------------------- 1 file changed, 204 insertions(+), 355 deletions(-) (limited to 'frontends/php/js/common.js') diff --git a/frontends/php/js/common.js b/frontends/php/js/common.js index 97befa5d..efed52ef 100644 --- a/frontends/php/js/common.js +++ b/frontends/php/js/common.js @@ -16,6 +16,8 @@ ** along with this program; if not, write to the Free Software ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. **/ + + var agt = navigator.userAgent.toLowerCase(); var OP = (agt.indexOf("opera") != -1) && window.opera; var IE = (agt.indexOf("msie") != -1) && document.all && !OP; @@ -61,20 +63,6 @@ function is_array(obj) { 'splice' in obj && 'join' in obj; } -if (!Array.prototype.forEach){ - Array.prototype.forEach = function(fun /*, thisp*/){ - var len = this.length; - if (typeof fun != "function") - throw new TypeError(); - - var thisp = arguments[1]; - for (var i = 0; i < len; i++){ - if (i in this) - fun.call(thisp, this[i], i, this); - } - }; -} - function SDI(msg){ var div_help = document.getElementById('div_help'); @@ -94,113 +82,20 @@ function SDI(msg){ div_help.appendChild(document.createElement("br")); } -function close_window(){ - - window.setTimeout("window.close()", 500); /* Solve bug for Internet Explorer */ - return false; -} - -function add2favorites(favobj,favid){ - if('undefined' == typeof(Ajax)){ - throw("Prototype.js lib is required!"); - return false; - } +/// Alpha-Betic sorting - if(typeof(favobj) == 'undefined'){ - var fav_form = document.getElementById('fav_form'); - if(!fav_form) throw "Object not found."; - - var favobj = fav_form.favobj.value; - var favid = fav_form.favid.value; - } - - if((typeof(favid) == 'undefined') || empty(favid)) return; - - var params = { - 'favobj': favobj, - 'favid': favid, - 'action': 'add' - } +function addListener(element, eventname, expression, bubbling){ + bubbling = bubbling || false; - send_params(params); -// json.onetime('dashboard.php?output=json&'+Object.toQueryString(params)); -} - -function rm4favorites(favobj,favid,menu_rowid){ -// alert(favobj+','+favid+','+menu_rowid); - if('undefined' == typeof(Ajax)){ - throw("Prototype.js lib is required!"); - return false; - } - - if((typeof(favobj) == 'undefined') || (typeof(favid) == 'undefined')) - throw "No agruments sent to function [rm4favorites()]."; - - var params = { - 'favobj': favobj, - 'favid': favid, - 'favcnt': menu_rowid, - 'action': 'remove' - } - - send_params(params); -// json.onetime('dashboard.php?output=json&'+Object.toQueryString(params)); -} - -function getPosition(obj){ - var pos = {top: 0, left: 0}; - if(typeof(obj.offsetParent) != 'undefined') { - pos.left = obj.offsetLeft; - pos.top = obj.offsetTop; - while (obj = obj.offsetParent) { - pos.left += obj.offsetLeft; - pos.top += obj.offsetTop; - } - } -return pos; -} - -function get_scroll_pos(){ - var scrOfX = 0, scrOfY = 0; -//Netscape compliant - if( typeof( window.pageYOffset ) == 'number' ){ - scrOfY = window.pageYOffset; - scrOfX = window.pageXOffset; - } -//DOM compliant - else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ){ - scrOfY = document.body.scrollTop; - scrOfX = document.body.scrollLeft; - } -//IE6 standards compliant mode - else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ){ - scrOfY = document.documentElement.scrollTop; - scrOfX = document.documentElement.scrollLeft; - } - return [ scrOfX, scrOfY ]; -} - -function get_cursor_position(e){ - e = e || window.event; - var cursor = {x:0, y:0}; - if(e.pageX || e.pageY){ - cursor.x = e.pageX; - cursor.y = e.pageY; + if(window.addEventListener) { + element.addEventListener(eventname, expression, bubbling); + return true; } - else { - var de = document.documentElement; - var b = document.body; - cursor.x = e.clientX + - (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0); - cursor.y = e.clientY + - (de.scrollTop || b.scrollTop) - (de.clientTop || 0); - } - return cursor; -} - -function redirect(url) { - window.location = url; - return false; + else if(window.attachEvent) { + element.attachEvent('on'+eventname, expression); + return true; + } + else return false; } function add_variable(o_el, s_name, x_value, s_formname, o_document){ @@ -235,6 +130,48 @@ function add_variable(o_el, s_name, x_value, s_formname, o_document){ return true; } +function cancelEvent(e){ + if (!e) var e = window.event; +//SDI(e); + if(e){ + if(IE){ + e.cancelBubble = true; + e.returnValue = false; + } + else{ + e.stopPropagation(); + e.preventDefault(); + } + } +return false; +} + +function CheckAll(form_name, chkMain, shkName){ + var frmForm = document.forms[form_name]; + var value = frmForm.elements[chkMain].checked; + for (var i=0; i < frmForm.length; i++){ + name = frmForm.elements[i].name.split('[')[0]; + if(frmForm.elements[i].type != 'checkbox') continue; + if(name == chkMain) continue; + if(shkName && shkName != name) continue; + if(frmForm.elements[i].disabled == true) continue; + frmForm.elements[i].checked = value; + } +} + +function close_window(){ + + window.setTimeout("window.close()", 500); /* Solve bug for Internet Explorer */ + return false; +} + +function Confirm(msg){ + if(confirm(msg,'title')) + return true; + else + return false; +} + function create_var(form_name, var_name, var_val, subm){ var frmForm = (is_string(form_name))?document.forms[form_name]:form_name; @@ -263,121 +200,6 @@ function create_var(form_name, var_name, var_val, subm){ return false; } -function Confirm(msg){ - if(confirm(msg,'title')) - return true; - else - return false; -} - -function ShowHide(obj,style){ - if(typeof(style) == 'undefined') - var style = 'inline'; - if(is_string(obj)) - obj = document.getElementById(obj); - if(!obj){ - throw 'ShowHide(): Object not foun.'; - return false; - } - - if(obj.style.display != 'none'){ - obj.style.display = 'none'; - return 0; - } - else{ - obj.style.display = style; - return 1; - } -return false; -} - -function switchElementsClass(obj,class1,class2){ - obj = $(obj); - if(!obj) return false; - - if(obj.className == class1){ - obj.className = class2; - return class2; - } - else{ - obj.className = class1; - return class1; - } -return false; -} - -function PopUp(url,width,height,form_name){ - if(!width) width = 600; - if(!height) height = 450; - if(!form_name) form_name = 'zbx_popup'; - - var left = (screen.width-(width+150))/2; - var top = (screen.height-(height+150))/2; - - var popup = window.open(url,form_name,'width=' + width +',height=' + height + ',top='+ top +',left='+ left + - ',resizable=yes,scrollbars=yes,location=no,menubar=no'); - - popup.focus(); - - return false; -} - -function CheckAll(form_name, chkMain, shkName){ - var frmForm = document.forms[form_name]; - var value = frmForm.elements[chkMain].checked; - for (var i=0; i < frmForm.length; i++){ - name = frmForm.elements[i].name.split('[')[0]; - if(frmForm.elements[i].type != 'checkbox') continue; - if(name == chkMain) continue; - if(shkName && shkName != name) continue; - if(frmForm.elements[i].disabled == true) continue; - frmForm.elements[i].checked = value; - } -} - - - -function openWinCentered(loc, winname, iwidth, iheight, params){ - tp=Math.ceil((screen.height-iheight)/2); - lf=Math.ceil((screen.width-iwidth)/2); - if (params.length > 0){ - params = ', ' + params; - } - - var WinObjReferer = window.open(loc,winname,"width="+iwidth+",height="+iheight+",top="+tp+",left="+lf+params); - WinObjReferer.focus(); -} - - -function addListener(element, eventname, expression, bubbling){ - bubbling = bubbling || false; - - if(window.addEventListener) { - element.addEventListener(eventname, expression, bubbling); - return true; - } - else if(window.attachEvent) { - element.attachEvent('on'+eventname, expression); - return true; - } - else return false; -} - -function cancelEvent(e){ - if (!e) var e = window.event; -//SDI(e); - if(e){ - if(IE){ - e.cancelBubble = true; - e.returnValue = false; - } - else{ - e.stopPropagation(); - e.preventDefault(); - } - } -return false; -} function deselectAll(){ if(IE){ @@ -389,6 +211,24 @@ function deselectAll(){ } } +function empty_form(id){ + id = $(id); + var count = 0; + + var inputs = id.getElementsByTagName('input'); + for(var i=0; i=0; i--){ - obj[i].src += "&width=" + (obj[i].parentNode.offsetWidth - obj[i].parentNode.offsetLeft - 10); + if(KQ){ + w = (w2 < w)?w2:w; + w-=16; + } + else{ + w = (w2 > w)?w2:w; } +return w; } -function insert_sizeable_graph(graph_id,url){ - if((typeof(ZBX_G_WIDTH) != 'undefined')) url += "&width="+ZBX_G_WIDTH; - document.write('graph
'); +function get_cursor_position(e){ + e = e || window.event; + var cursor = {x:0, y:0}; + if(e.pageX || e.pageY){ + cursor.x = e.pageX; + cursor.y = e.pageY; + } + else { + var de = document.documentElement; + var b = document.body; + cursor.x = e.clientX + + (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0); + cursor.y = e.clientY + + (de.scrollTop || b.scrollTop) - (de.clientTop || 0); + } + return cursor; +} + +function get_scroll_pos(){ + var scrOfX = 0, scrOfY = 0; +//Netscape compliant + if( typeof( window.pageYOffset ) == 'number' ){ + scrOfY = window.pageYOffset; + scrOfX = window.pageXOffset; + } +//DOM compliant + else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ){ + scrOfY = document.body.scrollTop; + scrOfX = document.body.scrollLeft; + } +//IE6 standards compliant mode + else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ){ + scrOfY = document.documentElement.scrollTop; + scrOfX = document.documentElement.scrollLeft; + } + return [ scrOfX, scrOfY ]; +} + + +function openWinCentered(loc, winname, iwidth, iheight, params){ + tp=Math.ceil((screen.height-iheight)/2); + lf=Math.ceil((screen.width-iwidth)/2); + if (params.length > 0){ + params = ', ' + params; + } + + var WinObjReferer = window.open(loc,winname,"width="+iwidth+",height="+iheight+",top="+tp+",left="+lf+params); + WinObjReferer.focus(); +} + +function PopUp(url,width,height,form_name){ + if(!width) width = 600; + if(!height) height = 450; + if(!form_name) form_name = 'zbx_popup'; + + var left = (screen.width-(width+150))/2; + var top = (screen.height-(height+150))/2; + + var popup = window.open(url,form_name,'width=' + width +',height=' + height + ',top='+ top +',left='+ left + + ',resizable=yes,scrollbars=yes,location=no,menubar=no'); + + popup.focus(); + + return false; +} + +function redirect(url) { + window.location = url; + return false; } function remove_childs(form_name,rmvbyname,tag){ @@ -552,69 +412,58 @@ function resizeiframe(id){ } } -function get_bodywidth(){ - var w = parseInt(document.body.scrollWidth); - var w2 = parseInt(document.body.offsetWidth); +function ShowHide(obj,style){ + if(typeof(style) == 'undefined') + var style = 'inline'; + if(is_string(obj)) + obj = document.getElementById(obj); + if(!obj){ + throw 'ShowHide(): Object not foun.'; + return false; + } - if(KQ){ - w = (w2 < w)?w2:w; - w-=16; + if(obj.style.display != 'none'){ + obj.style.display = 'none'; + return 0; } else{ - w = (w2 > w)?w2:w; + obj.style.display = style; + return 1; } -return w; +return false; } -function empty_form(id){ - id = $(id); - var count = 0; - - var inputs = id.getElementsByTagName('input'); - for(var i=0; i=0; i--){ + obj[i].src += "&width=" + (obj[i].parentNode.offsetWidth - obj[i].parentNode.offsetLeft - 10); } +} -return result; +function insert_sizeable_graph(graph_id,url){ + if((typeof(ZBX_G_WIDTH) != 'undefined')) url += "&width="+ZBX_G_WIDTH; + + document.write('graph
'); } \ No newline at end of file -- cgit