2150 |
mathias |
1 |
if(!dojo._hasResource["dijit.Tooltip"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
|
|
|
2 |
dojo._hasResource["dijit.Tooltip"] = true;
|
|
|
3 |
dojo.provide("dijit.Tooltip");
|
|
|
4 |
|
|
|
5 |
dojo.require("dijit._Widget");
|
|
|
6 |
dojo.require("dijit._Templated");
|
|
|
7 |
|
|
|
8 |
dojo.declare(
|
|
|
9 |
"dijit._MasterTooltip",
|
|
|
10 |
[dijit._Widget, dijit._Templated],
|
|
|
11 |
{
|
|
|
12 |
// summary
|
|
|
13 |
// Internal widget that holds the actual tooltip markup,
|
|
|
14 |
// which occurs once per page.
|
|
|
15 |
// Called by Tooltip widgets which are just containers to hold
|
|
|
16 |
// the markup
|
|
|
17 |
|
|
|
18 |
// duration: Integer
|
|
|
19 |
// Milliseconds to fade in/fade out
|
|
|
20 |
duration: 200,
|
|
|
21 |
|
|
|
22 |
templateString:"<div class=\"dijitTooltip dijitTooltipLeft\" id=\"dojoTooltip\">\n\t<div class=\"dijitTooltipContainer dijitTooltipContents\" dojoAttachPoint=\"containerNode\" waiRole='alert'></div>\n\t<div class=\"dijitTooltipConnector\"></div>\n</div>\n",
|
|
|
23 |
|
|
|
24 |
postCreate: function(){
|
|
|
25 |
dojo.body().appendChild(this.domNode);
|
|
|
26 |
|
|
|
27 |
this.bgIframe = new dijit.BackgroundIframe(this.domNode);
|
|
|
28 |
|
|
|
29 |
// Setup fade-in and fade-out functions.
|
|
|
30 |
this.fadeIn = dojo.fadeIn({ node: this.domNode, duration: this.duration, onEnd: dojo.hitch(this, "_onShow") });
|
|
|
31 |
this.fadeOut = dojo.fadeOut({ node: this.domNode, duration: this.duration, onEnd: dojo.hitch(this, "_onHide") });
|
|
|
32 |
|
|
|
33 |
},
|
|
|
34 |
|
|
|
35 |
show: function(/*String*/ innerHTML, /*DomNode*/ aroundNode){
|
|
|
36 |
// summary:
|
|
|
37 |
// Display tooltip w/specified contents to right specified node
|
|
|
38 |
// (To left if there's no space on the right, or if LTR==right)
|
|
|
39 |
|
|
|
40 |
if(this.aroundNode && this.aroundNode === aroundNode){
|
|
|
41 |
return;
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
if(this.fadeOut.status() == "playing"){
|
|
|
45 |
// previous tooltip is being hidden; wait until the hide completes then show new one
|
|
|
46 |
this._onDeck=arguments;
|
|
|
47 |
return;
|
|
|
48 |
}
|
|
|
49 |
this.containerNode.innerHTML=innerHTML;
|
|
|
50 |
|
|
|
51 |
// Firefox bug. when innerHTML changes to be shorter than previous
|
|
|
52 |
// one, the node size will not be updated until it moves.
|
|
|
53 |
this.domNode.style.top = (this.domNode.offsetTop + 1) + "px";
|
|
|
54 |
|
|
|
55 |
// position the element and change CSS according to position
|
|
|
56 |
var align = this.isLeftToRight() ? {'BR': 'BL', 'BL': 'BR'} : {'BL': 'BR', 'BR': 'BL'};
|
|
|
57 |
var pos = dijit.placeOnScreenAroundElement(this.domNode, aroundNode, align);
|
|
|
58 |
this.domNode.className="dijitTooltip dijitTooltip" + (pos.corner=='BL' ? "Right" : "Left");//FIXME: might overwrite class
|
|
|
59 |
|
|
|
60 |
// show it
|
|
|
61 |
dojo.style(this.domNode, "opacity", 0);
|
|
|
62 |
this.fadeIn.play();
|
|
|
63 |
this.isShowingNow = true;
|
|
|
64 |
this.aroundNode = aroundNode;
|
|
|
65 |
},
|
|
|
66 |
|
|
|
67 |
_onShow: function(){
|
|
|
68 |
if(dojo.isIE){
|
|
|
69 |
// the arrow won't show up on a node w/an opacity filter
|
|
|
70 |
this.domNode.style.filter="";
|
|
|
71 |
}
|
|
|
72 |
},
|
|
|
73 |
|
|
|
74 |
hide: function(aroundNode){
|
|
|
75 |
// summary: hide the tooltip
|
|
|
76 |
if(!this.aroundNode || this.aroundNode !== aroundNode){
|
|
|
77 |
return;
|
|
|
78 |
}
|
|
|
79 |
if(this._onDeck){
|
|
|
80 |
// this hide request is for a show() that hasn't even started yet;
|
|
|
81 |
// just cancel the pending show()
|
|
|
82 |
this._onDeck=null;
|
|
|
83 |
return;
|
|
|
84 |
}
|
|
|
85 |
this.fadeIn.stop();
|
|
|
86 |
this.isShowingNow = false;
|
|
|
87 |
this.aroundNode = null;
|
|
|
88 |
this.fadeOut.play();
|
|
|
89 |
},
|
|
|
90 |
|
|
|
91 |
_onHide: function(){
|
|
|
92 |
this.domNode.style.cssText=""; // to position offscreen again
|
|
|
93 |
if(this._onDeck){
|
|
|
94 |
// a show request has been queued up; do it now
|
|
|
95 |
this.show.apply(this, this._onDeck);
|
|
|
96 |
this._onDeck=null;
|
|
|
97 |
}
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
}
|
|
|
101 |
);
|
|
|
102 |
|
|
|
103 |
dijit.showTooltip = function(/*String*/ innerHTML, /*DomNode*/ aroundNode){
|
|
|
104 |
// summary:
|
|
|
105 |
// Display tooltip w/specified contents to right specified node
|
|
|
106 |
// (To left if there's no space on the right, or if LTR==right)
|
|
|
107 |
if(!dijit._masterTT){ dijit._masterTT = new dijit._MasterTooltip(); }
|
|
|
108 |
return dijit._masterTT.show(innerHTML, aroundNode);
|
|
|
109 |
};
|
|
|
110 |
|
|
|
111 |
dijit.hideTooltip = function(aroundNode){
|
|
|
112 |
// summary: hide the tooltip
|
|
|
113 |
if(!dijit._masterTT){ dijit._masterTT = new dijit._MasterTooltip(); }
|
|
|
114 |
return dijit._masterTT.hide(aroundNode);
|
|
|
115 |
};
|
|
|
116 |
|
|
|
117 |
dojo.declare(
|
|
|
118 |
"dijit.Tooltip",
|
|
|
119 |
dijit._Widget,
|
|
|
120 |
{
|
|
|
121 |
// summary
|
|
|
122 |
// Pops up a tooltip (a help message) when you hover over a node.
|
|
|
123 |
|
|
|
124 |
// label: String
|
|
|
125 |
// Text to display in the tooltip.
|
|
|
126 |
// Specified as innerHTML when creating the widget from markup.
|
|
|
127 |
label: "",
|
|
|
128 |
|
|
|
129 |
// showDelay: Integer
|
|
|
130 |
// Number of milliseconds to wait after hovering over/focusing on the object, before
|
|
|
131 |
// the tooltip is displayed.
|
|
|
132 |
showDelay: 400,
|
|
|
133 |
|
|
|
134 |
// connectId: String[]
|
|
|
135 |
// Id(s) of domNodes to attach the tooltip to.
|
|
|
136 |
// When user hovers over any of the specified dom nodes, the tooltip will appear.
|
|
|
137 |
connectId: [],
|
|
|
138 |
|
|
|
139 |
postCreate: function(){
|
|
|
140 |
if(this.srcNodeRef){
|
|
|
141 |
this.srcNodeRef.style.display = "none";
|
|
|
142 |
}
|
|
|
143 |
|
|
|
144 |
this._connectNodes = [];
|
|
|
145 |
|
|
|
146 |
dojo.forEach(this.connectId, function(id) {
|
|
|
147 |
var node = dojo.byId(id);
|
|
|
148 |
if (node) {
|
|
|
149 |
this._connectNodes.push(node);
|
|
|
150 |
dojo.forEach(["onMouseOver", "onMouseOut", "onFocus", "onBlur", "onHover", "onUnHover"], function(event){
|
|
|
151 |
this.connect(node, event.toLowerCase(), "_"+event);
|
|
|
152 |
}, this);
|
|
|
153 |
if(dojo.isIE){
|
|
|
154 |
// BiDi workaround
|
|
|
155 |
node.style.zoom = 1;
|
|
|
156 |
}
|
|
|
157 |
}
|
|
|
158 |
}, this);
|
|
|
159 |
},
|
|
|
160 |
|
|
|
161 |
_onMouseOver: function(/*Event*/ e){
|
|
|
162 |
this._onHover(e);
|
|
|
163 |
},
|
|
|
164 |
|
|
|
165 |
_onMouseOut: function(/*Event*/ e){
|
|
|
166 |
if(dojo.isDescendant(e.relatedTarget, e.target)){
|
|
|
167 |
// false event; just moved from target to target child; ignore.
|
|
|
168 |
return;
|
|
|
169 |
}
|
|
|
170 |
this._onUnHover(e);
|
|
|
171 |
},
|
|
|
172 |
|
|
|
173 |
_onFocus: function(/*Event*/ e){
|
|
|
174 |
this._focus = true;
|
|
|
175 |
this._onHover(e);
|
|
|
176 |
},
|
|
|
177 |
|
|
|
178 |
_onBlur: function(/*Event*/ e){
|
|
|
179 |
this._focus = false;
|
|
|
180 |
this._onUnHover(e);
|
|
|
181 |
},
|
|
|
182 |
|
|
|
183 |
_onHover: function(/*Event*/ e){
|
|
|
184 |
if(!this._showTimer){
|
|
|
185 |
var target = e.target;
|
|
|
186 |
this._showTimer = setTimeout(dojo.hitch(this, function(){this.open(target)}), this.showDelay);
|
|
|
187 |
}
|
|
|
188 |
},
|
|
|
189 |
|
|
|
190 |
_onUnHover: function(/*Event*/ e){
|
|
|
191 |
// keep a tooltip open if the associated element has focus
|
|
|
192 |
if(this._focus){ return; }
|
|
|
193 |
if(this._showTimer){
|
|
|
194 |
clearTimeout(this._showTimer);
|
|
|
195 |
delete this._showTimer;
|
|
|
196 |
}
|
|
|
197 |
this.close();
|
|
|
198 |
},
|
|
|
199 |
|
|
|
200 |
open: function(/*DomNode*/ target){
|
|
|
201 |
// summary: display the tooltip; usually not called directly.
|
|
|
202 |
target = target || this._connectNodes[0];
|
|
|
203 |
if(!target){ return; }
|
|
|
204 |
|
|
|
205 |
if(this._showTimer){
|
|
|
206 |
clearTimeout(this._showTimer);
|
|
|
207 |
delete this._showTimer;
|
|
|
208 |
}
|
|
|
209 |
dijit.showTooltip(this.label || this.domNode.innerHTML, target);
|
|
|
210 |
|
|
|
211 |
this._connectNode = target;
|
|
|
212 |
},
|
|
|
213 |
|
|
|
214 |
close: function(){
|
|
|
215 |
// summary: hide the tooltip; usually not called directly.
|
|
|
216 |
dijit.hideTooltip(this._connectNode);
|
|
|
217 |
delete this._connectNode;
|
|
|
218 |
if(this._showTimer){
|
|
|
219 |
clearTimeout(this._showTimer);
|
|
|
220 |
delete this._showTimer;
|
|
|
221 |
}
|
|
|
222 |
},
|
|
|
223 |
|
|
|
224 |
uninitialize: function(){
|
|
|
225 |
this.close();
|
|
|
226 |
}
|
|
|
227 |
}
|
|
|
228 |
);
|
|
|
229 |
|
|
|
230 |
}
|