dhtmlx=function(obj){ for (var a in obj) dhtmlx[a]=obj[a]; return dhtmlx; //simple singleton }; dhtmlx.extend_api=function(name,map,ext){ var t = window[name]; if (!t) return; //component not defined window[name]=function(obj){ if (obj && typeof obj == "object" && !obj.tagName){ var that = t.apply(this,(map._init?map._init(obj):arguments)); //global settings for (var a in dhtmlx) if (map[a]) this[map[a]](dhtmlx[a]); //local settings for (var a in obj){ if (map[a]) this[map[a]](obj[a]); else if (a.indexOf("on")==0){ this.attachEvent(a,obj[a]); } } } else var that = t.apply(this,arguments); if (map._patch) map._patch(this); return that||this; }; window[name].prototype=t.prototype; if (ext) dhtmlXHeir(window[name].prototype,ext); }; dhtmlxAjax={ get:function(url,callback){ var t=new dtmlXMLLoaderObject(true); t.async=(arguments.length<3); t.waitCall=callback; t.loadXML(url) return t; }, post:function(url,post,callback){ var t=new dtmlXMLLoaderObject(true); t.async=(arguments.length<4); t.waitCall=callback; t.loadXML(url,true,post) return t; }, getSync:function(url){ return this.get(url,null,true) }, postSync:function(url,post){ return this.post(url,post,null,true); } } /** * @desc: xmlLoader object * @type: private * @param: funcObject - xml parser function * @param: object - jsControl object * @param: async - sync/async mode (async by default) * @param: rSeed - enable/disable random seed ( prevent IE caching) * @topic: 0 */ function dtmlXMLLoaderObject(funcObject, dhtmlObject, async, rSeed){ this.xmlDoc=""; if (typeof (async) != "undefined") this.async=async; else this.async=true; this.onloadAction=funcObject||null; this.mainObject=dhtmlObject||null; this.waitCall=null; this.rSeed=rSeed||false; return this; }; /** * @desc: xml loading handler * @type: private * @param: dtmlObject - xmlLoader object * @topic: 0 */ dtmlXMLLoaderObject.prototype.waitLoadFunction=function(dhtmlObject){ var once = true; this.check=function (){ if ((dhtmlObject)&&(dhtmlObject.onloadAction != null)){ if ((!dhtmlObject.xmlDoc.readyState)||(dhtmlObject.xmlDoc.readyState == 4)){ if (!once) return; once=false; //IE 5 fix if (typeof dhtmlObject.onloadAction == "function") dhtmlObject.onloadAction(dhtmlObject.mainObject, null, null, null, dhtmlObject); if (dhtmlObject.waitCall){ dhtmlObject.waitCall.call(this,dhtmlObject); dhtmlObject.waitCall=null; } } } }; return this.check; }; /** * @desc: return XML top node * @param: tagName - top XML node tag name (not used in IE, required for Safari and Mozilla) * @type: private * @returns: top XML node * @topic: 0 */ dtmlXMLLoaderObject.prototype.getXMLTopNode=function(tagName, oldObj){ if (this.xmlDoc.responseXML){ var temp = this.xmlDoc.responseXML.getElementsByTagName(tagName); if(temp.length==0 && tagName.indexOf(":")!=-1) var temp = this.xmlDoc.responseXML.getElementsByTagName((tagName.split(":"))[1]); var z = temp[0]; } else var z = this.xmlDoc.documentElement; if (z){ this._retry=false; return z; } if ((_isIE)&&(!this._retry)){ //fall back to MS.XMLDOM var xmlString = this.xmlDoc.responseText; var oldObj = this.xmlDoc; this._retry=true; this.xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); this.xmlDoc.async=false; this.xmlDoc["loadXM"+"L"](xmlString); return this.getXMLTopNode(tagName, oldObj); } dhtmlxError.throwError("LoadXML", "Incorrect XML", [ (oldObj||this.xmlDoc), this.mainObject ]); return document.createElement("DIV"); }; /** * @desc: load XML from string * @type: private * @param: xmlString - xml string * @topic: 0 */ dtmlXMLLoaderObject.prototype.loadXMLString=function(xmlString){ { if (!_isIE){ var parser = new DOMParser(); this.xmlDoc=parser.parseFromString(xmlString, "text/xml"); } else { this.xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); this.xmlDoc.async=this.async; this.xmlDoc.onreadystatechange = function(){}; this.xmlDoc["loadXM"+"L"](xmlString); } } if (this.onloadAction) this.onloadAction(this.mainObject, null, null, null, this); if (this.waitCall){ this.waitCall(); this.waitCall=null; } } /** * @desc: load XML * @type: private * @param: filePath - xml file path * @param: postMode - send POST request * @param: postVars - list of vars for post request * @topic: 0 */ dtmlXMLLoaderObject.prototype.loadXML=function(filePath, postMode, postVars, rpc){ if (this.rSeed) filePath+=((filePath.indexOf("?") != -1) ? "&" : "?")+"a_dhx_rSeed="+(new Date()).valueOf(); this.filePath=filePath; if ((!_isIE)&&(window.XMLHttpRequest)) this.xmlDoc=new XMLHttpRequest(); else { this.xmlDoc=new ActiveXObject("Microsoft.XMLHTTP"); } if (this.async) this.xmlDoc.onreadystatechange=new this.waitLoadFunction(this); this.xmlDoc.open(postMode ? "POST" : "GET", filePath, this.async); if (rpc){ this.xmlDoc.setRequestHeader("User-Agent", "dhtmlxRPC v0.1 ("+navigator.userAgent+")"); this.xmlDoc.setRequestHeader("Content-type", "text/xml"); } else if (postMode) this.xmlDoc.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); this.xmlDoc.setRequestHeader("X-Requested-With","XMLHttpRequest"); this.xmlDoc.setRequestHeader("Access-Control-Allow-Origin", "*"); this.xmlDoc.setRequestHeader("Access-Control-Allow-Headers", "Content-Type"); this.xmlDoc.setRequestHeader("Access-Control-Allow-Methods", "*"); this.xmlDoc.send(null||postVars); if (!this.async) (new this.waitLoadFunction(this))(); }; /** * @desc: destructor, cleans used memory * @type: private * @topic: 0 */ dtmlXMLLoaderObject.prototype.destructor=function(){ this._filterXPath = null; this._getAllNamedChilds = null; this._retry = null; this.async = null; this.rSeed = null; this.filePath = null; this.onloadAction = null; this.mainObject = null; this.xmlDoc = null; this.doXPath = null; this.doXPathOpera = null; this.doXSLTransToObject = null; this.doXSLTransToString = null; this.loadXML = null; this.loadXMLString = null; // this.waitLoadFunction = null; this.doSerialization = null; this.xmlNodeToJSON = null; this.getXMLTopNode = null; this.setXSLParamValue = null; return null; } dtmlXMLLoaderObject.prototype.xmlNodeToJSON = function(node){ var t={}; for (var i=0; i-1) _isChrome=true; if ((navigator.userAgent.indexOf('Safari') != -1)||(navigator.userAgent.indexOf('Konqueror') != -1)){ var _KHTMLrv = parseFloat(navigator.userAgent.substr(navigator.userAgent.indexOf('Safari')+7, 5)); if (_KHTMLrv > 525){ //mimic FF behavior for Safari 3.1+ _isFF=true; var _FFrv = 1.9; } else _isKHTML=true; } else if (navigator.userAgent.indexOf('Opera') != -1){ _isOpera=true; _OperaRv=parseFloat(navigator.userAgent.substr(navigator.userAgent.indexOf('Opera')+6, 3)); } else if (navigator.appName.indexOf("Microsoft") != -1){ _isIE=true; if (navigator.appVersion.indexOf("MSIE 8.0")!= -1 && document.compatMode != "BackCompat") _isIE=8;if (navigator.appVersion.indexOf("MSIE 9.0")!= -1 && document.compatMode != "BackCompat") _isIE=8; if (navigator.appVersion.indexOf("MSIE 9.0")!= -1 && document.compatMode != "BackCompat") _isIE=8; } else { _isFF=true; var _FFrv = parseFloat(navigator.userAgent.split("rv:")[1]) } //multibrowser Xpath processor dtmlXMLLoaderObject.prototype.doXPath=function(xpathExp, docObj, namespace, result_type){ if (_isKHTML || (!_isIE && !window.XPathResult)) return this.doXPathOpera(xpathExp, docObj); if (_isIE){ //IE if (!docObj) if (!this.xmlDoc.nodeName) docObj=this.xmlDoc.responseXML else docObj=this.xmlDoc; if (!docObj) dhtmlxError.throwError("LoadXML", "Incorrect XML", [ (docObj||this.xmlDoc), this.mainObject ]); if (namespace != null) docObj.setProperty("SelectionNamespaces", "xmlns:xsl='"+namespace+"'"); // if (result_type == 'single'){ return docObj.selectSingleNode(xpathExp); } else { return docObj.selectNodes(xpathExp)||new Array(0); } } else { //Mozilla var nodeObj = docObj; if (!docObj){ if (!this.xmlDoc.nodeName){ docObj=this.xmlDoc.responseXML } else { docObj=this.xmlDoc; } } if (!docObj) dhtmlxError.throwError("LoadXML", "Incorrect XML", [ (docObj||this.xmlDoc), this.mainObject ]); if (docObj.nodeName.indexOf("document") != -1){ nodeObj=docObj; } else { nodeObj=docObj; docObj=docObj.ownerDocument; } var retType = XPathResult.ANY_TYPE; if (result_type == 'single') retType=XPathResult.FIRST_ORDERED_NODE_TYPE var rowsCol = new Array(); var col = docObj.evaluate(xpathExp, nodeObj, function(pref){ return namespace }, retType, null); if (retType == XPathResult.FIRST_ORDERED_NODE_TYPE){ return col.singleNodeValue; } var thisColMemb = col.iterateNext(); while (thisColMemb){ rowsCol[rowsCol.length]=thisColMemb; thisColMemb=col.iterateNext(); } return rowsCol; } } function _dhtmlxError(type, name, params){ if (!this.catches) this.catches=new Array(); return this; } _dhtmlxError.prototype.catchError=function(type, func_name){ this.catches[type]=func_name; } _dhtmlxError.prototype.throwError=function(type, name, params){ if (this.catches[type]) return this.catches[type](type, name, params); if (this.catches["ALL"]) return this.catches["ALL"](type, name, params); alert("Error type: "+arguments[0]+"\nDescription: "+arguments[1]); return null; } window.dhtmlxError=new _dhtmlxError(); //opera fake, while 9.0 not released //multibrowser Xpath processor dtmlXMLLoaderObject.prototype.doXPathOpera=function(xpathExp, docObj){ //this is fake for Opera var z = xpathExp.replace(/[\/]+/gi, "/").split('/'); var obj = null; var i = 1; if (!z.length) return []; if (z[0] == ".") obj=[docObj]; else if (z[0] == ""){ obj=(this.xmlDoc.responseXML||this.xmlDoc).getElementsByTagName(z[i].replace(/\[[^\]]*\]/g, "")); i++; } else return []; for (i; i < z.length; i++)obj=this._getAllNamedChilds(obj, z[i]); if (z[i-1].indexOf("[") != -1) obj=this._filterXPath(obj, z[i-1]); return obj; } dtmlXMLLoaderObject.prototype._filterXPath=function(a, b){ var c = new Array(); var b = b.replace(/[^\[]*\[\@/g, "").replace(/[\[\]\@]*/g, ""); for (var i = 0; i < a.length; i++) if (a[i].getAttribute(b)) c[c.length]=a[i]; return c; } dtmlXMLLoaderObject.prototype._getAllNamedChilds=function(a, b){ var c = new Array(); if (_isKHTML) b=b.toUpperCase(); for (var i = 0; i < a.length; i++)for (var j = 0; j < a[i].childNodes.length; j++){ if (_isKHTML){ if (a[i].childNodes[j].tagName&&a[i].childNodes[j].tagName.toUpperCase() == b) c[c.length]=a[i].childNodes[j]; } else if (a[i].childNodes[j].tagName == b) c[c.length]=a[i].childNodes[j]; } return c; } function dhtmlXHeir(a, b){ for (var c in b) if (typeof (b[c]) == "function") a[c]=b[c]; return a; } function dhtmlxEvent(el, event, handler){ if (el.addEventListener) el.addEventListener(event, handler, false); else if (el.attachEvent) el.attachEvent("on"+event, handler); } //============= XSL Extension =================================== dtmlXMLLoaderObject.prototype.xslDoc=null; dtmlXMLLoaderObject.prototype.setXSLParamValue=function(paramName, paramValue, xslDoc){ if (!xslDoc) xslDoc=this.xslDoc if (xslDoc.responseXML) xslDoc=xslDoc.responseXML; var item = this.doXPath("/xsl:stylesheet/xsl:variable[@name='"+paramName+"']", xslDoc, "http:/\/www.w3.org/1999/XSL/Transform", "single"); if (item != null) item.firstChild.nodeValue=paramValue } dtmlXMLLoaderObject.prototype.doXSLTransToObject=function(xslDoc, xmlDoc){ if (!xslDoc) xslDoc=this.xslDoc; if (xslDoc.responseXML) xslDoc=xslDoc.responseXML if (!xmlDoc) xmlDoc=this.xmlDoc; if (xmlDoc.responseXML) xmlDoc=xmlDoc.responseXML //MOzilla if (!_isIE){ if (!this.XSLProcessor){ this.XSLProcessor=new XSLTProcessor(); this.XSLProcessor.importStylesheet(xslDoc); } var result = this.XSLProcessor.transformToDocument(xmlDoc); } else { var result = new ActiveXObject("Msxml2.DOMDocument.3.0"); try{ xmlDoc.transformNodeToObject(xslDoc, result); }catch(e){ result = xmlDoc.transformNode(xslDoc); } } return result; } dtmlXMLLoaderObject.prototype.doXSLTransToString=function(xslDoc, xmlDoc){ var res = this.doXSLTransToObject(xslDoc, xmlDoc); if(typeof(res)=="string") return res; return this.doSerialization(res); } dtmlXMLLoaderObject.prototype.doSerialization=function(xmlDoc){ if (!xmlDoc) xmlDoc=this.xmlDoc; if (xmlDoc.responseXML) xmlDoc=xmlDoc.responseXML if (!_isIE){ var xmlSerializer = new XMLSerializer(); return xmlSerializer.serializeToString(xmlDoc); } else return xmlDoc.xml; } /** * @desc: * @type: private */ dhtmlxEventable=function(obj){ obj.attachEvent=function(name, catcher, callObj){ name='ev_'+name.toLowerCase(); if (!this[name]) this[name]=new this.eventCatcher(callObj||this); return(name+':'+this[name].addEvent(catcher)); //return ID (event name & event ID) } obj.callEvent=function(name, arg0){ name='ev_'+name.toLowerCase(); if (this[name]) return this[name].apply(this, arg0); return true; } obj.checkEvent=function(name){ return (!!this['ev_'+name.toLowerCase()]) } obj.eventCatcher=function(obj){ var dhx_catch = []; var z = function(){ var res = true; for (var i = 0; i < dhx_catch.length; i++){ if (dhx_catch[i] != null){ var zr = dhx_catch[i].apply(obj, arguments); res=res&&zr; } } return res; } z.addEvent=function(ev){ if (typeof (ev) != "function") ev=eval(ev); if (ev) return dhx_catch.push(ev)-1; return false; } z.removeEvent=function(id){ dhx_catch[id]=null; } return z; } obj.detachEvent=function(id){ if (id != false){ var list = id.split(':'); //get EventName and ID this[list[0]].removeEvent(list[1]); //remove event } } obj.detachAllEvents = function(){ for (var name in this){ if (name.indexOf("ev_")==0) delete this[name]; } } }