2
Copyright (c) 2008, Yahoo! Inc. All rights reserved.
3
Code licensed under the BSD License:
4
http://developer.yahoo.net/yui/license.txt
7
YUI.add('widget', function(Y) {
10
* Provides the base Widget class along with an augmentable PluginHost interface
16
* An augmentable class, which when added to a "Base" based class, allows
17
* the class to support Plugins, providing plug and unplug methods and performing
18
* instantiation and cleanup during the init and destroy lifecycle phases respectively.
25
function PluginHost(config) {
28
this.after("init", function(e, cfg) {this._initPlugins(cfg);});
29
this.after("destroy", this._destroyPlugins);
32
PluginHost.prototype = {
35
* Register and instantiate a plugin with the Widget.
39
* @param p {String | Object |Array} Accepts the registered
40
* namespace for the Plugin or an object literal with an "fn" property
41
* specifying the Plugin class and a "cfg" property specifying
42
* the configuration for the Plugin.
44
* Additionally an Array can also be passed in, with either the above String or
45
* Object literal values, allowing for multiple plugin registration in
53
for (var i = 0; i < ln; i++) {
56
} else if (L.isFunction(p)) {
59
this._plug(p.fn, p.cfg);
66
* Unregister and destroy a plugin already instantiated with the Widget.
69
* @param {String} ns The namespace key for the Plugin. If not provided,
70
* all registered plugins are unplugged.
73
unplug: function(ns) {
77
for (ns in this._plugins) {
78
if (Y.Object.owns(this._plugins, ns)) {
87
* Determines if a plugin has been registered and instantiated
92
* @return {Boolean} returns true, if the plugin has been applied
95
hasPlugin : function(ns) {
96
return (this._plugins[ns] && this[ns]);
100
* Initializes static plugins registered on the host (the
101
* "PLUGINS" static property) and any plugins passed in
102
* for the instance through the "plugins" configuration property.
104
* @method _initPlugins
105
* @param {Config} the user configuration object for the host.
108
_initPlugins: function(config) {
110
// Class Configuration
111
var classes = this._getClasses(), constructor;
112
for (var i = 0; i < classes.length; i++) {
113
constructor = classes[i];
114
if (constructor.PLUGINS) {
115
this.plug(constructor.PLUGINS);
119
// User Configuration
120
if (config && config.plugins) {
121
this.plug(config.plugins);
126
* Private method used to unplug and destroy all plugins on the host
127
* @method _destroyPlugins
130
_destroyPlugins: function() {
135
* Private method used to instantiate and attach plugins to the host
137
* @param {Function} PluginClass The plugin class to instantiate
138
* @param {Object} config The configuration object for the plugin
141
_plug: function(PluginClass, config) {
142
if (PluginClass && PluginClass.NS) {
143
var ns = PluginClass.NS;
145
config = config || {};
148
if (this.hasPlugin(ns)) {
150
this[ns].setAtts(config);
152
// Create new instance
153
this[ns] = new PluginClass(config);
154
this._plugins[ns] = PluginClass;
160
* Private method used to unregister and destroy a plugin already instantiated with the host.
164
* @param {String} ns The namespace key for the Plugin. If not provided,
165
* all registered plugins are unplugged.
167
_unplug : function(ns) {
173
if (this._plugins[ns]) {
174
delete this._plugins[ns];
180
Y.PluginHost = PluginHost;
183
* Provides the base Widget class along with an augmentable PluginHost interface
189
var WIDGET = "widget",
193
DISABLED = "disabled",
196
HAS_FOCUS = "hasFocus",
201
BOUNDING_BOX = "boundingBox",
202
CONTENT_BOX = "contentBox",
203
PARENT_NODE = "parentNode",
204
FIRST_CHILD = "firstChild",
205
OWNER_DOCUMENT = "ownerDocument",
207
TAB_INDEX = "tabIndex",
209
INIT_VALUE = "initValue",
212
RENDERED = "rendered",
213
DESTROYED = "destroyed",
215
ContentUpdate = "contentUpdate",
219
ClassNameManager = Y.ClassNameManager;
221
// Widget nodeid-to-instance map for now, 1-to-1.
225
* A base class for widgets, providing:
227
* <li>The render lifecycle method, in addition to the init and destroy
228
* lifecycle methods provide by Base</li>
229
* <li>Abstract methods to support consistent MVC structure across
230
* widgets: renderer, renderUI, bindUI, syncUI</li>
231
* <li>Support for common widget attributes, such as boundingBox, contentBox, visible,
232
* disabled, hasFocus, strings</li>
233
* <li>Plugin registration and activation support</li>
236
* @param config {Object} Object literal specifying widget configuration
243
function Widget(config) {
244
Y.log('constructor called', 'life', 'widget');
246
this._yuid = Y.guid(WIDGET);
249
Widget.superclass.constructor.apply(this, arguments);
253
* The build configuration for the Widget class.
255
* Defines the static fields which need to be aggregated,
256
* when this class is used as the main class passed to
257
* the <a href="Base.html#method_build">Base.build</a> method.
259
* @property _buildCfg
266
aggregates : ["PLUGINS", "HTML_PARSER"]
270
* Static property provides a string to identify the class.
272
* Currently used to apply class identifiers to the bounding box
273
* and to classify events fired by the widget.
276
* @property Widget.NAME
280
Widget.NAME = WIDGET;
283
* Constant used to identify state changes originating from
284
* the DOM (as opposed to the JavaScript model).
286
* @property Widget.UI_SRC
291
Widget.UI_SRC = "ui";
293
var UI = Widget.UI_SRC;
296
* Static property used to define the default attribute
297
* configuration for the Widget.
299
* @property Widget.ATTRS
306
* Flag indicating whether or not this object
307
* has been through the render lifecycle phase.
309
* @attribute rendered
320
* @attribute boundingBox
321
* @description The outermost DOM node for the Widget, used for sizing and positioning
322
* of a Widget as well as a containing element for any decorator elements used
328
set: function(node) {
329
return this._setBoundingBox(node);
335
* @attribute contentBox
336
* @description A DOM node that is a direct descendent of a Widget's bounding box that
337
* houses its content.
342
set: function(node) {
343
return this._setContentBox(node);
349
* @attribute tabIndex
350
* @description The tabIndex, applied to the bounding box
358
* @attribute hasFocus
359
* @description Boolean indicating if the Widget has focus.
368
* @attribute disabled
369
* @description Boolean indicating if the Widget should be disabled. The disabled implementation
370
* is left to the specific classes extending widget.
380
* @description Boolean indicating weather or not the Widget is visible.
390
* @description String with units, or number, representing the height of the Widget. If a number is provided,
391
* the default unit, defined by the Widgets DEF_UNIT, property is used.
393
* @type {String | Number}
401
* @description String with units, or number, representing the width of the Widget. If a number is provided,
402
* the default unit, defined by the Widgets DEF_UNIT, property is used.
404
* @type {String | Number}
411
* @attribute moveStyles
412
* @description Flag defining whether or not style properties from the content box
413
* should be moved to the bounding box when wrapped (as defined by the WRAP_STYLES property)
424
* The default locale for the widget. NOTE: Using get/set on the "strings" attribute will
425
* return/set strings for this locale.
435
* @description Collection of strings used to label elements of the Widget's UI.
441
return this._setStrings(val, this.get(LOCALE));
445
return this.getStrings(this.get(LOCALE));
451
* Cached lowercase version of Widget.NAME
453
* @property Widget._NAME_LOWERCASE
457
Widget._NAME_LOWERCASE = Widget.NAME.toLowerCase();
460
* Generate a standard prefixed classname for the Widget, prefixed by the default prefix defined
461
* by the <code>Y.config.classNamePrefix</code> attribute used by <code>ClassNameManager</code> and
462
* <code>Widget.NAME.toLowerCase()</code> (e.g. "yui-widget-xxxxx-yyyyy", based on default values for
463
* the prefix and widget class name).
465
* The instance based version of this method can be used to generate standard prefixed classnames,
466
* based on the instances NAME, as opposed to Widget.NAME. This method should be used when you
467
* need to use a constant class name across different types instances.
469
* @method getClassName
470
* @param {String*} args* 0..n strings which should be concatenated, using the default separator defined by ClassNameManager, to create the class name
472
Widget.getClassName = function() {
473
var args = Y.Array(arguments, 0, true);
474
args.splice(0, 0, this._NAME_LOWERCASE);
475
return ClassNameManager.getClassName.apply(ClassNameManager, args);
479
* Returns the widget instance whose bounding box contains, or is, the given node.
481
* In the case of nested widgets, the nearest bounding box ancestor is used to
482
* return the widget instance.
484
* @method Widget.getByNode
486
* @param node {Node | String} The node for which to return a Widget instance. If a selector
487
* string is passed in, which selects more than one node, the first node found is used.
488
* @return {Widget} Widget instance, or null if not found.
490
Widget.getByNode = function(node) {
492
bbMarker = Widget.getClassName();
494
node = Node.get(node);
496
node = (node.hasClass(bbMarker)) ? node : node.ancestor("." + bbMarker);
498
widget = _instances[node.get(ID)];
502
return widget || null;
506
* Object hash, defining how attribute values are to be parsed from
507
* markup contained in the widget's content box. e.g.:
510
* // Set single Node references using selector syntax
511
* // (selector is run through node.query)
512
* titleNode: "span.yui-title",
513
* // Set NodeList references using selector syntax
514
* // (array indicates selector is to be run through node.queryAll)
515
* listNodes: ["li.yui-item"],
516
* // Set other attribute types, using a parse function.
517
* // Context is set to the widget instance.
518
* label: function(contentBox) {
519
* return contentBox.query("span.title").get("innerHTML");
524
* @property Widget.HTML_PARSER
528
Widget.HTML_PARSER = {};
530
Y.extend(Widget, Y.Base, {
533
* Returns a class name prefixed with the the value of the
534
* <code>YUI.config.classNamePrefix</code> attribute + the instances <code>NAME</code> property.
535
* Uses <code>YUI.config.classNameDelimiter</code> attribute to delimit the provided strings.
539
* // returns "yui-slider-foo-bar", for a slider instance
540
* var scn = slider.getClassName('foo','bar');
542
* // returns "yui-overlay-foo-bar", for an overlay instance
543
* var ocn = slider.getClassName('foo','bar');
547
* @method getClassName
548
* @param {String}+ One or more classname bits to be joined and prefixed
550
getClassName: function () {
551
var args = Y.Array(arguments, 0, true);
552
args.splice(0, 0, this._name);
553
return ClassNameManager.getClassName.apply(ClassNameManager, args);
557
* Initializer lifecycle implementation for the Widget class. Registers the
558
* widget instance, and runs through the Widget's HTML_PARSER definition.
560
* @method initializer
562
* @param config {Object} Configuration object literal for the widget
564
initializer: function(config) {
565
Y.log('initializer called', 'life', 'widget');
568
* Notification event, which widget implementations can fire, when
569
* they change the content of the widget. This event has no default
570
* behavior and cannot be prevented, so the "on" or "after"
571
* moments are effectively equivalent (with on listeners being invoked before
574
* @event widget:contentUpdate
576
* @param {Event.Facade} e The Event Facade
578
this.publish(ContentUpdate, { preventable:false });
580
this._name = this.constructor.NAME.toLowerCase();
582
var nodeId = this.get(BOUNDING_BOX).get(ID);
584
_instances[nodeId] = this;
587
var htmlConfig = this._parseHTML(this.get(CONTENT_BOX));
589
Y.aggregate(config, htmlConfig, false);
592
Y.PluginHost.call(this, config);
596
* Descructor lifecycle implementation for the Widget class. Purges events attached
597
* to the bounding box (and all child nodes) and removes the Widget from the
598
* list of registered widgets.
603
destructor: function() {
604
Y.log('destructor called', 'life', 'widget');
606
var boundingBox = this.get(BOUNDING_BOX);
608
Y.Event.purgeElement(boundingBox, true);
610
var nodeId = boundingBox.get(ID);
611
if (nodeId && nodeId in _instances) {
612
delete _instances[nodeId];
617
* Establishes the initial DOM for the widget. Invoking this
618
* method will lead to the creating of all DOM elements for
619
* the widget (or the manipulation of existing DOM elements
620
* for the progressive enhancement use case).
622
* This method should only be invoked once for an initialized
626
* It delegates to the widget specific renderer method to do
633
* @param parentNode {Object | String} Optional. The Node under which the
634
* Widget is to be rendered. This can be a Node instance or a CSS selector string.
636
* If the selector string returns more than one Node, the first node will be used
637
* as the parentNode. NOTE: This argument is required if both the boundingBox and contentBox
638
* are not currently in the document. If it's not provided, the Widget will be rendered
639
* to the body of the current document in this case.
642
render: function(parentNode) {
644
if (this.get(DESTROYED)) {
645
Y.log("Render failed; widget has been destroyed", "error", "widget");
649
if (!this.get(RENDERED)) {
651
* Lifcyle event for the render phase, fired prior to rendering the UI
652
* for the widget (prior to invoking the widgets renderer method).
654
* Subscribers to the "on" moment of this event, will be notified
655
* before the widget is rendered.
658
* Subscribers to the "after" momemt of this event, will be notified
659
* after rendering is complete.
662
* @event widget:render
663
* @preventable _defRenderFn
664
* @param {Event.Facade} e The Event Facade
666
this.publish(RENDER, {queuable:false, defaultFn: this._defRenderFn});
668
parentNode = (parentNode) ? Node.get(parentNode) : null;
669
if (parentNode && !parentNode.inDoc()) {
673
this.fire(RENDER, null, parentNode);
680
* Default render handler
682
* @method _defRenderFn
684
* @param {Event.Facade} e The Event object
685
* @param {Node} parentNode The parent node to render to, if passed in to the <code>render</code> method
687
_defRenderFn : function(e, parentNode) {
689
this._renderUI(parentNode);
695
this._set(RENDERED, true);
699
* Creates DOM (or manipulates DOM for progressive enhancement)
700
* This method is invoked by render() and is not chained
701
* automatically for the class hierarchy (like initializer, destructor)
702
* so it should be chained manually for subclasses if required.
707
renderer: function() {
714
* Configures/Sets up listeners to bind Widget State to UI/DOM
716
* This method is not called by framework and is not chained
717
* automatically for the class hierarchy.
722
bindUI: function() {},
725
* Adds nodes to the DOM
727
* This method is not called by framework and is not chained
728
* automatically for the class hierarchy.
733
renderUI: function() {},
736
* Refreshes the rendered UI, based on Widget State
738
* This method is not called by framework and is not chained
739
* automatically for the class hierarchy.
744
syncUI: function(){},
748
* @description Shows the Module element by setting the "visible" attribute to "false".
751
return this.set(VISIBLE, false);
756
* @description Shows the Module element by setting the "visible" attribute to "true".
759
return this.set(VISIBLE, true);
764
* @description Causes the Widget to receive the focus by setting the "hasFocus"
765
* attribute to "true".
768
return this.set(HAS_FOCUS, true);
773
* @description Causes the Widget to lose focus by setting the "hasFocus" attribute
777
return this.set(HAS_FOCUS, false);
782
* @description Set the Widget's "disabled" attribute to "false".
785
return this.set(DISABLED, false);
790
* @description Set the Widget's "disabled" attribute to "true".
792
disable: function() {
793
return this.set(DISABLED, true);
797
* Utilitity method used to apply the <code>HTML_PARSER</code> configuration for the
798
* instance, to retrieve config data values.
802
* @param node {Node} Root node to use to parse markup for configuration data
803
* @return config {Object} configuration object, with values found in the HTML, populated
805
_parseHTML : function(node) {
807
var schema = this._getHtmlParser(),
811
if (schema && node && node.hasChildNodes()) {
813
O.each(schema, function(v, k, o) {
816
if (L.isFunction(v)) {
817
val = v.call(this, node);
820
val = node.queryAll(v[0]);
826
if (val !== null && val !== undefined) {
838
* Moves a pre-defined set of style rules (WRAP_STYLES) from one node to another.
840
* @method _moveStyles
842
* @param {Node} nodeFrom The node to gather the styles from
843
* @param {Node} nodeTo The node to apply the styles to
845
_moveStyles: function(nodeFrom, nodeTo) {
847
var styles = this.WRAP_STYLES,
848
pos = nodeFrom.getStyle('position'),
849
contentBox = this.get(CONTENT_BOX),
853
if (!this.get('height')) {
854
h = contentBox.get('offsetHeight');
857
if (!this.get('width')) {
858
w = contentBox.get('offsetWidth');
861
if (pos === 'absolute') {
862
xy = nodeFrom.getXY();
874
Y.each(styles, function(v, k) {
875
var s = nodeFrom.getStyle(k);
876
nodeTo.setStyle(k, s);
878
nodeFrom.setStyle(k, '');
880
nodeFrom.setStyle(k, v);
884
if (pos === 'absolute') {
889
this.set('height', h);
893
this.set('width', w);
898
* Helper method to collect the boundingBox and contentBox, set styles and append to the provided parentNode, if not
899
* already a child. The owner document of the boundingBox, or the owner document of the contentBox will be used
900
* as the document into which the Widget is rendered if a parentNode is node is not provided. If both the boundingBox and
901
* the contentBox are not currently in the document, and no parentNode is provided, the widget will be rendered
902
* to the current document's body.
906
* @param {Node} parentNode The parentNode to render the widget to. If not provided, and both the boundingBox and
907
* the contentBox are not currently in the document, the widget will be rendered to the current document's body.
909
_renderBox: function(parentNode) {
911
var contentBox = this.get(CONTENT_BOX),
912
boundingBox = this.get(BOUNDING_BOX),
913
doc = boundingBox.get(OWNER_DOCUMENT) || contentBox.get(OWNER_DOCUMENT),
916
if (!boundingBox.compareTo(contentBox.get(PARENT_NODE))) {
917
if (this.get('moveStyles')) {
918
this._moveStyles(contentBox, boundingBox);
920
// If contentBox box is already in the document, have boundingBox box take it's place
921
if (contentBox.inDoc(doc)) {
922
contentBox.get(PARENT_NODE).replaceChild(boundingBox, contentBox);
924
boundingBox.appendChild(contentBox);
927
if (!boundingBox.inDoc(doc) && !parentNode) {
928
body = Node.get(BODY);
929
if (body.get(FIRST_CHILD)) {
930
// Special case when handling body as default (no parentNode), always try to insert.
931
body.insertBefore(boundingBox, body.get(FIRST_CHILD));
933
body.appendChild(boundingBox);
936
if (parentNode && !parentNode.compareTo(boundingBox.get(PARENT_NODE))) {
937
parentNode.appendChild(boundingBox);
943
* Setter for the boundingBox attribute
945
* @method _setBoundingBox
950
_setBoundingBox: function(node) {
951
return this._setBox(node, this.BOUNDING_TEMPLATE);
955
* Setter for the contentBox attribute
957
* @method _setContentBox
959
* @param {Node|String} node
962
_setContentBox: function(node) {
963
return this._setBox(node, this.CONTENT_TEMPLATE);
967
* Helper method to set the bounding/content box, or create it from
968
* the provided template if not found.
973
* @param {Node|String} node The node reference
974
* @param {String} template HTML string template for the node
975
* @return {Node} The node
977
_setBox : function(node, template) {
978
node = Node.get(node) || Node.create(template);
980
var sid = Y.stamp(node);
988
* Initializes the UI state for the Widget's bounding/content boxes.
992
* @param {Node} The parent node to rendering the widget into
994
_renderUI: function(parentNode) {
995
this._renderBoxClassNames();
996
this._renderBox(parentNode);
1000
* Applies standard class names to the boundingBox and contentBox
1002
* @method _renderBoxClassNames
1005
_renderBoxClassNames : function() {
1006
var classes = this._getClasses(),
1007
boundingBox = this.get(BOUNDING_BOX),
1008
contentBox = this.get(CONTENT_BOX),
1011
boundingBox.addClass(Widget.getClassName());
1013
// Start from Widget Sub Class
1014
for (var i = 2, l = classes.length; i < l; ++i) {
1015
name = classes[i].NAME;
1017
boundingBox.addClass(ClassNameManager.getClassName(name.toLowerCase()));
1021
// Use instance based name for content box
1022
contentBox.addClass(this.getClassName(CONTENT));
1026
* Sets up DOM and CustomEvent listeners for the widget.
1031
_bindUI: function() {
1032
this.after('visibleChange', this._afterVisibleChange);
1033
this.after('disabledChange', this._afterDisabledChange);
1034
this.after('heightChange', this._afterHeightChange);
1035
this.after('widthChange', this._afterWidthChange);
1036
this.after('hasFocusChange', this._afterHasFocusChange);
1038
this._bindDOMListeners();
1042
* Sets up DOM listeners, on elements rendered by the widget.
1044
* @method _bindDOMListeners
1047
_bindDOMListeners : function() {
1048
this.get(BOUNDING_BOX).on(FOCUS, Y.bind(this._onFocus, this));
1049
this.get(BOUNDING_BOX).on(BLUR, Y.bind(this._onBlur, this));
1053
* Updates the widget UI to reflect the attribute state.
1058
_syncUI: function() {
1059
this._uiSetVisible(this.get(VISIBLE));
1060
this._uiSetDisabled(this.get(DISABLED));
1061
this._uiSetHeight(this.get(HEIGHT));
1062
this._uiSetWidth(this.get(WIDTH));
1063
this._uiSetHasFocus(this.get(HAS_FOCUS));
1064
this._uiSetTabIndex(this.get(TAB_INDEX));
1068
* Sets the height on the widget's bounding box element
1070
* @method _uiSetHeight
1072
* @param {String | Number} val
1074
_uiSetHeight: function(val) {
1075
if (L.isNumber(val)) {
1076
val = val + this.DEF_UNIT;
1078
this.get(BOUNDING_BOX).setStyle(HEIGHT, val);
1082
* Sets the width on the widget's bounding box element
1084
* @method _uiSetWidth
1086
* @param {String | Number} val
1088
_uiSetWidth: function(val) {
1089
if (L.isNumber(val)) {
1090
val = val + this.DEF_UNIT;
1092
this.get(BOUNDING_BOX).setStyle(WIDTH, val);
1096
* Sets the visible state for the UI
1098
* @method _uiSetVisible
1100
* @param {boolean} val
1102
_uiSetVisible: function(val) {
1104
var box = this.get(BOUNDING_BOX),
1105
sClassName = this.getClassName(HIDDEN);
1108
box.removeClass(sClassName);
1110
box.addClass(sClassName);
1115
* Sets the disabled state for the UI
1118
* @param {boolean} val
1120
_uiSetDisabled: function(val) {
1122
var box = this.get(BOUNDING_BOX),
1123
sClassName = this.getClassName(DISABLED);
1126
box.addClass(sClassName);
1128
box.removeClass(sClassName);
1133
* Sets the hasFocus state for the UI
1136
* @param {boolean} val
1137
* @param {string} src String representing the source that triggered an update to
1140
_uiSetHasFocus: function(val, src) {
1142
var box = this.get(BOUNDING_BOX),
1143
sClassName = this.getClassName(FOCUS);
1146
box.addClass(sClassName);
1151
box.removeClass(sClassName);
1159
* Set the tabIndex on the widget's rendered UI
1161
* @method _uiSetTabIndex
1165
_uiSetTabIndex: function(index) {
1166
this.get(BOUNDING_BOX).set(TAB_INDEX, index);
1170
* Default visible attribute state change handler
1172
* @method _afterVisibleChange
1174
* @param {Event.Facade} evt The event facade for the attribute change
1176
_afterVisibleChange: function(evt) {
1177
this._uiSetVisible(evt.newVal);
1181
* Default disabled attribute state change handler
1183
* @method _afterDisabledChange
1185
* @param {Event.Facade} evt The event facade for the attribute change
1187
_afterDisabledChange: function(evt) {
1188
this._uiSetDisabled(evt.newVal);
1192
* Default height attribute state change handler
1194
* @method _afterHeightChange
1196
* @param {Event.Facade} evt The event facade for the attribute change
1198
_afterHeightChange: function(evt) {
1199
this._uiSetHeight(evt.newVal);
1203
* Default widget attribute state change handler
1205
* @method _afterWidthChange
1207
* @param {Event.Facade} evt The event facade for the attribute change
1209
_afterWidthChange: function(evt) {
1210
this._uiSetWidth(evt.newVal);
1214
* Default hasFocus attribute state change handler
1216
* @method _afterHasFocusChange
1218
* @param {Event.Facade} evt The event facade for the attribute change
1220
_afterHasFocusChange: function(evt) {
1221
this._uiSetHasFocus(evt.newVal, evt.src);
1225
* DOM focus event handler, used to sync the state of the Widget with the DOM
1229
* @param {Event.Facade} evt The event facade for the DOM focus event
1231
_onFocus: function (evt) {
1232
this.set(HAS_FOCUS, true, { src: UI });
1236
* DOM blur event handler, used to sync the state of the Widget with the DOM
1240
* @param {Event.Facade} evt The event facade for the DOM blur event
1242
_onBlur: function (evt) {
1243
this.set(HAS_FOCUS, false, { src: UI });
1247
* Generic toString implementation for all widgets.
1250
* @return {String} The default string value for the widget [ displays the NAME of the instance, and the unique id ]
1252
toString: function() {
1253
return this.constructor.NAME + "[" + this._yuid + "]";
1257
* Default unit to use for dimension values
1259
* @property DEF_UNIT
1264
* Static property defining the markup template for content box.
1266
* @property CONTENT_TEMPLATE
1269
CONTENT_TEMPLATE : "<div></div>",
1272
* Static property defining the markup template for bounding box.
1274
* @property BOUNDING_TEMPLATE
1277
BOUNDING_TEMPLATE : "<div></div>",
1280
* Static property listing the styles that are mimiced on the bounding box from the content box.
1282
* @property WRAP_STYLES
1299
* Sets strings for a particular locale, merging with any existing
1300
* strings which may already be defined for the locale.
1302
* @method _setStrings
1304
* @param {Object} strings The hash of string key/values to set
1305
* @param {Object} locale The locale for the string values being set
1307
_setStrings : function(strings, locale) {
1308
var strs = this._strings;
1309
locale = locale.toLowerCase();
1311
if (!strs[locale]) {
1315
Y.aggregate(strs[locale], strings, true);
1316
return strs[locale];
1320
* Returns the strings key/value hash for a paricular locale, without locale lookup applied.
1322
* @method _getStrings
1324
* @param {Object} locale
1326
_getStrings : function(locale) {
1327
return this._strings[locale.toLowerCase()];
1331
* Gets the entire strings hash for a particular locale, performing locale lookup.
1333
* If no values of the key are defined for a particular locale the value for the
1334
* default locale (in initial locale set for the class) is returned.
1336
* @method getStrings
1337
* @param {String} locale (optional) The locale for which the string value is required. Defaults to the current locale, if not provided.
1339
// TODO: Optimize/Cache. Clear cache on _setStrings call.
1340
getStrings : function(locale) {
1342
locale = (locale || this.get(LOCALE)).toLowerCase();
1344
Y.log("getStrings: For " + locale, "info", "widget");
1346
var defLocale = this.getDefaultLocale().toLowerCase(),
1347
defStrs = this._getStrings(defLocale),
1348
strs = (defStrs) ? Y.merge(defStrs) : {},
1349
localeSegments = locale.split(HYPHEN);
1351
// If locale is different than the default, or needs lookup support
1352
if (locale !== defLocale || localeSegments.length > 1) {
1354
for (var i = 0, l = localeSegments.length; i < l; ++i) {
1355
lookup += localeSegments[i];
1357
Y.log("getStrings: Merging in strings from: " + lookup, "info", "widget");
1359
var localeStrs = this._getStrings(lookup);
1361
Y.aggregate(strs, localeStrs, true);
1371
* Gets the string for a particular key, for a particular locale, performing locale lookup.
1373
* If no values if defined for the key, for the given locale, the value for the
1374
* default locale (in initial locale set for the class) is returned.
1377
* @param {String} key The key.
1378
* @param {String} locale (optional) The locale for which the string value is required. Defaults to the current locale, if not provided.
1380
getString : function(key, locale) {
1382
locale = (locale || this.get(LOCALE)).toLowerCase();
1384
Y.log("getString: For " + locale, "info", "widget");
1386
var defLocale = (this.getDefaultLocale()).toLowerCase(),
1387
strs = this._getStrings(defLocale) || {},
1389
idx = locale.lastIndexOf(HYPHEN);
1391
// If locale is different than the default, or needs lookup support
1392
if (locale !== defLocale || idx != -1) {
1394
Y.log("getString: Performing lookup for: " + locale, "info", "widget");
1396
strs = this._getStrings(locale);
1397
if (strs && key in strs) {
1401
idx = locale.lastIndexOf(HYPHEN);
1402
// Chop of last locale segment
1404
locale = locale.substring(0, idx);
1407
} while (idx != -1);
1414
* Returns the default locale for the widget (the locale value defined by the
1415
* widget class, or provided by the user during construction).
1417
* @method getDefaultLocale
1418
* @return {String} The default locale for the widget
1420
getDefaultLocale : function() {
1421
return this._conf.get(LOCALE, INIT_VALUE);
1425
* Private stings hash, used to store strings in locale specific buckets.
1427
* @property _strings
1434
* Gets the HTML_PARSER definition for this instance, by merging HTML_PARSER
1435
* definitions across the class hierarchy.
1437
* @method _getHtmlParser
1438
* @return {Object} HTML_PARSER definition for this instance
1440
_getHtmlParser : function() {
1441
if (!this._HTML_PARSER) {
1442
var classes = this._getClasses(),
1445
for (var i = 0, l = classes.length; i < l; i++) {
1446
var p = classes[i].HTML_PARSER;
1448
Y.mix(parser, p, true);
1452
this._HTML_PARSER = parser;
1455
return this._HTML_PARSER;
1460
* Static registration of default plugins for the class.
1462
* @property Widget.PLUGINS
1465
Widget.PLUGINS = [];
1467
Y.mix(Widget, Y.PluginHost, false, null, 1); // straightup augment, no wrapper functions
1473
}, '3.0.0pr2' ,{requires:['base', 'node', 'classnamemanager']});