Team:DTU-Denmark/dhtmlxcommon.js
From 2014.igem.org
/* Product Name: dhtmlxCalendar Version: 4.0.3 Edition: Standard License: content of this file is covered by GPL. Usage outside GPL terms is prohibited. To obtain Commercial or Enterprise license contact sales@dhtmlx.com Copyright UAB Dinamenta http://www.dhtmlx.com
- /
/* dhtmlx.com */
if (typeof(window.dhx4) == "undefined") {
window.dhx4 = {
version: "4.0.3",
skin: null, // allow to be set by user
skinDetect: function(comp) { var t = document.createElement("DIV"); t.className = comp+"_skin_detect"; if (document.body.firstChild) document.body.insertBefore(t, document.body.firstChild); else document.body.appendChild(t); var w = t.offsetWidth; t.parentNode.removeChild(t); t = null; return {10:"dhx_skyblue",20:"dhx_web",30:"dhx_terrace"}[w]||null; },
// id manager lastId: 1, newId: function() { return this.lastId++; },
// z-index manager zim: { data: {}, step: 5, first: function() { return 100; }, last: function() { var t = this.first(); for (var a in this.data) t = Math.max(t, this.data[a]); return t; }, reserve: function(id) { this.data[id] = this.last()+this.step; return this.data[id]; }, clear: function(id) { if (this.data[id] != null) { this.data[id] = null; delete this.data[id]; } } },
// string to boolean s2b: function(r) { return (r == true || r == 1 || r == "true" || r == "1" || r == "yes" || r == "y"); },
// trim trim: function(t) { return String(t).replace(/^\s{1,}/,"").replace(/\s{1,}$/,""); },
// template parsing template: function(tpl, data, trim) { // tpl - template text // data - object with key-value // trim - true/false, trim values return tpl.replace(/#([a-zA-Z0-9_-]{1,})#/g, function(t,k){ if (k.length > 0 && typeof(data[k]) != "undefined") { if (trim == true) return window.dhx4.trim(data[k]); return String(data[k]); } return ""; }); },
// absolute top/left position on screen absLeft: function(obj) { if (typeof(obj) == "string") obj = document.getElementById(obj); return this._aOfs(obj).left; }, absTop: function(obj) { if (typeof(obj) == "string") obj = document.getElementById(obj); return this._aOfs(obj).top; }, _aOfsSum: function(elem) { var top = 0, left = 0; while (elem) { top = top + parseInt(elem.offsetTop); left = left + parseInt(elem.offsetLeft); elem = elem.offsetParent; } return {top: top, left: left}; }, _aOfsRect: function(elem) { var box = elem.getBoundingClientRect(); var body = document.body; var docElem = document.documentElement; var scrollTop = window.pageYOffset || docElem.scrollTop || body.scrollTop; var scrollLeft = window.pageXOffset || docElem.scrollLeft || body.scrollLeft; var clientTop = docElem.clientTop || body.clientTop || 0; var clientLeft = docElem.clientLeft || body.clientLeft || 0; var top = box.top + scrollTop - clientTop; var left = box.left + scrollLeft - clientLeft; return { top: Math.round(top), left: Math.round(left) }; }, _aOfs: function(elem) { if (elem.getBoundingClientRect) { return this._aOfsRect(elem); } else { return this._aOfsSum(elem); } },
// copy obj _isObj: function(k) { return (k != null && typeof(k) == "object" && typeof(k.length) == "undefined"); }, _copyObj: function(r) { if (this._isObj(r)) { var t = {}; for (var a in r) { if (typeof(r[a]) == "object" && r[a] != null) t[a] = this._copyObj(r[a]); else t[a] = r[a]; } } else { var t = []; for (var a=0; a<r.length; a++) { if (typeof(r[a]) == "object" && r[a] != null) t[a] = this._copyObj(r[a]); else t[a] = r[a]; } } return t; },
// screen dim screenDim: function() { var isIE = (navigator.userAgent.indexOf("MSIE") >= 0); var dim = {}; dim.left = document.body.scrollLeft; dim.right = dim.left+(window.innerWidth||document.body.clientWidth); dim.top = Math.max((isIE?document.documentElement:document.getElementsByTagName("html")[0]).scrollTop, document.body.scrollTop); dim.bottom = dim.top+(isIE?Math.max(document.documentElement.clientHeight||0,document.documentElement.offsetHeight||0):window.innerHeight); return dim; },
// input/textarea range selection selectTextRange: function(inp, start, end) {
inp = (typeof(inp)=="string"?document.getElementById(inp):inp);
var len = inp.value.length; start = Math.max(Math.min(start, len), 0); end = Math.min(end, len);
if (inp.setSelectionRange) { try {inp.setSelectionRange(start, end);} catch(e){}; // combo in grid under IE requires try/catch } else if (inp.createTextRange) { var range = inp.createTextRange(); range.moveStart("character", start); range.moveEnd("character", end-len); try {range.select();} catch(e){}; } },
// transition transData: null, transDetect: function() {
if (this.transData == null) {
this.transData = {transProp: false, transEv: null};
// transition, MozTransition, WebkitTransition, msTransition, OTransition var k = { "MozTransition": "transitionend", "WebkitTransition": "webkitTransitionEnd", "OTransition": "oTransitionEnd", "msTransition": "transitionend", "transition": "transitionend" };
for (var a in k) { if (this.transData.transProp == false && document.documentElement.style[a] != null) { this.transData.transProp = a; this.transData.transEv = k[a]; } } k = null; }
return this.transData;
}
};
// browser window.dhx4.isIE = (navigator.userAgent.indexOf("MSIE") >= 0 || navigator.userAgent.indexOf("Trident") >= 0); window.dhx4.isIE6 = (window.XMLHttpRequest == null && navigator.userAgent.indexOf("MSIE") >= 0); window.dhx4.isIE7 = (navigator.userAgent.indexOf("MSIE 7.0") >= 0 && navigator.userAgent.indexOf("Trident") < 0); window.dhx4.isOpera = (navigator.userAgent.indexOf("Opera") >= 0); window.dhx4.isChrome = (navigator.userAgent.indexOf("Chrome") >= 0); window.dhx4.isKHTML = (navigator.userAgent.indexOf("Safari") >= 0 || navigator.userAgent.indexOf("Konqueror") >= 0); window.dhx4.isFF = (navigator.userAgent.indexOf("Firefox") >= 0); window.dhx4.isIPad = (navigator.userAgent.search(/iPad/gi) >= 0); };
if (typeof(window.dhx4.ajax) == "undefined") {
window.dhx4.ajax = {
// if false - dhxr param will added to prevent caching on client side (default), // if true - do not add extra params cache: false,
// default method for load/loadStruct, post/get allowed method: "post",
get: function(url, onLoad) { this._call("GET", url, null, true, onLoad); }, getSync: function(url) { return this._call("GET", url, null, false); }, post: function(url, postData, onLoad) { if (arguments.length == 1) { postData = ""; } else if (arguments.length == 2 && (typeof(postData) == "function" || typeof(window[postData]) == "function")) { onLoad = postData; postData = ""; } else { postData = String(postData); } this._call("POST", url, postData, true, onLoad); }, postSync: function(url, postData) { postData = (postData == null ? "" : String(postData)); return this._call("POST", url, postData, false); }, getLong: function(url, onLoad) { this._call("GET", url, null, true, onLoad, {url:url}); }, postLong: function(url, postData, onLoad) { if (arguments.length == 2 && (typeof(postData) == "function" || typeof(window[postData]))) { onLoad = postData; postData = ""; } this._call("POST", url, postData, true, onLoad, {url:url, postData:postData}); }, _call: function(method, url, postData, async, onLoad, longParams) {
var t = (window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP")); var isQt = (navigator.userAgent.match(/AppleWebKit/) != null && navigator.userAgent.match(/Qt/) != null && navigator.userAgent.match(/Safari/) != null);
if (async == true) { t.onreadystatechange = function() { if ((t.readyState == 4 && t.status == 200) || (isQt == true && t.readyState == 3)) { // what for long response and status 404? window.setTimeout(function(){ if (typeof(onLoad) == "function") { onLoad.apply(window, [{xmlDoc:t}]); // dhtmlx-compat, response.xmlDoc.responseXML/responseText } if (longParams != null) { if (typeof(longParams.postData) != "undefined") { dhx4.ajax.postLong(longParams.url, longParams.postData, onLoad); } else { dhx4.ajax.getLong(longParams.url, onLoad); } } onLoad = null; t = null; },1); } } }
if (method == "GET" && this.cache != true) { url += (url.indexOf("?")>=0?"&":"?")+"dhxr"+new Date().getTime(); }
t.open(method, url, async);
if (method == "POST") { t.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); if (this.cache != true) postData += (postData.length>0?"&":"")+"dhxr"+new Date().getTime(); } else { postData = null; }
t.setRequestHeader("X-Requested-With", "XMLHttpRequest");
t.send(postData);
if (!async) return {xmlDoc:t}; // dhtmlx-compat, response.xmlDoc.responseXML/responseText
} };
};
if (typeof(window.dhx4._enableDataLoading) == "undefined") {
window.dhx4._enableDataLoading = function(obj, initObj, xmlToJson, xmlRootTag, mode) {
if (mode == "clear") {
// clear attached functionality
for (var a in obj._dhxdataload) { obj._dhxdataload[a] = null; delete obj._dhxdataload[a]; };
obj._loadData = null; obj._dhxdataload = null; obj.load = null; obj.loadStruct = null;
obj = null;
return;
}
obj._dhxdataload = { // move to obj.conf? initObj: initObj, xmlToJson: xmlToJson, xmlRootTag: xmlRootTag, onBeforeXLS: null };
obj._loadData = function(data, loadParams, onLoad) {
if (arguments.length == 2) { onLoad = loadParams; loadParams = null; }
var obj = null;
// deprecated from 4.0, compatability with version (url, type[json|xml], onLoad) if (arguments.length == 3) onLoad = arguments[2];
if (typeof(data) == "string") {
var k = data.replace(/^\s{1,}/,"").replace(/\s{1,}$/,"");
var tag = new RegExp("^<"+this._dhxdataload.xmlRootTag);
// xml if (tag.test(k.replace(/^<\?xml[^\?]*\?>\s*/, ""))) { // remove leading <?xml ...?> if any, \n can be also presenе if (window.DOMParser) { // ff,ie9 obj = (new window.DOMParser()).parseFromString(data, "text/xml"); } else if (typeof(window.ActiveXObject) != "undefined") { obj = new window.ActiveXObject("Microsoft.XMLDOM"); obj.async = "false"; obj.loadXML(data); } if (obj != null) obj = this[this._dhxdataload.xmlToJson].apply(this, [obj]); // xml to json }
if (obj == null && (k.match(/^\{.*\}$/) != null || k.match(/^\[.*\]$/) != null)) { try { eval("dhx4.temp="+k); } catch(e) { dhx4.temp = null; } obj = dhx4.temp; dhx4.temp = null; }
if (obj == null) {
this.callEvent("onXLS",[]);
var params = [];
// allow to modify url and add params if (typeof(this._dhxdataload.onBeforeXLS) == "function") { var k = this._dhxdataload.onBeforeXLS.apply(this,[data]); if (k != null && typeof(k) == "object") { if (k.url != null) data = k.url; if (k.params != null) { for (var a in k.params) params.push(a+"="+encodeURIComponent(k.params[a])); } } }
var t = this; var callBack = function(r) {
var obj = null;
if ((r.xmlDoc.getResponseHeader("Content-Type")||"").search(/xml/gi) >= 0 || (r.xmlDoc.responseText.replace(/^\s{1,}/,"")).match(/^</) != null) { obj = t[t._dhxdataload.xmlToJson].apply(t,[r.xmlDoc.responseXML]); } else { try { eval("dhx4.temp="+r.xmlDoc.responseText); } catch(e){ dhx4.temp = null; }; obj = dhx4.temp; dhx4.temp = null; }
// init if (obj != null) t[t._dhxdataload.initObj].apply(t,[obj,data]); // data => url
t.callEvent("onXLE",[]);
if (onLoad != null) { if (typeof(onLoad) == "function") { onLoad.apply(t,[]); } else if (typeof(window[onLoad]) == "function") { window[onLoad].apply(t,[]); } }
callBack = onLoad = null; obj = r = t = null;
};
params = params.join("&")+(typeof(loadParams)=="string"?"&"+loadParams:"");
if (dhx4.ajax.method == "post") { dhx4.ajax.post(data, params, callBack); } else if (dhx4.ajax.method == "get") { dhx4.ajax.get(data+(data.indexOf("?")>0?"":"")+params, callBack); }
return; }
} else { if (typeof(data.documentElement) == "object" || (typeof(data.tagName) != "undefined" && typeof(data.getElementsByTagName) != "undefined" && data.getElementsByTagName(this._dhxdataload.xmlRootTag).length > 0)) { // xml obj = this[this._dhxdataload.xmlToJson].apply(this, [data]); } else { // json obj = window.dhx4._copyObj(data); }
}
// init if (obj != null) this[this._dhxdataload.initObj].apply(this,[obj]);
if (onLoad != null) { if (typeof(onLoad) == "function") { onLoad.apply(this, []); } else if (typeof(window[onLoad]) == "function") { window[onLoad].apply(this, []); } onLoad = null; }
};
// loadStruct for hdr/conf // load for data if (mode != null) { var k = {struct: "loadStruct", data: "load"}; for (var a in mode) { if (mode[a] == true) obj[k[a]] = function() {return this._loadData.apply(this, arguments);} } }
obj = null;
}; }; if (typeof(window.dhx4._eventable) == "undefined") {
window.dhx4._eventable = function(obj, mode) {
if (mode == "clear") {
obj.detachAllEvents();
obj.dhxevs = null;
obj.attachEvent = null; obj.detachEvent = null; obj.checkEvent = null; obj.callEvent = null; obj.detachAllEvents = null;
obj = null;
return;
}
obj.dhxevs = { data: {} };
obj.attachEvent = function(name, func) { name = String(name).toLowerCase(); if (!this.dhxevs.data[name]) this.dhxevs.data[name] = {}; var eventId = window.dhx4.newId(); this.dhxevs.data[name][eventId] = func; return eventId; }
obj.detachEvent = function(eventId) { for (var a in this.dhxevs.data) { var k = 0; for (var b in this.dhxevs.data[a]) { if (b == eventId) { this.dhxevs.data[a][b] = null; delete this.dhxevs.data[a][b]; } else { k++; } } if (k == 0) { this.dhxevs.data[a] = null; delete this.dhxevs.data[a]; } } }
obj.checkEvent = function(name) { name = String(name).toLowerCase(); return (this.dhxevs.data[name] != null); }
obj.callEvent = function(name, params) { name = String(name).toLowerCase(); if (this.dhxevs.data[name] == null) return true; var r = true; for (var a in this.dhxevs.data[name]) { r = this.dhxevs.data[name][a].apply(this, params) && r; } return r; }
obj.detachAllEvents = function() { for (var a in this.dhxevs.data) { for (var b in this.dhxevs.data[a]) { this.dhxevs.data[a][b] = null; delete this.dhxevs.data[a][b]; } this.dhxevs.data[a] = null; delete this.dhxevs.data[a]; } }
obj = null; };
}; 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; };
dtmlXMLLoaderObject.count = 0;
/**
* @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 dtmlXMLLoaderObject.count++; 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 (typeof this.xmlDoc.status == "undefined" || this.xmlDoc.status < 400){ 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 (!this._retry&&_isIE){ this._retry=true; var oldObj = this.xmlDoc; this.loadXMLString(this.xmlDoc.responseText.replace(/^[\s]+/,""), true); 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, silent){
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 (silent) return;
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', (this.contenttype || 'application/x-www-form-urlencoded'));
this.xmlDoc.setRequestHeader("X-Requested-With","XMLHttpRequest"); 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<node.attributes.length; i++) t[node.attributes[i].name]=node.attributes[i].value; t["_tagvalue"]=node.firstChild?node.firstChild.nodeValue:""; for (var i=0; i<node.childNodes.length; i++){ var name=node.childNodes[i].tagName; if (name){ if (!t[name]) t[name]=[]; t[name].push(this.xmlNodeToJSON(node.childNodes[i])); } } return t; }
/**
* @desc: Call wrapper * @type: private * @param: funcObject - action handler * @param: dhtmlObject - user data * @returns: function handler * @topic: 0 */
function callerFunction(funcObject, dhtmlObject){ this.handler=function(e){ if (!e) e=window.event; funcObject(e, dhtmlObject); return true; }; return this.handler; };
/**
* @desc: Calculate absolute position of html object * @type: private * @param: htmlObject - html object * @topic: 0 */
function getAbsoluteLeft(htmlObject){ return getOffset(htmlObject).left; } /**
* @desc: Calculate absolute position of html object * @type: private * @param: htmlObject - html object * @topic: 0 */
function getAbsoluteTop(htmlObject){ return getOffset(htmlObject).top; }
function getOffsetSum(elem) { var top=0, left=0; while(elem) { top = top + parseInt(elem.offsetTop); left = left + parseInt(elem.offsetLeft); elem = elem.offsetParent; } return {top: top, left: left}; } function getOffsetRect(elem) { var box = elem.getBoundingClientRect(); var body = document.body; var docElem = document.documentElement; var scrollTop = window.pageYOffset || docElem.scrollTop || body.scrollTop; var scrollLeft = window.pageXOffset || docElem.scrollLeft || body.scrollLeft; var clientTop = docElem.clientTop || body.clientTop || 0; var clientLeft = docElem.clientLeft || body.clientLeft || 0; var top = box.top + scrollTop - clientTop; var left = box.left + scrollLeft - clientLeft; return { top: Math.round(top), left: Math.round(left) }; } function getOffset(elem) { if (elem.getBoundingClientRect) { return getOffsetRect(elem); } else { return getOffsetSum(elem); } }
/**
- @desc: Convert string to it boolean representation
- @type: private
- @param: inputString - string for covertion
- @topic: 0
- /
function convertStringToBoolean(inputString){ if (typeof (inputString) == "string") inputString=inputString.toLowerCase();
switch (inputString){ case "1": case "true": case "yes": case "y": case 1: case true: return true; break;
default: return false; } }
/**
- @desc: find out what symbol to use as url param delimiters in further params
- @type: private
- @param: str - current url string
- @topic: 0
- /
function getUrlSymbol(str){ if (str.indexOf("?") != -1) return "&" else return "?" }
function dhtmlDragAndDropObject(){ if (window.dhtmlDragAndDrop) return window.dhtmlDragAndDrop;
this.lastLanding=0; this.dragNode=0; this.dragStartNode=0; this.dragStartObject=0; this.tempDOMU=null; this.tempDOMM=null; this.waitDrag=0; window.dhtmlDragAndDrop=this;
return this; };
dhtmlDragAndDropObject.prototype.removeDraggableItem=function(htmlNode){ htmlNode.onmousedown=null; htmlNode.dragStarter=null; htmlNode.dragLanding=null; } dhtmlDragAndDropObject.prototype.addDraggableItem=function(htmlNode, dhtmlObject){ htmlNode.onmousedown=this.preCreateDragCopy; htmlNode.dragStarter=dhtmlObject; this.addDragLanding(htmlNode, dhtmlObject); } dhtmlDragAndDropObject.prototype.addDragLanding=function(htmlNode, dhtmlObject){ htmlNode.dragLanding=dhtmlObject; } dhtmlDragAndDropObject.prototype.preCreateDragCopy=function(e){ if ((e||window.event) && (e||event).button == 2) return;
if (window.dhtmlDragAndDrop.waitDrag){ window.dhtmlDragAndDrop.waitDrag=0; document.body.onmouseup=window.dhtmlDragAndDrop.tempDOMU; document.body.onmousemove=window.dhtmlDragAndDrop.tempDOMM; return false; }
if (window.dhtmlDragAndDrop.dragNode) window.dhtmlDragAndDrop.stopDrag(e);
window.dhtmlDragAndDrop.waitDrag=1; window.dhtmlDragAndDrop.tempDOMU=document.body.onmouseup; window.dhtmlDragAndDrop.tempDOMM=document.body.onmousemove; window.dhtmlDragAndDrop.dragStartNode=this; window.dhtmlDragAndDrop.dragStartObject=this.dragStarter; document.body.onmouseup=window.dhtmlDragAndDrop.preCreateDragCopy; document.body.onmousemove=window.dhtmlDragAndDrop.callDrag; window.dhtmlDragAndDrop.downtime = new Date().valueOf();
if ((e)&&(e.preventDefault)){
e.preventDefault();
return false;
}
return false;
};
dhtmlDragAndDropObject.prototype.callDrag=function(e){
if (!e)
e=window.event;
dragger=window.dhtmlDragAndDrop;
if ((new Date()).valueOf()-dragger.downtime<100) return;
//if ((e.button == 0)&&(_isIE)) // return dragger.stopDrag();
if (!dragger.dragNode){ if (dragger.waitDrag){ dragger.dragNode=dragger.dragStartObject._createDragNode(dragger.dragStartNode, e);
if (!dragger.dragNode) return dragger.stopDrag();
dragger.dragNode.onselectstart=function(){return false;} dragger.gldragNode=dragger.dragNode; document.body.appendChild(dragger.dragNode); document.body.onmouseup=dragger.stopDrag; dragger.waitDrag=0; dragger.dragNode.pWindow=window; dragger.initFrameRoute(); } else return dragger.stopDrag(e, true); }
if (dragger.dragNode.parentNode != window.document.body && dragger.gldragNode){ var grd = dragger.gldragNode;
if (dragger.gldragNode.old) grd=dragger.gldragNode.old;
//if (!document.all) dragger.calculateFramePosition(); grd.parentNode.removeChild(grd); var oldBody = dragger.dragNode.pWindow;
if (grd.pWindow && grd.pWindow.dhtmlDragAndDrop.lastLanding) grd.pWindow.dhtmlDragAndDrop.lastLanding.dragLanding._dragOut(grd.pWindow.dhtmlDragAndDrop.lastLanding);
// var oldp=dragger.dragNode.parentObject; if (_isIE){ var div = document.createElement("Div"); div.innerHTML=dragger.dragNode.outerHTML; dragger.dragNode=div.childNodes[0]; } else dragger.dragNode=dragger.dragNode.cloneNode(true);
dragger.dragNode.pWindow=window; // dragger.dragNode.parentObject=oldp;
dragger.gldragNode.old=dragger.dragNode; document.body.appendChild(dragger.dragNode); oldBody.dhtmlDragAndDrop.dragNode=dragger.dragNode; }
dragger.dragNode.style.left=e.clientX+15+(dragger.fx ? dragger.fx*(-1) : 0) +(document.body.scrollLeft||document.documentElement.scrollLeft)+"px"; dragger.dragNode.style.top=e.clientY+3+(dragger.fy ? dragger.fy*(-1) : 0) +(document.body.scrollTop||document.documentElement.scrollTop)+"px";
if (!e.srcElement) var z = e.target; else z=e.srcElement; dragger.checkLanding(z, e); }
dhtmlDragAndDropObject.prototype.calculateFramePosition=function(n){ //this.fx = 0, this.fy = 0; if (window.name){ var el = parent.frames[window.name].frameElement.offsetParent; var fx = 0; var fy = 0;
while (el){ fx+=el.offsetLeft; fy+=el.offsetTop; el=el.offsetParent; }
if ((parent.dhtmlDragAndDrop)){ var ls = parent.dhtmlDragAndDrop.calculateFramePosition(1); fx+=ls.split('_')[0]*1; fy+=ls.split('_')[1]*1; }
if (n) return fx+"_"+fy; else this.fx=fx; this.fy=fy; } return "0_0"; } dhtmlDragAndDropObject.prototype.checkLanding=function(htmlObject, e){ if ((htmlObject)&&(htmlObject.dragLanding)){ if (this.lastLanding) this.lastLanding.dragLanding._dragOut(this.lastLanding); this.lastLanding=htmlObject; this.lastLanding=this.lastLanding.dragLanding._dragIn(this.lastLanding, this.dragStartNode, e.clientX, e.clientY, e); this.lastLanding_scr=(_isIE ? e.srcElement : e.target); } else { if ((htmlObject)&&(htmlObject.tagName != "BODY")) this.checkLanding(htmlObject.parentNode, e); else { if (this.lastLanding) this.lastLanding.dragLanding._dragOut(this.lastLanding, e.clientX, e.clientY, e); this.lastLanding=0;
if (this._onNotFound) this._onNotFound(); } } } dhtmlDragAndDropObject.prototype.stopDrag=function(e, mode){ dragger=window.dhtmlDragAndDrop;
if (!mode){ dragger.stopFrameRoute(); var temp = dragger.lastLanding; dragger.lastLanding=null;
if (temp) temp.dragLanding._drag(dragger.dragStartNode, dragger.dragStartObject, temp, (_isIE ? event.srcElement : e.target)); } dragger.lastLanding=null;
if ((dragger.dragNode)&&(dragger.dragNode.parentNode == document.body)) dragger.dragNode.parentNode.removeChild(dragger.dragNode); dragger.dragNode=0; dragger.gldragNode=0; dragger.fx=0; dragger.fy=0; dragger.dragStartNode=0; dragger.dragStartObject=0; document.body.onmouseup=dragger.tempDOMU; document.body.onmousemove=dragger.tempDOMM; dragger.tempDOMU=null; dragger.tempDOMM=null; dragger.waitDrag=0; }
dhtmlDragAndDropObject.prototype.stopFrameRoute=function(win){ if (win) window.dhtmlDragAndDrop.stopDrag(1, 1);
for (var i = 0; i < window.frames.length; i++){ try{ if ((window.frames[i] != win)&&(window.frames[i].dhtmlDragAndDrop)) window.frames[i].dhtmlDragAndDrop.stopFrameRoute(window); } catch(e){} }
try{ if ((parent.dhtmlDragAndDrop)&&(parent != window)&&(parent != win)) parent.dhtmlDragAndDrop.stopFrameRoute(window); } catch(e){} } dhtmlDragAndDropObject.prototype.initFrameRoute=function(win, mode){ if (win){ window.dhtmlDragAndDrop.preCreateDragCopy(); window.dhtmlDragAndDrop.dragStartNode=win.dhtmlDragAndDrop.dragStartNode; window.dhtmlDragAndDrop.dragStartObject=win.dhtmlDragAndDrop.dragStartObject; window.dhtmlDragAndDrop.dragNode=win.dhtmlDragAndDrop.dragNode; window.dhtmlDragAndDrop.gldragNode=win.dhtmlDragAndDrop.dragNode; window.document.body.onmouseup=window.dhtmlDragAndDrop.stopDrag; window.waitDrag=0;
if (((!_isIE)&&(mode))&&((!_isFF)||(_FFrv < 1.8))) window.dhtmlDragAndDrop.calculateFramePosition(); } try{ if ((parent.dhtmlDragAndDrop)&&(parent != window)&&(parent != win)) parent.dhtmlDragAndDrop.initFrameRoute(window); }catch(e){}
for (var i = 0; i < window.frames.length; i++){ try{ if ((window.frames[i] != win)&&(window.frames[i].dhtmlDragAndDrop)) window.frames[i].dhtmlDragAndDrop.initFrameRoute(window, ((!win||mode) ? 1 : 0)); } catch(e){} } }
_isFF = false; _isIE = false; _isOpera = false; _isKHTML = false; _isMacOS = false; _isChrome = false; _FFrv = false; _KHTMLrv = false; _OperaRv = false;
if (navigator.userAgent.indexOf('Macintosh') != -1) _isMacOS=true;
if (navigator.userAgent.toLowerCase().indexOf('chrome')>-1)
_isChrome=true;
if ((navigator.userAgent.indexOf('Safari') != -1)||(navigator.userAgent.indexOf('Konqueror') != -1)){ _KHTMLrv = parseFloat(navigator.userAgent.substr(navigator.userAgent.indexOf('Safari')+7, 5));
if (_KHTMLrv > 525){ //mimic FF behavior for Safari 3.1+ _isFF=true; _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 ||
navigator.appVersion.indexOf("MSIE 9.0")!= -1 ||
navigator.appVersion.indexOf("MSIE 10.0")!= -1 ||
document.documentMode > 7) &&
document.compatMode != "BackCompat"){
_isIE=8;
}
} else if (navigator.appName == 'Netscape' && navigator.userAgent.indexOf("Trident") != -1){
//ie11
_isIE=8;
} else {
_isFF=true;
_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){ this.detachEvent(name); this[name] = null; } } } obj = null; };