]>
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
7 "dojo/_base/kernel", // kernel.deprecated
8 "dojo/_base/lang", // lang.hitch
11 "./registry", // registry.byNode
13 "./_OnDijitClickMixin",
15 "dojo/uacss", // browser sniffing (included for back-compat; subclasses may be using)
16 "./hccss" // high contrast mode sniffing (included to set CSS classes on <body>, module ret value unused)
17 ], function(aspect
, config
, connect
, declare
, has
, kernel
, lang
, query
, ready
,
18 registry
, _WidgetBase
, _OnDijitClickMixin
, _FocusMixin
){
25 function connectToDomNode(){
27 // If user connects to a widget method === this function, then they will
28 // instead actually be connecting the equivalent event on this.domNode
31 // Trap dojo.connect() calls to connectToDomNode methods, and redirect to _Widget.on()
32 function aroundAdvice(originalConnect
){
33 return function(obj
, event
, scope
, method
){
34 if(obj
&& typeof event
== "string" && obj
[event
] == connectToDomNode
){
35 return obj
.on(event
.substring(2).toLowerCase(), lang
.hitch(scope
, method
));
37 return originalConnect
.apply(connect
, arguments
);
40 aspect
.around(connect
, "connect", aroundAdvice
);
42 aspect
.around(kernel
, "connect", aroundAdvice
);
45 var _Widget
= declare("dijit._Widget", [_WidgetBase
, _OnDijitClickMixin
, _FocusMixin
], {
47 // Old base class for widgets. New widgets should extend `dijit/_WidgetBase` instead
49 // Old Base class for Dijit widgets.
51 // Extends _WidgetBase, adding support for:
53 // - declaratively/programatically specifying widget initialization parameters like
54 // onMouseMove="foo" that call foo when this.domNode gets a mousemove event
56 // Support new data-dojo-attach-event="ondijitclick: ..." that is triggered by a mouse click or a SPACE/ENTER keypress
57 // - focus related functions:
58 // In particular, the onFocus()/onBlur() callbacks. Driven internally by
59 // dijit/_base/focus.js.
60 // - deprecated methods
61 // - onShow(), onHide(), onClose()
63 // Also, by loading code in dijit/_base, turns on:
65 // - browser sniffing (putting browser class like `dj_ie` on `<html>` node)
66 // - high contrast mode sniffing (add `dijit_a11y` class to `<body>` if machine is in high contrast mode)
69 ////////////////// DEFERRED CONNECTS ///////////////////
71 onClick
: connectToDomNode
,
73 onClick: function(event){
75 // Connect to this function to receive notifications of mouse click events.
82 onDblClick
: connectToDomNode
,
84 onDblClick: function(event){
86 // Connect to this function to receive notifications of mouse double click events.
93 onKeyDown
: connectToDomNode
,
95 onKeyDown: function(event){
97 // Connect to this function to receive notifications of keys being pressed down.
104 onKeyPress
: connectToDomNode
,
106 onKeyPress: function(event){
108 // Connect to this function to receive notifications of printable keys being typed.
115 onKeyUp
: connectToDomNode
,
117 onKeyUp: function(event){
119 // Connect to this function to receive notifications of keys being released.
126 onMouseDown
: connectToDomNode
,
128 onMouseDown: function(event){
130 // Connect to this function to receive notifications of when the mouse button is pressed down.
137 onMouseMove
: connectToDomNode
,
139 onMouseMove: function(event){
141 // Connect to this function to receive notifications of when the mouse moves over nodes contained within this widget.
148 onMouseOut
: connectToDomNode
,
150 onMouseOut: function(event){
152 // Connect to this function to receive notifications of when the mouse moves off of nodes contained within this widget.
159 onMouseOver
: connectToDomNode
,
161 onMouseOver: function(event){
163 // Connect to this function to receive notifications of when the mouse moves onto nodes contained within this widget.
170 onMouseLeave
: connectToDomNode
,
172 onMouseLeave: function(event){
174 // Connect to this function to receive notifications of when the mouse moves off of this widget.
181 onMouseEnter
: connectToDomNode
,
183 onMouseEnter: function(event){
185 // Connect to this function to receive notifications of when the mouse moves onto this widget.
192 onMouseUp
: connectToDomNode
,
194 onMouseUp: function(event){
196 // Connect to this function to receive notifications of when the mouse button is released.
204 constructor: function(params
/*===== ,srcNodeRef =====*/){
206 // Create the widget.
207 // params: Object|null
208 // Hash of initialization parameters for widget, including scalar values (like title, duration etc.)
209 // and functions, typically callbacks like onClick.
210 // The hash can contain any of the widget's properties, excluding read-only properties.
211 // srcNodeRef: DOMNode|String?
212 // If a srcNodeRef (DOM node) is specified:
214 // - use srcNodeRef.innerHTML as my contents
215 // - if this is a behavioral widget then apply behavior to that srcNodeRef
216 // - otherwise, replace srcNodeRef with my generated DOM tree
218 // extract parameters like onMouseMove that should connect directly to this.domNode
219 this._toConnect
= {};
220 for(var name
in params
){
221 if(this[name
] === connectToDomNode
){
222 this._toConnect
[name
.replace(/^on/, "").toLowerCase()] = params
[name
];
228 postCreate: function(){
229 this.inherited(arguments
);
231 // perform connection from this.domNode to user specified handlers (ex: onMouseMove)
232 for(var name
in this._toConnect
){
233 this.on(name
, this._toConnect
[name
]);
235 delete this._toConnect
;
238 on: function(/*String|Function*/ type
, /*Function*/ func
){
239 if(this[this._onMap(type
)] === connectToDomNode
){
240 // Use connect.connect() rather than on() to get handling for "onmouseenter" on non-IE,
241 // normalization of onkeypress/onkeydown to behave like firefox, etc.
242 // Also, need to specify context as "this" rather than the default context of the DOMNode
244 return connect
.connect(this.domNode
, type
.toLowerCase(), this, func
);
246 return this.inherited(arguments
);
249 _setFocusedAttr: function(val
){
250 // Remove this method in 2.0 (or sooner), just here to set _focused == focused, for back compat
251 // (but since it's a private variable we aren't required to keep supporting it).
253 this._set("focused", val
);
256 ////////////////// DEPRECATED METHODS ///////////////////
258 setAttribute: function(/*String*/ attr
, /*anything*/ value
){
260 // Deprecated. Use set() instead.
263 kernel
.deprecated(this.declaredClass
+"::setAttribute(attr, value) is deprecated. Use set() instead.", "", "2.0");
264 this.set(attr
, value
);
267 attr: function(/*String|Object*/name
, /*Object?*/value
){
269 // Set or get properties on a widget instance.
271 // The property to get or set. If an object is passed here and not
272 // a string, its keys are used as names of attributes to be set
273 // and the value of the object as values to set in the widget.
275 // Optional. If provided, attr() operates as a setter. If omitted,
276 // the current value of the named property is returned.
278 // This method is deprecated, use get() or set() directly.
280 // Print deprecation warning but only once per calling function
282 var alreadyCalledHash
= arguments
.callee
._ach
|| (arguments
.callee
._ach
= {}),
283 caller
= (arguments
.callee
.caller
|| "unknown caller").toString();
284 if(!alreadyCalledHash
[caller
]){
285 kernel
.deprecated(this.declaredClass
+ "::attr() is deprecated. Use get() or set() instead, called from " +
287 alreadyCalledHash
[caller
] = true;
291 var args
= arguments
.length
;
292 if(args
>= 2 || typeof name
=== "object"){ // setter
293 return this.set.apply(this, arguments
);
295 return this.get(name
);
299 getDescendants: function(){
301 // Returns all the widgets contained by this, i.e., all widgets underneath this.containerNode.
302 // This method should generally be avoided as it returns widgets declared in templates, which are
303 // supposed to be internal/hidden, but it's left here for back-compat reasons.
305 kernel
.deprecated(this.declaredClass
+"::getDescendants() is deprecated. Use getChildren() instead.", "", "2.0");
306 return this.containerNode
? query('[widgetId]', this.containerNode
).map(registry
.byNode
) : []; // dijit/_WidgetBase[]
309 ////////////////// MISCELLANEOUS METHODS ///////////////////
313 // Internal method called when this widget is made visible.
314 // See `onShow` for details.
320 // Called when this widget becomes the selected pane in a
321 // `dijit/layout/TabContainer`, `dijit/layout/StackContainer`,
322 // `dijit/layout/AccordionContainer`, etc.
324 // Also called to indicate display of a `dijit.Dialog`, `dijit.TooltipDialog`, or `dijit.TitlePane`.
331 // Called when another widget becomes the selected pane in a
332 // `dijit/layout/TabContainer`, `dijit/layout/StackContainer`,
333 // `dijit/layout/AccordionContainer`, etc.
335 // Also called to indicate hide of a `dijit.Dialog`, `dijit.TooltipDialog`, or `dijit.TitlePane`.
342 // Called when this widget is being displayed as a popup (ex: a Calendar popped
343 // up from a DateTextBox), and it is hidden.
344 // This is called from the dijit.popup code, and should not be called directly.
346 // Also used as a parameter for children of `dijit/layout/StackContainer` or subclasses.
347 // Callback if a user tries to close the child. Child will be closed if this function returns true.
351 return true; // Boolean
355 // For back-compat, remove in 2.0.
356 if(has("dijit-legacy-requires")){
358 var requires
= ["dijit/_base"];
359 require(requires
); // use indirection so modules not rolled into a build