src/cm/media/js/lib/yui/yui_3.10.3/docs/attribute/index.html
author Yves-Marie Haussonne <ymh.work+github@gmail.com>
Fri, 09 May 2014 18:35:26 +0200
changeset 656 a84519031134
parent 525 89ef5ed3c48b
permissions -rw-r--r--
add link to "privacy policy" in the header test
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
525
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
     1
<!DOCTYPE html>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
     2
<html lang="en">
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
     3
<head>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
     4
    <meta charset="utf-8">
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
     5
    <title>Attribute</title>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
     6
    <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic,700italic">
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
     7
    <link rel="stylesheet" href="../../build/cssgrids/cssgrids-min.css">
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
     8
    <link rel="stylesheet" href="../assets/css/main.css">
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
     9
    <link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    10
    <link rel="shortcut icon" type="image/png" href="../assets/favicon.png">
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    11
    <script src="../../build/yui/yui-min.js"></script>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    12
    
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    13
</head>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    14
<body>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    15
<!--
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    16
<a href="https://github.com/yui/yui3"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"></a>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    17
-->
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    18
<div id="doc">
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    19
    <div id="hd">
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    20
        <h1><img src="http://yuilibrary.com/img/yui-logo.png"></h1>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    21
    </div>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    22
    
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    23
        <a href="#toc" class="jump">Jump to Table of Contents</a>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    24
    
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    25
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    26
            <h1>Attribute</h1>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    27
    <div class="yui3-g">
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    28
        <div class="yui3-u-3-4">
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    29
            <div id="main">
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    30
                <div class="content"><div class="intro">
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    31
    <p>The Attribute utility allows you to add attributes to any class through an augmentable Attribute interface.
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    32
       The interface adds <code>get and </code>set methods to your class to retrieve and store attribute values, as well as
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    33
       support for change events that can be used to listen for changes in attribute values.</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    34
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    35
    <p>In addition, attributes can be configured with custom getters, setters and validators, allowing the developer to
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    36
    normalize and validate values being stored or retrieved. Attributes can also be specified as read-only or write-once.</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    37
