~clinton-collins/familyproject/trunk

« back to all changes in this revision

Viewing changes to ZendFramework/externals/dojo/dojo/robot.js

  • Committer: Clinton Collins
  • Date: 2009-06-26 19:54:58 UTC
  • Revision ID: clinton.collins@gmail.com-20090626195458-5ebba0qcvo15xlpy
Initial Import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
dojo.provide("dojo.robot");
 
2
dojo.experimental("dojo.robot");
 
3
dojo.require("doh.robot");
 
4
 
 
5
(function(){
 
6
// users who use doh+dojo get the added convenience of dojo.mouseMoveAt,
 
7
// instead of computing the absolute coordinates of their elements themselves
 
8
dojo.mixin(doh.robot,{
 
9
 
 
10
        // TODO: point to dojo.scrollIntoView post 1.2
 
11
        _scrollIntoView : function(/*String||DOMNode||Function*/ node){
 
12
                // summary:
 
13
                //              Scroll the passed node into view, if it is not.
 
14
                //              Stub to be replaced dijit.robot.
 
15
                if(typeof node == "function"){
 
16
                        // if the user passed a function returning a node, evaluate it
 
17
                        node = node();
 
18
                }
 
19
                node.scrollIntoView(false);
 
20
        },
 
21
 
 
22
        scrollIntoView : function(/*String||DOMNode||Function*/ node, /*Number, optional*/ delay){
 
23
                // summary:
 
24
                //              Scroll the passed node into view, if it is not.
 
25
                //
 
26
                // node:
 
27
                //              The id of the node, or the node itself, to move the mouse to.
 
28
                //              If you pass an id or a function that returns a node, the node will not be evaluated until the movement executes.
 
29
                //              This is useful if you need to move the mouse to an node that is not yet present.
 
30
                //
 
31
                // delay:
 
32
                //              Delay, in milliseconds, to wait before firing.
 
33
                //              The delay is a delta with respect to the previous automation call.
 
34
                //
 
35
                doh.robot.sequence(function(){
 
36
                        doh.robot._scrollIntoView(node);
 
37
                }, delay);
 
38
        },
 
39
 
 
40
        mouseMoveAt : function(/*String||DOMNode||Function*/ node, /*Integer, optional*/ delay, /*Integer, optional*/ duration, /*Number, optional*/ offsetX, /*Number, optional*/ offsetY){
 
41
                // summary:
 
42
                //              Moves the mouse over the specified node at the specified relative x,y offset.
 
43
                //
 
44
                // description:
 
45
                //              Moves the mouse over the specified node at the specified relative x,y offset.
 
46
                //              You should manually scroll off-screen nodes into view; use dijit.robot for automatic scrolling support.
 
47
                //              If you do not specify an offset, mouseMove will default to move to the middle of the node.
 
48
                //              Example: to move the mouse over a ComboBox's down arrow node, call doh.mouseMoveAt(dijit.byId('setvaluetest').downArrowNode);
 
49
                //
 
50
                // node:
 
51
                //              The id of the node, or the node itself, to move the mouse to.
 
52
                //              If you pass an id or a function that returns a node, the node will not be evaluated until the movement executes.
 
53
                //              This is useful if you need to move the mouse to an node that is not yet present.
 
54
                //
 
55
                // delay:
 
56
                //              Delay, in milliseconds, to wait before firing.
 
57
                //              The delay is a delta with respect to the previous automation call.
 
58
                //              For example, the following code ends after 600ms:
 
59
                //                      doh.mouseClick({left:true}, 100) // first call; wait 100ms
 
60
                //                      doh.typeKeys("dij", 500) // 500ms AFTER previous call; 600ms in all
 
61
                //
 
62
                // duration:
 
63
                //              Approximate time Robot will spend moving the mouse
 
64
                //              The default is 100ms.
 
65
                //
 
66
                // offsetX:
 
67
                //              x offset relative to the node, in pixels, to move the mouse. The default is half the node's width.
 
68
                //
 
69
                // offsetY:
 
70
                //              y offset relative to the node, in pixels, to move the mouse. The default is half the node's height.
 
71
                //
 
72
 
 
73
                doh.robot._assertRobot();
 
74
                duration = duration||100;
 
75
                this.sequence(function(){
 
76
                if(typeof node == "function"){
 
77
                        // if the user passed a function returning a node, evaluate it
 
78
                        node = node();
 
79
                }
 
80
                if(!node) return;
 
81
                node=dojo.byId(node);
 
82
                if(offsetY === undefined){
 
83
                        var box=dojo.contentBox(node);
 
84
                        offsetX=box.w/2;
 
85
                        offsetY=box.h/2;
 
86
                }
 
87
                var x = offsetX;
 
88
                var y = offsetY;
 
89
                doh.robot._scrollIntoView(node);
 
90
                // coords relative to viewport be default
 
91
                var c = dojo.coords(node);
 
92
                x += c.x;
 
93
                y += c.y;
 
94
                doh.robot._mouseMove(x, y, false, duration);
 
95
                },delay,duration);
 
96
        }
 
97
});
 
98
 
 
99
})();