/** * The functions for cross browser */ /** * Project Constructor */ //if browser type not in [IE, Firefox, Chrome, Safari, Opera] //if(s == null){ // isMozilla = true; //} /** * Attach event */ function attachObjEvent(object, eventName, functionName){ try { if (window.attachEvent) { object.attachEvent(eventName, functionName); } else if (window.addEventListener) { //remove "on" from eventName object.addEventListener(eventName.substr(2), functionName, false); } } catch (e) { showExcpt("CrossBrowser", e); } } /** * Detach event */ function detachObjEvent(object, eventName, functionNameofEvent){ try { if (window.detachEvent) { object.detachEvent(eventName, functionNameofEvent); } else if (window.removeEventListener) { object.removeEventListener(eventName.substr(2), functionNameofEvent, false) } } catch (e) { showExcpt("CrossBrowser", e); } } /** * to do the same thing as fireEvent method of IE in Mozilla, i.e onchange, * onblur etc. */ function fireObjEvent(object, eventName, isFireParent){ try { //CEV2-07-01-02 john.zhong 2013-11-20 S if(isSupportFireEventIE) { //Change the condition object.fireEvent(eventName); } else if(isMozilla||isIE11) { var eventObj = null; if(isIE11&&isFireParent){ eventObj = getOpener().document.createEvent("HTMLEvents"); }else{ eventObj = document.createEvent("HTMLEvents"); } eventObj.initEvent(eventName.substr(2), false, true); object.dispatchEvent(eventObj); } //CEV2-07-01-02 john.zhong 2013-11-20 E } catch (e) { showExcpt("CrossBrowser", e); } } /** * Operate selection for removing */ function rmSelectOption(selectObj, indexOfOption){ try { if (isMSIE) { selectObj.options.remove(indexOfOption); } else if (isMozilla) { selectObj.remove(indexOfOption); } } catch (e) { showExcpt("CrossBrowser", e); } } //GOUSE ON 25-03-2019 S function getEvtTarget(evt){ try { if ((isMozilla || isIE11)&& evt) { var obj = evt.target; } else if (isMSIE) { var obj = window.event.srcElement; } //var obj = window.event.srcElement; return obj; } catch (e) { showExcpt("CrossBrowser", e); } } //GOUSE ON 25-03-2019 e /** * Get event type */ function getEvtType(evt){ try { var sEventType = ""; if (evt) { sEventType = evt.type; } else if (window.event) { sEventType = window.event.type; } return sEventType; } catch (e) { showExcpt("CrossBrowser", e); } } /** * get keycode */ function getKeyCode(evt){ try { var nKeyCode = -1; evt = (evt) ? evt : ((event) ? event : null); if (evt) { nKeyCode = (evt.charCode) ? evt.charCode : evt.keyCode; } return nKeyCode; } catch (e) { showExcpt("CrossBrowser", e); } } function stopEvent(evt){ try { stopPropagation(evt); preventDefault(evt); } catch (e) { showExcpt("CrossBrowser", e); } } function stopPropagation(evt){ try { if (evt.stopPropagation) { evt.stopPropagation(); } else { evt.cancelBubble = true; } } catch (e) { showExcpt("CrossBrowser", e); } } function preventDefault(evt){ try { if (evt.preventDefault) { evt.preventDefault(); } else { evt.returnValue = false; } } catch (e) { showExcpt("CrossBrowser", e); } } /** * get previouse sibling * * @param object Node */ function getPreviousSibling(oElm){ try { if (oElm.parentNode.previousSibling.nodeType == 3) { return oElm.parentNode.previousSibling.previousSibling; } else { return oElm.parentNode.previousSibling; } } catch (e) { showExcpt("CrossBrowser", e); } } /** * get next sibling * * @param object Node */ function getNextSibling(oElm){ try { if (oElm.parentNode.nextSibling.nodeType == 3) { return oElm.parentNode.nextSibling.nextSibling; } else { return oElm.parentNode.nextSibling; } } catch (e) { showExcpt("CrossBrowser", e); } } //CEV2-DO john.zhong 2009-08-06 S function getFirstChildElement(parent){ try { var cNode; if (parent.nodeType == 1) { // if parent is a table object , // then both IE and Mozilla would have a first child called // TBODY, all of TR //elements is inside TBODY NOT TABLE, even // you didn't specify TBODY //explicitly in your screen. // this is to say, for table, we will only return TR objects as // its children // one more thing, like here, if we got a TR object of a table, // we want to get the parent TABLE object, we have to call like: // _trObject.parentNode.parentNode; if (parent.tagName == "TABLE") { var tBodyNodes = parent.tBodies; parent = tBodyNodes[0]; tBodyNodes = null; } var child = parent.firstChild; while (child) { if (child.nodeType == 1) { cNode = child; break; } child = child.nextSibling; } child = null; } try { return cNode; } finally { cNode = null; } } catch (E) { DisExcpt("CrossBrowser", E); } } function getElementText(ele){ try { if (ele.textContent) { return ele.textContent; }//for firefox else if (ele.text) { return ele.text; }//for ie return ""; } catch (E) { DisExcpt("CrossBrowser", E); } } function getNextSiblingElement(currentEle){ try { var next; if (currentEle) { if (isMSIE) { return currentEle.nextSibling; } else if (isMozilla) { next = currentEle.nextSibling; while (next) { if (next.nodeType == 1) break; next = next.nextSibling; } } } try { return next; } finally { next = null; } } catch (E) { DisExcpt("CrossBrowser", E); } } //CEV2-DO john.zhong 2009-08-06 E