aboutsummaryrefslogtreecommitdiff
path: root/includes/js/dojox/gfx/demos/tooltip.html
blob: 96bb694dca7babcf7bfe32ad4d4aeb5d29ee2e1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
<head>
	<title>A Sample ToolTip using dijit and dojox.gfx</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<style type="text/css">
		@import "../../../dojo/resources/dojo.css";
		@import "../../../dijit/tests/css/dijitTests.css";
		@import "../../../dijit/themes/tundra/tundra.css";
		.tooltipBody {
			color:#fff;
		}
	</style>
	<!--
	The next line should include Microsoft's Silverligth.js, if you plan to use the silverlight backend
	<script type="text/javascript" src="Silverlight.js"></script>
	-->
	<script type="text/javascript" djConfig="parseOnLoad:true, isDebug:true" src="../../../dojo/dojo.js"></script>
	<script type="text/javascript">
		dojo.require("dijit.form.Button");
	
		dojo.require("dojox.gfx");
		dojo.require("dojox.gfx.move");
		dojo.require("dijit._Widget"); dojo.require("dijit._Templated");
		
		dojo.declare("demo.Tooltip",[dijit._Widget,dijit._Templated],{
			
			// attachId: String|DomNode?
			// 		the Id or domNode to attach this tooltip to
			attachId:"",

			// attachHover: Boolean
			// 		disable hover behavior for the target
			attachHover:true,

			// attachParent: Boolean
			//		automatically attach to our parentnode rather than byId or query
			attachParent:false,

			// attachQuery: String?
			//		an optional selector query to attach this tooltip to
			attachQuery:"",

			// attachScope: String|DomNode?
			//		and optional scope to run the query against, passed as the
			//		second arg to dojo.query()
			queryScope:"",

			// hideDelay: Int
			// 		time in my to delay automatically closing the node
			hideDelay: 123, // ms

			// persists: Boolean
			//		if true, the node will stay visible until explicitly closed
			//		via _hide() or click on closeIcon
			persists:false,
			
			templateString:
				'<div class="foo">'
					+'<div style="position:relative;">'
						+'<div dojoAttachPoint="surfaceNode"></div>'
						+'<div class="tooltipBody" dojoAttachPoint="containerNode"></div>'
					+'</div>'
				+'</div>',
			
			postCreate:function(){
				// call _Widget postCreate first
				this.inherited(arguments);
				// gfx version of "_Templated" idea:
				this._initSurface();
				
				if(this.attachParent){
					// over-ride and reuse attachId as domNode from now on
					this.attachId = this.domNode.parentNode;
				}
				if(this.attachId){
					// domNode again. setup connections
					this.attachId = dojo.byId(this.attachId);
					if(this.attachHover){
						this.connect(this.attachId,"onmouseenter","_show");
					}
					if(!this.persists){
						this.connect(this.attachId,"onmouseleave","_initHide");
					}
				}else if(this.attachQuery){
					// setup connections via dojo.query for multi-tooltips
					var nl = dojo.query(this.attachQuery,this.queryScope);
					if(this.attachHover){ nl.connect("onmouseenter",this,"_show") }
					if(!this.persists){ nl.connect("onmouseleave",this,"_initHide") }
				}
				// place the tooltip			
				dojo.body().appendChild(this.domNode);
				dojo.style(this.domNode,{
					position:"absolute"
				});
				// could do this in css:
				dojo.style(this.containerNode,{
					position:"absolute",
					top:"15px",
					left:"12px",
					height:"83px",
					width:"190px"
				});
				// setup our animations
				this._hideAnim = dojo.fadeOut({ node:this.domNode, duration:150 });
				this._showAnim = dojo.fadeIn({ node:this.domNode, duration:75 });
				this.connect(this._hideAnim,"onEnd","_postHide");
				if(!this.persists){
					this.connect(this.domNode,"onmouseleave","_initHide");
				}
				// hide quickly
				this._postHide();
			},
			
			_initHide: function(e){
				// summary: start the timer for the hideDelay
				if(!this.persists && this.hideDelay){
					this._delay = setTimeout(dojo.hitch(this,"_hide",e||null),this.hideDelay);
				}
			},
			
			_clearDelay: function(){
				// summary: clear our hide delay timeout
				if(this._delay){ clearTimeout(this._delay); }
			},
			
			_show: function(e){
				// summary: show the widget
				this._clearDelay();
				var pos = dojo.coords(e.target || this.attachId,true)
				// we need to more accurately position the domNode:
				dojo.style(this.domNode,{
					top: pos.y - (pos.h / 2) - 50,
					left: pos.x + pos.w - 25,
					display:"block"
				});
				dojo.fadeIn({ node: this.domNode, duration:75 }).play();
			},
			
			_hide: function(e){
				// summary: hide the tooltip
				this._hideAnim.play();
			},
			
			_postHide: function(){
				// summary: after hide animation cleanup
				dojo.style(this.domNode,"display","none");
			},
			
			_initSurface:function(){
				// made generally from an SVG file:
				this.surface = dojox.gfx.createSurface(this.surfaceNode,220,120);
				this.tooltip = this.surface.createGroup();
				this.tooltip.createPath("M213,101.072c0,6.675-5.411,12.086-12.086,12.086H13.586 c-6.675,0-12.086-5.411-12.086-12.086V21.004c0-6.675,5.411-12.086,12.086-12.086h187.328c6.675,0,12.086,5.411,12.086,12.086 V101.072z")
					.setFill("rgba(0,0,0,0.25)");
				
				this.tooltip.createPath("M211.5,97.418c0,6.627-5.373,12-12,12 h-186c-6.627,0-12-5.373-12-12v-79.5c0-6.627,5.373-12,12-12h186c6.627,0,12,5.373,12,12V97.418z")
					.setStroke({ width:2, color:"#FFF" })
					.setFill("rgba(0,0,0,0.5)")
					.connect("onmouseover",dojo.hitch(this,"_clearDelay"));
				
				if(this.persists){
					// make the close icon
					this._toolButton = this.surface.createGroup();
					this._toolButton.createEllipse({ cx:207.25, cy:12.32, rx: 7.866, ry: 7.099 })
						.setFill("#ededed");
					this._toolButton.createCircle({ cx:207.25, cy: 9.25, r:8.25 })
						.setStroke({ width:2, color:"#FFF" })
						.setFill("#000")
					;
					this._toolButton.connect("onclick",dojo.hitch(this,"_hide"));	
					// the X	
					this._toolButton.createLine({ x1:203.618, y1:5.04, x2: 210.89, y2:12.979 })
						.setStroke({ width:2, color:"#d6d6d6" });
					this._toolButton.createLine({ x1:203.539, y1:12.979, x2: 210.89, y2:5.04 })
						.setStroke({ width:2, color:"#d6d6d6" });
				}
			}	
		});
	</script>
	
