widget-base-debug.js revision f6d82be2d21a67d071b1d7a3d95a90f561d46c77
1067e734d6cec73ee954f2e43c1bba0e09d267cfPhill Cunnington * Provides the base Widget class, with HTML Parser support
1067e734d6cec73ee954f2e43c1bba0e09d267cfPhill Cunnington * @module widget
1067e734d6cec73ee954f2e43c1bba0e09d267cfPhill Cunnington * @main widget
1067e734d6cec73ee954f2e43c1bba0e09d267cfPhill Cunnington * Provides the base Widget class
1067e734d6cec73ee954f2e43c1bba0e09d267cfPhill Cunnington * @module widget
1067e734d6cec73ee954f2e43c1bba0e09d267cfPhill Cunnington * @submodule widget-base
1067e734d6cec73ee954f2e43c1bba0e09d267cfPhill Cunnington return str.substring(0, 1).toUpperCase() + str.substring(1);
1067e734d6cec73ee954f2e43c1bba0e09d267cfPhill Cunnington // K-Weight, IE GC optimizations
dfc4e0fc3052835b2a069aa9d869fa1161c33fe6Peter Major EMPTY_FN = function() {},
dfc4e0fc3052835b2a069aa9d869fa1161c33fe6Peter Major UI_ATTRS = [VISIBLE, DISABLED, HEIGHT, WIDTH, FOCUSED, TAB_INDEX],
dfc4e0fc3052835b2a069aa9d869fa1161c33fe6Peter Major // Widget nodeid-to-instance map.
dfc4e0fc3052835b2a069aa9d869fa1161c33fe6Peter Major * A base class for widgets, providing:
1067e734d6cec73ee954f2e43c1bba0e09d267cfPhill Cunnington * <li>The render lifecycle method, in addition to the init and destroy
dfc4e0fc3052835b2a069aa9d869fa1161c33fe6Peter Major * lifecycle methods provide by Base</li>
dfc4e0fc3052835b2a069aa9d869fa1161c33fe6Peter Major * <li>Abstract methods to support consistent MVC structure across
dfc4e0fc3052835b2a069aa9d869fa1161c33fe6Peter Major * widgets: renderer, renderUI, bindUI, syncUI</li>
dfc4e0fc3052835b2a069aa9d869fa1161c33fe6Peter Major * <li>Support for common widget attributes, such as boundingBox, contentBox, visible,
dfc4e0fc3052835b2a069aa9d869fa1161c33fe6Peter Major * disabled, focused, strings</li>
dfc4e0fc3052835b2a069aa9d869fa1161c33fe6Peter Major * @param config {Object} Object literal specifying widget configuration properties.
dfc4e0fc3052835b2a069aa9d869fa1161c33fe6Peter Major * @class Widget
dfc4e0fc3052835b2a069aa9d869fa1161c33fe6Peter Major * @constructor
dfc4e0fc3052835b2a069aa9d869fa1161c33fe6Peter Major * @extends Base
dfc4e0fc3052835b2a069aa9d869fa1161c33fe6Peter Major widget._cssPrefix = constructor.CSS_PREFIX || _getClassName(constructor.NAME.toLowerCase());
dfc4e0fc3052835b2a069aa9d869fa1161c33fe6Peter Major Widget.superclass.constructor.apply(widget, arguments);
dfc4e0fc3052835b2a069aa9d869fa1161c33fe6Peter Major // Render could be a node or boolean
1067e734d6cec73ee954f2e43c1bba0e09d267cfPhill Cunnington * Static property provides a string to identify the class.
1067e734d6cec73ee954f2e43c1bba0e09d267cfPhill Cunnington * Currently used to apply class identifiers to the bounding box
1067e734d6cec73ee954f2e43c1bba0e09d267cfPhill Cunnington * and to classify events fired by the widget.
1067e734d6cec73ee954f2e43c1bba0e09d267cfPhill Cunnington * @property NAME
1067e734d6cec73ee954f2e43c1bba0e09d267cfPhill Cunnington * @type String
1067e734d6cec73ee954f2e43c1bba0e09d267cfPhill Cunnington * Constant used to identify state changes originating from
1067e734d6cec73ee954f2e43c1bba0e09d267cfPhill Cunnington * the DOM (as opposed to the JavaScript model).
1067e734d6cec73ee954f2e43c1bba0e09d267cfPhill Cunnington * @property UI_SRC
1067e734d6cec73ee954f2e43c1bba0e09d267cfPhill Cunnington * @type String
dfc4e0fc3052835b2a069aa9d869fa1161c33fe6Peter Major * Static property used to define the default attribute
dfc4e0fc3052835b2a069aa9d869fa1161c33fe6Peter Major * configuration for the Widget.
dfc4e0fc3052835b2a069aa9d869fa1161c33fe6Peter Major * @property ATTRS
dfc4e0fc3052835b2a069aa9d869fa1161c33fe6Peter Major * @type Object
dfc4e0fc3052835b2a069aa9d869fa1161c33fe6Peter Major// Trying to optimize kweight by setting up attrs this way saves about 0.4K min'd
dfc4e0fc3052835b2a069aa9d869fa1161c33fe6Peter Major * @attribute id
dfc4e0fc3052835b2a069aa9d869fa1161c33fe6Peter Major * @writeOnce
dfc4e0fc3052835b2a069aa9d869fa1161c33fe6Peter Major * @default Generated using guid()
dfc4e0fc3052835b2a069aa9d869fa1161c33fe6Peter Major * @type String
value:null,
value: null,
* @description String with units, or number, representing the height of the Widget. If a number is provided,
* @description String with units, or number, representing the width of the Widget. If a number is provided,
value: {},
* Whether or not to render the widget automatically after init, and optionally, to which parent node.
* The css prefix which the static Widget.getClassName method should use when constructing class names
* by the <code>Y.config.classNamePrefix</code> attribute used by <code>ClassNameManager</code> and
* <code>Widget.NAME.toLowerCase()</code> (e.g. "yui-widget-xxxxx-yyyyy", based on default values for
* @param {String*} args* 0..n strings which should be concatenated, using the default separator defined by ClassNameManager, to create the class name
var widget,
if (node) {
if (node) {
return widget || null;
* <code>YUI.config.classNamePrefix</code> attribute + the instances <code>NAME</code> property.
* Uses <code>YUI.config.classNameDelimiter</code> attribute to delimit the provided strings.
getClassName: function () {
if (this._applyParser) {
destructor: function() {
bbid;
this._destroyBox();
* @param destroyAllNodes {Boolean} If true, all nodes contained within the Widget are removd and destroyed. Defaults to false due to potentially high run-time cost.
_destroyBox : function() {
same;
if (this.UI_EVENTS) {
this._destroyUIEvents();
if (deep) {
if (contentBox) {
if (!same) {
* @param {Node} parentNode The parent node to render to, if passed in to the <code>render</code> method
_defRenderFn : function(e) {
this.renderer();
this._removeLoadingClassNames();
renderer: function() {
var widget = this;
* Configures/Sets up listeners to bind Widget State to UI/DOM
hide: function() {
show: function() {
focus: function () {
blur: function () {
enable: function() {
disable: function() {
* Helper method to collect the boundingBox and contentBox and append to the provided parentNode, if not
* already a child. The owner document of the boundingBox, or the owner document of the contentBox will be used
* as the document into which the Widget is rendered if a parentNode is node is not provided. If both the boundingBox and
* the contentBox are not currently in the document, and no parentNode is provided, the widget will be rendered
* @param {Node} parentNode The parentNode to render the widget to. If not provided, and both the boundingBox and
* the contentBox are not currently in the document, the widget will be rendered to the current document's body.
doc = (srcNode && srcNode.get(OWNER_DOCUMENT)) || boundingBox.get(OWNER_DOCUMENT) || contentBox.get(OWNER_DOCUMENT);
// If srcNode (assume it's always in doc), have contentBox take its place (widget render responsible for re-use of srcNode contents)
if (parentNode) {
return (this.CONTENT_TEMPLATE === null) ? this.get(BOUNDING_BOX) : this._setBox(null, node, this.CONTENT_TEMPLATE);
return node;
_renderUI: function() {
this._renderBoxClassNames();
_renderBoxClassNames : function() {
cl,
_removeLoadingClassNames: function () {
_bindUI: function() {
this._bindDOM();
_bindDOM : function() {
if (WEBKIT) {
if (this._hDocFocus) {
_syncUI: function() {
if (val) {
if (this._domFocus) {
this._domFocus = this.get(BOUNDING_BOX).contains(evt.target); // contains() checks invoking node also
* @return {String} The default string value for the widget [ displays the NAME of the instance, and the unique id ]
toString: function() {
DEF_PARENT_NODE : null,
* need the dual boundingBox/contentBox structure, set CONTENT_TEMPLATE to null,
_guid : function() {
return Y.guid();
_setAttrUI : function(e) {
if (e.target === this) {
getStrings : function() {
_UI_ATTRS : {