Debian Codegraph @

dojox/app/tests/doh/helpers.js

raw symbols SCIP
1 // Helper methods for automated testing
2
3 function isVisible(/*dijit._Widget || DomNode*/ node){
4 // summary:
5 // Return true if node/widget is visible
6 var p;
7 if(node.domNode){ node = node.domNode; }
8 return (dojo.style(node, "display") != "none") &&
9 (dojo.style(node, "visibility") != "hidden") &&
10 (p = dojo.position(node, true), p.y + p.h >= 0 && p.x + p.w >= 0 && p.h && p.w);
11 }
12
13 function isHidden(/*dijit._Widget || DomNode*/ node){
14 // summary:
15 // Return true if node/widget is hidden
16 var p;
17 if(node.domNode){ node = node.domNode; }
18 return (dojo.style(node, "display") == "none") ||
19 (dojo.style(node, "visibility") == "hidden") ||
20 (p = dojo.position(node, true), p.y + p.h < 0 || p.x + p.w < 0 || p.h <= 0 || p.w <= 0);
21 }
22
23 function innerText(/*DomNode*/ node){
24 // summary:
25 // Browser portable function to get the innerText of specified DOMNode
26 return node.textContent || node.innerText || "";
27 }
28
29 function tabOrder(/*DomNode?*/ root){
30 // summary:
31 // Return all tab-navigable elements under specified node in the order that
32 // they will be visited (by repeated presses of the tab key)
33
34 var elems = [];
35
36 function walkTree(/*DOMNode*/parent){
37 dojo.query("> *", parent).forEach(function(child){
38 // Skip hidden elements, and also non-HTML elements (those in custom namespaces) in IE,
39 // since show() invokes getAttribute("type"), which crash on VML nodes in IE.
40 if((dojo.isIE && child.scopeName!=="HTML") || !dijit._isElementShown(child)){
41 return;
42 }
43
44 if(dijit.isTabNavigable(child)){
45 elems.push({
46 elem: child,
47 tabIndex: dojo.hasAttr(child, "tabIndex") ? dojo.attr(child, "tabIndex") : 0,
48 pos: elems.length
49 });
50 }
51 if(child.nodeName.toUpperCase() != 'SELECT'){
52 walkTree(child);
53 }
54 });
55 }
56 walkTree(root || dojo.body());
57
58 elems.sort(function(a, b){
59 return a.tabIndex != b.tabIndex ? a.tabIndex - b.tabIndex : a.pos - b.pos;
60 });
61 return dojo.map(elems, function(elem){ return elem.elem; });
62 }
63
64
65 function onFocus(func){
66 // summary:
67 // On the next change of focus, and after widget has had time to react to focus event,
68 // call func(node) with the newly focused node
69 var handle = dojo.subscribe("focusNode", function(node){
70 dojo.unsubscribe(handle);
71 setTimeout(function(){ func(node); }, 0);
72 });
73 }