dhtmlxcommon.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. /*
  2. * Copyright DHTMLX LTD. http://www.dhtmlx.com You allowed to use this component
  3. * or parts of it under GPL terms To use it on other terms or get Professional
  4. * edition of the component please contact us at sales@dhtmlx.com
  5. */
  6. function dtmlXMLLoaderObject(funcObject, dhtmlObject, async, rSeed) {
  7. this.xmlDoc = "";
  8. if (typeof(async) != "undefined")
  9. this.async = async;
  10. else
  11. this.async = true;
  12. this.onloadAction = funcObject || null;
  13. this.mainObject = dhtmlObject || null;
  14. this.waitCall = null;
  15. this.rSeed = rSeed || false;
  16. return this
  17. };
  18. dtmlXMLLoaderObject.prototype.waitLoadFunction = function(dhtmlObject) {
  19. var once = true;
  20. this.check = function() {
  21. if ((dhtmlObject) && (dhtmlObject.onloadAction != null)) {
  22. if ((!dhtmlObject.xmlDoc.readyState)
  23. || (dhtmlObject.xmlDoc.readyState == 4)) {
  24. if (!once)
  25. return;
  26. once = false;
  27. dhtmlObject.onloadAction(dhtmlObject.mainObject, null, null,
  28. null, dhtmlObject);
  29. if (dhtmlObject.waitCall) {
  30. dhtmlObject.waitCall();
  31. dhtmlObject.waitCall = null
  32. }
  33. }
  34. }
  35. };
  36. return this.check
  37. };
  38. dtmlXMLLoaderObject.prototype.getXMLTopNode = function(tagName, oldObj) {
  39. if (this.xmlDoc.responseXML) {
  40. var temp = this.xmlDoc.responseXML.getElementsByTagName(tagName);
  41. var z = temp[0]
  42. } else
  43. var z = this.xmlDoc.documentElement;
  44. if (z) {
  45. this._retry = false;
  46. return z
  47. };
  48. if ((_isIE) && (!this._retry)) {
  49. var xmlString = this.xmlDoc.responseText;
  50. var oldObj = this.xmlDoc;
  51. this._retry = true;
  52. this.xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
  53. this.xmlDoc.async = false;
  54. this.xmlDoc["loadXM" + "L"](xmlString);
  55. return this.getXMLTopNode(tagName, oldObj)
  56. };
  57. dhtmlxError.throwError("LoadXML", "Incorrect XML", [
  58. (oldObj || this.xmlDoc), this.mainObject]);
  59. return document.createElement("DIV")
  60. };
  61. dtmlXMLLoaderObject.prototype.loadXMLString = function(xmlString) {
  62. if (_isKHTML) {
  63. var z = document.createElement('div');
  64. z.innerHTML = xmlString;
  65. this.xmlDoc = z;
  66. z.responseXML = z
  67. } else {
  68. try {
  69. var parser = new DOMParser();
  70. this.xmlDoc = parser.parseFromString(xmlString, "text/xml")
  71. } catch (e) {
  72. this.xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
  73. this.xmlDoc.async = this.async;
  74. this.xmlDoc["loadXM" + "L"](xmlString)
  75. }
  76. };
  77. this.onloadAction(this.mainObject, null, null, null, this);
  78. if (this.waitCall) {
  79. this.waitCall();
  80. this.waitCall = null
  81. }
  82. };
  83. dtmlXMLLoaderObject.prototype.loadXML = function(filePath, postMode, postVars,
  84. rpc) {
  85. if (this.rSeed)
  86. filePath += ((filePath.indexOf("?") != -1) ? "&" : "?")
  87. + "a_dhx_rSeed=" + (allGetServerTime()).valueOf();
  88. this.filePath = filePath;
  89. if ((!_isIE) && (window.XMLHttpRequest))
  90. this.xmlDoc = new XMLHttpRequest();
  91. else {
  92. if (document.implementation && document.implementation.createDocument) {
  93. this.xmlDoc = document.implementation.createDocument("", "", null);
  94. this.xmlDoc.onload = new this.waitLoadFunction(this);
  95. this.xmlDoc.load(filePath);
  96. return
  97. } else
  98. this.xmlDoc = new ActiveXObject("Microsoft.XMLHTTP")
  99. };
  100. this.xmlDoc.open(postMode ? "POST" : "GET", filePath, this.async);
  101. if (rpc) {
  102. this.xmlDoc.setRequestHeader("User-Agent", "dhtmlxRPC v0.1 ("
  103. + navigator.userAgent + ")");
  104. this.xmlDoc.setRequestHeader("Content-type", "text/xml")
  105. } else if (postMode)
  106. this.xmlDoc.setRequestHeader('Content-type',
  107. 'application/x-www-form-urlencoded');
  108. this.xmlDoc.onreadystatechange = new this.waitLoadFunction(this);
  109. this.xmlDoc.send(null || postVars)
  110. };
  111. dtmlXMLLoaderObject.prototype.destructor = function() {
  112. this.onloadAction = null;
  113. this.mainObject = null;
  114. this.xmlDoc = null;
  115. return null
  116. };
  117. function callerFunction(funcObject, dhtmlObject) {
  118. this.handler = function(e) {
  119. if (!e)
  120. e = window.event;
  121. funcObject(e, dhtmlObject);
  122. return true
  123. };
  124. return this.handler
  125. };
  126. function getAbsoluteLeft(htmlObject) {
  127. var xPos = htmlObject.offsetLeft;
  128. var temp = htmlObject.offsetParent;
  129. while (temp != null) {
  130. xPos += temp.offsetLeft;
  131. temp = temp.offsetParent
  132. };
  133. return xPos
  134. };
  135. function getAbsoluteTop(htmlObject) {
  136. var yPos = htmlObject.offsetTop;
  137. var temp = htmlObject.offsetParent;
  138. while (temp != null) {
  139. yPos += temp.offsetTop;
  140. temp = temp.offsetParent
  141. };
  142. return yPos
  143. };
  144. function convertStringToBoolean(inputString) {
  145. if (typeof(inputString) == "string")
  146. inputString = inputString.toLowerCase();
  147. switch (inputString) {
  148. case "1" :
  149. case "true" :
  150. case "yes" :
  151. case "y" :
  152. case 1 :
  153. case true :
  154. return true;
  155. break;
  156. default :
  157. return false
  158. }
  159. };
  160. function getUrlSymbol(str) {
  161. if (str.indexOf("?") != -1)
  162. return "&"
  163. else
  164. return "?"
  165. };
  166. function dhtmlDragAndDropObject() {
  167. if (window.dhtmlDragAndDrop)
  168. return window.dhtmlDragAndDrop;
  169. this.lastLanding = 0;
  170. this.dragNode = 0;
  171. this.dragStartNode = 0;
  172. this.dragStartObject = 0;
  173. this.tempDOMU = null;
  174. this.tempDOMM = null;
  175. this.waitDrag = 0;
  176. window.dhtmlDragAndDrop = this;
  177. return this
  178. };
  179. dhtmlDragAndDropObject.prototype.removeDraggableItem = function(htmlNode) {
  180. htmlNode.onmousedown = null;
  181. htmlNode.dragStarter = null;
  182. htmlNode.dragLanding = null
  183. };
  184. dhtmlDragAndDropObject.prototype.addDraggableItem = function(htmlNode,
  185. dhtmlObject) {
  186. htmlNode.onmousedown = this.preCreateDragCopy;
  187. htmlNode.dragStarter = dhtmlObject;
  188. this.addDragLanding(htmlNode, dhtmlObject)
  189. };
  190. dhtmlDragAndDropObject.prototype.addDragLanding = function(htmlNode,
  191. dhtmlObject) {
  192. htmlNode.dragLanding = dhtmlObject
  193. };
  194. dhtmlDragAndDropObject.prototype.preCreateDragCopy = function(e) {
  195. if (window.dhtmlDragAndDrop.waitDrag) {
  196. window.dhtmlDragAndDrop.waitDrag = 0;
  197. document.body.onmouseup = window.dhtmlDragAndDrop.tempDOMU;
  198. document.body.onmousemove = window.dhtmlDragAndDrop.tempDOMM;
  199. return false
  200. };
  201. window.dhtmlDragAndDrop.waitDrag = 1;
  202. window.dhtmlDragAndDrop.tempDOMU = document.body.onmouseup;
  203. window.dhtmlDragAndDrop.tempDOMM = document.body.onmousemove;
  204. window.dhtmlDragAndDrop.dragStartNode = this;
  205. window.dhtmlDragAndDrop.dragStartObject = this.dragStarter;
  206. document.body.onmouseup = window.dhtmlDragAndDrop.preCreateDragCopy;
  207. document.body.onmousemove = window.dhtmlDragAndDrop.callDrag;
  208. if ((e) && (e.preventDefault)) {
  209. e.preventDefault();
  210. return false
  211. };
  212. return false
  213. };
  214. dhtmlDragAndDropObject.prototype.callDrag = function(e) {
  215. if (!e)
  216. e = window.event;
  217. dragger = window.dhtmlDragAndDrop;
  218. if ((e.button == 0) && (_isIE))
  219. return dragger.stopDrag();
  220. if (!dragger.dragNode) {
  221. dragger.dragNode = dragger.dragStartObject._createDragNode(
  222. dragger.dragStartNode, e);
  223. if (!dragger.dragNode)
  224. return dragger.stopDrag();
  225. dragger.gldragNode = dragger.dragNode;
  226. document.body.appendChild(dragger.dragNode);
  227. document.body.onmouseup = dragger.stopDrag;
  228. dragger.waitDrag = 0;
  229. dragger.dragNode.pWindow = window;
  230. dragger.initFrameRoute()
  231. };
  232. if (dragger.dragNode.parentNode != window.document.body) {
  233. var grd = dragger.gldragNode;
  234. if (dragger.gldragNode.old)
  235. grd = dragger.gldragNode.old;
  236. grd.parentNode.removeChild(grd);
  237. var oldBody = dragger.dragNode.pWindow;
  238. if (_isIE) {
  239. var div = document.createElement("Div");
  240. div.innerHTML = dragger.dragNode.outerHTML;
  241. dragger.dragNode = div.childNodes[0]
  242. } else
  243. dragger.dragNode = dragger.dragNode.cloneNode(true);
  244. dragger.dragNode.pWindow = window;
  245. dragger.gldragNode.old = dragger.dragNode;
  246. document.body.appendChild(dragger.dragNode);
  247. oldBody.dhtmlDragAndDrop.dragNode = dragger.dragNode
  248. };
  249. dragger.dragNode.style.left = e.clientX + 15
  250. + (dragger.fx ? dragger.fx * (-1) : 0)
  251. + (document.body.scrollLeft || document.documentElement.scrollLeft)
  252. + "px";
  253. dragger.dragNode.style.top = e.clientY + 3
  254. + (dragger.fy ? dragger.fy * (-1) : 0)
  255. + (document.body.scrollTop || document.documentElement.scrollTop)
  256. + "px";
  257. if (!e.srcElement)
  258. var z = e.target;
  259. else
  260. z = e.srcElement;
  261. dragger.checkLanding(z, e)
  262. };
  263. dhtmlDragAndDropObject.prototype.calculateFramePosition = function(n) {
  264. if (window.name) {
  265. var el = parent.frames[window.name].frameElement.offsetParent;
  266. var fx = 0;
  267. var fy = 0;
  268. while (el) {
  269. fx += el.offsetLeft;
  270. fy += el.offsetTop;
  271. el = el.offsetParent
  272. };
  273. if ((parent.dhtmlDragAndDrop)) {
  274. var ls = parent.dhtmlDragAndDrop.calculateFramePosition(1);
  275. fx += ls.split('_')[0] * 1;
  276. fy += ls.split('_')[1] * 1
  277. };
  278. if (n)
  279. return fx + "_" + fy;
  280. else
  281. this.fx = fx;
  282. this.fy = fy
  283. };
  284. return "0_0"
  285. };
  286. dhtmlDragAndDropObject.prototype.checkLanding = function(htmlObject, e) {
  287. if ((htmlObject) && (htmlObject.dragLanding)) {
  288. if (this.lastLanding)
  289. this.lastLanding.dragLanding._dragOut(this.lastLanding);
  290. this.lastLanding = htmlObject;
  291. this.lastLanding = this.lastLanding.dragLanding._dragIn(
  292. this.lastLanding, this.dragStartNode, e.clientX, e.clientY, e);
  293. this.lastLanding_scr = (_isIE ? e.srcElement : e.target)
  294. } else {
  295. if ((htmlObject) && (htmlObject.tagName != "BODY"))
  296. this.checkLanding(htmlObject.parentNode, e);
  297. else {
  298. if (this.lastLanding)
  299. this.lastLanding.dragLanding._dragOut(this.lastLanding,
  300. e.clientX, e.clientY, e);
  301. this.lastLanding = 0;
  302. if (this._onNotFound)
  303. this._onNotFound()
  304. }
  305. }
  306. };
  307. dhtmlDragAndDropObject.prototype.stopDrag = function(e, mode) {
  308. dragger = window.dhtmlDragAndDrop;
  309. if (!mode) {
  310. dragger.stopFrameRoute();
  311. var temp = dragger.lastLanding;
  312. dragger.lastLanding = null;
  313. if (temp)
  314. temp.dragLanding._drag(dragger.dragStartNode,
  315. dragger.dragStartObject, temp, (_isIE
  316. ? event.srcElement
  317. : e.target))
  318. };
  319. dragger.lastLanding = null;
  320. if ((dragger.dragNode) && (dragger.dragNode.parentNode == document.body))
  321. dragger.dragNode.parentNode.removeChild(dragger.dragNode);
  322. dragger.dragNode = 0;
  323. dragger.gldragNode = 0;
  324. dragger.fx = 0;
  325. dragger.fy = 0;
  326. dragger.dragStartNode = 0;
  327. dragger.dragStartObject = 0;
  328. document.body.onmouseup = dragger.tempDOMU;
  329. document.body.onmousemove = dragger.tempDOMM;
  330. dragger.tempDOMU = null;
  331. dragger.tempDOMM = null;
  332. dragger.waitDrag = 0
  333. };
  334. dhtmlDragAndDropObject.prototype.stopFrameRoute = function(win) {
  335. if (win)
  336. window.dhtmlDragAndDrop.stopDrag(1, 1);
  337. for (var i = 0; i < window.frames.length; i++)
  338. if ((window.frames[i] != win) && (window.frames[i].dhtmlDragAndDrop))
  339. window.frames[i].dhtmlDragAndDrop.stopFrameRoute(window);
  340. if ((parent.dhtmlDragAndDrop) && (parent != window) && (parent != win))
  341. parent.dhtmlDragAndDrop.stopFrameRoute(window)
  342. };
  343. dhtmlDragAndDropObject.prototype.initFrameRoute = function(win, mode) {
  344. if (win) {
  345. window.dhtmlDragAndDrop.preCreateDragCopy();
  346. window.dhtmlDragAndDrop.dragStartNode = win.dhtmlDragAndDrop.dragStartNode;
  347. window.dhtmlDragAndDrop.dragStartObject = win.dhtmlDragAndDrop.dragStartObject;
  348. window.dhtmlDragAndDrop.dragNode = win.dhtmlDragAndDrop.dragNode;
  349. window.dhtmlDragAndDrop.gldragNode = win.dhtmlDragAndDrop.dragNode;
  350. window.document.body.onmouseup = window.dhtmlDragAndDrop.stopDrag;
  351. window.waitDrag = 0;
  352. if (((!_isIE) && (mode)) && ((!_isFF) || (_FFrv < 1.8)))
  353. window.dhtmlDragAndDrop.calculateFramePosition()
  354. };
  355. if ((parent.dhtmlDragAndDrop) && (parent != window) && (parent != win))
  356. parent.dhtmlDragAndDrop.initFrameRoute(window);
  357. for (var i = 0; i < window.frames.length; i++)
  358. if ((window.frames[i] != win) && (window.frames[i].dhtmlDragAndDrop))
  359. window.frames[i].dhtmlDragAndDrop.initFrameRoute(window,
  360. ((!win || mode) ? 1 : 0))
  361. };
  362. var _isFF = false;
  363. var _isIE = false;
  364. var _isOpera = false;
  365. var _isKHTML = false;
  366. var _isMacOS = false;
  367. if (navigator.userAgent.indexOf('Macintosh') != -1)
  368. _isMacOS = true;
  369. if ((navigator.userAgent.indexOf('Safari') != -1)
  370. || (navigator.userAgent.indexOf('Konqueror') != -1))
  371. _isKHTML = true;
  372. else if (navigator.userAgent.indexOf('Opera') != -1) {
  373. _isOpera = true;
  374. _OperaRv = parseFloat(navigator.userAgent.substr(navigator.userAgent
  375. .indexOf('Opera')
  376. + 6, 3))
  377. } else if (navigator.appName.indexOf("Microsoft") != -1)
  378. _isIE = true;
  379. else {
  380. _isFF = true;
  381. var _FFrv = parseFloat(navigator.userAgent.split("rv:")[1])
  382. };
  383. function isIE() {
  384. if (navigator.appName.indexOf("Microsoft") != -1)
  385. if (navigator.userAgent.indexOf('Opera') == -1)
  386. return true;
  387. return false
  388. };
  389. dtmlXMLLoaderObject.prototype.doXPath = function(xpathExp, docObj) {
  390. if ((_isOpera) || (_isKHTML))
  391. return this.doXPathOpera(xpathExp, docObj);
  392. if (_isIE) {
  393. if (!docObj)
  394. if (!this.xmlDoc.nodeName)
  395. docObj = this.xmlDoc.responseXML
  396. else
  397. docObj = this.xmlDoc;
  398. return docObj.selectNodes(xpathExp)
  399. } else {
  400. var nodeObj = docObj;
  401. if (!docObj) {
  402. if (!this.xmlDoc.nodeName) {
  403. docObj = this.xmlDoc.responseXML
  404. } else {
  405. docObj = this.xmlDoc
  406. }
  407. };
  408. if (docObj.nodeName.indexOf("document") != -1) {
  409. nodeObj = docObj
  410. } else {
  411. nodeObj = docObj;
  412. docObj = docObj.ownerDocument
  413. };
  414. var rowsCol = new Array();
  415. var col = docObj.evaluate(xpathExp, nodeObj, null,
  416. XPathResult.ANY_TYPE, null);
  417. var thisColMemb = col.iterateNext();
  418. while (thisColMemb) {
  419. rowsCol[rowsCol.length] = thisColMemb;
  420. thisColMemb = col.iterateNext()
  421. };
  422. return rowsCol
  423. }
  424. };
  425. function _dhtmlxError(type, name, params) {
  426. if (!this.catches)
  427. this.catches = new Array();
  428. return this
  429. };
  430. _dhtmlxError.prototype.catchError = function(type, func_name) {
  431. this.catches[type] = func_name
  432. };
  433. _dhtmlxError.prototype.throwError = function(type, name, params) {
  434. if (this.catches[type])
  435. return this.catches[type](type, name, params);
  436. if (this.catches["ALL"])
  437. return this.catches["ALL"](type, name, params);
  438. alert("Error type: " + arguments[0] + "\nDescription: " + arguments[1]);
  439. return null
  440. };
  441. window.dhtmlxError = new _dhtmlxError();
  442. dtmlXMLLoaderObject.prototype.doXPathOpera = function(xpathExp, docObj) {
  443. var z = xpathExp.replace(/[\/]+/gi, "/").split('/');
  444. var obj = null;
  445. var i = 1;
  446. if (!z.length)
  447. return [];
  448. if (z[0] == ".")
  449. obj = [docObj];
  450. else if (z[0] == "") {
  451. obj = this.xmlDoc.responseXML.getElementsByTagName(z[i].replace(
  452. /\[[^\]]*\]/g, ""));
  453. i++
  454. } else
  455. return [];
  456. for (i; i < z.length; i++)
  457. obj = this._getAllNamedChilds(obj, z[i]);
  458. if (z[i - 1].indexOf("[") != -1)
  459. obj = this._filterXPath(obj, z[i - 1]);
  460. return obj
  461. };
  462. dtmlXMLLoaderObject.prototype._filterXPath = function(a, b) {
  463. var c = new Array();
  464. var b = b.replace(/[^\[]*\[\@/g, "").replace(/[\[\]\@]*/g, "");
  465. for (var i = 0; i < a.length; i++)
  466. if (a[i].getAttribute(b))
  467. c[c.length] = a[i];
  468. return c
  469. };
  470. dtmlXMLLoaderObject.prototype._getAllNamedChilds = function(a, b) {
  471. var c = new Array();
  472. if (_isKHTML)
  473. b = b.toUpperCase();
  474. for (var i = 0; i < a.length; i++)
  475. for (var j = 0; j < a[i].childNodes.length; j++) {
  476. if (_isKHTML) {
  477. if (a[i].childNodes[j].tagName
  478. && a[i].childNodes[j].tagName.toUpperCase() == b)
  479. c[c.length] = a[i].childNodes[j]
  480. } else if (a[i].childNodes[j].tagName == b)
  481. c[c.length] = a[i].childNodes[j]
  482. };
  483. return c
  484. };
  485. function dhtmlXHeir(a, b) {
  486. for (c in b)
  487. if (typeof(b[c]) == "function")
  488. a[c] = b[c];
  489. return a
  490. };
  491. function dhtmlxEvent(el, event, handler) {
  492. if (el.addEventListener)
  493. el.addEventListener(event, handler, false);
  494. else if (el.attachEvent)
  495. el.attachEvent("on" + event, handler)
  496. };
  497. /*
  498. * Copyright DHTMLX LTD. http://www.dhtmlx.com You allowed to use this component
  499. * or parts of it under GPL terms To use it on other terms or get Professional
  500. * edition of the component please contact us at sales@dhtmlx.com
  501. */