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