| 1 |
define([ |
| 2 |
"dojo/_base/array", |
| 3 |
"dojo/_base/declare", |
| 4 |
"dojo/_base/fx", |
| 5 |
"dojo/dom", |
| 6 |
"dojo/dom-class", |
| 7 |
"dojo/dom-geometry", |
| 8 |
"dojo/dom-style", |
| 9 |
"dojo/_base/lang", |
| 10 |
"dojo/mouse", |
| 11 |
"dojo/on", |
| 12 |
"dojo/sniff", |
| 13 |
"./_base/manager", |
| 14 |
"./place", |
| 15 |
"./_Widget", |
| 16 |
"./_TemplatedMixin", |
| 17 |
"./BackgroundIframe", |
| 18 |
"dojo/text!./templates/Tooltip.html", |
| 19 |
"./main" |
| 20 |
], function(array, declare, fx, dom, domClass, domGeometry, domStyle, lang, mouse, on, has, |
| 21 |
manager, place, _Widget, _TemplatedMixin, BackgroundIframe, template, dijit){ |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
var MasterTooltip = declare("dijit._MasterTooltip", [_Widget, _TemplatedMixin], { |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
duration: manager.defaultDuration, |
| 47 |
|
| 48 |
templateString: template, |
| 49 |
|
| 50 |
postCreate: function(){ |
| 51 |
this.ownerDocumentBody.appendChild(this.domNode); |
| 52 |
|
| 53 |
this.bgIframe = new BackgroundIframe(this.domNode); |
| 54 |
|
| 55 |
|
| 56 |
this.fadeIn = fx.fadeIn({ node: this.domNode, duration: this.duration, onEnd: lang.hitch(this, "_onShow") }); |
| 57 |
this.fadeOut = fx.fadeOut({ node: this.domNode, duration: this.duration, onEnd: lang.hitch(this, "_onHide") }); |
| 58 |
}, |
| 59 |
|
| 60 |
show: function(innerHTML, aroundNode, position, rtl, textDir, onMouseEnter, onMouseLeave){ |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
if(this.aroundNode && this.aroundNode === aroundNode && this.containerNode.innerHTML == innerHTML){ |
| 81 |
return; |
| 82 |
} |
| 83 |
|
| 84 |
if(this.fadeOut.status() == "playing"){ |
| 85 |
|
| 86 |
this._onDeck=arguments; |
| 87 |
return; |
| 88 |
} |
| 89 |
this.containerNode.innerHTML=innerHTML; |
| 90 |
|
| 91 |
if(textDir){ |
| 92 |
this.set("textDir", textDir); |
| 93 |
} |
| 94 |
|
| 95 |
this.containerNode.align = rtl? "right" : "left"; |
| 96 |
|
| 97 |
var pos = place.around(this.domNode, aroundNode, |
| 98 |
position && position.length ? position : Tooltip.defaultPosition, !rtl, lang.hitch(this, "orient")); |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
var aroundNodeCoords = pos.aroundNodePos; |
| 103 |
if(pos.corner.charAt(0) == 'M' && pos.aroundCorner.charAt(0) == 'M'){ |
| 104 |
this.connectorNode.style.top = aroundNodeCoords.y + ((aroundNodeCoords.h - this.connectorNode.offsetHeight) >> 1) - pos.y + "px"; |
| 105 |
this.connectorNode.style.left = ""; |
| 106 |
}else if(pos.corner.charAt(1) == 'M' && pos.aroundCorner.charAt(1) == 'M'){ |
| 107 |
this.connectorNode.style.left = aroundNodeCoords.x + ((aroundNodeCoords.w - this.connectorNode.offsetWidth) >> 1) - pos.x + "px"; |
| 108 |
}else{ |
| 109 |
|
| 110 |
this.connectorNode.style.left = ""; |
| 111 |
this.connectorNode.style.top = ""; |
| 112 |
} |
| 113 |
|
| 114 |
|
| 115 |
domStyle.set(this.domNode, "opacity", 0); |
| 116 |
this.fadeIn.play(); |
| 117 |
this.isShowingNow = true; |
| 118 |
this.aroundNode = aroundNode; |
| 119 |
|
| 120 |
this.onMouseEnter = onMouseEnter || noop; |
| 121 |
this.onMouseLeave = onMouseLeave || noop; |
| 122 |
}, |
| 123 |
|
| 124 |
orient: function( node, aroundCorner, tooltipCorner, spaceAvailable, aroundNodeCoords){ |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
this.connectorNode.style.top = ""; |
| 133 |
|
| 134 |
var heightAvailable = spaceAvailable.h, |
| 135 |
widthAvailable = spaceAvailable.w; |
| 136 |
|
| 137 |
node.className = "dijitTooltip " + |
| 138 |
{ |
| 139 |
"MR-ML": "dijitTooltipRight", |
| 140 |
"ML-MR": "dijitTooltipLeft", |
| 141 |
"TM-BM": "dijitTooltipAbove", |
| 142 |
"BM-TM": "dijitTooltipBelow", |
| 143 |
"BL-TL": "dijitTooltipBelow dijitTooltipABLeft", |
| 144 |
"TL-BL": "dijitTooltipAbove dijitTooltipABLeft", |
| 145 |
"BR-TR": "dijitTooltipBelow dijitTooltipABRight", |
| 146 |
"TR-BR": "dijitTooltipAbove dijitTooltipABRight", |
| 147 |
"BR-BL": "dijitTooltipRight", |
| 148 |
"BL-BR": "dijitTooltipLeft" |
| 149 |
}[aroundCorner + "-" + tooltipCorner]; |
| 150 |
|
| 151 |
|
| 152 |
this.domNode.style.width = "auto"; |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
var size = domGeometry.position(this.domNode); |
| 158 |
if(has("ie") || has("trident")){ |
| 159 |
|
| 160 |
size.w += 2; |
| 161 |
} |
| 162 |
|
| 163 |
var width = Math.min((Math.max(widthAvailable,1)), size.w); |
| 164 |
|
| 165 |
domGeometry.setMarginBox(this.domNode, {w: width}); |
| 166 |
|
| 167 |
|
| 168 |
if(tooltipCorner.charAt(0) == 'B' && aroundCorner.charAt(0) == 'B'){ |
| 169 |
var bb = domGeometry.position(node); |
| 170 |
var tooltipConnectorHeight = this.connectorNode.offsetHeight; |
| 171 |
if(bb.h > heightAvailable){ |
| 172 |
|
| 173 |
var aroundNodePlacement = heightAvailable - ((aroundNodeCoords.h + tooltipConnectorHeight) >> 1); |
| 174 |
this.connectorNode.style.top = aroundNodePlacement + "px"; |
| 175 |
this.connectorNode.style.bottom = ""; |
| 176 |
}else{ |
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
this.connectorNode.style.bottom = Math.min( |
| 181 |
Math.max(aroundNodeCoords.h/2 - tooltipConnectorHeight/2, 0), |
| 182 |
bb.h - tooltipConnectorHeight) + "px"; |
| 183 |
this.connectorNode.style.top = ""; |
| 184 |
} |
| 185 |
}else{ |
| 186 |
|
| 187 |
this.connectorNode.style.top = ""; |
| 188 |
this.connectorNode.style.bottom = ""; |
| 189 |
} |
| 190 |
|
| 191 |
return Math.max(0, size.w - widthAvailable); |
| 192 |
}, |
| 193 |
|
| 194 |
_onShow: function(){ |
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
if(has("ie")){ |
| 200 |
|
| 201 |
this.domNode.style.filter=""; |
| 202 |
} |
| 203 |
}, |
| 204 |
|
| 205 |
hide: function(aroundNode){ |
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
if(this._onDeck && this._onDeck[1] == aroundNode){ |
| 210 |
|
| 211 |
|
| 212 |
this._onDeck=null; |
| 213 |
}else if(this.aroundNode === aroundNode){ |
| 214 |
|
| 215 |
this.fadeIn.stop(); |
| 216 |
this.isShowingNow = false; |
| 217 |
this.aroundNode = null; |
| 218 |
this.fadeOut.play(); |
| 219 |
}else{ |
| 220 |
|
| 221 |
} |
| 222 |
|
| 223 |
this.onMouseEnter = this.onMouseLeave = noop; |
| 224 |
}, |
| 225 |
|
| 226 |
_onHide: function(){ |
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
this.domNode.style.cssText=""; |
| 233 |
this.containerNode.innerHTML=""; |
| 234 |
if(this._onDeck){ |
| 235 |
|
| 236 |
this.show.apply(this, this._onDeck); |
| 237 |
this._onDeck=null; |
| 238 |
} |
| 239 |
} |
| 240 |
}); |
| 241 |
|
| 242 |
if(has("dojo-bidi")){ |
| 243 |
MasterTooltip.extend({ |
| 244 |
_setAutoTextDir: function(node){ |
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
this.applyTextDir(node); |
| 251 |
array.forEach(node.children, function(child){ this._setAutoTextDir(child); }, this); |
| 252 |
}, |
| 253 |
|
| 254 |
_setTextDirAttr: function( textDir){ |
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
this._set("textDir", textDir); |
| 264 |
|
| 265 |
if (textDir == "auto"){ |
| 266 |
this._setAutoTextDir(this.containerNode); |
| 267 |
}else{ |
| 268 |
this.containerNode.dir = this.textDir; |
| 269 |
} |
| 270 |
} |
| 271 |
}); |
| 272 |
} |
| 273 |
|
| 274 |
dijit.showTooltip = function(innerHTML, aroundNode, position, rtl, textDir, onMouseEnter, onMouseLeave){ |
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
if(position){ |
| 298 |
position = array.map(position, function(val){ |
| 299 |
return {after: "after-centered", before: "before-centered"}[val] || val; |
| 300 |
}); |
| 301 |
} |
| 302 |
|
| 303 |
if(!Tooltip._masterTT){ dijit._masterTT = Tooltip._masterTT = new MasterTooltip(); } |
| 304 |
return Tooltip._masterTT.show(innerHTML, aroundNode, position, rtl, textDir, onMouseEnter, onMouseLeave); |
| 305 |
}; |
| 306 |
|
| 307 |
dijit.hideTooltip = function(aroundNode){ |
| 308 |
|
| 309 |
|
| 310 |
return Tooltip._masterTT && Tooltip._masterTT.hide(aroundNode); |
| 311 |
}; |
| 312 |
|
| 313 |
|
| 314 |
var DORMANT = "DORMANT", |
| 315 |
SHOW_TIMER = "SHOW TIMER", |
| 316 |
SHOWING = "SHOWING", |
| 317 |
HIDE_TIMER = "HIDE TIMER"; |
| 318 |
|
| 319 |
function noop(){} |
| 320 |
|
| 321 |
var Tooltip = declare("dijit.Tooltip", _Widget, { |
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
label: "", |
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
showDelay: 400, |
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
hideDelay: 400, |
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
connectId: [], |
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
position: [], |
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
selector: "", |
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
_setConnectIdAttr: function( newId){ |
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
array.forEach(this._connections || [], function(nested){ |
| 368 |
array.forEach(nested, function(handle){ handle.remove(); }); |
| 369 |
}, this); |
| 370 |
|
| 371 |
|
| 372 |
this._connectIds = array.filter(lang.isArrayLike(newId) ? newId : (newId ? [newId] : []), |
| 373 |
function(id){ return dom.byId(id, this.ownerDocument); }, this); |
| 374 |
|
| 375 |
|
| 376 |
this._connections = array.map(this._connectIds, function(id){ |
| 377 |
var node = dom.byId(id, this.ownerDocument), |
| 378 |
selector = this.selector, |
| 379 |
delegatedEvent = selector ? |
| 380 |
function(eventType){ return on.selector(selector, eventType); } : |
| 381 |
function(eventType){ return eventType; }, |
| 382 |
self = this; |
| 383 |
return [ |
| 384 |
on(node, delegatedEvent(mouse.enter), function(){ |
| 385 |
self._onHover(this); |
| 386 |
}), |
| 387 |
on(node, delegatedEvent("focusin"), function(){ |
| 388 |
self._onHover(this); |
| 389 |
}), |
| 390 |
on(node, delegatedEvent(mouse.leave), lang.hitch(self, "_onUnHover")), |
| 391 |
on(node, delegatedEvent("focusout"), lang.hitch(self, "set", "state", DORMANT)) |
| 392 |
]; |
| 393 |
}, this); |
| 394 |
|
| 395 |
this._set("connectId", newId); |
| 396 |
}, |
| 397 |
|
| 398 |
addTarget: function( node){ |
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
var id = node.id || node; |
| 405 |
if(array.indexOf(this._connectIds, id) == -1){ |
| 406 |
this.set("connectId", this._connectIds.concat(id)); |
| 407 |
} |
| 408 |
}, |
| 409 |
|
| 410 |
removeTarget: function( node){ |
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
var id = node.id || node, |
| 417 |
idx = array.indexOf(this._connectIds, id); |
| 418 |
if(idx >= 0){ |
| 419 |
|
| 420 |
this._connectIds.splice(idx, 1); |
| 421 |
this.set("connectId", this._connectIds); |
| 422 |
} |
| 423 |
}, |
| 424 |
|
| 425 |
buildRendering: function(){ |
| 426 |
this.inherited(arguments); |
| 427 |
domClass.add(this.domNode,"dijitTooltipData"); |
| 428 |
}, |
| 429 |
|
| 430 |
startup: function(){ |
| 431 |
this.inherited(arguments); |
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
var ids = this.connectId; |
| 436 |
array.forEach(lang.isArrayLike(ids) ? ids : [ids], this.addTarget, this); |
| 437 |
}, |
| 438 |
|
| 439 |
getContent: function( node){ |
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
return this.label || this.domNode.innerHTML; |
| 445 |
}, |
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
state: DORMANT, |
| 455 |
_setStateAttr: function(val){ |
| 456 |
if(this.state == val || |
| 457 |
(val == SHOW_TIMER && this.state == SHOWING) || |
| 458 |
(val == HIDE_TIMER && this.state == DORMANT)){ |
| 459 |
return; |
| 460 |
} |
| 461 |
|
| 462 |
if(this._hideTimer){ |
| 463 |
this._hideTimer.remove(); |
| 464 |
delete this._hideTimer; |
| 465 |
} |
| 466 |
if(this._showTimer){ |
| 467 |
this._showTimer.remove(); |
| 468 |
delete this._showTimer; |
| 469 |
} |
| 470 |
|
| 471 |
switch(val){ |
| 472 |
case DORMANT: |
| 473 |
if(this._connectNode){ |
| 474 |
Tooltip.hide(this._connectNode); |
| 475 |
delete this._connectNode; |
| 476 |
this.onHide(); |
| 477 |
} |
| 478 |
break; |
| 479 |
case SHOW_TIMER: |
| 480 |
|
| 481 |
if(this.state != SHOWING){ |
| 482 |
this._showTimer = this.defer(function(){ this.set("state", SHOWING); }, this.showDelay); |
| 483 |
} |
| 484 |
break; |
| 485 |
case SHOWING: |
| 486 |
var content = this.getContent(this._connectNode); |
| 487 |
if(!content){ |
| 488 |
this.set("state", DORMANT); |
| 489 |
return; |
| 490 |
} |
| 491 |
|
| 492 |
|
| 493 |
Tooltip.show(content, this._connectNode, this.position, !this.isLeftToRight(), this.textDir, |
| 494 |
lang.hitch(this, "set", "state", SHOWING), lang.hitch(this, "set", "state", HIDE_TIMER)); |
| 495 |
|
| 496 |
this.onShow(this._connectNode, this.position); |
| 497 |
break; |
| 498 |
case HIDE_TIMER: |
| 499 |
this._hideTimer = this.defer(function(){ this.set("state", DORMANT); }, this.hideDelay); |
| 500 |
break; |
| 501 |
} |
| 502 |
|
| 503 |
this._set("state", val); |
| 504 |
}, |
| 505 |
|
| 506 |
_onHover: function( target){ |
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
if(this._connectNode && target != this._connectNode){ |
| 514 |
|
| 515 |
this.set("state", DORMANT); |
| 516 |
} |
| 517 |
this._connectNode = target; |
| 518 |
|
| 519 |
this.set("state", SHOW_TIMER); |
| 520 |
}, |
| 521 |
|
| 522 |
_onUnHover: function( target){ |
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
this.set("state", HIDE_TIMER); |
| 529 |
}, |
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
open: function( target){ |
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
this.set("state", DORMANT); |
| 540 |
this._connectNode = target; |
| 541 |
this.set("state", SHOWING); |
| 542 |
}, |
| 543 |
|
| 544 |
close: function(){ |
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
this.set("state", DORMANT); |
| 551 |
}, |
| 552 |
|
| 553 |
onShow: function(){ |
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
}, |
| 559 |
|
| 560 |
onHide: function(){ |
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
}, |
| 566 |
|
| 567 |
destroy: function(){ |
| 568 |
this.set("state", DORMANT); |
| 569 |
|
| 570 |
|
| 571 |
array.forEach(this._connections || [], function(nested){ |
| 572 |
array.forEach(nested, function(handle){ handle.remove(); }); |
| 573 |
}, this); |
| 574 |
|
| 575 |
this.inherited(arguments); |
| 576 |
} |
| 577 |
}); |
| 578 |
|
| 579 |
Tooltip._MasterTooltip = MasterTooltip; |
| 580 |
Tooltip.show = dijit.showTooltip; |
| 581 |
Tooltip.hide = dijit.hideTooltip; |
| 582 |
|
| 583 |
Tooltip.defaultPosition = ["after-centered", "before-centered"]; |
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
return Tooltip; |
| 610 |
}); |