[256] | 1 | define([ |
---|
| 2 | "dojo/_base/declare", // declare |
---|
| 3 | "dojo/dom-class", // domClass.replace |
---|
| 4 | "dojo/_base/event", // event.stop |
---|
| 5 | "dojo/keys", // keys |
---|
| 6 | "dojo/_base/lang", // lang.hitch |
---|
| 7 | "./focus", |
---|
| 8 | "./layout/ContentPane", |
---|
| 9 | "./_DialogMixin", |
---|
| 10 | "./form/_FormMixin", |
---|
| 11 | "./_TemplatedMixin", |
---|
| 12 | "dojo/text!./templates/TooltipDialog.html", |
---|
| 13 | "." // exports methods to dijit global |
---|
| 14 | ], function(declare, domClass, event, keys, lang, |
---|
| 15 | focus, ContentPane, _DialogMixin, _FormMixin, _TemplatedMixin, template, dijit){ |
---|
| 16 | |
---|
| 17 | /*===== |
---|
| 18 | var ContentPane = dijit.layout.ContentPane; |
---|
| 19 | var _DialogMixin = dijit._DialogMixin; |
---|
| 20 | var _FormMixin = dijit.form._FormMixin; |
---|
| 21 | var _TemplatedMixin = dijit._TemplatedMixin; |
---|
| 22 | =====*/ |
---|
| 23 | |
---|
| 24 | // module: |
---|
| 25 | // dijit/TooltipDialog |
---|
| 26 | // summary: |
---|
| 27 | // Pops up a dialog that appears like a Tooltip |
---|
| 28 | |
---|
| 29 | |
---|
| 30 | return declare("dijit.TooltipDialog", |
---|
| 31 | [ContentPane, _TemplatedMixin, _FormMixin, _DialogMixin], { |
---|
| 32 | // summary: |
---|
| 33 | // Pops up a dialog that appears like a Tooltip |
---|
| 34 | |
---|
| 35 | // title: String |
---|
| 36 | // Description of tooltip dialog (required for a11y) |
---|
| 37 | title: "", |
---|
| 38 | |
---|
| 39 | // doLayout: [protected] Boolean |
---|
| 40 | // Don't change this parameter from the default value. |
---|
| 41 | // This ContentPane parameter doesn't make sense for TooltipDialog, since TooltipDialog |
---|
| 42 | // is never a child of a layout container, nor can you specify the size of |
---|
| 43 | // TooltipDialog in order to control the size of an inner widget. |
---|
| 44 | doLayout: false, |
---|
| 45 | |
---|
| 46 | // autofocus: Boolean |
---|
| 47 | // A Toggle to modify the default focus behavior of a Dialog, which |
---|
| 48 | // is to focus on the first dialog element after opening the dialog. |
---|
| 49 | // False will disable autofocusing. Default: true |
---|
| 50 | autofocus: true, |
---|
| 51 | |
---|
| 52 | // baseClass: [protected] String |
---|
| 53 | // The root className to use for the various states of this widget |
---|
| 54 | baseClass: "dijitTooltipDialog", |
---|
| 55 | |
---|
| 56 | // _firstFocusItem: [private] [readonly] DomNode |
---|
| 57 | // The pointer to the first focusable node in the dialog. |
---|
| 58 | // Set by `dijit._DialogMixin._getFocusItems`. |
---|
| 59 | _firstFocusItem: null, |
---|
| 60 | |
---|
| 61 | // _lastFocusItem: [private] [readonly] DomNode |
---|
| 62 | // The pointer to which node has focus prior to our dialog. |
---|
| 63 | // Set by `dijit._DialogMixin._getFocusItems`. |
---|
| 64 | _lastFocusItem: null, |
---|
| 65 | |
---|
| 66 | templateString: template, |
---|
| 67 | |
---|
| 68 | _setTitleAttr: function(/*String*/ title){ |
---|
| 69 | this.containerNode.title = title; |
---|
| 70 | this._set("title", title) |
---|
| 71 | }, |
---|
| 72 | |
---|
| 73 | postCreate: function(){ |
---|
| 74 | this.inherited(arguments); |
---|
| 75 | this.connect(this.containerNode, "onkeypress", "_onKey"); |
---|
| 76 | }, |
---|
| 77 | |
---|
| 78 | orient: function(/*DomNode*/ node, /*String*/ aroundCorner, /*String*/ corner){ |
---|
| 79 | // summary: |
---|
| 80 | // Configure widget to be displayed in given position relative to the button. |
---|
| 81 | // This is called from the dijit.popup code, and should not be called |
---|
| 82 | // directly. |
---|
| 83 | // tags: |
---|
| 84 | // protected |
---|
| 85 | var newC = "dijitTooltipAB" + (corner.charAt(1) == 'L' ? "Left" : "Right") |
---|
| 86 | + " dijitTooltip" |
---|
| 87 | + (corner.charAt(0) == 'T' ? "Below" : "Above"); |
---|
| 88 | |
---|
| 89 | domClass.replace(this.domNode, newC, this._currentOrientClass || ""); |
---|
| 90 | this._currentOrientClass = newC; |
---|
| 91 | }, |
---|
| 92 | |
---|
| 93 | focus: function(){ |
---|
| 94 | // summary: |
---|
| 95 | // Focus on first field |
---|
| 96 | this._getFocusItems(this.containerNode); |
---|
| 97 | focus.focus(this._firstFocusItem); |
---|
| 98 | }, |
---|
| 99 | |
---|
| 100 | onOpen: function(/*Object*/ pos){ |
---|
| 101 | // summary: |
---|
| 102 | // Called when dialog is displayed. |
---|
| 103 | // This is called from the dijit.popup code, and should not be called directly. |
---|
| 104 | // tags: |
---|
| 105 | // protected |
---|
| 106 | |
---|
| 107 | this.orient(this.domNode,pos.aroundCorner, pos.corner); |
---|
| 108 | this._onShow(); // lazy load trigger |
---|
| 109 | }, |
---|
| 110 | |
---|
| 111 | onClose: function(){ |
---|
| 112 | // summary: |
---|
| 113 | // Called when dialog is hidden. |
---|
| 114 | // This is called from the dijit.popup code, and should not be called directly. |
---|
| 115 | // tags: |
---|
| 116 | // protected |
---|
| 117 | this.onHide(); |
---|
| 118 | }, |
---|
| 119 | |
---|
| 120 | _onKey: function(/*Event*/ evt){ |
---|
| 121 | // summary: |
---|
| 122 | // Handler for keyboard events |
---|
| 123 | // description: |
---|
| 124 | // Keep keyboard focus in dialog; close dialog on escape key |
---|
| 125 | // tags: |
---|
| 126 | // private |
---|
| 127 | |
---|
| 128 | var node = evt.target; |
---|
| 129 | if(evt.charOrCode === keys.TAB){ |
---|
| 130 | this._getFocusItems(this.containerNode); |
---|
| 131 | } |
---|
| 132 | var singleFocusItem = (this._firstFocusItem == this._lastFocusItem); |
---|
| 133 | if(evt.charOrCode == keys.ESCAPE){ |
---|
| 134 | // Use setTimeout to avoid crash on IE, see #10396. |
---|
| 135 | setTimeout(lang.hitch(this, "onCancel"), 0); |
---|
| 136 | event.stop(evt); |
---|
| 137 | }else if(node == this._firstFocusItem && evt.shiftKey && evt.charOrCode === keys.TAB){ |
---|
| 138 | if(!singleFocusItem){ |
---|
| 139 | focus.focus(this._lastFocusItem); // send focus to last item in dialog |
---|
| 140 | } |
---|
| 141 | event.stop(evt); |
---|
| 142 | }else if(node == this._lastFocusItem && evt.charOrCode === keys.TAB && !evt.shiftKey){ |
---|
| 143 | if(!singleFocusItem){ |
---|
| 144 | focus.focus(this._firstFocusItem); // send focus to first item in dialog |
---|
| 145 | } |
---|
| 146 | event.stop(evt); |
---|
| 147 | }else if(evt.charOrCode === keys.TAB){ |
---|
| 148 | // we want the browser's default tab handling to move focus |
---|
| 149 | // but we don't want the tab to propagate upwards |
---|
| 150 | evt.stopPropagation(); |
---|
| 151 | } |
---|
| 152 | } |
---|
| 153 | }); |
---|
| 154 | }); |
---|