source: Dev/branches/rest-dojo-ui/client/dojox/mvc/tests/helpers.js @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

File size: 2.2 KB
Line 
1// Helper methods for automated testing
2
3function 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
13function 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
23function innerText(/*DomNode*/ node){
24        // summary:
25        //              Browser portable function to get the innerText of specified DOMNode
26        return node.textContent || node.innerText || "";
27}
28
29function 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
57        walkTree(root || dojo.body());
58
59        elems.sort(function(a, b){
60                return a.tabIndex != b.tabIndex ? a.tabIndex - b.tabIndex : a.pos - b.pos;
61        });
62        return dojo.map(elems, function(elem){ return elem.elem; });
63}
64
65
66function onFocus(func){
67        // summary:
68        //              On the next change of focus, and after widget has had time to react to focus event,
69        //              call func(node) with the newly focused node
70        var handle = dojo.subscribe("focusNode", function(node){
71                dojo.unsubscribe(handle);
72                setTimeout(function(){ func(node); }, 0);
73        });
74}
Note: See TracBrowser for help on using the repository browser.