src/cm/media/js/lib/yui/yui_3.10.3/build/attribute-extras/attribute-extras-debug.js
changeset 525 89ef5ed3c48b
equal deleted inserted replaced
524:322d0feea350 525:89ef5ed3c48b
       
     1 /*
       
     2 YUI 3.10.3 (build 2fb5187)
       
     3 Copyright 2013 Yahoo! Inc. All rights reserved.
       
     4 Licensed under the BSD License.
       
     5 http://yuilibrary.com/license/
       
     6 */
       
     7 
       
     8 YUI.add('attribute-extras', function (Y, NAME) {
       
     9 
       
    10     /**
       
    11      * The attribute module provides an augmentable Attribute implementation, which
       
    12      * adds configurable attributes and attribute change events to the class being
       
    13      * augmented. It also provides a State class, which is used internally by Attribute,
       
    14      * but can also be used independently to provide a name/property/value data structure to
       
    15      * store state.
       
    16      *
       
    17      * @module attribute
       
    18      */
       
    19 
       
    20     /**
       
    21      * The attribute-extras submodule provides less commonly used attribute methods, and can
       
    22      * be augmented/mixed into an implemention which used attribute-core.
       
    23      *
       
    24      * @module attribute
       
    25      * @submodule attribute-extras
       
    26      */
       
    27     var BROADCAST = "broadcast",
       
    28         PUBLISHED = "published",
       
    29         INIT_VALUE = "initValue",
       
    30 
       
    31         MODIFIABLE = {
       
    32             readOnly:1,
       
    33             writeOnce:1,
       
    34             getter:1,
       
    35             broadcast:1
       
    36         };
       
    37 
       
    38     /**
       
    39      * A augmentable implementation for AttributeCore, providing less frequently used
       
    40      * methods for Attribute management such as modifyAttrs(), removeAttr and reset()
       
    41      *
       
    42      * @class AttributeExtras
       
    43      * @extensionfor AttributeCore
       
    44      */
       
    45     function AttributeExtras() {}
       
    46 
       
    47     AttributeExtras.prototype = {
       
    48 
       
    49         /**
       
    50          * Updates the configuration of an attribute which has already been added.
       
    51          * <p>
       
    52          * The properties which can be modified through this interface are limited
       
    53          * to the following subset of attributes, which can be safely modified
       
    54          * after a value has already been set on the attribute: readOnly, writeOnce,
       
    55          * broadcast and getter.
       
    56          * </p>
       
    57          * @method modifyAttr
       
    58          * @param {String} name The name of the attribute whose configuration is to be updated.
       
    59          * @param {Object} config An object with configuration property/value pairs, specifying the configuration properties to modify.
       
    60          */
       
    61         modifyAttr: function(name, config) {
       
    62             var host = this, // help compression
       
    63                 prop, state;
       
    64 
       
    65             if (host.attrAdded(name)) {
       
    66 
       
    67                 if (host._isLazyAttr(name)) {
       
    68                     host._addLazyAttr(name);
       
    69                 }
       
    70 
       
    71                 state = host._state;
       
    72                 for (prop in config) {
       
    73                     if (MODIFIABLE[prop] && config.hasOwnProperty(prop)) {
       
    74                         state.add(name, prop, config[prop]);
       
    75 
       
    76                         // If we reconfigured broadcast, need to republish
       
    77                         if (prop === BROADCAST) {
       
    78                             state.remove(name, PUBLISHED);
       
    79                         }
       
    80                     }
       
    81                 }
       
    82             }
       
    83             /*jshint maxlen:200*/
       
    84             if (!host.attrAdded(name)) {Y.log('Attribute modifyAttr:' + name + ' has not been added. Use addAttr to add the attribute', 'warn', 'attribute');}
       
    85             /*jshint maxlen:150 */
       
    86         },
       
    87 
       
    88         /**
       
    89          * Removes an attribute from the host object
       
    90          *
       
    91          * @method removeAttr
       
    92          * @param {String} name The name of the attribute to be removed.
       
    93          */
       
    94         removeAttr: function(name) {
       
    95             this._state.removeAll(name);
       
    96         },
       
    97 
       
    98         /**
       
    99          * Resets the attribute (or all attributes) to its initial value, as long as
       
   100          * the attribute is not readOnly, or writeOnce.
       
   101          *
       
   102          * @method reset
       
   103          * @param {String} name Optional. The name of the attribute to reset.  If omitted, all attributes are reset.
       
   104          * @return {Object} A reference to the host object.
       
   105          * @chainable
       
   106          */
       
   107         reset : function(name) {
       
   108             var host = this;  // help compression
       
   109 
       
   110             if (name) {
       
   111                 if (host._isLazyAttr(name)) {
       
   112                     host._addLazyAttr(name);
       
   113                 }
       
   114                 host.set(name, host._state.get(name, INIT_VALUE));
       
   115             } else {
       
   116                 Y.each(host._state.data, function(v, n) {
       
   117                     host.reset(n);
       
   118                 });
       
   119             }
       
   120             return host;
       
   121         },
       
   122 
       
   123         /**
       
   124          * Returns an object with the configuration properties (and value)
       
   125          * for the given attribute. If attrName is not provided, returns the
       
   126          * configuration properties for all attributes.
       
   127          *
       
   128          * @method _getAttrCfg
       
   129          * @protected
       
   130          * @param {String} name Optional. The attribute name. If not provided, the method will return the configuration for all attributes.
       
   131          * @return {Object} The configuration properties for the given attribute, or all attributes.
       
   132          */
       
   133         _getAttrCfg : function(name) {
       
   134             var o,
       
   135                 state = this._state;
       
   136 
       
   137             if (name) {
       
   138                 o = state.getAll(name) || {};
       
   139             } else {
       
   140                 o = {};
       
   141                 Y.each(state.data, function(v, n) {
       
   142                     o[n] = state.getAll(n);
       
   143                 });
       
   144             }
       
   145 
       
   146             return o;
       
   147         }
       
   148     };
       
   149 
       
   150     Y.AttributeExtras = AttributeExtras;
       
   151 
       
   152 
       
   153 }, '3.10.3', {"requires": ["oop"]});