| 1 |
define([ |
| 2 |
"dojo/_base/declare", |
| 3 |
"dojo/dom-class", |
| 4 |
"dojo/has", |
| 5 |
"dojo/keys", |
| 6 |
"dojo/_base/lang", |
| 7 |
"dojo/on", |
| 8 |
"./focus", |
| 9 |
"./layout/ContentPane", |
| 10 |
"./_DialogMixin", |
| 11 |
"./form/_FormMixin", |
| 12 |
"./_TemplatedMixin", |
| 13 |
"dojo/text!./templates/TooltipDialog.html", |
| 14 |
"./main" |
| 15 |
], function(declare, domClass, has, keys, lang, on, focus, ContentPane, _DialogMixin, _FormMixin, _TemplatedMixin, template, dijit){ |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
var TooltipDialog = declare("dijit.TooltipDialog", |
| 22 |
[ContentPane, _TemplatedMixin, _FormMixin, _DialogMixin], { |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
title: "", |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
doLayout: false, |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
autofocus: true, |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
baseClass: "dijitTooltipDialog", |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
_firstFocusItem: null, |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
_lastFocusItem: null, |
| 56 |
|
| 57 |
templateString: template, |
| 58 |
|
| 59 |
_setTitleAttr: "containerNode", |
| 60 |
|
| 61 |
postCreate: function(){ |
| 62 |
this.inherited(arguments); |
| 63 |
this.own(on(this.domNode, "keydown", lang.hitch(this, "_onKey"))); |
| 64 |
}, |
| 65 |
|
| 66 |
orient: function( node, aroundCorner, tooltipCorner){ |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
var newC = { |
| 77 |
|
| 78 |
"MR-ML": "dijitTooltipRight", |
| 79 |
"ML-MR": "dijitTooltipLeft", |
| 80 |
"TM-BM": "dijitTooltipAbove", |
| 81 |
"BM-TM": "dijitTooltipBelow", |
| 82 |
"BL-TL": "dijitTooltipBelow dijitTooltipABLeft", |
| 83 |
"TL-BL": "dijitTooltipAbove dijitTooltipABLeft", |
| 84 |
"BR-TR": "dijitTooltipBelow dijitTooltipABRight", |
| 85 |
"TR-BR": "dijitTooltipAbove dijitTooltipABRight", |
| 86 |
"BR-BL": "dijitTooltipRight", |
| 87 |
"BL-BR": "dijitTooltipLeft", |
| 88 |
|
| 89 |
|
| 90 |
"BR-TL": "dijitTooltipBelow dijitTooltipABLeft", |
| 91 |
"BL-TR": "dijitTooltipBelow dijitTooltipABRight", |
| 92 |
"TL-BR": "dijitTooltipAbove dijitTooltipABRight", |
| 93 |
"TR-BL": "dijitTooltipAbove dijitTooltipABLeft" |
| 94 |
}[aroundCorner + "-" + tooltipCorner]; |
| 95 |
|
| 96 |
domClass.replace(this.domNode, newC, this._currentOrientClass || ""); |
| 97 |
this._currentOrientClass = newC; |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
}, |
| 103 |
|
| 104 |
focus: function(){ |
| 105 |
|
| 106 |
|
| 107 |
this._getFocusItems(); |
| 108 |
focus.focus(this._firstFocusItem); |
| 109 |
}, |
| 110 |
|
| 111 |
onOpen: function( pos){ |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
this.orient(this.domNode, pos.aroundCorner, pos.corner); |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
var aroundNodeCoords = pos.aroundNodePos; |
| 123 |
if(pos.corner.charAt(0) == 'M' && pos.aroundCorner.charAt(0) == 'M'){ |
| 124 |
this.connectorNode.style.top = aroundNodeCoords.y + ((aroundNodeCoords.h - this.connectorNode.offsetHeight) >> 1) - pos.y + "px"; |
| 125 |
this.connectorNode.style.left = ""; |
| 126 |
}else if(pos.corner.charAt(1) == 'M' && pos.aroundCorner.charAt(1) == 'M'){ |
| 127 |
this.connectorNode.style.left = aroundNodeCoords.x + ((aroundNodeCoords.w - this.connectorNode.offsetWidth) >> 1) - pos.x + "px"; |
| 128 |
} |
| 129 |
|
| 130 |
this._onShow(); |
| 131 |
}, |
| 132 |
|
| 133 |
onClose: function(){ |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
this.onHide(); |
| 140 |
}, |
| 141 |
|
| 142 |
_onKey: function( evt){ |
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
if(evt.keyCode == keys.ESCAPE){ |
| 151 |
|
| 152 |
|
| 153 |
this.defer("onCancel"); |
| 154 |
evt.stopPropagation(); |
| 155 |
evt.preventDefault(); |
| 156 |
}else if(evt.keyCode == keys.TAB){ |
| 157 |
var node = evt.target; |
| 158 |
this._getFocusItems(); |
| 159 |
if(this._firstFocusItem == this._lastFocusItem){ |
| 160 |
evt.stopPropagation(); |
| 161 |
evt.preventDefault(); |
| 162 |
}else if(node == this._firstFocusItem && evt.shiftKey){ |
| 163 |
focus.focus(this._lastFocusItem); |
| 164 |
evt.stopPropagation(); |
| 165 |
evt.preventDefault(); |
| 166 |
}else if(node == this._lastFocusItem && !evt.shiftKey){ |
| 167 |
focus.focus(this._firstFocusItem); |
| 168 |
evt.stopPropagation(); |
| 169 |
evt.preventDefault(); |
| 170 |
}else{ |
| 171 |
|
| 172 |
|
| 173 |
evt.stopPropagation(); |
| 174 |
} |
| 175 |
} |
| 176 |
} |
| 177 |
}); |
| 178 |
|
| 179 |
if(has("dojo-bidi")){ |
| 180 |
TooltipDialog.extend({ |
| 181 |
_setTitleAttr: function( title){ |
| 182 |
this.containerNode.title = (this.textDir && this.enforceTextDirWithUcc) ? this.enforceTextDirWithUcc(null, title) : title; |
| 183 |
this._set("title", title); |
| 184 |
}, |
| 185 |
|
| 186 |
_setTextDirAttr: function( textDir){ |
| 187 |
if(!this._created || this.textDir != textDir){ |
| 188 |
this._set("textDir", textDir); |
| 189 |
if(this.textDir && this.title){ |
| 190 |
this.containerNode.title = this.enforceTextDirWithUcc(null, this.title); |
| 191 |
} |
| 192 |
} |
| 193 |
} |
| 194 |
}); |
| 195 |
} |
| 196 |
|
| 197 |
return TooltipDialog; |
| 198 |
}); |