Debian Codegraph @

dojox/grid/util.js

raw symbols SCIP
1 define([
2 "../main",
3 "dojo/_base/lang",
4 "dojo/dom",
5 "dojo/_base/sniff"
6 ], function(dojox, lang, dom, has){
7
8 var dgu = lang.getObject("grid.util", true, dojox);
9
10 /*=====
11 dgu = {
12 // summary:
13 // grid utility library
14 };
15 =====*/
16
17 dgu.na = '...';
18 dgu.rowIndexTag = "gridRowIndex";
19 dgu.gridViewTag = "gridView";
20
21 dgu.fire = function(ob, ev, args){
22 // Find parent node that scrolls, either vertically or horizontally
23 function getScrollParent(node, horizontal){
24 if(node == null) {
25 return null;
26 }
27
28 var dimension = horizontal ? 'Width' : 'Height';
29 if(node['scroll' + dimension] > node['client' + dimension]){
30 return node;
31 }else{
32 return getScrollParent(node.parentNode, horizontal);
33 }
34 }
35
36 // In Webkit browsers focusing an element will scroll this element into view.
37 // This may even happen if the element already is in view, but near the edge.
38 // This may move the element away from the mouse cursor on the first click
39 // of a double click and you end up hitting a different element.
40 // Avoid this by storing the scroll position and restoring it after focusing.
41 var verticalScrollParent, horizontalScrollParent, scrollTop, scrollLeft, obNode;
42 if(has("webkit") && (ev == "focus")){
43 obNode = ob.domNode ? ob.domNode : ob;
44 verticalScrollParent = getScrollParent(obNode, false);
45 if(verticalScrollParent){
46 scrollTop = verticalScrollParent.scrollTop;
47 }
48 horizontalScrollParent = getScrollParent(obNode, true);
49 if(horizontalScrollParent){
50 scrollLeft = horizontalScrollParent.scrollLeft;
51 }
52 }
53
54 var fn = ob && ev && ob[ev];
55 var result = fn && (args ? fn.apply(ob, args) : ob[ev]());
56
57 // Restore scrolling position
58 if(has("webkit") && (ev == "focus")){
59 if(verticalScrollParent){
60 verticalScrollParent.scrollTop = scrollTop;
61 }
62 if(horizontalScrollParent){
63 horizontalScrollParent.scrollLeft = scrollLeft;
64 }
65 }
66
67 return result;
68 };
69
70 dgu.setStyleHeightPx = function(inElement, inHeight){
71 if(inHeight >= 0){
72 var s = inElement.style;
73 var v = inHeight + 'px';
74 if(inElement && s['height'] != v){
75 s['height'] = v;
76 }
77 }
78 };
79
80 dgu.mouseEvents = [ 'mouseover', 'mouseout', /*'mousemove',*/ 'mousedown', 'mouseup', 'click', 'dblclick', 'contextmenu' ];
81
82 dgu.keyEvents = [ 'keyup', 'keydown', 'keypress' ];
83
84 dgu.funnelEvents = function(inNode, inObject, inMethod, inEvents){
85 var evts = (inEvents ? inEvents : dgu.mouseEvents.concat(dgu.keyEvents));
86 for (var i=0, l=evts.length; i<l; i++){
87 inObject.connect(inNode, 'on' + evts[i], inMethod);
88 }
89 };
90
91 dgu.removeNode = function(inNode){
92 inNode = dom.byId(inNode);
93 inNode && inNode.parentNode && inNode.parentNode.removeChild(inNode);
94 return inNode;
95 };
96
97 dgu.arrayCompare = function(inA, inB){
98 for(var i=0,l=inA.length; i<l; i++){
99 if(inA[i] != inB[i]){return false;}
100 }
101 return (inA.length == inB.length);
102 };
103
104 dgu.arrayInsert = function(inArray, inIndex, inValue){
105 if(inArray.length <= inIndex){
106 inArray[inIndex] = inValue;
107 }else{
108 inArray.splice(inIndex, 0, inValue);
109 }
110 };
111
112 dgu.arrayRemove = function(inArray, inIndex){
113 inArray.splice(inIndex, 1);
114 };
115
116 dgu.arraySwap = function(inArray, inI, inJ){
117 var cache = inArray[inI];
118 inArray[inI] = inArray[inJ];
119 inArray[inJ] = cache;
120 };
121
122 return dgu;
123
124 });