/** * eGroupWare - API * http://www.egroupware.org * * This file was originally created Tyamad, but their content is now completly removed! * It still contains some commonly used javascript functions, always included by EGroupware. * * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License * @package api * @subpackage jsapi * @version $Id$ */ /***********************************************\ * INITIALIZATION * \***********************************************/ if (document.all) { navigator.userAgent.toLowerCase().indexOf('msie 5') != -1 ? is_ie5 = true : is_ie5 = false; is_ie = true; is_moz1_6 = false; is_mozilla = false; is_ns4 = false; } else if (document.getElementById) { navigator.userAgent.toLowerCase().match('mozilla.*rv[:]1\.6.*gecko') ? is_moz1_6 = true : is_moz1_6 = false; is_ie = false; is_ie5 = false; is_mozilla = true; is_ns4 = false; } else if (document.layers) { is_ie = false; is_ie5 = false is_moz1_6 = false; is_mozilla = false; is_ns4 = true; } //console.log('is_ie='+is_ie+', is_ie5='+is_ie5+', is_mozilla='+is_mozilla+', is_moz1_6='+is_moz1_6+', is_ns4='+is_ns4); /** * Check whether the console object is defined - if not, define one */ if (typeof window.console == 'undefined') { window.console = { 'log': function() { }, 'warn': function() { }, 'error': function() { }, 'info': function() { } } } function egw_set_checkbox_multiselect_enabled(_id, _enabled) { //Retrieve the checkbox_multiselect base div var ms = document.getElementById('exec['+_id+']'); if (ms !== null) { //Set the background color var label_color = ""; if (_enabled) { ms.style.backgroundColor = "white"; label_color = "black"; } else { ms.style.backgroundColor = "#EEEEEE"; label_color = "gray" } //Enable/Disable all children input elements for (var i = 0; i = 1) && (ms.childNodes[i].childNodes[0].nodeName == 'INPUT')) { ms.childNodes[i].childNodes[0].disabled = !_enabled; ms.childNodes[i].childNodes[0].checked &= _enabled; } } } } } //works only correctly in Mozilla/FF and Konqueror function egw_openWindowCentered2(_url, _windowName, _width, _height, _status, _app, _returnID) { if (typeof(_app) == 'undefined') _app = false; if (typeof(_returnID) == 'undefined') _returnID = false; windowWidth = egw_getWindowOuterWidth(); windowHeight = egw_getWindowOuterHeight(); positionLeft = (windowWidth/2)-(_width/2)+egw_getWindowLeft(); positionTop = (windowHeight/2)-(_height/2)+egw_getWindowTop(); if (is_ie) _windowName = _windowName.replace(/[^a-z0-9_]+/,''); // IE fails, if name contains eg. a dash (-) windowID = window.open(_url, _windowName, "width=" + _width + ",height=" + _height + ",screenX=" + positionLeft + ",left=" + positionLeft + ",screenY=" + positionTop + ",top=" + positionTop + ",location=no,menubar=no,directories=no,toolbar=no,scrollbars=yes,resizable=yes,status="+_status); // returning something, replaces whole window in FF, if used in link as "javascript:egw_openWindowCentered2()" if (_returnID === false) { // return nothing } else { return windowID; } } function egw_openWindowCentered(_url, _windowName, _width, _height) { return egw_openWindowCentered2(_url, _windowName, _width, _height, 'no', false, true); } // return the left position of the window function egw_getWindowLeft() { // workaround for Fennec bug https://bugzilla.mozilla.org/show_bug.cgi?format=multiple&id=648250 window.(outerHeight|outerWidth|screenX|screenY) throw exception try { if(is_mozilla) return window.screenX; } catch (e) {} return window.screenLeft; } // return the left position of the window function egw_getWindowTop() { // workaround for Fennec bug https://bugzilla.mozilla.org/show_bug.cgi?format=multiple&id=648250 window.(outerHeight|outerWidth|screenX|screenY) throw exception try { if(is_mozilla) return window.screenY; } catch (e) {} return window.screenTop-90; } // get the outerWidth of the browser window. For IE we simply return the innerWidth function egw_getWindowInnerWidth() { if (is_mozilla) { return window.innerWidth; } else { // works only after the body has parsed //return document.body.offsetWidth; return document.body.clientWidth; //return document.documentElement.clientWidth; } } // get the outerHeight of the browser window. For IE we simply return the innerHeight function egw_getWindowInnerHeight() { if (is_mozilla) { return window.innerHeight; } else { // works only after the body has parsed //return document.body.offsetHeight; //return document.body.clientHeight; return document.documentElement.clientHeight; } } // get the outerWidth of the browser window. For IE we simply return the innerWidth function egw_getWindowOuterWidth() { // workaround for Fennec bug https://bugzilla.mozilla.org/show_bug.cgi?format=multiple&id=648250 window.(outerHeight|outerWidth|screenX|screenY) throw exception try { if (is_mozilla) return window.outerWidth; } catch (e) {} return egw_getWindowInnerWidth(); } // get the outerHeight of the browser window. For IE we simply return the innerHeight function egw_getWindowOuterHeight() { // workaround for Fennec bug https://bugzilla.mozilla.org/show_bug.cgi?format=multiple&id=648250 window.(outerHeight|outerWidth|screenX|screenY) throw exception try { if (is_mozilla) return window.outerHeight; } catch (e) {} return egw_getWindowInnerHeight(); } // ie selectbox dropdown menu hack. as ie is not able to resize dropdown menus from selectboxes, we // read the content of the dropdown menu and present it as popup resized for the user. if the user // clicks/seleckts a value, the selection is posted back to the origial selectbox function dropdown_menu_hack(el) { if(el.runtimeStyle) { if(typeof(enable_ie_dropdownmenuhack)!=='undefined') { if (enable_ie_dropdownmenuhack==1){} else return; } else { return; } if(el.runtimeStyle.behavior.toLowerCase()=="none"){return;} el.runtimeStyle.behavior="none"; if (el.multiple ==1) {return;} if (el.size > 1) {return;} var ie5 = (document.namespaces==null); el.ondblclick = function(e) { window.event.returnValue=false; return false; } if(window.createPopup==null) { var fid = "dropdown_menu_hack_" + Date.parse(new Date()); window.createPopup = function() { if(window.createPopup.frameWindow==null) { el.insertAdjacentHTML("MyFrame",""); var f = document.frames[fid]; f.document.open(); f.document.write(""); f.document.close(); f.fid = fid; var fwin = document.getElementById(fid); fwin.style.cssText="position:absolute;top:0;left:0;display:none;z-index:99999;"; f.show = function(px,py,pw,ph,baseElement) { py = py + baseElement.getBoundingClientRect().top + Math.max( document.body.scrollTop, document.documentElement.scrollTop) ; px = px + baseElement.getBoundingClientRect().left + Math.max( document.body.scrollLeft, document.documentElement.scrollLeft) ; fwin.style.width = pw + "px"; fwin.style.height = ph + "px"; fwin.style.posLeft =px ; fwin.style.posTop = py ; fwin.style.display="block"; } f_hide = function(e) { if(window.event && window.event.srcElement && window.event.srcElement.tagName && window.event.srcElement.tagName.toLowerCase()=="select"){return true;} fwin.style.display="none"; } f.hide = f_hide; document.attachEvent("onclick",f_hide); document.attachEvent("onkeydown",f_hide); } return f; } } function showMenu() { function selectMenu(obj) { var o = document.createElement("option"); o.value = obj.value; //alert("val"+o.value+', text:'+obj.innerHTML+'selected:'+obj.selectedIndex); o.text = obj.innerHTML; o.text = o.text.replace('',''); o.text = o.text.replace('',''); //if there is no value, you should not try to set the innerHTML, as it screws up the empty selection ... if (o.value != '') o.innerHTML = o.text; while(el.options.length>0){el.options[0].removeNode(true);} el.appendChild(o); el.title = o.innerHTML; el.contentIndex = obj.selectedIndex ; el.menu.hide(); if(el.onchange) { el.onchange(); } } el.menu.show(0 , el.offsetHeight , 10, 10, el); var mb = el.menu.document.body; mb.style.cssText ="border:solid 1px black;margin:0;padding:0;overflow-y:auto;overflow-x:auto;background:white;font:12px Tahoma, sans-serif;"; var t = el.contentHTML; //alert("1"+t); t = t.replace(/