1 | define(["dojo", "../util/oo", "../plugins/_Plugin", "../manager/_registry"], |
---|
2 | function(dojo, oo, Plugin, registry){ |
---|
3 | |
---|
4 | var master = null; |
---|
5 | var MasterC = oo.declare( |
---|
6 | Plugin, |
---|
7 | function(options){ |
---|
8 | this.createDom(); |
---|
9 | }, |
---|
10 | { |
---|
11 | // summary: |
---|
12 | // Used for UI tooltips. Buttons in the toolbar. |
---|
13 | // This file is not complete. |
---|
14 | |
---|
15 | show: function(button, text){ |
---|
16 | this.domNode.innerHTML = text; |
---|
17 | |
---|
18 | var dx = 30; |
---|
19 | var px = button.data.x + button.data.width; |
---|
20 | var py = button.data.y + button.data.height; |
---|
21 | var x = px + this.mouse.origin.x + dx; |
---|
22 | var y = py + this.mouse.origin.y + dx; |
---|
23 | |
---|
24 | dojo.style(this.domNode, { |
---|
25 | display: "inline", |
---|
26 | left:x +"px", |
---|
27 | top:y+"px" |
---|
28 | }); |
---|
29 | |
---|
30 | var box = dojo.marginBox(this.domNode); |
---|
31 | |
---|
32 | this.createShape(x-this.mouse.origin.x, y-this.mouse.origin.y, box.w, box.h); |
---|
33 | }, |
---|
34 | |
---|
35 | |
---|
36 | createShape: function(x,y,w,h){ |
---|
37 | this.balloon && this.balloon.destroy(); |
---|
38 | var r = 5, x2 = x+w, y2 = y+h, points = []; |
---|
39 | var add = function(){ |
---|
40 | for(var i=0;i<arguments.length;i++){ |
---|
41 | points.push(arguments[i]); |
---|
42 | } |
---|
43 | }; |
---|
44 | |
---|
45 | add({x:x,y:y+5}, |
---|
46 | {t:"Q", x:x,y:y}, |
---|
47 | {x:x+r,y:y}); |
---|
48 | |
---|
49 | add({t:"L", x:x2-r,y:y}); |
---|
50 | |
---|
51 | add({t:"Q", x:x2,y:y}, |
---|
52 | {x:x2,y:y+r}); |
---|
53 | |
---|
54 | add({t:"L", x:x2,y:y2-r}); |
---|
55 | |
---|
56 | add({t:"Q", x:x2,y:y2}, |
---|
57 | {x:x2-r,y:y2}); |
---|
58 | |
---|
59 | add({t:"L", x:x+r,y:y2}); |
---|
60 | |
---|
61 | add({t:"Q", x:x,y:y2}, |
---|
62 | {x:x,y:y2-r}); |
---|
63 | |
---|
64 | add({t:"L", x:x,y:y+r}); |
---|
65 | |
---|
66 | this.balloon = this.drawing.addUI("path", {points:points}); |
---|
67 | }, |
---|
68 | |
---|
69 | createDom: function(){ |
---|
70 | this.domNode = dojo.create('span', {"class":"drawingTooltip"}, document.body); |
---|
71 | dojo.style(this.domNode, { |
---|
72 | display: "none", |
---|
73 | position:"absolute" |
---|
74 | }); |
---|
75 | } |
---|
76 | } |
---|
77 | ); |
---|
78 | |
---|
79 | var Tooltip = oo.declare( |
---|
80 | |
---|
81 | Plugin, |
---|
82 | function(options){ |
---|
83 | if(!master){ |
---|
84 | master = new MasterC(options); |
---|
85 | } |
---|
86 | if(options.stencil){ |
---|
87 | //todo |
---|
88 | }else if(this.button){ |
---|
89 | this.connect(this.button, "onOver", this, "onOver"); |
---|
90 | this.connect(this.button, "onOut", this, "onOut"); |
---|
91 | } |
---|
92 | |
---|
93 | }, |
---|
94 | { |
---|
95 | width:300, |
---|
96 | height:200, |
---|
97 | onOver: function(){ |
---|
98 | //console.log(" tooltip over", this.data.text) |
---|
99 | master.show(this.button, this.data.text); |
---|
100 | }, |
---|
101 | |
---|
102 | onOut: function(){ |
---|
103 | //console.log(" tooltip out") |
---|
104 | } |
---|
105 | } |
---|
106 | ); |
---|
107 | dojo.setObject('dojox.drawing.ui.Tooltip', Tooltip); |
---|
108 | registry.register({ |
---|
109 | name:"dojox.drawing.ui.Tooltip" |
---|
110 | }, "stencil"); |
---|
111 | return Tooltip; |
---|
112 | }); |
---|