widget-base.js revision 81ed0aaa8456bd5c6a54e7797258b1f182eb1f5b
// Widget nodeguid-to-instance map. * A base class for widgets, providing: * <li>The render lifecycle method, in addition to the init and destroy * lifecycle methods provide by Base</li> * <li>Abstract methods to support consistent MVC structure across * widgets: renderer, renderUI, bindUI, syncUI</li> * <li>Support for common widget attributes, such as boundingBox, contentBox, visible, * disabled, focused, strings</li> * @param config {Object} Object literal specifying widget configuration properties. // Render could be a node or boolean * Static property provides a string to identify the class. * Currently used to apply class identifiers to the bounding box * and to classify events fired by the widget. * Constant used to identify state changes originating from * the DOM (as opposed to the JavaScript model). * @property Widget.UI_SRC * Static property used to define the default attribute * configuration for the Widget. // Trying to optimize kweight by setting up attrs this way saves about 0.4K min'd * @default Generated using guid() * Flag indicating whether or not this Widget * has been through the render lifecycle phase. * @description The outermost DOM node for the Widget, used for sizing and positioning * of a Widget as well as a containing element for any decorator elements used * @description A DOM node that is a direct descendant of a Widget's bounding box that * @description Number (between -32767 to 32767) indicating the widget's * position in the default tab flow. The value is used to set the * "tabIndex" attribute on the widget's bounding box. Negative values allow * the widget to receive DOM focus programmatically (by calling the focus * method), while being removed from the default tab flow. A value of * null removes the "tabIndex" attribute from the widget's bounding box. * @description Boolean indicating if the Widget, or one of its descendants, * @description Boolean indicating if the Widget should be disabled. The disabled implementation * is left to the specific classes extending widget. * @description Boolean indicating weather or not the Widget is visible. * @description String with units, or number, representing the height of the Widget. If a number is provided, * the default unit, defined by the Widgets DEF_UNIT, property is used. * @type {String | Number} * @description String with units, or number, representing the width of the Widget. If a number is provided, * the default unit, defined by the Widgets DEF_UNIT, property is used. * @type {String | Number} * @description Collection of strings used to label elements of the Widget's UI. * 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 * @property Widget.CSS_PREFIX * @default Widget.NAME.toLowerCase() * Generate a standard prefixed classname for the Widget, prefixed by the default prefix defined * 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 * the prefix and widget class name). * The instance based version of this method can be used to generate standard prefixed classnames, * based on the instances NAME, as opposed to Widget.NAME. This method should be used when you * need to use a constant class name across different types instances. * @param {String*} args* 0..n strings which should be concatenated, using the default separator defined by ClassNameManager, to create the class name // arguments needs to be array'fied to concat * Returns the widget instance whose bounding box contains, or is, the given node. * In the case of nested widgets, the nearest bounding box ancestor is used to * return the widget instance. * @method Widget.getByNode * @param node {Node | String} The node for which to return a Widget instance. If a selector * string is passed in, which selects more than one node, the first node found is used. * @return {Widget} Widget instance, or null if not found. * Returns a class name prefixed with the the value of the * <code>YUI.config.classNamePrefix</code> attribute + the instances <code>NAME</code> property. * Uses <code>YUI.config.classNameDelimiter</code> attribute to delimit the provided strings. * // returns "yui-slider-foo-bar", for a slider instance * var scn = slider.getClassName('foo','bar'); * // returns "yui-overlay-foo-bar", for an overlay instance * var ocn = overlay.getClassName('foo','bar'); * @param {String}+ One or more classname bits to be joined and prefixed * Initializer lifecycle implementation for the Widget class. Registers the * widget instance, and runs through the Widget's HTML_PARSER definition. * @param config {Object} Configuration object literal for the widget * Notification event, which widget implementations can fire, when * they change the content of the widget. This event has no default * behavior and cannot be prevented, so the "on" or "after" * moments are effectively equivalent (with on listeners being invoked before * @event widget:contentUpdate * @param {EventFacade} e The Event Facade * Destructor lifecycle implementation for the Widget class. Purges events attached * to the bounding box (and all child nodes) and removes the Widget from the * list of registered widgets. * Removes and destroys the widgets rendered boundingBox, contentBox, * and detaches bound UI events. * Establishes the initial DOM for the widget. Invoking this * method will lead to the creating of all DOM elements for * the widget (or the manipulation of existing DOM elements * for the progressive enhancement use case). * This method should only be invoked once for an initialized * It delegates to the widget specific renderer method to do * @param parentNode {Object | String} Optional. The Node under which the * Widget is to be rendered. This can be a Node instance or a CSS selector string. * If the selector string returns more than one Node, the first node will be used * as the parentNode. NOTE: This argument is required if both the boundingBox and contentBox * are not currently in the document. If it's not provided, the Widget will be rendered * to the body of the current document in this case. * Lifecycle event for the render phase, fired prior to rendering the UI * for the widget (prior to invoking the widget's renderer method). * Subscribers to the "on" moment of this event, will be notified * before the widget is rendered. * Subscribers to the "after" moment of this event, will be notified * after rendering is complete. * @preventable _defRenderFn * @param {EventFacade} e The Event Facade * @param {EventFacade} e The Event object * @param {Node} parentNode The parent node to render to, if passed in to the <code>render</code> method * Creates DOM (or manipulates DOM for progressive enhancement) * This method is invoked by render() and is not chained * automatically for the class hierarchy (unlike initializer, destructor) * so it should be chained manually for subclasses if required. * This method is not called by framework and is not chained * automatically for the class hierarchy. * This method is not called by framework and is not chained * automatically for the class hierarchy. * Refreshes the rendered UI, based on Widget State * This method is not called by framework and is not chained * automatically for the class hierarchy. * @description Hides the Widget by setting the "visible" attribute to "false". * @description Shows the Widget by setting the "visible" attribute to "true". * @description Causes the Widget to receive the focus by setting the "focused" * @description Causes the Widget to lose focus by setting the "focused" attribute * @description Set the Widget's "disabled" attribute to "false". * @description Set the Widget's "disabled" attribute to "true". * @param {boolean} expand * Helper method to collect the boundingBox and contentBox, set styles 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 * to the current document's body. * @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. // TODO: Performance Optimization [ More effective algo to reduce Node refs, compares, replaces? ] // If srcNode (assume it's always in doc), have contentBox take its place (widget render responsible for re-use of srcNode contents) // If contentBox box is already in the document, have boundingBox box take it's place * Setter for the boundingBox attribute * Setter for the contentBox attribute * @param {Node|String} node * Returns the default value for the contentBox attribute. * For the Widget class, this will be the srcNode if provided, otherwise null (resulting in * a new contentBox node instance being created) * the provided template if not found. * @param {String} id The node's id attribute * @param {Node|String} node The node reference * @param {String} template HTML string template for the node * @return {Node} The node * Applies standard class names to the boundingBox and contentBox * @method _renderBoxClassNames // Start from Widget Sub Class // Use instance based name for content box * Removes class names representative of the widget's loading state from * @method _removeLoadingClassNames * Sets up DOM and CustomEvent listeners for the widget. * Sets up DOM listeners, on elements rendered by the widget. // TODO: Perf Optimization: Use Widget.getByNode delegation, to get by // with just one _onDocFocus subscription per sandbox, instead of one per widget // Document doesn't receive focus in Webkit when the user mouses // down on it, so the "focused" attribute won't get set to the * Updates the widget UI to reflect the attribute state. * Sets the height on the widget's bounding box element * @param {String | Number} val * Sets the width on the widget's bounding box element * @param {String | Number} val * @param {String} dim The dimension - "width" or "height" * @param {Number | String} val The value to set * Sets the visible state for the UI * Sets the disabled state for the UI * Sets the focused state for the UI * @param {string} src String representing the source that triggered an update to * Set the tabIndex on the widget's rendered UI * @method _onDocMouseDown * @description "mousedown" event handler for the owner document of the * @param {EventFacade} evt The event facade for the DOM focus event * DOM focus event handler, used to sync the state of the Widget with the DOM * @param {EventFacade} evt The event facade for the DOM focus event * Generic toString implementation for all widgets. * @return {String} The default string value for the widget [ displays the NAME of the instance, and the unique id ] // Using deprecated name prop for kweight squeeze. * Default unit to use for dimension values * Default node to render the bounding box to. If not set, * will default to the current document body. * @property DEF_PARENT_NODE * Property defining the markup template for content box. If your Widget doesn't * and contentBox and boundingBox will both point to the same Node. * @property CONTENT_TEMPLATE * Property defining the markup template for bounding box. * @property BOUNDING_TEMPLATE * @param {Number} tabIndex * Binds after listeners for the list of attributes provided for (i =
0; i < l; i++) {
* Invokes the _uiSet=ATTR NAME> method for the list of attributes provided for (i =
0; i < l; i++) {
* The default setter for the strings attribute. Merges partial sets * into the full string set, to allow users to partial sets of strings * @param {Object} strings * @return {String} The full set of strings to set * Helper method to get a specific string value * @deprecated Used by deprecated WidgetLocale implementations. * @return {String} The string * Helper method to get the complete set of strings for the widget * @deprecated Used by deprecated WidgetLocale implementations. * @return {String} The string * The lists of UI attributes to bind and sync for widget's _bindUI and _syncUI implementations },
'@VERSION@' ,{
requires:[
'attribute',
'event-focus',
'base-base',
'base-pluginhost',
'node-base',
'node-style',
'node-event-delegate',
'classnamemanager']});