CList.js 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085
  1. /********************************************************************************************************************************
  2. * Licensed Materials - Property of IBM *
  3. * *
  4. * IBM Cognos Products: AGS *
  5. * *
  6. * (C) Copyright IBM Corp. 2005, 2008 *
  7. * *
  8. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. *
  9. *********************************************************************************************************************************/
  10. function CList (sId, bAllowDuplicates, sStyle,oUiStyle) {
  11. this.m_sId = sId;
  12. this.m_bAllowDuplicates = bAllowDuplicates;
  13. this.childCount = 0;
  14. this.m_oUiStyle = oUiStyle;
  15. this.m_bDisabled = false;
  16. this.m_fOnContextMenu = null;
  17. this.m_fSingleClickFunc = null;
  18. this.m_fDoubleClickFunc = null;
  19. this.m_fDragStartFunc = null;
  20. this.m_fDragFunc = null;
  21. this.m_fDragEndFunc = null;
  22. this.m_fDragEnterFunc = null;
  23. this.m_fDragLeaveFunc = null;
  24. this.m_fDragOverFunc = null;
  25. this.m_fOnDropFunc = null;
  26. this.m_fEqualityFunc = null;
  27. this.listElement = document.createElement("ul");
  28. this.listElement.listObject = this;
  29. this.listElement.getParentListObject = function() {return this.listObject};
  30. this.listElement.style.cursor = 'default';
  31. this.listElement.setAttribute("id", sId);
  32. if (sStyle && sStyle != 'undefined')
  33. this.listElement.className = sStyle;
  34. }
  35. function CList_getListElement() {
  36. return this.listElement;
  37. }
  38. function CList_getId() {
  39. return this.m_sId;
  40. }
  41. function CList_size() {
  42. return this.childCount;
  43. }
  44. function CList_setDisabled(val) {
  45. this.m_bDisabled = val;
  46. }
  47. function CList_isDisabled() {
  48. return this.m_bDisabled;
  49. }
  50. function CList_setDblClickFunc(val) {
  51. this.m_fDoubleClickFunc = val;
  52. }
  53. function CList_setSingleClickFunc(val) {
  54. this.m_fSingleClickFunc = val;
  55. }
  56. function CList_setContextMenuClickFunc(val) {
  57. this.m_fOnContextMenu = val;
  58. }
  59. function CList_setDragStartFunc(val) {
  60. this.m_fDragStartFunc = val;
  61. }
  62. function CList_setDragFunc(val) {
  63. this.m_fDragFunc = val;
  64. }
  65. function CList_setDragEndFunc(val) {
  66. this.m_fDragEndFunc = val;
  67. }
  68. function CList_setDragEnterFunc(val) {
  69. this.m_fDragEnterFunc = val;
  70. }
  71. function CList_setDragLeaveFunc(val) {
  72. this.m_fDragLeaveFunc = val;
  73. }
  74. function CList_setDragOverFunc(val) {
  75. this.m_fDragOverFunc = val;
  76. }
  77. function CList_setOnDropFunc(val) {
  78. this.m_fOnDropFunc = val;
  79. }
  80. function CList_setEqualityFunc(val) {
  81. this.m_fEqualityFunc = val;
  82. }
  83. function CList_getDblClickFunc() {
  84. return this.m_fDoubleClickFunc;
  85. }
  86. function CList_getSingleClickFunc() {
  87. return this.m_fSingleClickFunc;
  88. }
  89. function CList_getContextMenuClickFunc() {
  90. return this.m_fOnContextMenu;
  91. }
  92. function CList_getDragStartFunc() {
  93. return this.m_fDragStartFunc;
  94. }
  95. function CList_getDragFunc() {
  96. return this.m_fDragFunc;
  97. }
  98. function CList_getDragEndFunc() {
  99. return this.m_fDragEndFunc;
  100. }
  101. function CList_getDragEnterFunc() {
  102. return this.m_fDragEnterFunc;
  103. }
  104. function CList_getDragLeaveFunc() {
  105. return this.m_fDragLeaveFunc;
  106. }
  107. function CList_getDragOverFunc() {
  108. return this.m_fDragOverFunc;
  109. }
  110. function CList_getOnDropFunc() {
  111. return this.m_fOnDropFunc;
  112. }
  113. function CList_getEqualityFunc() {
  114. return this.m_fEqualityFunc;
  115. }
  116. function CList_getStyle() {
  117. return this.m_oUiStyle;
  118. }
  119. function CList_setStyle(style) {
  120. this.m_oUiStyle = style;
  121. }
  122. function CList_onmouseOver() {
  123. CList_doMouseOver(this);
  124. }
  125. function CList_doMouseOver(object) {
  126. if (object && object.getParentListObject().isDisabled()) {
  127. return;
  128. }
  129. if (typeof object.getParentListObject().getStyle() == "object") {
  130. object.className = object.getParentListObject().getStyle().getRolloverState();
  131. }
  132. var ul = object.getParentListObject().getListElement();
  133. ul.overId = object.id;
  134. }
  135. function CList_onmouseOut() {
  136. CList_doMouseOut(this);
  137. }
  138. function CList_doMouseOut(object) {
  139. if (object && object.getParentListObject().isDisabled()) {
  140. return;
  141. }
  142. if (typeof object.getParentListObject().getStyle() == "object") {
  143. object.className = object.getParentListObject().getStyle().getNormalState();
  144. }
  145. var ul = object.getParentListObject().getListElement();
  146. ul.overId = "";
  147. }
  148. function CList_doClick(event,object) {
  149. if (object && object.getParentListObject().isDisabled()) {
  150. return;
  151. }
  152. if (event.ctrlKey) {
  153. CList_ctrlClicked(object);
  154. } else if (event.shiftKey) {
  155. CList_shiftClicked(object);
  156. } else {
  157. CList_clicked(object);
  158. }
  159. }
  160. function CList_clicked(object) {
  161. var parent = object.getParentListObject();
  162. var ul = parent.getListElement();
  163. ul.selectedId = object.id;
  164. if (object.isSelected && parent.getSelectedNodes().length < 2) {
  165. parent.deSelectAll();
  166. } else {
  167. parent.deSelectAll();
  168. parent.selectNodeList(object);
  169. }
  170. }
  171. function CList_shiftClicked(object) {
  172. var parent = object.getParentListObject();
  173. parent.deSelectAll();
  174. var ul = parent.getListElement();
  175. var startIndex = parent.indexById(ul.selectedId);
  176. var endIndex = parent.indexById(object.id);
  177. if (startIndex >= endIndex) {
  178. endIndex = startIndex;
  179. startIndex = parent.indexById(object.id);
  180. }
  181. parent.selectRange(startIndex,endIndex);
  182. }
  183. function CList_ctrlClicked(object) {
  184. var parent = object.getParentListObject();
  185. var ul = parent.getListElement();
  186. ul.selectedId = object.id;
  187. if (object.isSelected) {
  188. parent.deSelectNodeList(object);
  189. } else {
  190. parent.selectNodeList(object);
  191. }
  192. }
  193. function CList_selectRange(start,end) {
  194. var ul = this.getListElement();
  195. for (var i = start; i <= end; ++i) {
  196. var li = ul.childNodes[i];
  197. if (li && li.tagName == 'LI') {
  198. this.selectNodeList(li);
  199. }
  200. }
  201. }
  202. function CList_selectNodeList(object) {
  203. object.onclick = CList_singleClickCaller;
  204. if (typeof this.getStyle() == "object") {
  205. object.className = this.getStyle().getDepressedState();
  206. }
  207. object.onmouseover = null;
  208. object.onmouseout = null;
  209. object.isSelected = true;
  210. }
  211. function CList_deSelectNodeList(object) {
  212. if (typeof this.getStyle() == "object") {
  213. object.className = this.getStyle().getNormalState();
  214. }
  215. object.onmouseover = CList_onmouseOver;
  216. object.onmouseout = CList_onmouseOut;
  217. object.isSelected = false;
  218. }
  219. function CList_deSelectAll () {
  220. var ul = this.getListElement();
  221. for (var i = 0; i < ul.childNodes.length; ++i) {
  222. var li = ul.childNodes[i];
  223. if (li && li.tagName == 'LI') {
  224. this.deSelectNodeList(li);
  225. }
  226. }
  227. }
  228. function CList_getAllItems() {
  229. return this.item(0, this.childCount);
  230. }
  231. function CList_getAllNodes() {
  232. var result = new Array();
  233. var ul = this.getListElement();
  234. for (var i = 0; i < ul.childNodes.length; ++i) {
  235. var li = ul.childNodes[i];
  236. if (li && li.tagName == 'LI') {
  237. result.push(li);
  238. }
  239. }
  240. return result;
  241. }
  242. function CList_getAllSelectedItems () {
  243. var result = new Array();
  244. var ul = this.getListElement();
  245. for (var i = 0; i < ul.childNodes.length; ++i) {
  246. var li = ul.childNodes[i];
  247. if (li && li.tagName == 'LI' && li.isSelected) {
  248. //Should ever be only one here from our side
  249. //of the border at least. This is the node
  250. //The user has given for us to insert.
  251. result.push(li.childNodes.item(0));
  252. }
  253. }
  254. return result;
  255. }
  256. function CList_getNodeByIndex (idx) {
  257. var ul = this.getListElement();
  258. if (ul.childNodes.length > 0) {
  259. return ul.childNodes[idx];
  260. }
  261. return null;
  262. }
  263. function CList_getNodeByProperty(value, property) {
  264. var result = new Array();
  265. var ul = this.getListElement();
  266. for (var i = 0; i < ul.childNodes.length; ++i) {
  267. var li = this.getNodeByIndex(i);
  268. if (li && li.tagName == 'LI' && li[property] == value) {
  269. result.push(li);
  270. }
  271. }
  272. return result;
  273. }
  274. function CList_getNodeById(id) {
  275. //only one with this id
  276. var nodeArray = this.getNodeByProperty(id, 'id')
  277. if (nodeArray.length == 1) {
  278. return nodeArray[0];
  279. }
  280. return null;
  281. }
  282. function CList_getSelectedNodes () {
  283. return this.getNodeByProperty(true,'isSelected');
  284. /*
  285. var result = new Array();
  286. var ul = this.getListElement();
  287. for (var i = 0; i < ul.childNodes.length; ++i) {
  288. var li = ul.childNodes[i];
  289. if (li && li.tagName == 'LI' && li.isSelected) {
  290. result.push(li);
  291. }
  292. }
  293. return result;
  294. */
  295. }
  296. function CList_containsItem(value) {
  297. if (this.getEqualityFunc() != null) {
  298. var equalFunc = this.getEqualityFunc();
  299. return equalFunc(this,value);
  300. }
  301. return false;
  302. }
  303. function CList_item(start,end) {
  304. var ul = this.getListElement();
  305. if (start && !end || end == 'undefined') {
  306. //Return the actual node inside the LI
  307. return ul.childNodes[start].childNodes.item(0);
  308. }
  309. var result = new Array();
  310. for (var i = start; i <= end; ++i) {
  311. var li = ul.childNodes[i];
  312. if (li && li.tagName == 'LI') {
  313. result.push(li.childNodes.item(0));
  314. }
  315. }
  316. return result;
  317. }
  318. function CList_add(node,index,existingId) {
  319. if (!this.m_bAllowDuplicates && this.getEqualityFunc() != null && this.containsItem(node)) {
  320. //We should not allow duplicates and we have an equality check functions and item
  321. //exists.
  322. return false;
  323. }
  324. var el = this.getListElement();
  325. var referenceNode =null;
  326. if (index && index != 'undefined') {
  327. referenceNode = el.childNodes[index];
  328. } else if (el.overId && el.overId != "") {
  329. referenceNode = this.getNodeById(el.overId);
  330. } else if (this.getSelectedNodes().length == 1) {
  331. referenceNode = this.getSelectedNodes()[0];
  332. }
  333. var insertNode = CList_createNode(this,existingId);
  334. insertNode.appendChild(node);
  335. if (referenceNode) {
  336. el.insertBefore(insertNode,referenceNode);
  337. } else {
  338. el.appendChild(insertNode);
  339. }
  340. insertNode.style.height="16px";
  341. this.deSelectAll();
  342. this.selectNodeList(insertNode);
  343. return true;
  344. }
  345. function CList_removeSelected() {
  346. var selectedNodes = this.getSelectedNodes();
  347. var ul = this.getListElement();
  348. for (var i=0; i < selectedNodes.length;i++) {
  349. ul.removeChild(selectedNodes[i]);
  350. --this.childCount;
  351. }
  352. }
  353. function CList_remove(index) {
  354. if (!index || index == 'undefined') {
  355. index = 0;
  356. }
  357. var ul = this.getListElement();
  358. if (ul && ul.hasChildNodes && ul.removeChild) {
  359. var node = ul.childNodes[index]
  360. ul.removeChild(node);
  361. }
  362. --this.childCount;
  363. }
  364. function CList_removeAllNodes() {
  365. var rootNode = this.getListElement();
  366. if (rootNode && rootNode.hasChildNodes && rootNode.removeChild) {
  367. while (rootNode.hasChildNodes()) {
  368. rootNode.removeChild(rootNode.firstChild);
  369. }
  370. }
  371. this.childCount = 0;
  372. }
  373. function CList_createNode(parent,existingId) {
  374. var li = document.createElement('li');
  375. CList_disableAllEvents(li);
  376. li.onmouseover = CList_onmouseOver;
  377. li.onmouseout = CList_onmouseOut;
  378. li.onclick = CList_singleClickCaller;
  379. li.ondblclick = CList_doubleClickCaller;
  380. li.oncontextmenu = CList_contextMenuCaller;
  381. li.ondragstart = CList_dragStartCaller;
  382. li.ondrag = CList_dragCaller;
  383. li.ondragend = CList_dragEndCaller;
  384. li.ondragenter = CList_dragEnterCaller;
  385. li.ondragleave = CList_dragLeaveCaller;
  386. li.ondragover = CList_dragOverCaller;
  387. li.ondrop = CList_OnDropCaller;
  388. ++parent.childCount;
  389. if (existingId == undefined) {
  390. li.setAttribute('id',parent.getId() + parent.childCount);
  391. }
  392. else {
  393. li.setAttribute('id',existingId);
  394. }
  395. li.listObject = parent;
  396. li.getParentListObject = function() {return this.listObject};
  397. return li;
  398. }
  399. function CList_indexById(id) {
  400. if (!id || id == 'undefined') {
  401. return;
  402. }
  403. var result = 0;
  404. var ul = this.getListElement();
  405. for (var i = 0; i < ul.childNodes.length; ++i) {
  406. var li = ul.childNodes[i];
  407. if (li && li.tagName == 'LI' && id == li.id) {
  408. result = i;
  409. break;
  410. }
  411. }
  412. return result;
  413. }
  414. function CList_contextMenuCaller(evt)
  415. {
  416. //get the event in a cross-browser fashion
  417. evt = (evt) ? evt : ((event) ? event : null);
  418. //cancel any text selection
  419. CList_clearSelection();
  420. //prevent the event from bubbling to other elements
  421. CList_cancelBub(evt);
  422. var rootNode = this.getParentListObject();
  423. if (rootNode.getContextMenuClickFunc() != null && !rootNode.isDisabled())
  424. {
  425. var contextMenuFunc = rootNode.getContextMenuClickFunc();
  426. contextMenuFunc(evt);
  427. CList_cancelBub(evt);
  428. if (!document.all)
  429. {
  430. evt.preventDefault();
  431. }
  432. return false;
  433. }
  434. }
  435. function CList_singleClickCaller(evt)
  436. {
  437. if (this.parentNode.listObject.isDisabled()) {
  438. return;
  439. }
  440. //get the event in a cross-browser fashion
  441. evt = (evt) ? evt : ((event) ? event : null);
  442. if ((evt.keyCode != null) && (evt.keyCode != 13) && (evt.keyCode != 0))
  443. {
  444. return false;
  445. }
  446. //cancel any text selection
  447. CList_clearSelection();
  448. //prevent the event from bubbling to other elements
  449. CList_cancelBub(evt);
  450. var rootNode = this.getParentListObject();
  451. if (rootNode.isDisabled()) {
  452. return;
  453. }
  454. CList_doClick(evt,this);
  455. if (rootNode.getSingleClickFunc() != null)
  456. {
  457. var singleClickFunc = rootNode.getSingleClickFunc();
  458. singleClickFunc(evt);
  459. CList_cancelBub(evt);
  460. if (!document.all)
  461. {
  462. evt.preventDefault();
  463. }
  464. return false;
  465. }
  466. }
  467. function CList_doubleClickCaller(evt)
  468. {
  469. if (this.parentNode.listObject.isDisabled()) {
  470. return;
  471. }
  472. //get the event in a cross-browser fashion
  473. evt = (evt) ? evt : ((event) ? event : null);
  474. //cancel any text selection
  475. CList_clearSelection();
  476. //prevent the event from bubbling to other elements
  477. CList_cancelBub(evt);
  478. var rootNode = this.getParentListObject();
  479. if (rootNode.getDblClickFunc() != null && !rootNode.isDisabled())
  480. {
  481. var doubleClickFunc = rootNode.getDblClickFunc();
  482. doubleClickFunc(evt);
  483. CList_cancelBub(evt);
  484. if (!document.all)
  485. {
  486. evt.preventDefault();
  487. }
  488. return false;
  489. }
  490. }
  491. function CList_dragStartCaller(evt)
  492. {
  493. if (this.parentNode.listObject.isDisabled()) {
  494. return;
  495. }
  496. //get the event in a cross-browser fashion
  497. evt = (evt) ? evt : ((event) ? event : null);
  498. //cancel any text selection
  499. CList_clearSelection();
  500. //prevent the event from bubbling to other elements
  501. CList_cancelBub(evt);
  502. var rootNode = this.getParentListObject();
  503. if (rootNode.getDragStartFunc() != null && !rootNode.isDisabled())
  504. {
  505. var dragStartFunc = rootNode.getDragStartFunc();
  506. dragStartFunc(evt);
  507. CList_cancelBub(evt);
  508. if (!document.all)
  509. {
  510. evt.preventDefault();
  511. }
  512. return false;
  513. }
  514. }
  515. function CList_dragCaller(evt)
  516. {
  517. if (this.parentNode.listObject.isDisabled()) {
  518. return;
  519. }
  520. //get the event in a cross-browser fashion
  521. evt = (evt) ? evt : ((event) ? event : null);
  522. //cancel any text selection
  523. CList_clearSelection();
  524. //prevent the event from bubbling to other elements
  525. CList_cancelBub(evt);
  526. var rootNode = this.getParentListObject();
  527. if (rootNode.getDragFunc() != null && !rootNode.isDisabled())
  528. {
  529. var dragFunc = rootNode.getDragFunc();
  530. dragFunc(evt);
  531. CList_cancelBub(evt);
  532. if (!document.all)
  533. {
  534. evt.preventDefault();
  535. }
  536. return false;
  537. }
  538. }
  539. function CList_dragEndCaller(evt)
  540. {
  541. if (this.parentNode.listObject.isDisabled()) {
  542. return;
  543. }
  544. //get the event in a cross-browser fashion
  545. evt = (evt) ? evt : ((event) ? event : null);
  546. //cancel any text selection
  547. CList_clearSelection();
  548. //prevent the event from bubbling to other elements
  549. CList_cancelBub(evt);
  550. var rootNode = this.getParentListObject();
  551. if (rootNode.getDragEndFunc() != null && !rootNode.isDisabled())
  552. {
  553. var dragEndFunc = rootNode.getDragEndFunc();
  554. dragEndFunc(evt);
  555. CList_cancelBub(evt);
  556. if (!document.all)
  557. {
  558. evt.preventDefault();
  559. }
  560. return false;
  561. }
  562. }
  563. function CList_dragEnterCaller(evt)
  564. {
  565. if (this.parentNode.listObject.isDisabled()) {
  566. return;
  567. }
  568. //get the event in a cross-browser fashion
  569. evt = (evt) ? evt : ((event) ? event : null);
  570. // set the cursor shape
  571. evt.dataTransfer.dropEffect="move";
  572. //cancel any text selection
  573. CList_clearSelection();
  574. //prevent the event from bubbling to other elements
  575. CList_cancelBub(evt);
  576. var rootNode = this.getParentListObject();
  577. if (rootNode.getDragEnterFunc() != null && !rootNode.isDisabled())
  578. {
  579. var dragEnterFunc = rootNode.getDragEnterFunc();
  580. dragEnterFunc(evt);
  581. CList_cancelBub(evt);
  582. if (!document.all)
  583. {
  584. evt.preventDefault();
  585. }
  586. }
  587. return false;
  588. }
  589. function CList_dragLeaveCaller(evt)
  590. {
  591. //get the event in a cross-browser fashion
  592. evt = (evt) ? evt : ((event) ? event : null);
  593. //cancel any text selection
  594. CList_clearSelection();
  595. //prevent the event from bubbling to other elements
  596. CList_cancelBub(evt);
  597. var rootNode = this.getParentListObject();
  598. if (rootNode.isDisabled()) {
  599. return;
  600. }
  601. var liNode = CList_getUINode(evt,this);
  602. if (liNode.isSelected) {
  603. rootNode.selectNodeList(liNode);
  604. } else {
  605. CList_doMouseOut(liNode);
  606. }
  607. if (rootNode.getDragLeaveFunc() != null)
  608. {
  609. var dragOverFunc = rootNode.getDragLeaveFunc();
  610. dragLeaveFunc(evt);
  611. CList_cancelBub(evt);
  612. if (!document.all)
  613. {
  614. evt.preventDefault();
  615. }
  616. }
  617. return false;
  618. }
  619. function CList_dragOverCaller(evt)
  620. {
  621. if (this.parentNode.listObject.isDisabled()) {
  622. return;
  623. }
  624. //get the event in a cross-browser fashion
  625. evt = (evt) ? evt : ((event) ? event : null);
  626. //cancel any text selection
  627. CList_clearSelection();
  628. //prevent the event from bubbling to other elements
  629. CList_cancelBub(evt);
  630. var rootNode = this.getParentListObject();
  631. if (rootNode.isDisabled()) {
  632. return;
  633. }
  634. var liNode = CList_getUINode(evt,this);
  635. CList_doMouseOver(liNode);
  636. if (rootNode.getDragOverFunc() != null)
  637. {
  638. var dragOverFunc = rootNode.getDragOverFunc();
  639. dragOverFunc(evt);
  640. CList_cancelBub(evt);
  641. if (!document.all)
  642. {
  643. evt.preventDefault();
  644. }
  645. }
  646. return false;
  647. }
  648. function CList_OnDropCaller(evt)
  649. {
  650. if (this.parentNode.listObject.isDisabled()) {
  651. return;
  652. }
  653. //get the event in a cross-browser fashion
  654. evt = (evt) ? evt : ((event) ? event : null);
  655. //cancel any text selection
  656. CList_clearSelection();
  657. //prevent the event from bubbling to other elements
  658. CList_cancelBub(evt);
  659. var rootNode = this.getParentListObject();
  660. if (rootNode.isDisabled()) {
  661. return;
  662. }
  663. var liNode = CList_getUINode(evt,this);
  664. if (rootNode.getOnDropFunc() != null)
  665. {
  666. var onDropFunc = rootNode.getOnDropFunc();
  667. onDropFunc(evt);
  668. CList_cancelBub(evt);
  669. if (!document.all)
  670. {
  671. evt.preventDefault();
  672. }
  673. }
  674. return false;
  675. }
  676. //find the element that the event occurred
  677. function CList_getUINode (evt,parent)
  678. {
  679. //get the element that trapped the event in a cross-browser fashion
  680. var uiNode = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
  681. //check to see if this is a text node.
  682. while (uiNode.tagName != 'LI')
  683. {
  684. if (uiNode.parentNode.getAttribute('id').toString().localeCompare(parent.id) != 0) {
  685. //We have reached the parent UL stop here.
  686. break;
  687. }
  688. //this is a text node, get the parent node
  689. uiNode = uiNode.parentNode;
  690. }
  691. return uiNode;
  692. }
  693. function CList_disableAllEvents(element) {
  694. if (document.all)
  695. {
  696. element.attachEvent("onmouseover", function() {window.status='';return true;});
  697. element.attachEvent("onmouseout", function() {window.status='';return true;});
  698. element.attachEvent("onmouseup", function(e) {window.status='';CList_clearSelection();CList_cancelBub(e);e.returnValue = false;});
  699. element.attachEvent("onmousedown", function(e) {window.status='';CList_clearSelection();CList_cancelBub(e);e.returnValue = false;});
  700. element.attachEvent("onmousemove", function(e) {window.status='';CList_clearSelection();CList_cancelBub(e);e.returnValue = false;});
  701. element.attachEvent("onclick", function(e) {window.status='';CList_clearSelection();CList_cancelBub(e);e.returnValue = false;});
  702. element.attachEvent("ondblclick", function(e) {window.status='';CList_clearSelection();CList_cancelBub(e);e.returnValue = false;});
  703. }
  704. else
  705. {
  706. element.addEventListener("mouseover", function() {window.status='';return false;}, true);
  707. element.addEventListener("mouseout", function() {window.status='';return false;}, true);
  708. element.addEventListener("mouseup", function(e) {window.status='';e.preventDefault();return false;}, true);
  709. element.addEventListener("mousedown", function(e) {window.status='';e.preventDefault();return false;}, true);
  710. element.addEventListener("mousemove", function(e) {window.status='';e.preventDefault();return false;}, true);
  711. element.addEventListener("click", function(e) {window.status='';e.preventDefault();return false;}, true);
  712. element.addEventListener("dblclick", function(e) {window.status='';CList_clearSelection();CList_cancelBub(e);e.preventDefault();return false;}, true);
  713. }
  714. }
  715. //prevent the event from bubbling to other elements
  716. function CList_cancelBub(evt)
  717. {
  718. //get the event in a cross-browser fashion
  719. evt = (evt) ? evt : ((event) ? event : null);
  720. //prevent the click from proceeding to other nodes
  721. if (typeof evt.cancelBubble != 'undefined')
  722. {
  723. evt.cancelBubble = true;
  724. }
  725. if (typeof evt.stopPropagation != 'undefined')
  726. {
  727. evt.stopPropagation();
  728. }
  729. }
  730. function CList_clearSelection()
  731. {
  732. if (typeof document.selection != 'undefined' && document.selection.createRange().text != "")
  733. {
  734. //IE specific
  735. document.selection.empty();
  736. }
  737. else if (typeof window.getSelection == 'function' && typeof window.getSelection() == "object")
  738. {
  739. //NS6 specific
  740. window.getSelection().removeAllRanges();
  741. }
  742. }
  743. function CList_up(nodeId)
  744. {
  745. var node = this.getNodeById(nodeId);
  746. if (node != null && node.childNodes.length==1) {
  747. var index = this.indexById(nodeId);
  748. //is the node already at the top of the list?
  749. if (index > 0) {
  750. var newPos = index-1;
  751. var el = this.getListElement();
  752. var previousNode = el.childNodes[newPos];
  753. //create the new node
  754. var insertNode = CList_createNode(this,nodeId);
  755. var nodeContent = node.childNodes[0];
  756. insertNode.appendChild(nodeContent);
  757. //remove the old one
  758. this.remove(index);
  759. //insert the node
  760. el.insertBefore(insertNode,previousNode);
  761. this.selectRange(newPos,newPos);
  762. }
  763. }
  764. }
  765. function CList_down(nodeId)
  766. {
  767. var index = this.indexById(nodeId);
  768. var node = this.getNodeById(nodeId);
  769. if (node != null && node.childNodes.length==1) {
  770. var lastIndex = this.size()-1;
  771. //the position of the sibling underneath the one to be inserted
  772. var nextSiblingPos = index+2;
  773. //the position of the new item
  774. var newPos = index+1
  775. if (nextSiblingPos > lastIndex) {
  776. this.toBottom(nodeId);
  777. }
  778. //is the node already the last item in the list?
  779. else if (index < lastIndex) {
  780. var el = this.getListElement();
  781. var nextNode = el.childNodes[nextSiblingPos];
  782. //create the new node
  783. var insertNode = CList_createNode(this,nodeId);
  784. var nodeContent = node.childNodes[0];
  785. insertNode.appendChild(nodeContent);
  786. //remove the old one
  787. this.remove(index);
  788. //insert the node
  789. el.insertBefore(insertNode,nextNode);
  790. this.selectRange(index+1,index+1);
  791. }
  792. }
  793. }
  794. function CList_toTop(nodeId)
  795. {
  796. var node = this.getNodeById(nodeId);
  797. if (node != null && node.childNodes.length==1) {
  798. var index = this.indexById(nodeId);
  799. //is the node already the first item in the list?
  800. if (index > 0) {
  801. this.remove(index);
  802. var el = this.getListElement();
  803. var firstNode = el.childNodes[0];
  804. //create the new node
  805. var nodeContent = node.childNodes[0];
  806. var insertNode = CList_createNode(this,nodeId);
  807. insertNode.appendChild(nodeContent);
  808. //place the node at the top
  809. el.insertBefore(insertNode,firstNode);
  810. this.selectRange(0,0);
  811. }
  812. }
  813. }
  814. function CList_toBottom(nodeId)
  815. {
  816. var node = this.getNodeById(nodeId);
  817. if (node != null && node.childNodes.length==1) {
  818. var index = this.indexById(nodeId);
  819. var lastIndex = this.size()-1;
  820. //is the node already at the bottom of the list?
  821. if (index < lastIndex) {
  822. this.remove(index);
  823. var el = this.getListElement();
  824. //create the new node
  825. var nodeContent = node.childNodes[0];
  826. var insertNode = CList_createNode(this,nodeId);
  827. insertNode.appendChild(nodeContent);
  828. //place the node at the bottom
  829. el.appendChild(insertNode);
  830. this.selectRange(lastIndex,lastIndex);
  831. }
  832. }
  833. }
  834. CList.prototype.getAllSelectedItems = CList_getAllSelectedItems;
  835. CList.prototype.getSelectedNodes = CList_getSelectedNodes;
  836. CList.prototype.selectRange = CList_selectRange;
  837. CList.prototype.selectNodeList = CList_selectNodeList;
  838. CList.prototype.deSelectNodeList = CList_deSelectNodeList;
  839. CList.prototype.deSelectAll = CList_deSelectAll;
  840. CList.prototype.size = CList_size;
  841. CList.prototype.getAllItems = CList_getAllItems;
  842. CList.prototype.getAllNodes = CList_getAllNodes;
  843. CList.prototype.getNodeByIndex = CList_getNodeByIndex;
  844. CList.prototype.getNodeByProperty = CList_getNodeByProperty;
  845. CList.prototype.getNodeById = CList_getNodeById;
  846. CList.prototype.containsItem = CList_containsItem;
  847. CList.prototype.up = CList_up;
  848. CList.prototype.down = CList_down;
  849. CList.prototype.toTop = CList_toTop;
  850. CList.prototype.toBottom = CList_toBottom;
  851. CList.prototype.add = CList_add;
  852. CList.prototype.item = CList_item;
  853. CList.prototype.remove = CList_remove;
  854. CList.prototype.removeSelected = CList_removeSelected;
  855. CList.prototype.removeAllNodes = CList_removeAllNodes;
  856. CList.prototype.getId = CList_getId;
  857. CList.prototype.setStyle = CList_setStyle;
  858. CList.prototype.getStyle = CList_getStyle;
  859. CList.prototype.getListElement = CList_getListElement;
  860. CList.prototype.indexById = CList_indexById;
  861. CList.prototype.setDisabled = CList_setDisabled;
  862. CList.prototype.isDisabled = CList_isDisabled;
  863. CList.prototype.setDblClickFunc = CList_setDblClickFunc;
  864. CList.prototype.setSingleClickFunc = CList_setSingleClickFunc;
  865. CList.prototype.setContextMenuClickFunc = CList_setContextMenuClickFunc;
  866. CList.prototype.getDblClickFunc = CList_getDblClickFunc;
  867. CList.prototype.getSingleClickFunc = CList_getSingleClickFunc;
  868. CList.prototype.getContextMenuClickFunc = CList_getContextMenuClickFunc;
  869. CList.prototype.setDragStartFunc = CList_setDragStartFunc;
  870. CList.prototype.setDragFunc = CList_setDragFunc;
  871. CList.prototype.setDragEndFunc = CList_setDragEndFunc;
  872. CList.prototype.setDragEnterFunc = CList_setDragEnterFunc;
  873. CList.prototype.setDragLeaveFunc = CList_setDragLeaveFunc;
  874. CList.prototype.setDragOverFunc = CList_setDragOverFunc;
  875. CList.prototype.setOnDropFunc = CList_setOnDropFunc;
  876. CList.prototype.setEqualityFunc = CList_setEqualityFunc;
  877. CList.prototype.getDragStartFunc = CList_getDragStartFunc;
  878. CList.prototype.getDragFunc = CList_getDragFunc;
  879. CList.prototype.getDragEndFunc = CList_getDragEndFunc;
  880. CList.prototype.getDragEnterFunc = CList_getDragEnterFunc;
  881. CList.prototype.getDragLeaveFunc = CList_getDragLeaveFunc;
  882. CList.prototype.getDragOverFunc = CList_getDragOverFunc;
  883. CList.prototype.getOnDropFunc = CList_getOnDropFunc;
  884. CList.prototype.getEqualityFunc = CList_getEqualityFunc;