if (typeof(_cas) == "undefined") _cas = {}; // ======================= DOM PROTOTYPE ======================= if (typeof(_cas.DOM) == "undefined") _cas.DOM = {}; /** * Get element. * * @param {Object} elementOrId - element itself or it's id */ _cas.DOM.getElement = function(elementOrId){ var t = typeof(elementOrId); if (t == "undefined") return 0; else if (t == "string") { var re = document.getElementById(elementOrId); if (!re) return 0; else if (typeof(re.appendChild) != "undefined") return re; else return 0; } else if (typeof(elementOrId.appendChild) != "undefined") return elementOrId; else return 0; }; /** * Remove all children in given container. * @param {Object} element - element id or element itself */ _cas.DOM.removeChildren = function(element){ var element = _cas.DOM.getElement(element); while (element.firstChild) element.removeChild(element.firstChild); //while (element.hasChildNodes()) // element.removeChild(element.childNodes[0]); } /** * Set inner html or inner text or set child (removing others if exists) * * @param {Object} elementOrId * @param {Object} content object to be appended, inner HTML or inner text * @param {Object} isHTML */ _cas.DOM.setContent = function(elementOrId, content, isHTML){ //get element object var elt = _cas.DOM.getElement(elementOrId); _cas.DOM.removeChildren(elt); //set inner text/html/child var contentType = typeof(content); if (contentType == "string" && !isHTML) elt.appendChild(document.createTextNode(content)); else if (contentType == "string" && isHTML) elt.innerHTML = content; else if (contentType == "object") elt.appendChild(content); } /** * Hide element * * @param {Object} e - element id or element itself */ _cas.DOM.hideElement = function(e){ var element = _cas.DOM.getElement(e); element.style.display = 'none'; } /** * Show element * * @param {Object} e - element id or element itself */ _cas.DOM.showElement = function(e){ var element = _cas.DOM.getElement(e); element.style.display = 'block'; } /** * Get origin position of [given] event * @param {Object} event */ _cas.DOM.getEventPosition = function(event){ event = event || window.event; var cursor = { x: 0, y: 0 }; if (event.pageX || event.pageY) { cursor.x = event.pageX; cursor.y = event.pageY; } else { var de = document.documentElement; var b = document.body; cursor.x = event.clientX + (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0); cursor.y = event.clientY + (de.scrollTop || b.scrollTop) - (de.clientTop || 0); } return cursor; } // ======================= WINDOW ======================= if (typeof(_cas.window) == "undefined") _cas.window = {}; /** * Popup opener * * @param {Object} URL * @param {Object} id */ _cas.window.openWindow = function(URL, id){ /// popup opener date = new Date(); if (window[id]) { window[id].close(); } window[id] = window.open(URL, 'ID' + date.getTime(), 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=400,height=300'); window[id].focus(); } /** * Get window size */ _cas.window.getWindowSize = function(){ var wsize = { width: 900, height: 600 }; if (window.innerWidth) { wsize.width = window.innerWidth; wsize.height = window.innerHeight; } else if (document.documentElement.clientWidth) { wsize.width = document.documentElement.clientWidth; wsize.height = document.documentElement.clientHeight; } else if (document.body.clientWidth) { wsize.width = document.body.clientWidth; wsize.height = document.body.clientHeight; } return wsize; } _cas.window.getViewPort = function(){ var viewport = { x1: 0, y1: 0, x2: 0, y2: 0 }; if (window.pageXOffset || window.pageYOffset) { viewport.x1 = window.pageXOffset; viewport.y1 = window.pageYOffset; } else { var de = document.documentElement; var b = document.body; viewport.x1 = (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0); viewport.y1 = (de.scrollTop || b.scrollTop) - (de.clientTop || 0); } var wsize = _cas.window.getWindowSize(); viewport.x2 = viewport.x1 + wsize.width - 1; viewport.y2 = viewport.y1 + wsize.height - 1; // alert("(" + viewport.x1 + ", " + viewport.y1 + "), (" + viewport.x2 + ", " + viewport.y2 + ")"); return viewport; } /** * Resize & center window * * @param {Object} width * @param {Object} height */ _cas.window.resizeWindow = function(width, height){ /// resizing //XXX: id of body element is hardcoded here. This is suxx if (height) { winHeight = height } else { winHeight = document.getElementById('bodyArea').offsetHeight + 30 }; if (width) { winWidth = width } else { winWidth = document.getElementById('bodyArea').offsetWidth + 50 }; window.resizeTo(winWidth, winHeight); /// centering window.moveTo((screen.availWidth - winWidth) / 2, (screen.availHeight - winHeight) / 2); window.focus(); } // cannot combine reload_window(extra, go2top) from meetings.js and the one from timeline.js // they use their own variables inside // also cannot combine it with _cas.window.reloadWindow(anchorName) // because of internal variable filter_state // So, i leave it as it is // upd: // XXX: by the way, filter_state is not used anywhere (does not work) // so we can get rid of it... // ======================== COMMON ========================= if (typeof(_cas.common) == "undefined") _cas.common = {}; /** * System event notifier. Show given element and center it. * * @param {Object} elementOrId */ _cas.common.showSystemMessagBox = function(elementOrId) { var systemMessageBox = _cas.DOM.getElement(elementOrId); if (systemMessageBox) { window.setTimeout( function(){ _cas.common.doShowSystemMessagBox(systemMessageBox)}, 400); } } //helper for _cas.common.showSystemMessagBox. //We need it because IE scrolls window to desired anchor not immediately //so without this trick system message will not be scrolled. _cas.common.doShowSystemMessagBox = function(systemMessageBox) { _cas.DOM.showElement(systemMessageBox); var size = {x : systemMessageBox.offsetWidth, y : systemMessageBox.offsetHeight}; var viewPort = _cas.window.getViewPort(); systemMessageBox.style.left = (viewPort.x1 + viewPort.x2 - size.x)/2; systemMessageBox.style.top = (viewPort.y1 + viewPort.y2 - size.y)/2; }