</head>
<body class="tundra">

	<h1>dojox.gfx: A Sample tooltip</h1>

	<ul style="width:150px; border:2px solid #ededed; cursor:pointer">
		
	
		<!-- you can put any content you want in there -->
		<li id="warn2">
			Tooltip + Button
			<div attachId="warn2" id="warn2tt" dojoType="demo.Tooltip"><p style="margin-top:0">Canvas renderer doesn't implement event handling.
				<button dojoType="dijit.form.Button">
					Button
					<script type="dojo/method" event="onClick">
						alert(" woo hoo! ");
						dijit.byId("warn2tt")._hide();
					</script>
				</button>
			</p></div>
		</li>

		<!-- a simple tooltip -->
		<li id="warn1">
			Hover trigger / persists
			<div persists="true" attachId="warn1" dojoType="demo.Tooltip">Canvas renderer doesn't implement event handling.</div>
		</li>

		<!-- these get the same tooltip from the attachQuery=".multitip" below -->
		<li class="multitip">MultiTip trigger 1</li>
		<li>I do nothing</li>
		<li class="multitip">Trigger two</li>

		<li><a href="#" onclick="dijit.byId('nohover')._show(arguments[0])">show this way
			<label dojoType="demo.Tooltip" attachParent="true" attachHover="false" id="nohover">some text</label>
			</a>	
		</li>

		<!-- attachParent makes the tooltip look for domNode.parentNode before moving to body() -->
		<li>
			Parent Attached Tooltip
			<div attachParent="true" persists="true" dojoType="demo.Tooltip">
				<form id="fooForm">
					<p style="margin-top:0;">
					Name:<br> <input type="text" name="username" style="border:1px solid #ededed" /><br>
					Pass:<br> <input type="password" name="password" style="border:1px solid #ededed" />
					</p>
				</form>
			</div>
		</li>

	</ul>

	<!-- attach a single tooltip message to a number of nodes at once -->
	<div attachQuery=".multitip" dojoType="demo.Tooltip">Canvas renderer doesn't implement event handling. (shared tooltip)</div>

</body>
</html>