util.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
  3. Available via Academic Free License >= 2.1 OR the modified BSD license.
  4. see: http://dojotoolkit.org/license for details
  5. */
  6. if(!dojo._hasResource["dojox.grid.util"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.grid.util"] = true;
  8. dojo.provide("dojox.grid.util");
  9. // summary: grid utility library
  10. (function(){
  11. var dgu = dojox.grid.util;
  12. dgu.na = '...';
  13. dgu.rowIndexTag = "gridRowIndex";
  14. dgu.gridViewTag = "gridView";
  15. dgu.fire = function(ob, ev, args){
  16. var fn = ob && ev && ob[ev];
  17. return fn && (args ? fn.apply(ob, args) : ob[ev]());
  18. };
  19. dgu.setStyleHeightPx = function(inElement, inHeight){
  20. if(inHeight >= 0){
  21. var s = inElement.style;
  22. var v = inHeight + 'px';
  23. if(inElement && s['height'] != v){
  24. s['height'] = v;
  25. }
  26. }
  27. };
  28. dgu.mouseEvents = [ 'mouseover', 'mouseout', /*'mousemove',*/ 'mousedown', 'mouseup', 'click', 'dblclick', 'contextmenu' ];
  29. dgu.keyEvents = [ 'keyup', 'keydown', 'keypress' ];
  30. dgu.funnelEvents = function(inNode, inObject, inMethod, inEvents){
  31. var evts = (inEvents ? inEvents : dgu.mouseEvents.concat(dgu.keyEvents));
  32. for (var i=0, l=evts.length; i<l; i++){
  33. inObject.connect(inNode, 'on' + evts[i], inMethod);
  34. }
  35. };
  36. dgu.removeNode = function(inNode){
  37. inNode = dojo.byId(inNode);
  38. inNode && inNode.parentNode && inNode.parentNode.removeChild(inNode);
  39. return inNode;
  40. };
  41. dgu.arrayCompare = function(inA, inB){
  42. for(var i=0,l=inA.length; i<l; i++){
  43. if(inA[i] != inB[i]){return false;}
  44. }
  45. return (inA.length == inB.length);
  46. };
  47. dgu.arrayInsert = function(inArray, inIndex, inValue){
  48. if(inArray.length <= inIndex){
  49. inArray[inIndex] = inValue;
  50. }else{
  51. inArray.splice(inIndex, 0, inValue);
  52. }
  53. };
  54. dgu.arrayRemove = function(inArray, inIndex){
  55. inArray.splice(inIndex, 1);
  56. };
  57. dgu.arraySwap = function(inArray, inI, inJ){
  58. var cache = inArray[inI];
  59. inArray[inI] = inArray[inJ];
  60. inArray[inJ] = cache;
  61. };
  62. })();
  63. }