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