[483] | 1 | define([ |
---|
| 2 | "dojo/_base/declare", // declare |
---|
| 3 | "dojo/dom-class", // domClass.replace |
---|
| 4 | "dojo/has", |
---|
| 5 | "dojo/keys", // keys |
---|
| 6 | "dojo/_base/lang", // lang.hitch |
---|
| 7 | "dojo/on", |
---|
| 8 | "./focus", |
---|
| 9 | "./layout/ContentPane", |
---|
| 10 | "./_DialogMixin", |
---|
| 11 | "./form/_FormMixin", |
---|
| 12 | "./_TemplatedMixin", |
---|
| 13 | "dojo/text!./templates/TooltipDialog.html", |
---|
| 14 | "./main" // exports methods to dijit global |
---|
| 15 | ], function(declare, domClass, has, keys, lang, on, focus, ContentPane, _DialogMixin, _FormMixin, _TemplatedMixin, template, dijit){ |
---|
| 16 | |
---|
| 17 | // module: |
---|
| 18 | // dijit/TooltipDialog |
---|
| 19 | |
---|
| 20 | |
---|
| 21 | var TooltipDialog = declare("dijit.TooltipDialog", |
---|
| 22 | [ContentPane, _TemplatedMixin, _FormMixin, _DialogMixin], { |
---|
| 23 | // summary: |
---|
| 24 | // Pops up a dialog that appears like a Tooltip |
---|
| 25 | |
---|
| 26 | // title: String |
---|
| 27 | // Description of tooltip dialog (required for a11y) |
---|
| 28 | title: "", |
---|
| 29 | |
---|
| 30 | // doLayout: [protected] Boolean |
---|
| 31 | // Don't change this parameter from the default value. |
---|
| 32 | // This ContentPane parameter doesn't make sense for TooltipDialog, since TooltipDialog |
---|
| 33 | // is never a child of a layout container, nor can you specify the size of |
---|
| 34 | // TooltipDialog in order to control the size of an inner widget. |
---|
| 35 | doLayout: false, |
---|
| 36 | |
---|
| 37 | // autofocus: Boolean |
---|
| 38 | // A Toggle to modify the default focus behavior of a Dialog, which |
---|
| 39 | // is to focus on the first dialog element after opening the dialog. |
---|
| 40 | // False will disable autofocusing. Default: true. |
---|
| 41 | autofocus: true, |
---|
| 42 | |
---|
| 43 | // baseClass: [protected] String |
---|
| 44 | // The root className to use for the various states of this widget |
---|
| 45 | baseClass: "dijitTooltipDialog", |
---|
| 46 | |
---|
| 47 | // _firstFocusItem: [private readonly] DomNode |
---|
| 48 | // The pointer to the first focusable node in the dialog. |
---|
| 49 | // Set by `dijit/_DialogMixin._getFocusItems()`. |
---|
| 50 | _firstFocusItem: null, |
---|
| 51 | |
---|
| 52 | // _lastFocusItem: [private readonly] DomNode |
---|
| 53 | // The pointer to which node has focus prior to our dialog. |
---|
| 54 | // Set by `dijit/_DialogMixin._getFocusItems()`. |
---|
| 55 | _lastFocusItem: null, |
---|
| 56 | |
---|
| 57 | templateString: template, |
---|
| 58 | |
---|
| 59 | _setTitleAttr: "containerNode", |
---|
| 60 | |
---|
| 61 | postCreate: function(){ |
---|
| 62 | this.inherited(arguments); |
---|
| 63 | this.own(on(this.containerNode, "keydown", lang.hitch(this, "_onKey"))); |
---|
| 64 | }, |
---|
| 65 | |
---|
| 66 | orient: function(/*DomNode*/ node, /*String*/ aroundCorner, /*String*/ tooltipCorner){ |
---|
| 67 | // summary: |
---|
| 68 | // Configure widget to be displayed in given position relative to the button. |
---|
| 69 | // This is called from the dijit.popup code, and should not be called |
---|
| 70 | // directly. |
---|
| 71 | // tags: |
---|
| 72 | // protected |
---|
| 73 | |
---|
| 74 | // Note: intentionally not using dijitTooltip class since that sets position:absolute, which |
---|
| 75 | // confuses dijit/popup trying to get the size of the tooltip. |
---|
| 76 | var newC = { |
---|
| 77 | // Real around node |
---|
| 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 | // Positioning "around" a point, ex: mouse position |
---|
| 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 | // Tooltip.orient() has code to reposition connector for when Tooltip is before/after anchor. |
---|
| 100 | // Not putting here to avoid code bloat, and since TooltipDialogs are generally above/below. |
---|
| 101 | // Should combine code from Tooltip and TooltipDialog. |
---|
| 102 | }, |
---|
| 103 | |
---|
| 104 | focus: function(){ |
---|
| 105 | // summary: |
---|
| 106 | // Focus on first field |
---|
| 107 | this._getFocusItems(this.containerNode); |
---|
| 108 | focus.focus(this._firstFocusItem); |
---|
| 109 | }, |
---|
| 110 | |
---|
| 111 | onOpen: function(/*Object*/ pos){ |
---|
| 112 | // summary: |
---|
| 113 | // Called when dialog is displayed. |
---|
| 114 | // This is called from the dijit.popup code, and should not be called directly. |
---|
| 115 | // tags: |
---|
| 116 | // protected |
---|
| 117 | |
---|
| 118 | this.orient(this.domNode, pos.aroundCorner, pos.corner); |
---|
| 119 | |
---|
| 120 | // Position the tooltip connector for middle alignment. |
---|
| 121 | // This could not have been done in orient() since the tooltip wasn't positioned at that time. |
---|
| 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(); // lazy load trigger (TODO: shouldn't we load before positioning?) |
---|
| 131 | }, |
---|
| 132 | |
---|
| 133 | onClose: function(){ |
---|
| 134 | // summary: |
---|
| 135 | // Called when dialog is hidden. |
---|
| 136 | // This is called from the dijit.popup code, and should not be called directly. |
---|
| 137 | // tags: |
---|
| 138 | // protected |
---|
| 139 | this.onHide(); |
---|
| 140 | }, |
---|
| 141 | |
---|
| 142 | _onKey: function(/*Event*/ evt){ |
---|
| 143 | // summary: |
---|
| 144 | // Handler for keydown events |
---|
| 145 | // description: |
---|
| 146 | // Keep keyboard focus in dialog; close dialog on escape key |
---|
| 147 | // tags: |
---|
| 148 | // private |
---|
| 149 | |
---|
| 150 | if(evt.keyCode == keys.ESCAPE){ |
---|
| 151 | // Use defer to avoid crash on IE, see #10396. Not sure if this is still needed or not. |
---|
| 152 | // If this if() wasn't here, presumably dijit/popup would catch the ESCAPE key and close the popup. |
---|
| 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(this.containerNode); |
---|
| 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); // send focus to last item in dialog |
---|
| 164 | evt.stopPropagation(); |
---|
| 165 | evt.preventDefault(); |
---|
| 166 | }else if(node == this._lastFocusItem && !evt.shiftKey){ |
---|
| 167 | focus.focus(this._firstFocusItem); // send focus to first item in dialog |
---|
| 168 | evt.stopPropagation(); |
---|
| 169 | evt.preventDefault(); |
---|
| 170 | }else{ |
---|
| 171 | // we want the browser's default tab handling to move focus |
---|
| 172 | // but we don't want the tab to propagate upwards |
---|
| 173 | evt.stopPropagation(); |
---|
| 174 | } |
---|
| 175 | } |
---|
| 176 | } |
---|
| 177 | }); |
---|
| 178 | |
---|
| 179 | if(has("dojo-bidi")){ |
---|
| 180 | TooltipDialog.extend({ |
---|
| 181 | _setTitleAttr: function(/*String*/ title){ |
---|
| 182 | this.containerNode.title = (this.textDir && this.enforceTextDirWithUcc) ? this.enforceTextDirWithUcc(null, title) : title; |
---|
| 183 | this._set("title", title); |
---|
| 184 | }, |
---|
| 185 | |
---|
| 186 | _setTextDirAttr: function(/*String*/ 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 | }); |
---|