• Register
  • Log In
  • Home
  • Quick Start
    • Configurator
    • Download YUI 3
  • Documentation
    • User Guides
    • Examples
    • API Docs
    • Environments
    • Tutorials
  • Community
    • Gallery
    • Blog
    • Forums
    • YUI Theater
    • Calendar
  • Contribute
    • YUI on GitHub »
    • File a Ticket
    • View Tickets
    • Dashboard
  • Other Projects
    • Shifter »
    • Yogi »
    • YUI 2
    • YUI Doc »
    • YUI Test
    • YUI Website
    • YUI Compressor »
    • YUI Builder »
    • YUI PHP Loader
    • Grid Builder »
    • Skin Builder »
  • YUI
  • >
  • Community
  • >
  • Gallery

Gallery

Modules

  • Home
  • Featured
  • Popular
  • New
  • All

Documentation

  • Yogi Documentation
  • Shifter Documentation
  • Developer Guide
  • Module Setup

Tag Cloud

Context Navigation

    YUI Library is not responsible for bugs or support with this module. It is available as a free service. For support please contact the module owner with the provided links.

    MakeNode (gallery-makenode) on cdn

    Last Updated: 05/3/13
    + 2 -

    Satyam

    YUI Contributor

    See 12 more by this user.

    Created: 08/20/11
    Last CDN Push: 01/16/13
    Build Tag: gallery-2013.01.16-21-05
    Project: YUI 3
    License: YUI BSD
    YUI Version: 3.10.0
    Free for use.

    When MakeNode is added as an extension when defining a Widget, it will read several static protected properties and link together many pieces of code. A Widget defined with MakeNode usually has a much simpler renderUI method than a normal Widget, quite often no bindUI or syncUI and possibly no initializer either. The pieces of code handling the behavior of the widget are very clearly specified, each doing a very simple task. Code size is reduced and what is left turns out to be much simpler.

    All properties and methods added by MakeNode are protected, as they are meant to be used by the developer of the widget and need not be seen by the application developer using the widget.

    MakeNode makes it easy to:

    • Define the markup of the Widget via a simple template which can have placeholders which MakeNode will fill with the values of properties, attributes, return values of methods and CSS classNames defined in the widget
    • Create classNames by simply declaring an array of suffixes to be added to the Widget's own CSS prefix
    • Create references to the Node elements that make up the widget by searching them by their classNames
    • Link attributes to methods that will reflect their state in the UI
    • Link UI events to methods that will listen to them
    • Link global and widget events to their listeners

    • Tags:
    • satyam
    • Download
    • Docs
    • Homepage
    • Bugs
    • Source
    • Example
    • Forum
    • History

    Code Sample

    <script src="http://yui.yahooapis.com/3.10.0/build/yui/yui-min.js"></script>
    Y.Something= Y.Base.create(
        'something', 
        Y.Widget, 
        [Y.MakeNode], 
        {
     
            renderUI: function () {
                // _makeNode will use the default _TEMPLATE property if none is provided
                this.get('contentBox').append(this._makeNode());
                // _locateNodes will produce properties _labelNode and _iconNode 
                // via the CSS classNames listed in _CLASS_NAMES
                this._locateNodes();
            },
            // The previous code for renderUI is so frequent that MakeNode will add it automatically
            // if it doesn't find any explicit renderUI method in the class or the ones it inherits from.
     
     
            // This _uiSetXxxx methods will be called automatically when the Xxxx attribute changes.
            // There has to be one of this for each attribute listed in _ATTRS_2_UI
            _uiSetLabel: function (value) {
                // _labelNode was produced by _locateNodes
                this._labelNode.setContent(value || '');
            },
            _uiSetIcon: function (value) {
                value = value || 'none';
     
                // MakeNode will create the hash _classNames from _CLASS_NAMES using the values 
                // in that array as keys (for example, 'icon') and the full className as the value
                // (for example: "yui3-something-icon").
                var newName = this._classNames.icon + '-' + value;
                this.get('boundingBox').replaceClass(
                    this._prevIconClassName, 
                    newName
                );
                this._prevIconClassName = newName;
            },
     
            // These are the event listeners for the events listed below in _EVENTS.
            // Default listeners are 'after' event listeners (Y.after) so, by default, the functions
            // start with '_after', then the element it is bound to, with the initial capitalized
            // and then the event type, with the initial capitalized.
            // If a before event is set (Y.on) the listener would be, for example _beforeFormSubmit
            // For delegated events (Y.delegate), it might be:  _delegateListItemClick
            _afterBoundingBoxClick: function (ev) {
     
            },
            _afterBoundingBoxMousedown: function (ev) {
     
            },
            _afterDocumentMouseup: function (ev) {
     
            }
        },
        {
            // This is the default template that _makeNode will use.  
            // You can have several templates if you want any other, just pass it as the first argument to _makeNode.
            // The placeholder {c} will use the className generated for that key in _CLASS_NAMES.
            // The {@} placeholder will read the value of the attribute mentioned.
            _TEMPLATE: '<span class="{c icon}"></span><span class="{c label}">{@ label}</span>',
     
            // MakeNode will generate classNames using ClassNameManager
            _CLASS_NAMES: ['label','icon'],
     
            // MakeNode will set event listeners for nodes listed here and link each type of event 
            // to the method whose name is listed.  Nodes are usually identified by the keys of their classNames
            // as listed in _CLASS_NAMES.  There are also several 'virtual' nodes, such as those used here:
            // boundingBox and document (the document the widget is in) or 
            // THIS the widget itself and Y the Y instance for events broadcast.
            // Event listeners are expected to comply with a naming convention but can be overridden, 
            // along with a series of other alternatives (using before event listeners instead of after, or event delegation)
            _EVENTS: {
                boundingBox: ['click','mousedown' ],
                document: 'mouseup'
                /* Should there be a form whose submittal I might want to supervise, I might do:
                form: {
                	when:'before',
                	type: 'submit'
                }
                */
                /*
                Should I want to use a particular function name, I can do that, for example, 
                for a click on the element with the className key of icon, it would go:
                icon: {
                	type: 'click',
                	fn: '_onIconClick'
                }
                */
            }, 
            ATTRS: {
                label: {
                    value: '',
                    validator: Lang.isString
                },
                icon: {
                    value: null,
                    validator: function(value) {
                        return Lang.isString(value) || Lang.isNull(value);
                    }
                }
            },
     
            // Attributes listed here will have methods named _uiSetXxxx handling any change in them.
            _ATTRS_2_UI: {
                BIND: ['label', 'icon'],
                SYNC: ['label', 'icon']
            }
        }
    );
     

    Forum Posts

    Subject Author Date
    Additional Template Handlers Brian J. Miller 09/28/11
    _EVENTS Marc 10/1/11
    Re: _EVENTS Satyam 10/3/11
    How do you reference the original node Marc 10/4/11
    Re: How do you reference the original node Satyam 10/6/11
    Re: How do you reference the original node Marc 10/7/11
    Re: How do you reference the original node Marc 10/7/11

    © 2006-2013 Yahoo! Inc. All rights reserved.
    All code on this site is licensed under the BSD License unless stated otherwise.
    About This Site · Security Contact Info