bb94d9418f78a78c9a5ca8d09797a909060efd6d.svn-base 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. if (!dojo._hasResource["dojox.grid._grid.lib"]) { // _hasResource checks added
  2. // by build. Do not use
  3. // _hasResource directly in
  4. // your code.
  5. dojo._hasResource["dojox.grid._grid.lib"] = true;
  6. dojo.provide("dojox.grid._grid.lib");
  7. dojo.isNumber = function(v) {
  8. return (typeof v == 'number') || (v instanceof Number);
  9. }
  10. // summary:
  11. // grid utility library
  12. dojo.mixin(dojox.grid, {
  13. na : '...',
  14. nop : function() {
  15. },
  16. getTdIndex : function(td) {
  17. return td.cellIndex >= 0 ? td.cellIndex : dojo.indexOf(
  18. td.parentNode.cells, td);
  19. },
  20. getTrIndex : function(tr) {
  21. return tr.rowIndex >= 0 ? tr.rowIndex : dojo.indexOf(
  22. tr.parentNode.childNodes, tr);
  23. },
  24. getTr : function(rowOwner, index) {
  25. return rowOwner
  26. && ((rowOwner.rows || 0)[index] || rowOwner.childNodes[index]);
  27. },
  28. getTd : function(rowOwner, rowIndex, cellIndex) {
  29. return (dojox.grid.getTr(inTable, rowIndex) || 0)[cellIndex];
  30. },
  31. findTable : function(node) {
  32. for (var n = node; n && n.tagName != 'TABLE'; n = n.parentNode);
  33. return n;
  34. },
  35. ascendDom : function(inNode, inWhile) {
  36. for (var n = inNode; n && inWhile(n); n = n.parentNode);
  37. return n;
  38. },
  39. makeNotTagName : function(inTagName) {
  40. var name = inTagName.toUpperCase();
  41. return function(node) {
  42. return node.tagName != name;
  43. };
  44. },
  45. fire : function(ob, ev, args) {
  46. var fn = ob && ev && ob[ev];
  47. return fn && (args ? fn.apply(ob, args) : ob[ev]());
  48. },
  49. // from lib.js
  50. setStyleText : function(inNode, inStyleText) {
  51. if (inNode.style.cssText == undefined) {
  52. inNode.setAttribute("style", inStyleText);
  53. } else {
  54. inNode.style.cssText = inStyleText;
  55. }
  56. },
  57. getStyleText : function(inNode, inStyleText) {
  58. return (inNode.style.cssText == undefined ? inNode
  59. .getAttribute("style") : inNode.style.cssText);
  60. },
  61. setStyle : function(inElement, inStyle, inValue) {
  62. if (inElement && inElement.style[inStyle] != inValue) {
  63. inElement.style[inStyle] = inValue;
  64. }
  65. },
  66. setStyleHeightPx : function(inElement, inHeight) {
  67. if (inHeight >= 0) {
  68. dojox.grid.setStyle(inElement, 'height', inHeight + 'px');
  69. }
  70. },
  71. mouseEvents : ['mouseover', 'mouseout', /* 'mousemove', */'mousedown',
  72. 'mouseup', 'click', 'dblclick', 'contextmenu'],
  73. keyEvents : ['keyup', 'keydown', 'keypress'],
  74. funnelEvents : function(inNode, inObject, inMethod, inEvents) {
  75. var evts = (inEvents ? inEvents : dojox.grid.mouseEvents
  76. .concat(dojox.grid.keyEvents));
  77. for (var i = 0, l = evts.length; i < l; i++) {
  78. dojo.connect(inNode, 'on' + evts[i], inObject, inMethod);
  79. }
  80. },
  81. removeNode : function(inNode) {
  82. inNode = dojo.byId(inNode);
  83. inNode && inNode.parentNode
  84. && inNode.parentNode.removeChild(inNode);
  85. return inNode;
  86. },
  87. getScrollbarWidth : function() {
  88. if (this._scrollBarWidth) {
  89. return this._scrollBarWidth;
  90. }
  91. this._scrollBarWidth = 18;
  92. try {
  93. var e = document.createElement("div");
  94. e.style.cssText = "top:0;left:0;width:100px;height:100px;overflow:scroll;position:absolute;visibility:hidden;";
  95. document.body.appendChild(e);
  96. this._scrollBarWidth = e.offsetWidth - e.clientWidth;
  97. document.body.removeChild(e);
  98. delete e;
  99. } catch (ex) {
  100. }
  101. return this._scrollBarWidth;
  102. },
  103. // needed? dojo has _getProp
  104. getRef : function(name, create, context) {
  105. var obj = context || dojo.global, parts = name.split("."), prop = parts
  106. .pop();
  107. for (var i = 0, p; obj && (p = parts[i]); i++) {
  108. obj = (p in obj ? obj[p] : (create ? obj[p] = {} : undefined));
  109. }
  110. return {
  111. obj : obj,
  112. prop : prop
  113. };
  114. },
  115. getProp : function(name, create, context) {
  116. with (dojox.grid.getRef(name, create, context)) {
  117. return (obj)
  118. && (prop)
  119. && (prop in obj ? obj[prop] : (create
  120. ? obj[prop] = {}
  121. : undefined));
  122. }
  123. },
  124. indexInParent : function(inNode) {
  125. var i = 0, n, p = inNode.parentNode;
  126. while (n = p.childNodes[i++]) {
  127. if (n == inNode) {
  128. return i - 1;
  129. }
  130. }
  131. return -1;
  132. },
  133. cleanNode : function(inNode) {
  134. if (!inNode) {
  135. return;
  136. }
  137. var filter = function(inW) {
  138. return inW.domNode
  139. && dojo.isDescendant(inW.domNode, inNode, true);
  140. }
  141. var ws = dijit.registry.filter(filter);
  142. for (var i = 0, w; (w = ws[i]); i++) {
  143. w.destroy();
  144. }
  145. delete ws;
  146. },
  147. getTagName : function(inNodeOrId) {
  148. var node = dojo.byId(inNodeOrId);
  149. return (node && node.tagName ? node.tagName.toLowerCase() : '');
  150. },
  151. nodeKids : function(inNode, inTag) {
  152. var result = [];
  153. var i = 0, n;
  154. while (n = inNode.childNodes[i++]) {
  155. if (dojox.grid.getTagName(n) == inTag) {
  156. result.push(n);
  157. }
  158. }
  159. return result;
  160. },
  161. divkids : function(inNode) {
  162. return dojox.grid.nodeKids(inNode, 'div');
  163. },
  164. focusSelectNode : function(inNode) {
  165. try {
  166. dojox.grid.fire(inNode, "focus");
  167. dojox.grid.fire(inNode, "select");
  168. } catch (e) {// IE sux bad
  169. }
  170. },
  171. whenIdle : function(/* inContext, inMethod, args ... */) {
  172. setTimeout(dojo.hitch.apply(dojo, arguments), 0);
  173. },
  174. arrayCompare : function(inA, inB) {
  175. for (var i = 0, l = inA.length; i < l; i++) {
  176. if (inA[i] != inB[i]) {
  177. return false;
  178. }
  179. }
  180. return (inA.length == inB.length);
  181. },
  182. arrayInsert : function(inArray, inIndex, inValue) {
  183. if (inArray.length <= inIndex) {
  184. inArray[inIndex] = inValue;
  185. } else {
  186. inArray.splice(inIndex, 0, inValue);
  187. }
  188. },
  189. arrayRemove : function(inArray, inIndex) {
  190. inArray.splice(inIndex, 1);
  191. },
  192. arraySwap : function(inArray, inI, inJ) {
  193. var cache = inArray[inI];
  194. inArray[inI] = inArray[inJ];
  195. inArray[inJ] = cache;
  196. },
  197. initTextSizePoll : function(inInterval) {
  198. var f = document.createElement("div");
  199. with (f.style) {
  200. top = "0px";
  201. left = "0px";
  202. position = "absolute";
  203. visibility = "hidden";
  204. }
  205. f.innerHTML = "TheQuickBrownFoxJumpedOverTheLazyDog";
  206. document.body.appendChild(f);
  207. var fw = f.offsetWidth;
  208. var job = function() {
  209. if (f.offsetWidth != fw) {
  210. fw = f.offsetWidth;
  211. dojox.grid.textSizeChanged();
  212. }
  213. }
  214. window.setInterval(job, inInterval || 200);
  215. dojox.grid.initTextSizePoll = dojox.grid.nop;
  216. },
  217. textSizeChanged : function() {
  218. }
  219. });
  220. dojox.grid.jobs = {
  221. cancel : function(inHandle) {
  222. if (inHandle) {
  223. window.clearTimeout(inHandle);
  224. }
  225. },
  226. jobs : [],
  227. job : function(inName, inDelay, inJob) {
  228. dojox.grid.jobs.cancelJob(inName);
  229. var job = function() {
  230. delete dojox.grid.jobs.jobs[inName];
  231. inJob();
  232. }
  233. dojox.grid.jobs.jobs[inName] = setTimeout(job, inDelay);
  234. },
  235. cancelJob : function(inName) {
  236. dojox.grid.jobs.cancel(dojox.grid.jobs.jobs[inName]);
  237. }
  238. }
  239. }