]>
git.wh0rd.org - tt-rss.git/blob - lib/dijit/_Widget.js.uncompressed.js
1 define("dijit/_Widget", [
2 "dojo/aspect", // aspect.around
3 "dojo/_base/config", // config.isDebug
4 "dojo/_base/connect", // connect.connect
5 "dojo/_base/declare", // declare
6 "dojo/_base/kernel", // kernel.deprecated
7 "dojo/_base/lang", // lang.hitch
10 "./registry", // registry.byNode
12 "./_OnDijitClickMixin",
14 "dojo/uacss", // browser sniffing (included for back-compat; subclasses may be using)
15 "./hccss" // high contrast mode sniffing (included to set CSS classes on <body>, module ret value unused)
16 ], function(aspect
, config
, connect
, declare
, kernel
, lang
, query
, ready
,
17 registry
, _WidgetBase
, _OnDijitClickMixin
, _FocusMixin
){
20 var _WidgetBase = dijit._WidgetBase;
21 var _OnDijitClickMixin = dijit._OnDijitClickMixin;
22 var _FocusMixin = dijit._FocusMixin;
29 // Old base for widgets. New widgets should extend _WidgetBase instead
32 function connectToDomNode(){
34 // If user connects to a widget method === this function, then they will
35 // instead actually be connecting the equivalent event on this.domNode
38 // Trap dojo.connect() calls to connectToDomNode methods, and redirect to _Widget.on()
39 function aroundAdvice(originalConnect
){
40 return function(obj
, event
, scope
, method
){
41 if(obj
&& typeof event
== "string" && obj
[event
] == connectToDomNode
){
42 return obj
.on(event
.substring(2).toLowerCase(), lang
.hitch(scope
, method
));
44 return originalConnect
.apply(connect
, arguments
);
47 aspect
.around(connect
, "connect", aroundAdvice
);
49 aspect
.around(kernel
, "connect", aroundAdvice
);
52 var _Widget
= declare("dijit._Widget", [_WidgetBase
, _OnDijitClickMixin
, _FocusMixin
], {
54 // Base class for all Dijit widgets.
56 // Extends _WidgetBase, adding support for:
57 // - declaratively/programatically specifying widget initialization parameters like
58 // onMouseMove="foo" that call foo when this.domNode gets a mousemove event
60 // Support new data-dojo-attach-event="ondijitclick: ..." that is triggered by a mouse click or a SPACE/ENTER keypress
61 // - focus related functions
62 // In particular, the onFocus()/onBlur() callbacks. Driven internally by
63 // dijit/_base/focus.js.
64 // - deprecated methods
65 // - onShow(), onHide(), onClose()
67 // Also, by loading code in dijit/_base, turns on:
68 // - browser sniffing (putting browser id like .dj_ie on <html> node)
69 // - high contrast mode sniffing (add .dijit_a11y class to <body> if machine is in high contrast mode)
72 ////////////////// DEFERRED CONNECTS ///////////////////
74 onClick
: connectToDomNode
,
76 onClick: function(event){
78 // Connect to this function to receive notifications of mouse click events.
85 onDblClick
: connectToDomNode
,
87 onDblClick: function(event){
89 // Connect to this function to receive notifications of mouse double click events.
96 onKeyDown
: connectToDomNode
,
98 onKeyDown: function(event){
100 // Connect to this function to receive notifications of keys being pressed down.
107 onKeyPress
: connectToDomNode
,
109 onKeyPress: function(event){
111 // Connect to this function to receive notifications of printable keys being typed.
118 onKeyUp
: connectToDomNode
,
120 onKeyUp: function(event){
122 // Connect to this function to receive notifications of keys being released.
129 onMouseDown
: connectToDomNode
,
131 onMouseDown: function(event){
133 // Connect to this function to receive notifications of when the mouse button is pressed down.
140 onMouseMove
: connectToDomNode
,
142 onMouseMove: function(event){
144 // Connect to this function to receive notifications of when the mouse moves over nodes contained within this widget.
151 onMouseOut
: connectToDomNode
,
153 onMouseOut: function(event){
155 // Connect to this function to receive notifications of when the mouse moves off of nodes contained within this widget.
162 onMouseOver
: connectToDomNode
,
164 onMouseOver: function(event){
166 // Connect to this function to receive notifications of when the mouse moves onto nodes contained within this widget.
173 onMouseLeave
: connectToDomNode
,
175 onMouseLeave: function(event){
177 // Connect to this function to receive notifications of when the mouse moves off of this widget.
184 onMouseEnter
: connectToDomNode
,
186 onMouseEnter: function(event){
188 // Connect to this function to receive notifications of when the mouse moves onto this widget.
195 onMouseUp
: connectToDomNode
,
197 onMouseUp: function(event){
199 // Connect to this function to receive notifications of when the mouse button is released.
207 constructor: function(params
){
208 // extract parameters like onMouseMove that should connect directly to this.domNode
209 this._toConnect
= {};
210 for(var name
in params
){
211 if(this[name
] === connectToDomNode
){
212 this._toConnect
[name
.replace(/^on/, "").toLowerCase()] = params
[name
];
218 postCreate: function(){
219 this.inherited(arguments
);
221 // perform connection from this.domNode to user specified handlers (ex: onMouseMove)
222 for(var name
in this._toConnect
){
223 this.on(name
, this._toConnect
[name
]);
225 delete this._toConnect
;
228 on: function(/*String*/ type
, /*Function*/ func
){
229 if(this[this._onMap(type
)] === connectToDomNode
){
230 // Use connect.connect() rather than on() to get handling for "onmouseenter" on non-IE, etc.
231 // Also, need to specify context as "this" rather than the default context of the DOMNode
232 return connect
.connect(this.domNode
, type
.toLowerCase(), this, func
);
234 return this.inherited(arguments
);
237 _setFocusedAttr: function(val
){
238 // Remove this method in 2.0 (or sooner), just here to set _focused == focused, for back compat
239 // (but since it's a private variable we aren't required to keep supporting it).
241 this._set("focused", val
);
244 ////////////////// DEPRECATED METHODS ///////////////////
246 setAttribute: function(/*String*/ attr
, /*anything*/ value
){
248 // Deprecated. Use set() instead.
251 kernel
.deprecated(this.declaredClass
+"::setAttribute(attr, value) is deprecated. Use set() instead.", "", "2.0");
252 this.set(attr
, value
);
255 attr: function(/*String|Object*/name
, /*Object?*/value
){
257 // Set or get properties on a widget instance.
259 // The property to get or set. If an object is passed here and not
260 // a string, its keys are used as names of attributes to be set
261 // and the value of the object as values to set in the widget.
263 // Optional. If provided, attr() operates as a setter. If omitted,
264 // the current value of the named property is returned.
266 // This method is deprecated, use get() or set() directly.
268 // Print deprecation warning but only once per calling function
270 var alreadyCalledHash
= arguments
.callee
._ach
|| (arguments
.callee
._ach
= {}),
271 caller
= (arguments
.callee
.caller
|| "unknown caller").toString();
272 if(!alreadyCalledHash
[caller
]){
273 kernel
.deprecated(this.declaredClass
+ "::attr() is deprecated. Use get() or set() instead, called from " +
275 alreadyCalledHash
[caller
] = true;
279 var args
= arguments
.length
;
280 if(args
>= 2 || typeof name
=== "object"){ // setter
281 return this.set.apply(this, arguments
);
283 return this.get(name
);
287 getDescendants: function(){
289 // Returns all the widgets contained by this, i.e., all widgets underneath this.containerNode.
290 // This method should generally be avoided as it returns widgets declared in templates, which are
291 // supposed to be internal/hidden, but it's left here for back-compat reasons.
293 kernel
.deprecated(this.declaredClass
+"::getDescendants() is deprecated. Use getChildren() instead.", "", "2.0");
294 return this.containerNode
? query('[widgetId]', this.containerNode
).map(registry
.byNode
) : []; // dijit._Widget[]
297 ////////////////// MISCELLANEOUS METHODS ///////////////////
301 // Internal method called when this widget is made visible.
302 // See `onShow` for details.
308 // Called when this widget becomes the selected pane in a
309 // `dijit.layout.TabContainer`, `dijit.layout.StackContainer`,
310 // `dijit.layout.AccordionContainer`, etc.
312 // Also called to indicate display of a `dijit.Dialog`, `dijit.TooltipDialog`, or `dijit.TitlePane`.
319 // Called when another widget becomes the selected pane in a
320 // `dijit.layout.TabContainer`, `dijit.layout.StackContainer`,
321 // `dijit.layout.AccordionContainer`, etc.
323 // Also called to indicate hide of a `dijit.Dialog`, `dijit.TooltipDialog`, or `dijit.TitlePane`.
330 // Called when this widget is being displayed as a popup (ex: a Calendar popped
331 // up from a DateTextBox), and it is hidden.
332 // This is called from the dijit.popup code, and should not be called directly.
334 // Also used as a parameter for children of `dijit.layout.StackContainer` or subclasses.
335 // Callback if a user tries to close the child. Child will be closed if this function returns true.
339 return true; // Boolean
343 // For back-compat, remove in 2.0.
346 var requires
= ["dijit/_base"];
347 require(requires
); // use indirection so modules not rolled into a build