</div>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    38
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    39
<h2 id="getting-started">Getting Started</h2>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    40
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    41
<p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    42
To include the source files for Attribute and its dependencies, first load
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    43
the YUI seed file if you haven't already loaded it.
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    44
</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    45
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    46
<pre class="code prettyprint">&lt;script src=&quot;http:&#x2F;&#x2F;yui.yahooapis.com&#x2F;3.10.3&#x2F;build&#x2F;yui&#x2F;yui-min.js&quot;&gt;&lt;&#x2F;script&gt;</pre>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    47
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    48
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    49
<p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    50
Next, create a new YUI instance for your application and populate it with the
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    51
modules you need by specifying them as arguments to the <code>YUI().use()</code> method.
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    52
YUI will automatically load any dependencies required by the modules you
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    53
specify.
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    54
</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    55
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    56
<pre class="code prettyprint">&lt;script&gt;
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    57
&#x2F;&#x2F; Create a new YUI instance and populate it with the required modules.
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    58
YUI().use(&#x27;attribute&#x27;, function (Y) {
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    59
    &#x2F;&#x2F; Attribute is available and ready for use. Add implementation
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    60
    &#x2F;&#x2F; code here.
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    61
});
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    62
&lt;&#x2F;script&gt;</pre>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    63
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    64
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    65
<p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    66
For more information on creating YUI instances and on the
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    67
<a href="http://yuilibrary.com/yui/docs/api/classes/YUI.html#method_use"><code>use()</code> method</a>, see the
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    68
documentation for the <a href="../yui/index.html">YUI Global Object</a>.
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    69
</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    70
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    71
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    72
<h2 id="augment">Augmenting Your Class With Attribute</h2>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    73
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    74
<p>The Attribute class is designed to be augmented to an existing class (we'll refer to this class as the 'host' class) and adds attribute
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    75
management support to it. For example, assuming you have a class constructor, `MyClass, to which you'd like to add attribute support,
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    76
you can simply augment your class with Attribute, as shown below:</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    77
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    78
<pre class="code prettyprint">YUI().use(&quot;attribute&quot;, function(Y) {
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    79
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    80
    function MyClass() {
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    81
        ...
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    82
    }
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    83
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    84
    Y.augment(MyClass, Y.Attribute);
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    85
});</pre>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    86
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    87
<p>Instances of your class will now have Attribute methods available, which your class can use to configure attributes for itself, and which users of your
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    88
class can use to get and set attribute values. See the <a href="http://yuilibrary.com/yui/docs/api/Attribute.html">Attribute API documentation</a> for a complete list of
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    89
methods which Attribute will add to your class.</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    90
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    91
<p>Note that in general, rather than augmenting Attribute directly, most implementations will simply extend <a href="../base/index.html">Base</a>, which
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    92
augments Attribute, and handles attribute setup for you. Base also sets up all attributes to be lazily initialized (initialized on the first call to get or set) by default, improving performance.</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    93
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    94
<h2 id="adding">Adding Attributes</h2>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    95
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    96
<p>Once augmented with Attribute, your class can either use the <code>addAttrs</code> method to setup attributes en mass, or use the
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    97
<code>addAttr</code> method, to add them individually. <code>addAttrs</code> is tailored towards use by host classes, since in addition
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    98
to being able to initialize multiple attributes in one call, it also accepts an additional name/value hash, which can be used to allow the
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    99
user to define the initial value of attributes when instantiating Attribute driven classes, as shown below:</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   100
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   101
<pre class="code prettyprint">...
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   102
function MyClass(userValues) {
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   103
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   104
    &#x2F;&#x2F; Use addAttrs, to setup default attributes for
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   105
    &#x2F;&#x2F; your class, and mixing in user provided initial values.
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   106
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   107
    var attributeConfig = {
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   108
        attrA : {
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   109
            &#x2F;&#x2F; ... Configuration for attribute &quot;attrA&quot; ...
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   110
        },
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   111
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   112
        attrB : {
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   113
            &#x2F;&#x2F; ... Configuration for attribute &quot;attrB&quot; ...
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   114
        }
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   115
    };
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   116
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   117
    this.addAttrs(attributeConfig, userValues);
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   118
};</pre>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   119
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   120
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   121
<p>Users of your class now have the ability to pass attribute values to the constructor,
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   122
or set values using the <code>set</code> method as shown below:</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   123
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   124
<pre class="code prettyprint">&#x2F;&#x2F; Set initial value for attrA during instantiation
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   125
var o = new MyClass({
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   126
    attrA:5
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   127
});
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   128
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   129
&#x2F;&#x2F; Set attrB later on
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   130
o.set(&quot;attrB&quot;, &quot;Hello World!&quot;);</pre>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   131
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   132
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   133
<h2 id="configuration">Attribute Configuration Properties</h2>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   134
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   135
<p>Each attribute you add can be configured with the properties listed in the table below (all properties are optional and case-sensitive):</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   136
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   137
<table>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   138
    <caption>Attribute Configuration Properties</caption>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   139
    <thead>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   140
        <tr>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   141
            <th>Property Name</th>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   142
            <th>Type</th>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   143
            <th>Description</th>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   144
        </tr>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   145
    </thead>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   146
    <tbody>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   147
        <tr>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   148
            <td><code>value</code></td>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   149
            <td>Any</td>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   150
            <td>The default value for this attribute</td>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   151
        </tr>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   152
        <tr>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   153
            <td><code>valueFn</code></td>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   154
            <td>Function</td>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   155
            <td>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   156
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   157
            <p>A function, the return value of which is the value for the attribute. This property can be used instead of the
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   158
            value property for static configurations, if you need to set default values which require access to instance state
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   159
            ("this.something").</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   160
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   161
            <p>If both the value and valueFn properties are defined, the value returned by valueFn has precedence over the value property,
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   162
            unless it returns undefined, in which case the value property is used.</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   163
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   164
            <p>The valueFn is passed the name of the attribute, allowing users to share valueFn implementations across attributes if required.</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   165
            </td>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   166
        </tr>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   167
        <tr>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   168
            <td><code>getter</code></td>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   169
            <td>Function</td>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   170
            <td>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   171
                <p>Custom 'get' handler, which is invoked when the user calls Attribute's <code>get</code> method. It can
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   172
                be used to manipulate or normalize the stored value before it is returned to the user.</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   173
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   174
                <p>The function will be passed the currently stored value of the attribute as the first argument and the name
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   175
                of the attribute as the second argument. If configured, the value returned by this function will be
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   176
                the value returned to the user.</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   177
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   178
                <p>Attribute also supports the ability to return sub-attribute values (<code>get(&#x27;a.b.c&#x27;)</code>). The getter implications for
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   179
                this are discussed in the <a href="#subattrs-gsv">Getters, Setters, Validators and Sub Attributes</a> section.</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   180
            </td>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   181
        </tr>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   182
        <tr>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   183
            <td><code>setter</code></td>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   184
            <td>Function</td>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   185
            <td>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   186
                <p>Custom 'set' handler, which is invoked when the user calls Attribute's <code>set</code> method. It can
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   187
                be used to manipulate the value which is stored for the attribute.</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   188
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   189
                <p>The function will be passed the value which the user passed to the set method as the first
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   190
                argument, the name of the attribute as the second argument and the third argument passed to the <code>set</code>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   191
                method as the third argument. If configured, the value returned by this
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   192
                function will be the value stored as the attribute value.</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   193
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   194
                <p>The setter may return the constant <code>Y.Attribute.INVALID_VALUE</code> to reject a value.</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   195
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   196
                <p>The getter and setter can be used to normalize values on input/output for the user while storing the
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   197
                value in a format most effective for internal operation.</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   198
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   199
                <p>Attribute also supports the ability to set sub-attribute values (<code>set(&#x27;a.b.c&#x27;, 10)</code>). The setter
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   200
                implications for this are discussed in the  <a href="#subattrs-gsv">Getters, Setters, Validators and Sub Attributes</a>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   201
                section.</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   202
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   203
                <p>The third argument is optional and it should have been an object.  It may be used to give the reason or origin of
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   204
                the change.  This allows the setter to manipulate the value in special ways when it comes from certain
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   205
                sources or to decide whether to accept it or not.</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   206
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   207
            </td>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   208
        </tr>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   209
        <tr>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   210
            <td><code>validator</code></td>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   211
            <td>Function</td>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   212
            <td>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   213
                <p>Validation function, which if defined, is called before the <code>setter</code>.
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   214
                The validation function is passed the value which the user is trying to set as the first argument, the name of the
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   215
                attribute as the second argument and the third argument passed to the <code>set</code> method
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   216
                as the third argument.</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   217
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   218
                <p>If the function returns <code>false</code>, the attribute's stored value is not updated (and the <code>setter</code>, if defined, will not be invoked).
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   219
                If it returns <code>true</code>, the <code>setter</code> is invoked if defined, and the attribute's stored value is updated.</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   220
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   221
                <p>If validation is a potentially expensive task and contains code which would be repeated in a <code>setter</code> (for example, converting a string to a Node reference),
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   222
                you can combine validation into the <code>setter</code> function, by returning <code>Attribute.INVALID_VALUE</code> from a <code>setter</code> if it
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   223
                encounters an invalid value.</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   224
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   225
                <p>Attribute also supports the ability to set sub-attribute values (set('a.b.c', 10)). The 'validator'
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   226
                implications for this are discussed in the  <a href="#subattrs-gsv">Getters, Setters, Validators and Sub Attributes</a>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   227
                section.</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   228
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   229
                <p>The third argument is optional and it should have been an object.  It may be used to give the reason or origin of
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   230
                the change.  This allows the validator to accept a value when it comes from certain sources
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   231
                while rejecting it in general.</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   232
            </td>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   233
        </tr>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   234
        <tr>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   235
            <td><code>readOnly</code></td>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   236
            <td>boolean</td>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   237
            <td>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   238
                Configures the attribute to be read-only. Users will not be able to set the value of the attribute using
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   239
                Attribute's public API.
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   240
            </td>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   241
        </tr>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   242
        <tr>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   243
            <td><code>writeOnce</code></td>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   244
            <td>boolean or "initOnly"</td>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   245
            <td>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   246
                <p>Configures the attribute to be write-once. Users will only be able to set the value of the attribute using
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   247
                Attribute's <code>set</code> method once. Once a value has been set for the attribute, calling <code>set</code> will not change it's value.
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   248
                </p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   249
                <p>If set to "initOnly", the attribute can only be set during initialization. In the case of Base, this means that the attribute can
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   250
                only be set through the constructor.</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   251
                <p>Code within your class can update the value of readOnly or writeOnce attributes by using the private <code>_set</code> method.</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   252
            </td>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   253
        </tr>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   254
        <tr>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   255
            <td><code>broadcast</code></td>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   256
            <td>int</td>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   257
            <td>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   258
             By default attribute change events are not broadcast to the YUI instance or global YUI object. The broadcast property
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   259
             can be used to set specific attribute change events to be broadcast to either the YUI instance or the global YUI object.
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   260
             See CustomEvent's <a href="http://yuilibrary.com/yui/docs/api/CustomEvent.html#property_broadcast">broadcast</a> property for valid values.
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   261
            </td>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   262
        </tr>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   263
        <tr>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   264
            <td><code>lazyAdd</code></td>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   265
            <td>boolean</td>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   266
            <td>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   267
                <p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   268
                Whether or not to delay initialization of the attribute until the first call to get/set it.
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   269
                This flag can be used to over-ride lazy initialization on a per attribute basis, when adding multiple attributes through
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   270
                the <a href="http://yuilibrary.com/yui/docs/api/Attribute.html#method_addAttrs"><code>addAttrs</code></a> method.
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   271
                </p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   272
                <p>When extending Base, all attributes are added lazily, so this flag can be used to over-ride
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   273
                lazyAdd behavior for specific attributes.</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   274
                <p><strong>The only reason you should need to disable <code>lazyAdd</code> is if your setter is doing more
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   275
                than normalizing the attribute value</strong>. For example if your setter is storing some other state, in <code>this._someProp</code>, which is being used
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   276
                by other parts of your component. In this case, since you're not getting or setting the attribute to access <code>this._someProp</code>,
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   277
                it won't get set up lazily, until someone actually calls <code>get</code> or <code>set</code> for the related attribute.</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   278
            </td>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   279
        </tr>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   280
        <tr>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   281
            <td><code>cloneDefaultValue</code></td>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   282
            <td>"shallow", "deep", true, false</td>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   283
            <td>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   284
                <p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   285
                This configuration value is not actually supported by Attribute natively, but is available when
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   286
                working with Base, and defining attribute configurations using Base's static <a href="http://yuilibrary.com/yui/docs/api/Base.html#property_ATTRS">ATTRS</a> property.
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   287
                </p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   288
                <p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   289
                This property controls how the statically defined default <code>value</code> field in Base's <code>ATTRS</code> attribute configuration is handled,
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   290
                when setting it up as the value for an instance. By default (if this property is not defined) object literals and arrays are deep cloned, to protect the default value from
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   291
                being modified. Setting cloneDefaultValue to <code>false</code> will disable cloning. This is useful in cases where you intend to use arrays or
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   292
                object literals by reference (e.g. they point to utilities). A shallow clone will be used if cloneDefaultValue is set to <code>&quot;shallow&quot;</code> and a
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   293
                deep clone will be used for <code>&quot;deep&quot;</code> or <code>true</code>.
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   294
                </p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   295
            </td>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   296
        </tr>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   297
    </tbody>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   298
</table>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   299
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   300
<h4 id="howtoconfig">Configuring Attributes</h4>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   301
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   302
<p>The above attribute properties are set using an object with property name/value pairs, which is passed to either <code>addAttrs</code> or <code>addAttr</code> as the
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   303
configuration argument. For example, expanding on the code snippet above:</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   304
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   305
<pre class="code prettyprint">...
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   306
var attributeConfig = {
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   307
    attrA : {
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   308
        &#x2F;&#x2F; Configuration for attribute &quot;attrA&quot;
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   309
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   310
        value: 5,
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   311
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   312
        setter: function(val) {
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   313
            return Math.min(val, 10);
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   314
        },
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   315
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   316
        validator: function(val) {
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   317
            return Y.Lang.isNumber(val);
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   318
        }
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   319
    },
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   320
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   321
    attrB : {
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   322
        &#x2F;&#x2F; Configuration for attribute &quot;attrB&quot;
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   323
    }
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   324
};
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   325
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   326
this.addAttrs(attributeConfig, userValues);
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   327
...</pre>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   328
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   329
<p>Or, if using <code>addAttr</code>:</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   330
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   331
<pre class="code prettyprint">this.addAttr(&quot;attrA&quot;, {
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   332
    &#x2F;&#x2F; Configuration for attribute &quot;attrA&quot;
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   333
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   334
    value: 5,
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   335
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   336
    setter: function(val) {
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   337
        return Math.min(val, 10);
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   338
    },
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   339
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   340
    validator: function(val) {
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   341
        return Y.Lang.isNumber(val);
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   342
    }
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   343
});</pre>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   344
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   345
<h2 id="setting-and-getting-attributes">Setting and Getting Attributes</h2>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   346
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   347
<p>Attribute adds <code>set</code> and <code>get</code> methods to the object it augments.</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   348
<pre class="code prettyprint">myObject.set(&quot;attrA&quot;, 6);
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   349
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   350
Y.log(myObject.get(&quot;attrA&quot;)); &#x2F;&#x2F; should log 6</pre>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   351
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   352
<p>Several attributes can be set or read at once via the <code>setAttrs</code> and <code>getAttrs</code>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   353
methods.</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   354
<pre class="code prettyprint">myObject.setAttrs({
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   355
    age: 6,
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   356
    name: &quot;John&quot;
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   357
});
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   358
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   359
Y.log(Y.Lang.sub(&quot;{name} is {age} years old&quot;, myObject.getAttrs()));</pre>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   360
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   361
<p>Calling <code>getAttrs</code> without any arguments will return all the configured attributes.
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   362
Passing an array of attribute names will return only those. Passing <code>true</code>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   363
will return only those modified from its initially configured value.</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   364
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   365
<p>A protected <code>_set</code> method allows changing the value of attributes configured as <code>readOnly</code>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   366
or past the first write in those configured as <code>writeOnce</code>, to allow the
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   367
object to still enforce those rules in the public API while allowing the
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   368
object to change the values internally.</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   369
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   370
<p>An extra argument can be provided to <code>set</code> and <code>setAttrs</code> indicating the
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   371
reason or origin of the change.  This argument must be an object and it will
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   372
be passed to the <code>setter</code> and/or <code>validator</code> methods, if any, and it will
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   373
be merged into the event facade of the attribute change events.</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   374
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   375
<pre class="code prettyprint">myObject.set(&quot;attrA&quot;, inputNode.get(&quot;value&quot;), {src:&quot;UI&quot;});
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   376
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   377
myObject.setAttrs({
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   378
    attrA: null,
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   379
    attrB: &quot;&quot;
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   380
},{src:&quot;internal&quot;});</pre>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   381
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   382
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   383
<p>This may allow an object to set an attribute to a value otherwise forbidden
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   384
in the public API, to have the <code>setter</code> manipulate it in a special way or
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   385
an attribute change event to respond in a particular manner. For example, as shown
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   386
in the sample code above,
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   387
a <code>setter</code> may accept and parse a numeric string when the the source of the
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   388
change is the UI while it would reject it otherwise.</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   389
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   390
<h2 id="events">Attribute Change Events</h2>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   391
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   392
<p>The availability of attribute change events are one of the key benefits of using
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   393
attributes to store state for your objects, instead of regular object properties.
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   394
Attribute change events are fired whenever <code>set</code> is invoked for an
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   395
attribute, allowing you to execute code in response to a change in the attribute's
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   396
value.</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   397
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   398
<h4 id="listening-for-change-events">Listening for Change Events</h4>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   399
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   400
<p>Attribute change events are Custom Events, having the type: "[attributeName]Change", where
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   401
[attributeName] is the name of the attribute which you're monitoring for changes.</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   402
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   403
<p>For example, if you were interested in listening for changes to an attribute named
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   404
"enabled", you would subscribe to events of type "enabledChange".</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   405
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   406
<pre class="code prettyprint">o.on(&quot;enabledChange&quot;, function(event) {
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   407
    &#x2F;&#x2F; Do something just before &quot;enabled&quot; is about to be set
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   408
});</pre>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   409
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   410
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   411
<p><em>NOTE:</em> Context and additional arguments for the listener function can either be
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   412
defined using YUI's <code>bind</code> method, or by passing in the context and
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   413
additional arguments to the <code>on</code> method.</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   414
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   415
<p>Attribute change event listeners can be registered using either the <code>on</code>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   416
(as shown above) or <code>after</code> Attribute methods.</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   417
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   418
<p>Attribute change event listeners may respond differently according to the
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   419
source or reason of the change as specified in the third argument to <code>set</code>.
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   420
This argument will be merged into the event facade and can be checked by the
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   421
event listener.</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   422
<pre class="code prettyprint">myObject.after(&quot;nameChange&quot;, function (event) {
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   423
    if (event.src !== &quot;UI&quot;) {
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   424
        inputNode.set(&quot;value&quot;, event.newVal);
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   425
    }
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   426
});</pre>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   427
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   428
<p>The code above listens to changes in the <code>name</code> attribute and, if it comes
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   429
from anywhere but the UI, it sets the input box to the new value.</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   430
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   431
<h4 id="on-vs-after">On vs. After</h4>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   432
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   433
<h5 id="on">On</h5>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   434
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   435
<p>Listeners registered using the <code>on</code> method, are notified <strong>before</strong> the stored state of the attribute has been updated.
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   436
Functions registered as "on" listeners receive an <code>Event</code> object as the first argument (actually an
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   437
instance of <a href="http://yuilibrary.com/yui/docs/api/EventFacade.html"><code>EventFacade</code></a>) which contains information
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   438
about the attribute being modified.</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   439
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   440
<p>Since these listeners are invoked before any state change has occurred, they have the ability to
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   441
prevent the change in state from occurring, by invoking <code>event.preventDefault()</code> on
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   442
the event object passed to them, or to modify the value being set, by modifying the <code>event.newVal</code> property.</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   443
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   444
<p>The value passed to the "on" event listener has not yet been checked via the <code>validator</code> or
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   445
normalized by the <code>setter</code> method.  Since the change may later be rejected or prevented
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   446
by further event listeners attached later, an "on" event listener should not
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   447
produce any secondary effects.</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   448
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   449
<pre class="code prettyprint">o.on(&quot;enabledChange&quot;, function(event) {
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   450
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   451
    &#x2F;&#x2F; event.prevVal will contain the current attribute value
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   452
    var val = event.prevVal;
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   453
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   454
    if (val !== someCondition) {
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   455
        &#x2F;&#x2F; Prevent &quot;enabled&quot; from being changed
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   456
        event.preventDefault();
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   457
    }
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   458
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   459
});</pre>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   460
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   461
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   462
<h5 id="after">After</h5>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   463
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   464
<p>Listeners registered using the <code>after</code> method, are notified <strong>after</strong>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   465
the stored state of the attribute has been updated. As with "on" listeners, the subscribed function
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   466
receives an <code>Event</code> object as the first parameter.</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   467
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   468
<p>Based on the definition above, "after" listeners are not invoked if state change is prevented,
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   469
for example, due to one of the "on" listeners calling <code>preventDefault</code> on the event object.
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   470
They are not invoked either if the <code>validator</code> or <code>setter</code> methods
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   471
rejected the value and they will receive the value already modified by the <code>setter</code> thus
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   472
it is safe to produce any secondary effects based on the changed value.</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   473
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   474
<pre class="code prettyprint">o.after(&quot;enabledChange&quot;, function(event) {
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   475
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   476
    &#x2F;&#x2F; event.newVal will contain the currently set value
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   477
    var val = event.newVal;
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   478
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   479
    &#x2F;&#x2F; Calling preventDefault() in an &quot;after&quot; listener has no impact
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   480
    event.preventDefault();
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   481
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   482
});</pre>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   483
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   484
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   485
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   486
<h4 id="the-event-object">The Event Object</h4>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   487
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   488
<p>The event facade passed to attribute change event listeners, has a number of attributes which provide information about the attribute being modified,
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   489
as well methods used to manage event propagation. These are described below:</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   490
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   491
<dl>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   492
    <dt>newVal</dt>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   493
    <dd>The value which the attribute will be set to (in the case of "on" listeners), or has been set to (in the case of "after" listeners)</dd>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   494
    <dt>prevVal</dt>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   495
    <dd>The value which the attribute is currently set to (in the case of "on" listeners), or was previously set to (in the case of "after" listeners)</dd>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   496
    <dt>attrName</dt>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   497
    <dd>The name of the attribute which is being set</dd>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   498
    <dt>subAttrName</dt>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   499
    <dd><p>Attribute also allows you to set individual properties of attributes having values which are objects through the
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   500
    <code>set</code> method (e.g. <code>o.set(&quot;X.a.b&quot;, 5)</code>, discussed below). This event property will contain the complete dot notation path for the object property which was changed.</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   501
    <p>For example, during <code>o.set(&quot;X.a.b&quot;, 5);</code>, <code>event.subAttrName</code> will be <code>&quot;X.a.b&quot;</code>, the path of the property which was modified, and <code>event.attrName</code> will be <code>&quot;X&quot;</code>, the attribute name.</p></dd>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   502
    <dt>preventDefault()<dt>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   503
    <dd>This method can be called in an "on" listener function to prevent the attribute's value from being updated (the default behavior). Calling this method in an "after" listener has no impact, since the default behavior has already been invoked.</dd>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   504
    <dt>stopImmediatePropagation()</dt>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   505
    <dd>This method can be called in "on" or "after" listener functions, and will prevent the rest of the listener stack from
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   506
    being notified, but will not prevent the attribute's value from being updated (viz. will not prevent the default behavior).</dd>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   507
    <dt>-- Custom properties --</dt>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   508
    <dd>Any other properties in the object passed as the last argument in a <code>set</code> or <code>setAttrs</code> call.</dd>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   509
</dl>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   510
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   511
<h2 id="attrsetflow">Attribute Set Flow Diagram</h2>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   512
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   513
<p>The diagram below shows the order in which attribute setters, validators and change event subscribers are invoked during the set operation:</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   514
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   515
<p><a href="setflow.html" title="Click too see full-size image"><img src="../assets/attribute/img/attribute-set-flow.png" alt="Flow diagram for the attribute 'set' operation" height="466" width="538"></a></p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   516
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   517
<p><em>NOTE:</em> Any decision blocks for which an exit path is not explicitly shown will effectively exit the set operation, without storing the new value. These paths are not explicitly shown, in order to avoid clutter.</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   518
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   519
<h2 id="subattrs">Getting/Setting Sub Attribute Values</h2>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   520
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   521
<p>If you have attribute values which are objects (as opposed to primitive values, such as numbers or booleans), the <code>set</code> method will let
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   522
you set properties of the object directly, using a dot notation syntax. For example, if you have an attribute, "strings" with the following value:</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   523
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   524
<pre class="code prettyprint">o.set(&quot;strings&quot;, {
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   525
    ui : {
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   526
        accept_label : &quot;OK&quot;,
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   527
        decline_label : &quot;Cancel&quot;,
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   528
    },
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   529
    errors : {
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   530
        e1000 : &quot;Not Supported&quot;,
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   531
        e1001 : &quot;Network Error&quot;
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   532
    }
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   533
});</pre>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   534
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   535
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   536
<p>You can set individual properties on the "strings" attribute value object, without having to get and then set the whole string's attribute value. This is done
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   537
by using the dot notation to reference properties within the attribute's value:</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   538
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   539
<pre class="code prettyprint">&#x2F;&#x2F; Set existing properties
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   540
o.set(&quot;strings.ui.accept_label&quot;, &quot;Yes&quot;);
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   541
o.set(&quot;strings.ui.decline_label&quot;, &quot;No&quot;);
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   542
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   543
&#x2F;&#x2F; Add a new property
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   544
o.set(&quot;strings.errors.e2000&quot;, &quot;New Error&quot;);
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   545
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   546
&#x2F;&#x2F; Cannot set new intermediate properties:
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   547
&#x2F;&#x2F; &quot;strings.messages&quot; does not exist so can&#x27;t set
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   548
&#x2F;&#x2F; &quot;strings.messages.intro&quot;
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   549
o.set(&quot;strings.messages.intro&quot;, &quot;Welcome&quot;);</pre>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   550
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   551
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   552
<p>Setting sub attribute values, will fire an attribute change event for the
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   553
main attribute (<code>&quot;stringsChange&quot;</code> in the above example), however the event object passed
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   554
to the listeners with have a "subAttrName" property set to reflect the full path to the
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   555
attribute set (e.g. <code>event.subAttrName</code> will be <code>&quot;strings.ui.accept_label&quot;</code> for the set call on line 2 in the code snippet above).</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   556
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   557
<p>You can also retrieve sub attribute values using the same dot notation syntax</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   558
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   559
<pre class="code prettyprint">&#x2F;&#x2F; Get the string for the accept label
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   560
var lbl = o.get(&quot;strings.ui.accept_label&quot;);</pre>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   561
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   562
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   563
<h3 id="subattrs-gsv">Getters, Setters, Validators and Sub Attributes</h3>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   564
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   565
<p>Getter, setter and validator attribute configuration functions are only defined for the top level
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   566
attribute (<code>&quot;strings&quot;</code> in this case) and will be invoked when getting/setting sub attribute values.
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   567
What this means is that getters and setters should always return the massaged value for the top level
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   568
attribute (e.g. <code>&quot;strings&quot;</code>), and not the sub attribute value being set (e.g. <code>&quot;strings.ui.accept_label&quot;</code>).
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   569
The sub attribute being set is passed in as the second argument to the getter/setter/validator, so that it
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   570
can fork for sub attribute handling if required.</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   571
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   572
<p>For example:</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   573
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   574
<pre class="code prettyprint">this.addAttr(&quot;strings&quot;, {
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   575
    getter : function(val, fullName) {
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   576
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   577
        &#x2F;&#x2F; &#x27;fullName&#x27; is &quot;strings.errors.e4500&quot;
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   578
        &#x2F;&#x2F; &#x27;val&#x27; is the whole strings hash: { ui : {...}, errors : {...}}.
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   579
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   580
        &#x2F;&#x2F; &#x27;path&#x27; is [&quot;strings&quot;, &quot;errors&quot;, &quot;e4500&quot;]
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   581
        var path = fullName.split(&quot;.&quot;);
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   582
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   583
        if (path.length &gt; 1) {
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   584
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   585
            &#x2F;&#x2F; Someone&#x27;s asking for a sub-attribute value
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   586
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   587
            &#x2F;&#x2F; Maybe we want to do some special normalization just for this use case.
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   588
            &#x2F;&#x2F; For example, return a default error message instead of undefined.
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   589
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   590
            path.shift();
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   591
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   592
            if (path[0] == &quot;errors&quot;) {
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   593
                var leafValue = Y.Object.getValue(val, path);
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   594
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   595
                if (leafValue === undefined) {
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   596
                    Y.Object.setValue(val, path, &quot;Unknown Error&quot;);
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   597
                }
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   598
            }
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   599
        }
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   600
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   601
        &#x2F;&#x2F; In either case (sub attribute or not) val is always the full hash for the &#x27;strings&#x27; attribute.
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   602
        return val;
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   603
    }
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   604
});</pre>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   605
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   606
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   607
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   608
</div>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   609
            </div>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   610
        </div>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   611
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   612
        <div class="yui3-u-1-4">
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   613
            <div class="sidebar">
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   614
                
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   615
                    <div id="toc" class="sidebox">
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   616
                        <div class="hd">
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   617
                            <h2 class="no-toc">Table of Contents</h2>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   618
                        </div>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   619
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   620
                        <div class="bd">
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   621
                            <ul class="toc">
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   622
<li>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   623
<a href="#getting-started">Getting Started</a>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   624
</li>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   625
<li>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   626
<a href="#augment">Augmenting Your Class With Attribute</a>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   627
</li>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   628
<li>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   629
<a href="#adding">Adding Attributes</a>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   630
</li>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   631
<li>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   632
<a href="#configuration">Attribute Configuration Properties</a>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   633
<ul class="toc">
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   634
<li>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   635
<a href="#howtoconfig">Configuring Attributes</a>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   636
</li>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   637
</ul>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   638
</li>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   639
<li>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   640
<a href="#setting-and-getting-attributes">Setting and Getting Attributes</a>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   641
</li>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   642
<li>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   643
<a href="#events">Attribute Change Events</a>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   644
<ul class="toc">
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   645
<li>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   646
<a href="#listening-for-change-events">Listening for Change Events</a>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   647
</li>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   648
<li>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   649
<a href="#on-vs-after">On vs. After</a>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   650
<ul class="toc">
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   651
<li>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   652
<a href="#on">On</a>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   653
</li>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   654
<li>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   655
<a href="#after">After</a>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   656
</li>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   657
</ul>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   658
</li>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   659
<li>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   660
<a href="#the-event-object">The Event Object</a>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   661
</li>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   662
</ul>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   663
</li>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   664
<li>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   665
<a href="#attrsetflow">Attribute Set Flow Diagram</a>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   666
</li>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   667
<li>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   668
<a href="#subattrs">Getting/Setting Sub Attribute Values</a>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   669
<ul class="toc">
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   670
<li>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   671
<a href="#subattrs-gsv">Getters, Setters, Validators and Sub Attributes</a>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   672
</li>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   673
</ul>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   674
</li>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   675
</ul>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   676
                        </div>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   677
                    </div>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   678
                
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   679
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   680
                
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   681
                    <div class="sidebox">
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   682
                        <div class="hd">
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   683
                            <h2 class="no-toc">Examples</h2>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   684
                        </div>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   685
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   686
                        <div class="bd">
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   687
                            <ul class="examples">
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   688
                                
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   689
                                    
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   690
                                        <li data-description="Use the Attribute API to define, set and get attribute values.">
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   691
                                            <a href="attribute-basic.html">Basic Attribute Configuration</a>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   692
                                        </li>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   693
                                    
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   694
                                
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   695
                                    
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   696
                                        <li data-description="Configure attributes to be readOnly or writeOnce.">
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   697
                                            <a href="attribute-rw.html">Read-Only and Write-Once Attributes</a>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   698
                                        </li>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   699
                                    
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   700
                                
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   701
                                    
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   702
                                        <li data-description="How to listen for changes in attribute values.">
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   703
                                            <a href="attribute-event.html">Attribute Change Events</a>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   704
                                        </li>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   705
                                    
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   706
                                
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   707
                                    
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   708
                                        <li data-description="Create a basic SpeedDater class, with Attribute support.">
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   709
                                            <a href="attribute-basic-speeddate.html">Attribute Based Speed Dating</a>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   710
                                        </li>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   711
                                    
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   712
                                
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   713
                                    
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   714
                                        <li data-description="Refactors the basic Speed Dating example, to use attribute change events to update rendered elements, and have two instances react to another.">
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   715
                                            <a href="attribute-event-speeddate.html">Attribute Event Based Speed Dating</a>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   716
                                        </li>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   717
                                    
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   718
                                
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   719
                                    
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   720
                                        <li data-description="Add custom methods to get and set attribute values and provide validation support.">
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   721
                                            <a href="attribute-getset.html">Attribute Getters, Setters and Validators</a>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   722
                                        </li>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   723
                                    
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   724
                                
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   725
                            </ul>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   726
                        </div>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   727
                    </div>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   728
                
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   729
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   730
                
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   731
            </div>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   732
        </div>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   733
    </div>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   734
</div>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   735
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   736
<script src="../assets/vendor/prettify/prettify-min.js"></script>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   737
<script>prettyPrint();</script>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   738
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   739
<script>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   740
YUI.Env.Tests = {
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   741
    examples: [],
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   742
    project: '../assets',
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   743
    assets: '../assets/attribute',
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   744
    name: 'attribute',
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   745
    title: 'Attribute',
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   746
    newWindow: '',
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   747
    auto:  false 
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   748
};
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   749
YUI.Env.Tests.examples.push('attribute-basic');
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   750
YUI.Env.Tests.examples.push('attribute-rw');
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   751
YUI.Env.Tests.examples.push('attribute-event');
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   752
YUI.Env.Tests.examples.push('attribute-basic-speeddate');
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   753
YUI.Env.Tests.examples.push('attribute-event-speeddate');
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   754
YUI.Env.Tests.examples.push('attribute-getset');
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   755
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   756
</script>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   757
<script src="../assets/yui/test-runner.js"></script>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   758
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   759
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   760
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   761
</body>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
   762
</html>