2 Copyright (c) 2009, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.net/yui/license.txt
8 YUI.add('widget', function(Y) {
11 * Provides the base Widget class
20 ClassNameManager = Y.ClassNameManager,
26 DISABLED = "disabled",
32 BOUNDING_BOX = "boundingBox",
33 CONTENT_BOX = "contentBox",
34 PARENT_NODE = "parentNode",
35 FIRST_CHILD = "firstChild",
36 OWNER_DOCUMENT = "ownerDocument",
38 TAB_INDEX = "tabIndex",
40 INIT_VALUE = "initValue",
43 RENDERED = "rendered",
44 DESTROYED = "destroyed",
46 ContentUpdate = "contentUpdate",
48 // Widget nodeid-to-instance map for now, 1-to-1.
52 * A base class for widgets, providing:
54 * <li>The render lifecycle method, in addition to the init and destroy
55 * lifecycle methods provide by Base</li>
56 * <li>Abstract methods to support consistent MVC structure across
57 * widgets: renderer, renderUI, bindUI, syncUI</li>
58 * <li>Support for common widget attributes, such as boundingBox, contentBox, visible,
59 * disabled, focused, strings</li>
62 * @param config {Object} Object literal specifying widget configuration
69 function Widget(config) {
71 this._yuid = Y.guid(WIDGET);
74 Widget.superclass.constructor.apply(this, arguments);
78 * The build configuration for the Widget class.
80 * Defines the static fields which need to be aggregated,
81 * when this class is used as the main class passed to
82 * the <a href="Base.html#method_build">Base.build</a> method.
91 aggregates : ["HTML_PARSER"]
95 * Static property provides a string to identify the class.
97 * Currently used to apply class identifiers to the bounding box
98 * and to classify events fired by the widget.
101 * @property Widget.NAME
105 Widget.NAME = WIDGET;
108 * Constant used to identify state changes originating from
109 * the DOM (as opposed to the JavaScript model).
111 * @property Widget.UI_SRC
116 Widget.UI_SRC = "ui";
118 var UI = Widget.UI_SRC;
121 * Static property used to define the default attribute
122 * configuration for the Widget.
124 * @property Widget.ATTRS
131 * Flag indicating whether or not this object
132 * has been through the render lifecycle phase.
134 * @attribute rendered
145 * @attribute boundingBox
146 * @description The outermost DOM node for the Widget, used for sizing and positioning
147 * of a Widget as well as a containing element for any decorator elements used
153 setter: function(node) {
154 return this._setBoundingBox(node);
160 * @attribute contentBox
161 * @description A DOM node that is a direct descendent of a Widget's bounding box that
162 * houses its content.
167 setter: function(node) {
168 return this._setContentBox(node);
174 * @attribute tabIndex
175 * @description Number (between -32767 to 32767) indicating the widget's
176 * position in the default tab flow. The value is used to set the
177 * "tabIndex" attribute on the widget's bounding box. Negative values allow
178 * the widget to receive DOM focus programmatically (by calling the focus
179 * method), while being removed from the default tab flow. A value of
180 * null removes the "tabIndex" attribute from the widget's bounding box.
187 validator: function (val) {
188 return (L.isNumber(val) || L.isNull(val));
195 * @description Boolean indicating if the Widget, or one of its descendants,
207 * @attribute disabled
208 * @description Boolean indicating if the Widget should be disabled. The disabled implementation
209 * is left to the specific classes extending widget.
219 * @description Boolean indicating weather or not the Widget is visible.
229 * @description String with units, or number, representing the height of the Widget. If a number is provided,
230 * the default unit, defined by the Widgets DEF_UNIT, property is used.
232 * @type {String | Number}
240 * @description String with units, or number, representing the width of the Widget. If a number is provided,
241 * the default unit, defined by the Widgets DEF_UNIT, property is used.
243 * @type {String | Number}
250 * @attribute moveStyles
251 * @description Flag defining whether or not style properties from the content box
252 * should be moved to the bounding box when wrapped (as defined by the WRAP_STYLES property)
263 * The default locale for the widget. NOTE: Using get/set on the "strings" attribute will
264 * return/set strings for this locale.
274 * @description Collection of strings used to label elements of the Widget's UI.
279 setter: function(val) {
280 return this._setStrings(val, this.get(LOCALE));
284 return this.getStrings(this.get(LOCALE));
290 * Cached lowercase version of Widget.NAME
292 * @property Widget._NAME_LOWERCASE
296 Widget._NAME_LOWERCASE = Widget.NAME.toLowerCase();
299 * Generate a standard prefixed classname for the Widget, prefixed by the default prefix defined
300 * by the <code>Y.config.classNamePrefix</code> attribute used by <code>ClassNameManager</code> and
301 * <code>Widget.NAME.toLowerCase()</code> (e.g. "yui-widget-xxxxx-yyyyy", based on default values for
302 * the prefix and widget class name).
304 * The instance based version of this method can be used to generate standard prefixed classnames,
305 * based on the instances NAME, as opposed to Widget.NAME. This method should be used when you
306 * need to use a constant class name across different types instances.
308 * @method getClassName
309 * @param {String*} args* 0..n strings which should be concatenated, using the default separator defined by ClassNameManager, to create the class name
311 Widget.getClassName = function() {
312 var args = Y.Array(arguments, 0, true);
313 args.splice(0, 0, this._NAME_LOWERCASE);
314 return ClassNameManager.getClassName.apply(ClassNameManager, args);
318 * Returns the widget instance whose bounding box contains, or is, the given node.
320 * In the case of nested widgets, the nearest bounding box ancestor is used to
321 * return the widget instance.
323 * @method Widget.getByNode
325 * @param node {Node | String} The node for which to return a Widget instance. If a selector
326 * string is passed in, which selects more than one node, the first node found is used.
327 * @return {Widget} Widget instance, or null if not found.
329 Widget.getByNode = function(node) {
331 bbMarker = Widget.getClassName();
333 node = Node.get(node);
335 node = (node.hasClass(bbMarker)) ? node : node.ancestor("." + bbMarker);
337 widget = _instances[node.get(ID)];
341 return widget || null;
345 * Object hash, defining how attribute values are to be parsed from
346 * markup contained in the widget's content box. e.g.:
349 * // Set single Node references using selector syntax
350 * // (selector is run through node.query)
351 * titleNode: "span.yui-title",
352 * // Set NodeList references using selector syntax
353 * // (array indicates selector is to be run through node.queryAll)
354 * listNodes: ["li.yui-item"],
355 * // Set other attribute types, using a parse function.
356 * // Context is set to the widget instance.
357 * label: function(contentBox) {
358 * return contentBox.query("span.title").get("innerHTML");
363 * @property Widget.HTML_PARSER
367 Widget.HTML_PARSER = {};
369 Y.extend(Widget, Y.Base, {
372 * Returns a class name prefixed with the the value of the
373 * <code>YUI.config.classNamePrefix</code> attribute + the instances <code>NAME</code> property.
374 * Uses <code>YUI.config.classNameDelimiter</code> attribute to delimit the provided strings.
378 * // returns "yui-slider-foo-bar", for a slider instance
379 * var scn = slider.getClassName('foo','bar');
381 * // returns "yui-overlay-foo-bar", for an overlay instance
382 * var ocn = slider.getClassName('foo','bar');
386 * @method getClassName
387 * @param {String}+ One or more classname bits to be joined and prefixed
389 getClassName: function () {
390 var args = Y.Array(arguments, 0, true);
391 args.splice(0, 0, this._name);
392 return ClassNameManager.getClassName.apply(ClassNameManager, args);
396 * Initializer lifecycle implementation for the Widget class. Registers the
397 * widget instance, and runs through the Widget's HTML_PARSER definition.
399 * @method initializer
401 * @param config {Object} Configuration object literal for the widget
403 initializer: function(config) {
406 * Notification event, which widget implementations can fire, when
407 * they change the content of the widget. This event has no default
408 * behavior and cannot be prevented, so the "on" or "after"
409 * moments are effectively equivalent (with on listeners being invoked before
412 * @event widget:contentUpdate
414 * @param {EventFacade} e The Event Facade
416 this.publish(ContentUpdate, { preventable:false });
418 this._name = this.constructor.NAME.toLowerCase();
420 var nodeId = this.get(BOUNDING_BOX).get(ID);
422 _instances[nodeId] = this;
425 var htmlConfig = this._parseHTML(this.get(CONTENT_BOX));
427 Y.aggregate(config, htmlConfig, false);
432 * Descructor lifecycle implementation for the Widget class. Purges events attached
433 * to the bounding box (and all child nodes) and removes the Widget from the
434 * list of registered widgets.
439 destructor: function() {
441 var boundingBox = this.get(BOUNDING_BOX);
443 Y.Event.purgeElement(boundingBox, true);
445 var nodeId = boundingBox.get(ID);
446 if (nodeId && nodeId in _instances) {
447 delete _instances[nodeId];
452 * Establishes the initial DOM for the widget. Invoking this
453 * method will lead to the creating of all DOM elements for
454 * the widget (or the manipulation of existing DOM elements
455 * for the progressive enhancement use case).
457 * This method should only be invoked once for an initialized
461 * It delegates to the widget specific renderer method to do
468 * @param parentNode {Object | String} Optional. The Node under which the
469 * Widget is to be rendered. This can be a Node instance or a CSS selector string.
471 * If the selector string returns more than one Node, the first node will be used
472 * as the parentNode. NOTE: This argument is required if both the boundingBox and contentBox
473 * are not currently in the document. If it's not provided, the Widget will be rendered
474 * to the body of the current document in this case.
477 render: function(parentNode) {
479 if (this.get(DESTROYED)) {
483 if (!this.get(RENDERED)) {
485 * Lifcyle event for the render phase, fired prior to rendering the UI
486 * for the widget (prior to invoking the widgets renderer method).
488 * Subscribers to the "on" moment of this event, will be notified
489 * before the widget is rendered.
492 * Subscribers to the "after" momemt of this event, will be notified
493 * after rendering is complete.
496 * @event widget:render
497 * @preventable _defRenderFn
498 * @param {EventFacade} e The Event Facade
500 this.publish(RENDER, {queuable:false, defaultFn: this._defRenderFn});
502 parentNode = (parentNode) ? Node.get(parentNode) : null;
503 if (parentNode && !parentNode.inDoc()) {
507 this.fire(RENDER, {parentNode: parentNode});
514 * Default render handler
516 * @method _defRenderFn
518 * @param {EventFacade} e The Event object
519 * @param {Node} parentNode The parent node to render to, if passed in to the <code>render</code> method
521 _defRenderFn : function(e) {
523 this._renderUI(e.parentNode);
529 this._set(RENDERED, true);
533 * Creates DOM (or manipulates DOM for progressive enhancement)
534 * This method is invoked by render() and is not chained
535 * automatically for the class hierarchy (like initializer, destructor)
536 * so it should be chained manually for subclasses if required.
541 renderer: function() {
548 * Configures/Sets up listeners to bind Widget State to UI/DOM
550 * This method is not called by framework and is not chained
551 * automatically for the class hierarchy.
556 bindUI: function() {},
559 * Adds nodes to the DOM
561 * This method is not called by framework and is not chained
562 * automatically for the class hierarchy.
567 renderUI: function() {},
570 * Refreshes the rendered UI, based on Widget State
572 * This method is not called by framework and is not chained
573 * automatically for the class hierarchy.
578 syncUI: function(){},
582 * @description Shows the Module element by setting the "visible" attribute to "false".
585 return this.set(VISIBLE, false);
590 * @description Shows the Module element by setting the "visible" attribute to "true".
593 return this.set(VISIBLE, true);
598 * @description Causes the Widget to receive the focus by setting the "focused"
599 * attribute to "true".
602 return this._set(FOCUSED, true);
607 * @description Causes the Widget to lose focus by setting the "focused" attribute
611 return this._set(FOCUSED, false);
616 * @description Set the Widget's "disabled" attribute to "false".
619 return this.set(DISABLED, false);
624 * @description Set the Widget's "disabled" attribute to "true".
626 disable: function() {
627 return this.set(DISABLED, true);
631 * Utilitity method used to apply the <code>HTML_PARSER</code> configuration for the
632 * instance, to retrieve config data values.
636 * @param node {Node} Root node to use to parse markup for configuration data
637 * @return config {Object} configuration object, with values found in the HTML, populated
639 _parseHTML : function(node) {
641 var schema = this._getHtmlParser(),
645 if (schema && node && node.hasChildNodes()) {
647 O.each(schema, function(v, k, o) {
650 if (L.isFunction(v)) {
651 val = v.call(this, node);
654 val = node.queryAll(v[0]);
660 if (val !== null && val !== undefined) {
672 * Moves a pre-defined set of style rules (WRAP_STYLES) from one node to another.
674 * @method _moveStyles
676 * @param {Node} nodeFrom The node to gather the styles from
677 * @param {Node} nodeTo The node to apply the styles to
679 _moveStyles: function(nodeFrom, nodeTo) {
681 var styles = this.WRAP_STYLES,
682 pos = nodeFrom.getStyle('position'),
683 contentBox = this.get(CONTENT_BOX),
687 if (!this.get('height')) {
688 h = contentBox.get('offsetHeight');
691 if (!this.get('width')) {
692 w = contentBox.get('offsetWidth');
695 if (pos === 'absolute') {
696 xy = nodeFrom.getXY();
708 Y.each(styles, function(v, k) {
709 var s = nodeFrom.getStyle(k);
710 nodeTo.setStyle(k, s);
712 nodeFrom.setStyle(k, '');
714 nodeFrom.setStyle(k, v);
718 if (pos === 'absolute') {
723 this.set('height', h);
727 this.set('width', w);
732 * Helper method to collect the boundingBox and contentBox, set styles and append to the provided parentNode, if not
733 * already a child. The owner document of the boundingBox, or the owner document of the contentBox will be used
734 * as the document into which the Widget is rendered if a parentNode is node is not provided. If both the boundingBox and
735 * the contentBox are not currently in the document, and no parentNode is provided, the widget will be rendered
736 * to the current document's body.
740 * @param {Node} parentNode The parentNode to render the widget to. If not provided, and both the boundingBox and
741 * the contentBox are not currently in the document, the widget will be rendered to the current document's body.
743 _renderBox: function(parentNode) {
745 var contentBox = this.get(CONTENT_BOX),
746 boundingBox = this.get(BOUNDING_BOX),
747 doc = boundingBox.get(OWNER_DOCUMENT) || contentBox.get(OWNER_DOCUMENT),
750 if (!boundingBox.compareTo(contentBox.get(PARENT_NODE))) {
751 if (this.get('moveStyles')) {
752 this._moveStyles(contentBox, boundingBox);
754 // If contentBox box is already in the document, have boundingBox box take it's place
755 if (contentBox.inDoc(doc)) {
756 contentBox.get(PARENT_NODE).replaceChild(boundingBox, contentBox);
758 boundingBox.appendChild(contentBox);
761 if (!boundingBox.inDoc(doc) && !parentNode) {
762 body = Node.get(BODY);
763 if (body.get(FIRST_CHILD)) {
764 // Special case when handling body as default (no parentNode), always try to insert.
765 body.insertBefore(boundingBox, body.get(FIRST_CHILD));
767 body.appendChild(boundingBox);
770 if (parentNode && !parentNode.compareTo(boundingBox.get(PARENT_NODE))) {
771 parentNode.appendChild(boundingBox);
777 * Setter for the boundingBox attribute
779 * @method _setBoundingBox
784 _setBoundingBox: function(node) {
785 return this._setBox(node, this.BOUNDING_TEMPLATE);
789 * Setter for the contentBox attribute
791 * @method _setContentBox
793 * @param {Node|String} node
796 _setContentBox: function(node) {
797 return this._setBox(node, this.CONTENT_TEMPLATE);
801 * Helper method to set the bounding/content box, or create it from
802 * the provided template if not found.
807 * @param {Node|String} node The node reference
808 * @param {String} template HTML string template for the node
809 * @return {Node} The node
811 _setBox : function(node, template) {
812 node = Node.get(node) || Node.create(template);
814 var sid = Y.stamp(node);
822 * Initializes the UI state for the Widget's bounding/content boxes.
826 * @param {Node} The parent node to rendering the widget into
828 _renderUI: function(parentNode) {
829 this._renderBoxClassNames();
830 this._renderBox(parentNode);
834 * Applies standard class names to the boundingBox and contentBox
836 * @method _renderBoxClassNames
839 _renderBoxClassNames : function() {
840 var classes = this._getClasses(),
841 boundingBox = this.get(BOUNDING_BOX),
842 contentBox = this.get(CONTENT_BOX),
845 boundingBox.addClass(Widget.getClassName());
847 // Start from Widget Sub Class
848 for (i = classes.length-3; i >= 0; i--) {
849 name = classes[i].NAME;
851 boundingBox.addClass(ClassNameManager.getClassName(name.toLowerCase()));
855 // Use instance based name for content box
856 contentBox.addClass(this.getClassName(CONTENT));
860 * Sets up DOM and CustomEvent listeners for the widget.
865 _bindUI: function() {
866 this.after('visibleChange', this._afterVisibleChange);
867 this.after('disabledChange', this._afterDisabledChange);
868 this.after('heightChange', this._afterHeightChange);
869 this.after('widthChange', this._afterWidthChange);
870 this.after('focusedChange', this._afterFocusedChange);
872 this._bindDOMListeners();
876 * Sets up DOM listeners, on elements rendered by the widget.
878 * @method _bindDOMListeners
881 _bindDOMListeners : function() {
883 var oDocument = this.get(BOUNDING_BOX).get("ownerDocument");
885 oDocument.on("focus", this._onFocus, this);
888 // Document doesn't receive focus in Webkit when the user mouses
889 // down on it, so the "focused" attribute won't get set to the
893 oDocument.on("mousedown", this._onDocMouseDown, this);
899 * Updates the widget UI to reflect the attribute state.
904 _syncUI: function() {
905 this._uiSetVisible(this.get(VISIBLE));
906 this._uiSetDisabled(this.get(DISABLED));
907 this._uiSetHeight(this.get(HEIGHT));
908 this._uiSetWidth(this.get(WIDTH));
909 this._uiSetFocused(this.get(FOCUSED));
910 this._uiSetTabIndex(this.get(TAB_INDEX));
914 * Sets the height on the widget's bounding box element
916 * @method _uiSetHeight
918 * @param {String | Number} val
920 _uiSetHeight: function(val) {
921 if (L.isNumber(val)) {
922 val = val + this.DEF_UNIT;
924 this.get(BOUNDING_BOX).setStyle(HEIGHT, val);
928 * Sets the width on the widget's bounding box element
930 * @method _uiSetWidth
932 * @param {String | Number} val
934 _uiSetWidth: function(val) {
935 if (L.isNumber(val)) {
936 val = val + this.DEF_UNIT;
938 this.get(BOUNDING_BOX).setStyle(WIDTH, val);
942 * Sets the visible state for the UI
944 * @method _uiSetVisible
946 * @param {boolean} val
948 _uiSetVisible: function(val) {
950 var box = this.get(BOUNDING_BOX),
951 sClassName = this.getClassName(HIDDEN);
954 box.removeClass(sClassName);
956 box.addClass(sClassName);
961 * Sets the disabled state for the UI
964 * @param {boolean} val
966 _uiSetDisabled: function(val) {
968 var box = this.get(BOUNDING_BOX),
969 sClassName = this.getClassName(DISABLED);
972 box.addClass(sClassName);
974 box.removeClass(sClassName);
980 * Set the tabIndex on the widget's rendered UI
982 * @method _uiSetTabIndex
986 _uiSetTabIndex: function(index) {
988 var boundingBox = this.get(BOUNDING_BOX);
990 if (L.isNumber(index)) {
991 boundingBox.set(TAB_INDEX, index);
994 boundingBox.removeAttribute(TAB_INDEX);
1001 * Sets the focused state for the UI
1004 * @param {boolean} val
1005 * @param {string} src String representing the source that triggered an update to
1008 _uiSetFocused: function(val, src) {
1010 var box = this.get(BOUNDING_BOX),
1011 sClassName = this.getClassName(FOCUSED);
1014 box.addClass(sClassName);
1019 box.removeClass(sClassName);
1029 * Default visible attribute state change handler
1031 * @method _afterVisibleChange
1033 * @param {EventFacade} evt The event facade for the attribute change
1035 _afterVisibleChange: function(evt) {
1036 this._uiSetVisible(evt.newVal);
1040 * Default disabled attribute state change handler
1042 * @method _afterDisabledChange
1044 * @param {EventFacade} evt The event facade for the attribute change
1046 _afterDisabledChange: function(evt) {
1047 this._uiSetDisabled(evt.newVal);
1051 * Default height attribute state change handler
1053 * @method _afterHeightChange
1055 * @param {EventFacade} evt The event facade for the attribute change
1057 _afterHeightChange: function(evt) {
1058 this._uiSetHeight(evt.newVal);
1062 * Default widget attribute state change handler
1064 * @method _afterWidthChange
1066 * @param {EventFacade} evt The event facade for the attribute change
1068 _afterWidthChange: function(evt) {
1069 this._uiSetWidth(evt.newVal);
1073 * Default focused attribute state change handler
1075 * @method _afterFocusedChange
1077 * @param {EventFacade} evt The event facade for the attribute change
1079 _afterFocusedChange: function(evt) {
1080 this._uiSetFocused(evt.newVal, evt.src);
1084 * @method _onDocMouseDown
1085 * @description "mousedown" event handler for the owner document of the
1086 * widget's bounding box.
1088 * @param {EventFacade} evt The event facade for the DOM focus event
1090 _onDocMouseDown: function (evt) {
1092 if (this._hasDOMFocus) {
1099 * DOM focus event handler, used to sync the state of the Widget with the DOM
1103 * @param {EventFacade} evt The event facade for the DOM focus event
1105 _onFocus: function (evt) {
1107 var target = evt.target,
1108 boundingBox = this.get(BOUNDING_BOX),
1109 bFocused = (boundingBox.compareTo(target) || boundingBox.contains(target));
1111 this._hasDOMFocus = bFocused;
1112 this._set(FOCUSED, bFocused, { src: UI });
1117 * Generic toString implementation for all widgets.
1120 * @return {String} The default string value for the widget [ displays the NAME of the instance, and the unique id ]
1122 toString: function() {
1123 return this.constructor.NAME + "[" + this._yuid + "]";
1127 * Default unit to use for dimension values
1129 * @property DEF_UNIT
1134 * Static property defining the markup template for content box.
1136 * @property CONTENT_TEMPLATE
1139 CONTENT_TEMPLATE : "<div></div>",
1142 * Static property defining the markup template for bounding box.
1144 * @property BOUNDING_TEMPLATE
1147 BOUNDING_TEMPLATE : "<div></div>",
1150 * Static property listing the styles that are mimiced on the bounding box from the content box.
1152 * @property WRAP_STYLES
1169 * Sets strings for a particular locale, merging with any existing
1170 * strings which may already be defined for the locale.
1172 * @method _setStrings
1174 * @param {Object} strings The hash of string key/values to set
1175 * @param {Object} locale The locale for the string values being set
1177 _setStrings : function(strings, locale) {
1178 var strs = this._strings;
1179 locale = locale.toLowerCase();
1181 if (!strs[locale]) {
1185 Y.aggregate(strs[locale], strings, true);
1186 return strs[locale];
1190 * Returns the strings key/value hash for a paricular locale, without locale lookup applied.
1192 * @method _getStrings
1194 * @param {Object} locale
1196 _getStrings : function(locale) {
1197 return this._strings[locale.toLowerCase()];
1201 * Gets the entire strings hash for a particular locale, performing locale lookup.
1203 * If no values of the key are defined for a particular locale the value for the
1204 * default locale (in initial locale set for the class) is returned.
1206 * @method getStrings
1207 * @param {String} locale (optional) The locale for which the string value is required. Defaults to the current locale, if not provided.
1209 // TODO: Optimize/Cache. Clear cache on _setStrings call.
1210 getStrings : function(locale) {
1212 locale = (locale || this.get(LOCALE)).toLowerCase();
1215 var defLocale = this.getDefaultLocale().toLowerCase(),
1216 defStrs = this._getStrings(defLocale),
1217 strs = (defStrs) ? Y.merge(defStrs) : {},
1218 localeSegments = locale.split(HYPHEN);
1220 // If locale is different than the default, or needs lookup support
1221 if (locale !== defLocale || localeSegments.length > 1) {
1223 for (var i = 0, l = localeSegments.length; i < l; ++i) {
1224 lookup += localeSegments[i];
1227 var localeStrs = this._getStrings(lookup);
1229 Y.aggregate(strs, localeStrs, true);
1239 * Gets the string for a particular key, for a particular locale, performing locale lookup.
1241 * If no values if defined for the key, for the given locale, the value for the
1242 * default locale (in initial locale set for the class) is returned.
1245 * @param {String} key The key.
1246 * @param {String} locale (optional) The locale for which the string value is required. Defaults to the current locale, if not provided.
1248 getString : function(key, locale) {
1250 locale = (locale || this.get(LOCALE)).toLowerCase();
1253 var defLocale = (this.getDefaultLocale()).toLowerCase(),
1254 strs = this._getStrings(defLocale) || {},
1256 idx = locale.lastIndexOf(HYPHEN);
1258 // If locale is different than the default, or needs lookup support
1259 if (locale !== defLocale || idx != -1) {
1262 strs = this._getStrings(locale);
1263 if (strs && key in strs) {
1267 idx = locale.lastIndexOf(HYPHEN);
1268 // Chop of last locale segment
1270 locale = locale.substring(0, idx);
1273 } while (idx != -1);
1280 * Returns the default locale for the widget (the locale value defined by the
1281 * widget class, or provided by the user during construction).
1283 * @method getDefaultLocale
1284 * @return {String} The default locale for the widget
1286 getDefaultLocale : function() {
1287 return this._conf.get(LOCALE, INIT_VALUE);
1291 * Private stings hash, used to store strings in locale specific buckets.
1293 * @property _strings
1300 * Gets the HTML_PARSER definition for this instance, by merging HTML_PARSER
1301 * definitions across the class hierarchy.
1303 * @method _getHtmlParser
1304 * @return {Object} HTML_PARSER definition for this instance
1306 _getHtmlParser : function() {
1307 if (!this._HTML_PARSER) {
1308 var classes = this._getClasses(),
1312 for (i = classes.length - 1; i >= 0; i--) {
1313 p = classes[i].HTML_PARSER;
1315 Y.mix(parser, p, true);
1319 this._HTML_PARSER = parser;
1322 return this._HTML_PARSER;
1329 }, '3.0.0' ,{requires:['attribute', 'event-focus', 'base', 'node', 'classnamemanager']});