CList.js 33 KB

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