Attribute.js.html revision 4fcbec6145d16637205990699912fb90f6a3807c
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>API: attribute Attribute.js (YUI Library)</title>
<link rel="stylesheet" type="text/css" href="assets/api.css">
<script type="text/javascript" src="assets/api-js"></script>
<script type="text/javascript" src="assets/ac-js"></script>
</head>
<body id="yahoo-com">
<div id="doc3" class="yui-t2">
<div id="hd">
<a href="http://developer.yahoo.com/yui/"><h1>Yahoo! UI Library</h1></a>
<h3>attribute&nbsp; <span class="subtitle">3.00PR1</span></h3>
<p>
<a href="/index.html">Yahoo! UI Library</a>
&gt; <a href="/module_attribute.html">attribute</a>
&gt; Attribute.js (source view)
</p>
</div>
<div id="bd">
<div id="yui-main">
<div class="yui-b">
<form name="yui-classopts-form">
<span id="classopts"><input type="checkbox" name="showprivate" id="showprivate" /> <label for="showprivate">Show Private</label></span>
<span id="classopts"><input type="checkbox" name="showprotected" id="showprotected" /> <label for="showprotected">Show Protected</label></span>
<span id="classopts"><input type="checkbox" name="showdeprecated" id="showdeprecated" /> <label for="showdeprecated">Show Deprecated</label></span>
</form>
<div id="srcout">
<style>
#doc3 #classopts { display:none; }
</style>
<div class="highlight" ><pre> <span class="c">/**</span>
<span class="c"> * Managed Attribute Provider</span>
<span class="c"> * @module attribute</span>
<span class="c"> */</span>
<span class="k">var</span> <span class="nx">O</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nb">Object</span><span class="o">,</span>
<span class="nx">DOT</span> <span class="o">=</span> <span class="s2">&quot;.&quot;</span><span class="o">,</span>
<span class="nx">CHANGE</span> <span class="o">=</span> <span class="s2">&quot;Change&quot;</span><span class="o">,</span>
<span class="nx">GET</span> <span class="o">=</span> <span class="s2">&quot;get&quot;</span><span class="o">,</span>
<span class="nx">SET</span> <span class="o">=</span> <span class="s2">&quot;set&quot;</span><span class="o">,</span>
<span class="nx">VALUE</span> <span class="o">=</span> <span class="s2">&quot;value&quot;</span><span class="o">,</span>
<span class="nx">CLONE</span> <span class="o">=</span> <span class="s2">&quot;clone&quot;</span><span class="o">,</span>
<span class="nx">READ_ONLY</span> <span class="o">=</span> <span class="s2">&quot;readOnly&quot;</span><span class="o">,</span>
<span class="nx">WRITE_ONCE</span> <span class="o">=</span> <span class="s2">&quot;writeOnce&quot;</span><span class="o">,</span>
<span class="nx">VALIDATOR</span> <span class="o">=</span> <span class="s2">&quot;validator&quot;</span><span class="o">,</span>
<span class="nx">CLONE_ENUM</span><span class="o">;</span>
<span class="c">/**</span>
<span class="c"> * &lt;p&gt;</span>
<span class="c"> * Attribute provides managed attribute support. </span>
<span class="c"> * &lt;/p&gt;</span>
<span class="c"> * &lt;p&gt;</span>
<span class="c"> * The class is designed to be augmented onto a host class, </span>
<span class="c"> * and allows the host to support get/set methods for attributes,</span>
<span class="c"> * initial configuration support and attribute change events.</span>
<span class="c"> * &lt;/p&gt;</span>
<span class="c"> * &lt;p&gt;Attributes added to the host can:&lt;/p&gt;</span>
<span class="c"> * &lt;ul&gt;</span>
<span class="c"> * &lt;li&gt;Be defined as read-only.&lt;/li&gt;</span>
<span class="c"> * &lt;li&gt;Be defined as write-once.&lt;/li&gt;</span>
<span class="c"> * &lt;li&gt;Be defined with a set function, used to manipulate</span>
<span class="c"> * values passed to Attribute&#39;s set method, before they are stored.&lt;/li&gt;</span>
<span class="c"> * &lt;li&gt;Be defined with a validator function, to validate values before they are stored.&lt;/li&gt;</span>
<span class="c"> * &lt;li&gt;Be defined with a get function, which can be used to manipulate stored values,</span>
<span class="c"> * before they are returned by Attribute&#39;s get method.&lt;/li&gt;</span>
<span class="c"> * &lt;li&gt;Specify if and how they should be cloned on &#39;get&#39; (see Attribute.CLONE for supported clone modes).&lt;/li&gt;</span>
<span class="c"> * &lt;/ul&gt;</span>
<span class="c"> *</span>
<span class="c"> * &lt;em&gt;See the addAtt method, for details about how to add attributes with</span>
<span class="c"> * a specific configuration&lt;/em&gt;</span>
<span class="c"> *</span>
<span class="c"> * @class Attribute</span>
<span class="c"> * @uses Event.Target</span>
<span class="c"> */</span>
<span class="k">function</span> <span class="nx">Attribute</span><span class="o">()</span> <span class="o">{</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">Event</span><span class="o">.</span><span class="nx">Target</span><span class="o">.</span><span class="nx">call</span><span class="o">(</span><span class="k">this</span><span class="o">,</span> <span class="o">{</span><span class="nx">emitFacade</span><span class="o">:</span><span class="kc">true</span><span class="o">});</span>
<span class="k">this</span><span class="o">.</span><span class="nx">_conf</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_conf</span> <span class="o">||</span> <span class="k">new</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">State</span><span class="o">();</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s1">&#39;att constructor called&#39;</span><span class="o">,</span> <span class="s1">&#39;info&#39;</span><span class="o">,</span> <span class="s1">&#39;attribute&#39;</span><span class="o">);</span>
<span class="o">}</span>
<span class="c">/**</span>
<span class="c"> * @property CLONE</span>
<span class="c"> * @static</span>
<span class="c"> * @final</span>
<span class="c"> * @type Object</span>
<span class="c"> * &lt;p&gt;</span>
<span class="c"> * Constants for clone formats supported by Attribute.</span>
<span class="c"> * &lt;/p&gt;</span>
<span class="c"> * &lt;p&gt;</span>
<span class="c"> * By default attribute values returned by the get method</span>
<span class="c"> * are not cloned. However setting the attribute&#39;s &quot;clone&quot;</span>
<span class="c"> * property to:</span>
<span class="c"> * &lt;/p&gt;</span>
<span class="c"> * &lt;dl&gt;</span>
<span class="c"> * &lt;dt&gt;Attribute.CLONE.DEEP&lt;/dt&gt;</span>
<span class="c"> * &lt;dd&gt;Will result in a deep cloned value being returned</span>
<span class="c"> * (using Y.clone). This can be expensive for complex</span>
<span class="c"> * objects.</span>
<span class="c"> * &lt;/dd&gt;</span>
<span class="c"> * &lt;dt&gt;Attribute.CLONE.SHALLOW&lt;/dt&gt;</span>
<span class="c"> * &lt;dd&gt;Will result in a shallow cloned value being returned</span>
<span class="c"> * (using Y.merge).</span>
<span class="c"> * &lt;/dd&gt;</span>
<span class="c"> * &lt;dt&gt;Attribute.CLONE.IMMUTABLE&lt;/dt&gt;</span>
<span class="c"> * &lt;dd&gt;Will result in a deep cloned value being returned</span>
<span class="c"> * when using the get method. Additionally users will</span>
<span class="c"> * not be able to set sub values of the attribute </span>
<span class="c"> * using the complex attribute notation (obj.set(&quot;x.y.z, 5)).</span>
<span class="c"> * However the value of the attribute can be changed, making</span>
<span class="c"> * it different from a READONLY attribute.</span>
<span class="c"> * &lt;/dd&gt;</span>
<span class="c"> * &lt;dt&gt;Attribute.CLONE.NONE&lt;/dt&gt;</span>
<span class="c"> * &lt;dd&gt;</span>
<span class="c"> * The value will not be cloned, resulting in a reference</span>
<span class="c"> * to the stored value being passed back, if the value is an object.</span>
<span class="c"> * This is the default behavior.</span>
<span class="c"> * &lt;/dd&gt;</span>
<span class="c"> * &lt;/dl&gt;</span>
<span class="c"> */</span>
<span class="nx">Attribute</span><span class="o">.</span><span class="nx">CLONE</span> <span class="o">=</span> <span class="o">{</span>
<span class="nx">NONE</span> <span class="o">:</span> <span class="m">0</span><span class="o">,</span>
<span class="nx">DEEP</span> <span class="o">:</span> <span class="m">1</span><span class="o">,</span>
<span class="nx">SHALLOW</span> <span class="o">:</span> <span class="m">2</span><span class="o">,</span>
<span class="nx">IMMUTABLE</span><span class="o">:</span> <span class="m">3</span>
<span class="o">};</span>
<span class="nx">CLONE_ENUM</span> <span class="o">=</span> <span class="nx">Attribute</span><span class="o">.</span><span class="nx">CLONE</span><span class="o">;</span>
<span class="nx">Attribute</span><span class="o">.</span><span class="nx">prototype</span> <span class="o">=</span> <span class="o">{</span>
<span class="c">/**</span>
<span class="c"> * &lt;p&gt;</span>
<span class="c"> * Adds an attribute, with the provided configuration to the host object. Intended</span>
<span class="c"> * to be used by the host object to setup it&#39;s set of available attributes.</span>
<span class="c"> * &lt;/p&gt;</span>
<span class="c"> * &lt;p&gt;</span>
<span class="c"> * The config argument object literal supports the following optional properties:</span>
<span class="c"> * &lt;/p&gt;</span>
<span class="c"> * &lt;dl&gt;</span>
<span class="c"> * &lt;dt&gt;value {Any}&lt;/dt&gt;</span>
<span class="c"> * &lt;dd&gt;The initial value to set on the attribute&lt;/dd&gt;</span>
<span class="c"> * &lt;dt&gt;readOnly {Boolean}&lt;/dt&gt;</span>
<span class="c"> * &lt;dd&gt;Whether or not the attribute is read only. Attributes having readOnly set to true</span>
<span class="c"> * cannot be set by invoking the set method.&lt;/dd&gt;</span>
<span class="c"> * &lt;dt&gt;writeOnce {Boolean}&lt;/dt&gt;</span>
<span class="c"> * &lt;dd&gt;Whether or not the attribute is &quot;write once&quot;. Attributes having writeOnce set to true, </span>
<span class="c"> * can only have their values set once, be it through the default configuration, </span>
<span class="c"> * constructor configuration arguments, or by invoking set.&lt;/dd&gt;</span>
<span class="c"> * &lt;dt&gt;set {Function}&lt;/dt&gt;</span>
<span class="c"> * &lt;dd&gt;The setter function to be invoked (within the context of the host object) before </span>
<span class="c"> * the attribute is stored by a call to the set method. The value returned by the </span>
<span class="c"> * set function will be the finally stored value.&lt;/dd&gt;</span>
<span class="c"> * &lt;dt&gt;get {Function}&lt;/dt&gt;</span>
<span class="c"> * &lt;dd&gt;The getter function to be invoked (within the context of the host object) before</span>
<span class="c"> * the stored values is returned to a user invoking the get method for the attribute.</span>
<span class="c"> * The value returned by the get function is the final value which will be returned to the </span>
<span class="c"> * user when they invoke get.&lt;/dd&gt;</span>
<span class="c"> * &lt;dt&gt;validator {Function}&lt;/dt&gt;</span>
<span class="c"> * &lt;dd&gt;The validator function which is invoked prior to setting the stored value. Returning</span>
<span class="c"> * false from the validator function will prevent the value from being stored&lt;/dd&gt;</span>
<span class="c"> * &lt;dt&gt;clone {int}&lt;/dt&gt;</span>
<span class="c"> * &lt;dd&gt;If and how the value returned by a call to the get method, should be de-referenced from</span>
<span class="c"> * the stored value. By default values are not cloned, and hence a call to get will return</span>
<span class="c"> * a reference to the stored value. See Attribute.CLONE for more details about the clone </span>
<span class="c"> * options available&lt;/dd&gt;</span>
<span class="c"> * &lt;/dl&gt;</span>
<span class="c"> *</span>
<span class="c"> * @method addAtt</span>
<span class="c"> * </span>
<span class="c"> * @param {String} name The attribute key</span>
<span class="c"> * @param {Object} config (optional) An object literal specifying the configuration for the attribute.</span>
<span class="c"> * &lt;strong&gt;NOTE:&lt;/strong&gt; The config object is modified when adding an attribute, </span>
<span class="c"> * so if you need to protect the original values, you will need to merge or clone the object.</span>
<span class="c"> * </span>
<span class="c"> */</span>
<span class="nx">addAtt</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">name</span><span class="o">,</span> <span class="nx">config</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s1">&#39;adding attribute: &#39;</span> <span class="o">+</span> <span class="nx">name</span><span class="o">,</span> <span class="s1">&#39;info&#39;</span><span class="o">,</span> <span class="s1">&#39;attribute&#39;</span><span class="o">);</span>
<span class="k">var</span> <span class="nx">value</span><span class="o">,</span> <span class="nx">hasValue</span> <span class="o">=</span> <span class="o">(</span><span class="nx">VALUE</span> <span class="k">in</span> <span class="nx">config</span><span class="o">);</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">config</span><span class="o">[</span><span class="nx">READ_ONLY</span><span class="o">]</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="nx">hasValue</span><span class="o">)</span> <span class="o">{</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s1">&#39;readOnly attribute: &#39;</span> <span class="o">+</span> <span class="nx">name</span> <span class="o">+</span> <span class="s1">&#39;, added without an initial value. Value will be set on intial call to set&#39;</span><span class="o">,</span> <span class="s1">&#39;warn&#39;</span><span class="o">,</span> <span class="s1">&#39;attribute&#39;</span><span class="o">);}</span>
<span class="k">if</span><span class="o">(</span><span class="nx">hasValue</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">value</span> <span class="o">=</span> <span class="nx">config</span><span class="o">.</span><span class="nx">value</span><span class="o">;</span>
<span class="nx">delete</span> <span class="nx">config</span><span class="o">.</span><span class="nx">value</span><span class="o">;</span>
<span class="o">}</span>
<span class="k">this</span><span class="o">.</span><span class="nx">_conf</span><span class="o">.</span><span class="nx">add</span><span class="o">(</span><span class="nx">name</span><span class="o">,</span> <span class="nx">config</span><span class="o">);</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">hasValue</span><span class="o">)</span> <span class="o">{</span>
<span class="k">this</span><span class="o">.</span><span class="nx">set</span><span class="o">(</span><span class="nx">name</span><span class="o">,</span> <span class="nx">value</span><span class="o">);</span>
<span class="o">}</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Removes an attribute.</span>
<span class="c"> *</span>
<span class="c"> * @method removeAtt</span>
<span class="c"> * @param {String} name The attribute key</span>
<span class="c"> */</span>
<span class="nx">removeAtt</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">name</span><span class="o">)</span> <span class="o">{</span>
<span class="k">this</span><span class="o">.</span><span class="nx">_conf</span><span class="o">.</span><span class="nx">remove</span><span class="o">(</span><span class="nx">name</span><span class="o">);</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Returns the current value of the attribute. If the attribute</span>
<span class="c"> * has been configured with a &#39;get&#39; handler, this method will delegate</span>
<span class="c"> * to the &#39;get&#39; handler to obtain the value of the attribute.</span>
<span class="c"> * The &#39;get&#39; handler will be passed the current value of the attribute </span>
<span class="c"> * as the only argument.</span>
<span class="c"> *</span>
<span class="c"> * @method get</span>
<span class="c"> *</span>
<span class="c"> * @param {String} key The attribute whose value will be returned. If</span>
<span class="c"> * the value of the attribute is an Object, dot notation can be used to</span>
<span class="c"> * obtain the value of a property of the object (e.g. &lt;code&gt;get(&quot;x.y.z&quot;)&lt;/code&gt;)</span>
<span class="c"> */</span>
<span class="nx">get</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">name</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">conf</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_conf</span><span class="o">,</span>
<span class="nx">path</span><span class="o">,</span>
<span class="nx">getFn</span><span class="o">,</span>
<span class="nx">clone</span><span class="o">,</span>
<span class="nx">val</span><span class="o">;</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">name</span><span class="o">.</span><span class="nx">indexOf</span><span class="o">(</span><span class="nx">DOT</span><span class="o">)</span> <span class="o">!==</span> <span class="o">-</span><span class="m">1</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">path</span> <span class="o">=</span> <span class="nx">name</span><span class="o">.</span><span class="nx">split</span><span class="o">(</span><span class="nx">DOT</span><span class="o">);</span>
<span class="nx">name</span> <span class="o">=</span> <span class="nx">path</span><span class="o">.</span><span class="nx">shift</span><span class="o">();</span>
<span class="o">}</span>
<span class="nx">val</span> <span class="o">=</span> <span class="nx">conf</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="nx">name</span><span class="o">,</span> <span class="nx">VALUE</span><span class="o">);</span>
<span class="nx">getFn</span> <span class="o">=</span> <span class="nx">conf</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="nx">name</span><span class="o">,</span> <span class="nx">GET</span><span class="o">);</span>
<span class="nx">clone</span> <span class="o">=</span> <span class="nx">conf</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="nx">name</span><span class="o">,</span> <span class="nx">CLONE</span><span class="o">);</span>
<span class="nx">val</span> <span class="o">=</span> <span class="o">(</span><span class="nx">clone</span><span class="o">)</span> <span class="o">?</span> <span class="k">this</span><span class="o">.</span><span class="nx">_cloneAttVal</span><span class="o">(</span><span class="nx">val</span><span class="o">,</span> <span class="nx">clone</span><span class="o">)</span> <span class="o">:</span> <span class="nx">val</span><span class="o">;</span>
<span class="nx">val</span> <span class="o">=</span> <span class="o">(</span><span class="nx">getFn</span><span class="o">)</span> <span class="o">?</span> <span class="nx">getFn</span><span class="o">.</span><span class="nx">call</span><span class="o">(</span><span class="k">this</span><span class="o">,</span> <span class="nx">val</span><span class="o">)</span> <span class="o">:</span> <span class="nx">val</span><span class="o">;</span>
<span class="nx">val</span> <span class="o">=</span> <span class="o">(</span><span class="nx">path</span><span class="o">)</span> <span class="o">?</span> <span class="k">this</span><span class="o">.</span><span class="nx">_getSubAttVal</span><span class="o">(</span><span class="nx">path</span><span class="o">,</span> <span class="nx">val</span><span class="o">)</span> <span class="o">:</span> <span class="nx">val</span><span class="o">;</span>
<span class="k">return</span> <span class="nx">val</span><span class="o">;</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Sets the value of an attribute.</span>
<span class="c"> *</span>
<span class="c"> * @method set</span>
<span class="c"> * @chainable</span>
<span class="c"> * </span>
<span class="c"> * @param {String} name The name of the attribute. Note, if the </span>
<span class="c"> * value of the attribute is an Object, dot notation can be used</span>
<span class="c"> * to set the value of a property within the object </span>
<span class="c"> * (e.g. &lt;code&gt;set(&quot;x.y.z&quot;, 5)&lt;/code&gt;), if the attribute has not</span>
<span class="c"> * been declared as an immutable attribute (see Attribute.CLONE).</span>
<span class="c"> * </span>
<span class="c"> * @param {Any} value The value to apply to the attribute</span>
<span class="c"> * </span>
<span class="c"> * @param {Object} opts Optional event data. This object will be mixed into</span>
<span class="c"> * the event facade passed as the first argument to subscribers </span>
<span class="c"> * of attribute change events</span>
<span class="c"> */</span>
<span class="nx">set</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">name</span><span class="o">,</span> <span class="nx">val</span><span class="o">,</span> <span class="nx">opts</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">conf</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_conf</span><span class="o">,</span>
<span class="nx">data</span> <span class="o">=</span> <span class="nx">conf</span><span class="o">.</span><span class="nx">data</span><span class="o">,</span>
<span class="nx">strPath</span><span class="o">,</span>
<span class="nx">path</span><span class="o">,</span>
<span class="nx">currVal</span><span class="o">,</span>
<span class="nx">initialSet</span> <span class="o">=</span> <span class="o">(!</span><span class="nx">data</span><span class="o">.</span><span class="nx">value</span> <span class="o">||</span> <span class="o">!(</span><span class="nx">name</span> <span class="k">in</span> <span class="nx">data</span><span class="o">.</span><span class="nx">value</span><span class="o">));</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">name</span><span class="o">.</span><span class="nx">indexOf</span><span class="o">(</span><span class="nx">DOT</span><span class="o">)</span> <span class="o">!==</span> <span class="o">-</span><span class="m">1</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">strPath</span> <span class="o">=</span> <span class="nx">name</span><span class="o">;</span>
<span class="nx">path</span> <span class="o">=</span> <span class="nx">name</span><span class="o">.</span><span class="nx">split</span><span class="o">(</span><span class="nx">DOT</span><span class="o">);</span>
<span class="nx">name</span> <span class="o">=</span> <span class="nx">path</span><span class="o">.</span><span class="nx">shift</span><span class="o">();</span>
<span class="o">}</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">path</span> <span class="o">&amp;&amp;</span> <span class="nx">conf</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="nx">name</span><span class="o">,</span> <span class="nx">CLONE</span><span class="o">)</span> <span class="o">===</span> <span class="nx">CLONE_ENUM</span><span class="o">.</span><span class="nx">IMMUTABLE</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s1">&#39;set &#39;</span> <span class="o">+</span> <span class="nx">name</span> <span class="o">+</span> <span class="s1">&#39; failed; Attribute is IMMUTABLE. Setting a sub value is not permitted&#39;</span><span class="o">,</span> <span class="s1">&#39;info&#39;</span><span class="o">,</span> <span class="s1">&#39;attribute&#39;</span><span class="o">);</span>
<span class="k">return</span> <span class="k">this</span><span class="o">;</span>
<span class="o">}</span>
<span class="k">if</span> <span class="o">(!</span><span class="nx">initialSet</span><span class="o">)</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">conf</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="nx">name</span><span class="o">,</span> <span class="nx">WRITE_ONCE</span><span class="o">))</span> <span class="o">{</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s1">&#39;set &#39;</span> <span class="o">+</span> <span class="nx">name</span> <span class="o">+</span> <span class="s1">&#39; failed; Attribute is writeOnce&#39;</span><span class="o">,</span> <span class="s1">&#39;info&#39;</span><span class="o">,</span> <span class="s1">&#39;attribute&#39;</span><span class="o">);</span>
<span class="k">return</span> <span class="k">this</span><span class="o">;</span>
<span class="o">}</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">conf</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="nx">name</span><span class="o">,</span> <span class="nx">READ_ONLY</span><span class="o">))</span> <span class="o">{</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s1">&#39;set &#39;</span> <span class="o">+</span> <span class="nx">name</span> <span class="o">+</span> <span class="s1">&#39; failed; Attribute is readOnly&#39;</span><span class="o">,</span> <span class="s1">&#39;info&#39;</span><span class="o">,</span> <span class="s1">&#39;attribute&#39;</span><span class="o">);</span>
<span class="k">return</span> <span class="k">this</span><span class="o">;</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="k">if</span> <span class="o">(!</span><span class="nx">conf</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="nx">name</span><span class="o">))</span> <span class="o">{</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s1">&#39;Set called with unconfigured attribute. Adding a new attribute: &#39;</span> <span class="o">+</span> <span class="nx">name</span><span class="o">,</span> <span class="s1">&#39;info&#39;</span><span class="o">,</span> <span class="s1">&#39;attribute&#39;</span><span class="o">);</span>
<span class="o">}</span>
<span class="nx">currVal</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="nx">name</span><span class="o">);</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">path</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">val</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_setSubAttVal</span><span class="o">(</span><span class="nx">path</span><span class="o">,</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">clone</span><span class="o">(</span><span class="nx">currVal</span><span class="o">),</span> <span class="nx">val</span><span class="o">);</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">val</span> <span class="o">===</span> <span class="kc">undefined</span><span class="o">)</span> <span class="o">{</span>
<span class="c">// Path not valid, don&#39;t set anything.</span>
<span class="c"></span> <span class="nx">Y</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s1">&#39;set &#39;</span> <span class="o">+</span> <span class="nx">strPath</span> <span class="o">+</span> <span class="s1">&#39;failed; attribute sub path is invalid&#39;</span><span class="o">,</span> <span class="s1">&#39;error&#39;</span><span class="o">,</span> <span class="s1">&#39;attribute&#39;</span><span class="o">);</span>
<span class="k">return</span> <span class="k">this</span><span class="o">;</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="k">this</span><span class="o">.</span><span class="nx">_fireAttChange</span><span class="o">(</span><span class="nx">name</span><span class="o">,</span> <span class="nx">currVal</span><span class="o">,</span> <span class="nx">val</span><span class="o">,</span> <span class="nx">name</span><span class="o">,</span> <span class="nx">strPath</span><span class="o">,</span> <span class="nx">opts</span><span class="o">);</span>
<span class="k">return</span> <span class="k">this</span><span class="o">;</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Alias for the &lt;a href=&quot;Event.Target.html#method_subscribe&quot;&gt;Event.Target subscribe method&lt;/a&gt;.</span>
<span class="c"> * @method on</span>
<span class="c"> */</span>
<span class="nx">on</span> <span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
<span class="k">return</span> <span class="k">this</span><span class="o">.</span><span class="nx">subscribe</span><span class="o">.</span><span class="nx">apply</span><span class="o">(</span><span class="k">this</span><span class="o">,</span> <span class="nx">arguments</span><span class="o">);</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Default handler implementation for set events</span>
<span class="c"> *</span>
<span class="c"> * @private</span>
<span class="c"> * @method _defAttSet</span>
<span class="c"> * @param {Event.Facade} e The event object for the custom event</span>
<span class="c"> */</span>
<span class="nx">_defAttSet</span> <span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">e</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">conf</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_conf</span><span class="o">,</span>
<span class="nx">name</span> <span class="o">=</span> <span class="nx">e</span><span class="o">.</span><span class="nx">attrName</span><span class="o">,</span>
<span class="nx">val</span> <span class="o">=</span> <span class="nx">e</span><span class="o">.</span><span class="nx">newVal</span><span class="o">,</span>
<span class="nx">retVal</span><span class="o">,</span>
<span class="nx">valFn</span> <span class="o">=</span> <span class="nx">conf</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="nx">name</span><span class="o">,</span> <span class="nx">VALIDATOR</span><span class="o">),</span>
<span class="nx">setFn</span> <span class="o">=</span> <span class="nx">conf</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="nx">name</span><span class="o">,</span> <span class="nx">SET</span><span class="o">);</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">setFn</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">retVal</span> <span class="o">=</span> <span class="nx">setFn</span><span class="o">.</span><span class="nx">call</span><span class="o">(</span><span class="k">this</span><span class="o">,</span> <span class="nx">val</span><span class="o">);</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">retVal</span> <span class="o">!==</span> <span class="kc">undefined</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s1">&#39;attribute: &#39;</span> <span class="o">+</span> <span class="nx">name</span> <span class="o">+</span> <span class="s1">&#39; modified by setter&#39;</span><span class="o">,</span> <span class="s1">&#39;info&#39;</span><span class="o">,</span> <span class="s1">&#39;attribute&#39;</span><span class="o">);</span>
<span class="nx">val</span> <span class="o">=</span> <span class="nx">retVal</span><span class="o">;</span> <span class="c">// setter can change value</span>
<span class="c"></span> <span class="o">}</span>
<span class="o">}</span>
<span class="k">if</span> <span class="o">(!</span><span class="nx">valFn</span> <span class="o">||</span> <span class="nx">valFn</span><span class="o">.</span><span class="nx">call</span><span class="o">(</span><span class="k">this</span><span class="o">,</span> <span class="nx">val</span><span class="o">))</span> <span class="o">{</span>
<span class="nx">conf</span><span class="o">.</span><span class="nx">add</span><span class="o">(</span><span class="nx">name</span><span class="o">,</span> <span class="o">{</span> <span class="nx">value</span><span class="o">:</span> <span class="nx">val</span> <span class="o">});</span>
<span class="nx">e</span><span class="o">.</span><span class="nx">newVal</span> <span class="o">=</span> <span class="nx">conf</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="nx">name</span><span class="o">,</span> <span class="nx">VALUE</span><span class="o">);</span>
<span class="o">}</span> <span class="k">else</span> <span class="o">{</span>
<span class="c">// Prevent &quot;after&quot; listeners from being </span>
<span class="c"></span> <span class="c">// invoked since nothing changed.</span>
<span class="c"></span> <span class="nx">e</span><span class="o">.</span><span class="nx">stopImmediatePropagation</span><span class="o">();</span>
<span class="o">}</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Retrieves the sub value at the provided path,</span>
<span class="c"> * from the value object provided.</span>
<span class="c"> *</span>
<span class="c"> * @method _getSubAttVal</span>
<span class="c"> * @private</span>
<span class="c"> *</span>
<span class="c"> * @param {Array} path A path array, specifying the object traversal path</span>
<span class="c"> * from which to obtain the sub value.</span>
<span class="c"> * @param {Object} val The object from which to extract the property value</span>
<span class="c"> * @return {Any} The value stored in the path or undefined if not found.</span>
<span class="c"> */</span>
<span class="nx">_getSubAttVal</span><span class="o">:</span> <span class="k">function</span> <span class="o">(</span><span class="nx">path</span><span class="o">,</span> <span class="nx">val</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">pl</span> <span class="o">=</span> <span class="nx">path</span><span class="o">.</span><span class="nx">length</span><span class="o">,</span>
<span class="nx">i</span><span class="o">;</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">pl</span> <span class="o">&gt;</span> <span class="m">0</span><span class="o">)</span> <span class="o">{</span>
<span class="k">for</span> <span class="o">(</span><span class="nx">i</span> <span class="o">=</span> <span class="m">0</span><span class="o">;</span> <span class="nx">val</span> <span class="o">!==</span> <span class="kc">undefined</span> <span class="o">&amp;&amp;</span> <span class="nx">i</span> <span class="o">&lt;</span> <span class="nx">pl</span><span class="o">;</span> <span class="o">++</span><span class="nx">i</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">val</span> <span class="o">=</span> <span class="nx">val</span><span class="o">[</span><span class="nx">path</span><span class="o">[</span><span class="nx">i</span><span class="o">]];</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="k">return</span> <span class="nx">val</span><span class="o">;</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Sets the sub value at the provided path on the value object.</span>
<span class="c"> * Returns the modified value object, or undefined if the path is invalid.</span>
<span class="c"> *</span>
<span class="c"> * @method _setSubAttVal</span>
<span class="c"> * @private</span>
<span class="c"> * </span>
<span class="c"> * @param {Array} path A path array, specifying the object traversal path</span>
<span class="c"> * at which to set the sub value.</span>
<span class="c"> * @param {Object} val The object on which to set the sub value.</span>
<span class="c"> * @param {Any} subval The sub value to set.</span>
<span class="c"> * @return {Object} The modified object, with the new sub value set, or </span>
<span class="c"> * undefined, if the path was invalid.</span>
<span class="c"> */</span>
<span class="nx">_setSubAttVal</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">path</span><span class="o">,</span> <span class="nx">val</span><span class="o">,</span> <span class="nx">subval</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">leafIdx</span> <span class="o">=</span> <span class="nx">path</span><span class="o">.</span><span class="nx">length</span><span class="o">-</span><span class="m">1</span><span class="o">,</span>
<span class="nx">i</span><span class="o">,</span>
<span class="nx">o</span><span class="o">;</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">leafIdx</span> <span class="o">&gt;=</span> <span class="m">0</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">o</span> <span class="o">=</span> <span class="nx">val</span><span class="o">;</span>
<span class="k">for</span> <span class="o">(</span><span class="nx">i</span> <span class="o">=</span> <span class="m">0</span><span class="o">;</span> <span class="nx">o</span> <span class="o">!==</span> <span class="kc">undefined</span> <span class="o">&amp;&amp;</span> <span class="nx">i</span> <span class="o">&lt;</span> <span class="nx">leafIdx</span><span class="o">;</span> <span class="o">++</span><span class="nx">i</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">o</span> <span class="o">=</span> <span class="nx">o</span><span class="o">[</span><span class="nx">path</span><span class="o">[</span><span class="nx">i</span><span class="o">]];</span>
<span class="o">}</span>
<span class="c">// Not preventing new properties from being added</span>
<span class="c"></span> <span class="k">if</span> <span class="o">(</span><span class="nx">o</span> <span class="o">!==</span> <span class="kc">undefined</span> <span class="c">/* &amp;&amp; o[path[i]] !== undefined */</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">o</span><span class="o">[</span><span class="nx">path</span><span class="o">[</span><span class="nx">i</span><span class="o">]]</span> <span class="o">=</span> <span class="nx">subval</span><span class="o">;</span>
<span class="o">}</span> <span class="k">else</span> <span class="o">{</span>
<span class="nx">val</span> <span class="o">=</span> <span class="kc">undefined</span><span class="o">;</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="k">return</span> <span class="nx">val</span><span class="o">;</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Sets multiple attribute values.</span>
<span class="c"> * </span>
<span class="c"> * @method setAtts</span>
<span class="c"> * @param {Object} atts A hash of attributes: name/value pairs</span>
<span class="c"> */</span>
<span class="nx">setAtts</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">atts</span><span class="o">)</span> <span class="o">{</span>
<span class="k">for</span> <span class="o">(</span><span class="k">var</span> <span class="nx">att</span> <span class="k">in</span> <span class="nx">atts</span><span class="o">)</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(</span> <span class="nx">O</span><span class="o">.</span><span class="nx">owns</span><span class="o">(</span><span class="nx">atts</span><span class="o">,</span> <span class="nx">att</span><span class="o">)</span> <span class="o">)</span> <span class="o">{</span>
<span class="k">this</span><span class="o">.</span><span class="nx">set</span><span class="o">(</span><span class="nx">att</span><span class="o">,</span> <span class="nx">atts</span><span class="o">[</span><span class="nx">att</span><span class="o">]);</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Gets multiple attribute values.</span>
<span class="c"> *</span>
<span class="c"> * @method getAtts</span>
<span class="c"> * @return {Object} A hash of attributes: name/value pairs</span>
<span class="c"> */</span>
<span class="nx">getAtts</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">atts</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">o</span> <span class="o">=</span> <span class="o">{};</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">atts</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">o</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">clone</span><span class="o">(</span><span class="nx">atts</span><span class="o">);</span>
<span class="o">}</span> <span class="k">else</span> <span class="o">{</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">each</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">_conf</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="nx">VALUE</span><span class="o">),</span> <span class="k">function</span><span class="o">(</span><span class="nx">val</span><span class="o">,</span> <span class="nx">att</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">o</span><span class="o">[</span><span class="nx">att</span><span class="o">]</span> <span class="o">=</span> <span class="nx">val</span><span class="o">;</span>
<span class="o">});</span>
<span class="o">}</span>
<span class="k">return</span> <span class="nx">o</span><span class="o">;</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Configures attributes, and sets initial values</span>
<span class="c"> *</span>
<span class="c"> * @method _initAtts</span>
<span class="c"> * @protected</span>
<span class="c"> * </span>
<span class="c"> * @param {Object} cfg Attribute configuration object literal</span>
<span class="c"> * @param {Object} initValues Name/value hash of initial values to apply</span>
<span class="c"> */</span>
<span class="nx">_initAtts</span> <span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">cfg</span><span class="o">,</span> <span class="nx">initValues</span><span class="o">)</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">cfg</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">att</span><span class="o">,</span>
<span class="nx">attCfg</span><span class="o">,</span>
<span class="nx">values</span><span class="o">,</span>
<span class="nx">value</span><span class="o">,</span>
<span class="nx">atts</span> <span class="o">=</span> <span class="nx">cfg</span><span class="o">;</span>
<span class="nx">values</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_splitAttVals</span><span class="o">(</span><span class="nx">initValues</span><span class="o">);</span>
<span class="k">for</span> <span class="o">(</span><span class="nx">att</span> <span class="k">in</span> <span class="nx">atts</span><span class="o">)</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">O</span><span class="o">.</span><span class="nx">owns</span><span class="o">(</span><span class="nx">atts</span><span class="o">,</span> <span class="nx">att</span><span class="o">))</span> <span class="o">{</span>
<span class="nx">attCfg</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">merge</span><span class="o">(</span><span class="nx">atts</span><span class="o">[</span><span class="nx">att</span><span class="o">]);</span>
<span class="nx">value</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_initAttVal</span><span class="o">(</span><span class="nx">att</span><span class="o">,</span> <span class="nx">attCfg</span><span class="o">,</span> <span class="nx">values</span><span class="o">);</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">value</span> <span class="o">!==</span> <span class="kc">undefined</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">attCfg</span><span class="o">.</span><span class="nx">value</span> <span class="o">=</span> <span class="nx">value</span><span class="o">;</span>
<span class="o">}</span>
<span class="k">this</span><span class="o">.</span><span class="nx">addAtt</span><span class="o">(</span><span class="nx">att</span><span class="o">,</span> <span class="nx">attCfg</span><span class="o">);</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Utility to split out regular attribute values</span>
<span class="c"> * from complex attribute values, so that complex</span>
<span class="c"> * attributes can be keyed by top level attribute name.</span>
<span class="c"> *</span>
<span class="c"> * @method _splitAttrValues</span>
<span class="c"> * @param {Object} valueHash Name/value hash of initial values</span>
<span class="c"> *</span>
<span class="c"> * @return {Object} Object literal with 2 properties - &quot;simple&quot; and &quot;complex&quot;,</span>
<span class="c"> * containing simple and complex attribute values respectively keyed </span>
<span class="c"> * by attribute the top level attribute name.</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">_splitAttVals</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">valueHash</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">vals</span> <span class="o">=</span> <span class="o">{},</span>
<span class="nx">subvals</span> <span class="o">=</span> <span class="o">{},</span>
<span class="nx">path</span><span class="o">,</span>
<span class="nx">attr</span><span class="o">,</span>
<span class="nx">v</span><span class="o">;</span>
<span class="k">for</span> <span class="o">(</span><span class="k">var</span> <span class="nx">k</span> <span class="k">in</span> <span class="nx">valueHash</span><span class="o">)</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">O</span><span class="o">.</span><span class="nx">owns</span><span class="o">(</span><span class="nx">valueHash</span><span class="o">,</span> <span class="nx">k</span><span class="o">))</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">k</span><span class="o">.</span><span class="nx">indexOf</span><span class="o">(</span><span class="nx">DOT</span><span class="o">)</span> <span class="o">!==</span> <span class="o">-</span><span class="m">1</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">path</span> <span class="o">=</span> <span class="nx">k</span><span class="o">.</span><span class="nx">split</span><span class="o">(</span><span class="nx">DOT</span><span class="o">);</span>
<span class="nx">attr</span> <span class="o">=</span> <span class="nx">path</span><span class="o">.</span><span class="nx">shift</span><span class="o">();</span>
<span class="nx">v</span> <span class="o">=</span> <span class="nx">subvals</span><span class="o">[</span><span class="nx">attr</span><span class="o">]</span> <span class="o">=</span> <span class="nx">subvals</span><span class="o">[</span><span class="nx">attr</span><span class="o">]</span> <span class="o">||</span> <span class="o">[];</span>
<span class="nx">v</span><span class="o">[</span><span class="nx">v</span><span class="o">.</span><span class="nx">length</span><span class="o">]</span> <span class="o">=</span> <span class="o">{</span>
<span class="nx">path</span> <span class="o">:</span> <span class="nx">path</span><span class="o">,</span>
<span class="nx">value</span><span class="o">:</span> <span class="nx">valueHash</span><span class="o">[</span><span class="nx">k</span><span class="o">]</span>
<span class="o">};</span>
<span class="o">}</span> <span class="k">else</span> <span class="o">{</span>
<span class="nx">vals</span><span class="o">[</span><span class="nx">k</span><span class="o">]</span> <span class="o">=</span> <span class="nx">valueHash</span><span class="o">[</span><span class="nx">k</span><span class="o">];</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="k">return</span> <span class="o">{</span> <span class="nx">simple</span><span class="o">:</span><span class="nx">vals</span><span class="o">,</span> <span class="nx">complex</span><span class="o">:</span><span class="nx">subvals</span> <span class="o">};</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Returns the initial value of the given attribute from</span>
<span class="c"> * either the default configuration provided, or the </span>
<span class="c"> * over-ridden value if it exists in the initValues </span>
<span class="c"> * hash provided.</span>
<span class="c"> *</span>
<span class="c"> * @param {String} att Attribute name</span>
<span class="c"> * @param {Object} cfg Default attribute configuration</span>
<span class="c"> * object literal</span>
<span class="c"> * @param {Object} initVales Initial attribute values, provided </span>
<span class="c"> * for the instance</span>
<span class="c"> *</span>
<span class="c"> * @return {Any} Initial value of the attribute.</span>
<span class="c"> *</span>
<span class="c"> * @method _initAttVal</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">_initAttVal</span> <span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">att</span><span class="o">,</span> <span class="nx">cfg</span><span class="o">,</span> <span class="nx">initValues</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">hasVal</span> <span class="o">=</span> <span class="o">(</span><span class="nx">VALUE</span> <span class="k">in</span> <span class="nx">cfg</span><span class="o">),</span>
<span class="nx">val</span> <span class="o">=</span> <span class="nx">cfg</span><span class="o">.</span><span class="nx">value</span><span class="o">,</span>
<span class="nx">simple</span><span class="o">,</span>
<span class="nx">complex</span><span class="o">,</span>
<span class="nx">i</span><span class="o">,</span>
<span class="nx">l</span><span class="o">,</span>
<span class="nx">path</span><span class="o">,</span>
<span class="nx">subval</span><span class="o">,</span>
<span class="nx">subvals</span><span class="o">;</span>
<span class="k">if</span> <span class="o">(!</span><span class="nx">cfg</span><span class="o">[</span><span class="nx">READ_ONLY</span><span class="o">]</span> <span class="o">&amp;&amp;</span> <span class="nx">initValues</span><span class="o">)</span> <span class="o">{</span>
<span class="c">// Simple Attributes</span>
<span class="c"></span> <span class="nx">simple</span> <span class="o">=</span> <span class="nx">initValues</span><span class="o">.</span><span class="nx">simple</span><span class="o">;</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">simple</span> <span class="o">&amp;&amp;</span> <span class="nx">O</span><span class="o">.</span><span class="nx">owns</span><span class="o">(</span><span class="nx">simple</span><span class="o">,</span> <span class="nx">att</span><span class="o">))</span> <span class="o">{</span>
<span class="nx">hasVal</span> <span class="o">=</span> <span class="kc">true</span><span class="o">;</span>
<span class="nx">val</span> <span class="o">=</span> <span class="nx">simple</span><span class="o">[</span><span class="nx">att</span><span class="o">];</span>
<span class="o">}</span>
<span class="c">// Complex Attributes</span>
<span class="c"></span> <span class="nx">complex</span> <span class="o">=</span> <span class="nx">initValues</span><span class="o">.</span><span class="nx">complex</span><span class="o">;</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">complex</span> <span class="o">&amp;&amp;</span> <span class="nx">O</span><span class="o">.</span><span class="nx">owns</span><span class="o">(</span><span class="nx">complex</span><span class="o">,</span> <span class="nx">att</span><span class="o">))</span> <span class="o">{</span>
<span class="nx">hasVal</span> <span class="o">=</span> <span class="kc">true</span><span class="o">;</span>
<span class="nx">subvals</span> <span class="o">=</span> <span class="nx">complex</span><span class="o">[</span><span class="nx">att</span><span class="o">];</span>
<span class="k">for</span> <span class="o">(</span><span class="nx">i</span> <span class="o">=</span> <span class="m">0</span><span class="o">,</span> <span class="nx">l</span> <span class="o">=</span> <span class="nx">subvals</span><span class="o">.</span><span class="nx">length</span><span class="o">;</span> <span class="nx">i</span> <span class="o">&lt;</span> <span class="nx">l</span><span class="o">;</span> <span class="o">++</span><span class="nx">i</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">path</span> <span class="o">=</span> <span class="nx">subvals</span><span class="o">[</span><span class="nx">i</span><span class="o">].</span><span class="nx">path</span><span class="o">;</span>
<span class="nx">subval</span> <span class="o">=</span> <span class="nx">subvals</span><span class="o">[</span><span class="nx">i</span><span class="o">].</span><span class="nx">value</span><span class="o">;</span>
<span class="nx">val</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_setSubAttVal</span><span class="o">(</span><span class="nx">path</span><span class="o">,</span> <span class="nx">val</span><span class="o">,</span> <span class="nx">subval</span><span class="o">);</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="k">return</span> <span class="nx">val</span><span class="o">;</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Clone utility method, which will </span>
<span class="c"> * clone the provided value using YUI&#39;s </span>
<span class="c"> * merge, or clone utilities based</span>
<span class="c"> * on the clone type provided.</span>
<span class="c"> * </span>
<span class="c"> * @see Attribute.CLONE</span>
<span class="c"> * @method _cloneAttVal</span>
<span class="c"> * @private </span>
<span class="c"> * @param {Any} val Value to clone</span>
<span class="c"> * @param {int} type Clone type to use, See the CLONE property</span>
<span class="c"> */</span>
<span class="nx">_cloneAttVal</span> <span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">val</span><span class="o">,</span> <span class="nx">type</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">switch</span><span class="o">(</span><span class="nx">type</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">case</span> <span class="nx">CLONE_ENUM</span><span class="o">.</span><span class="nx">SHALLOW</span><span class="o">:</span>
<span class="nx">val</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">merge</span><span class="o">(</span><span class="nx">val</span><span class="o">);</span>
<span class="k">break</span><span class="o">;</span>
<span class="nx">case</span> <span class="nx">CLONE_ENUM</span><span class="o">.</span><span class="nx">DEEP</span><span class="o">:</span>
<span class="nx">case</span> <span class="nx">CLONE_ENUM</span><span class="o">.</span><span class="nx">IMMUTABLE</span><span class="o">:</span>
<span class="nx">val</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">clone</span><span class="o">(</span><span class="nx">val</span><span class="o">);</span>
<span class="k">break</span><span class="o">;</span>
<span class="o">}</span>
<span class="k">return</span> <span class="nx">val</span><span class="o">;</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Utility method to help setup the event payload and </span>
<span class="c"> * fire the attribute change event.</span>
<span class="c"> * </span>
<span class="c"> * @method _fireAttChange</span>
<span class="c"> * @private</span>
<span class="c"> * @param {String} type The event name</span>
<span class="c"> * @param {Any} currVal The current value of the attribute</span>
<span class="c"> * @param {Any} newVal The new value of the attribute</span>
<span class="c"> * @param {String} attrName The name of the attribute</span>
<span class="c"> * @param {String} strFullPath The full path of the property being changed, </span>
<span class="c"> * if this is a sub-attribute value being change</span>
<span class="c"> * @param {Function} defaultFn The default handler for the change event</span>
<span class="c"> * @param {Object} opts Any additional event data to mix into the attribute change event&#39;s event facade.</span>
<span class="c"> */</span>
<span class="nx">_fireAttChange</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">type</span><span class="o">,</span> <span class="nx">currVal</span><span class="o">,</span> <span class="nx">newVal</span><span class="o">,</span> <span class="nx">attrName</span><span class="o">,</span> <span class="nx">strFullPath</span><span class="o">,</span> <span class="nx">defaultFn</span><span class="o">,</span> <span class="nx">opts</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">type</span> <span class="o">=</span> <span class="nx">type</span> <span class="o">+</span> <span class="nx">CHANGE</span><span class="o">;</span>
<span class="c">// TODO: Publishing temporarily, while we address event bubbling/queuing</span>
<span class="c"></span> <span class="k">this</span><span class="o">.</span><span class="nx">publish</span><span class="o">(</span><span class="nx">type</span><span class="o">,</span> <span class="o">{</span><span class="nx">queuable</span><span class="o">:</span><span class="kc">false</span><span class="o">,</span> <span class="nx">defaultFn</span><span class="o">:</span><span class="k">this</span><span class="o">.</span><span class="nx">_defAttSet</span><span class="o">});</span>
<span class="k">var</span> <span class="nx">eData</span> <span class="o">=</span> <span class="o">{</span>
<span class="nx">type</span><span class="o">:</span> <span class="nx">type</span><span class="o">,</span>
<span class="nx">prevVal</span><span class="o">:</span> <span class="nx">currVal</span><span class="o">,</span>
<span class="nx">newVal</span><span class="o">:</span> <span class="nx">newVal</span><span class="o">,</span>
<span class="nx">attrName</span><span class="o">:</span> <span class="nx">attrName</span><span class="o">,</span>
<span class="nx">subAttrName</span><span class="o">:</span> <span class="nx">strFullPath</span>
<span class="o">};</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">opts</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">mix</span><span class="o">(</span><span class="nx">eData</span><span class="o">,</span> <span class="nx">opts</span><span class="o">);</span>
<span class="o">}</span>
<span class="k">this</span><span class="o">.</span><span class="nx">fire</span><span class="o">(</span><span class="nx">eData</span><span class="o">);</span>
<span class="o">}</span>
<span class="o">};</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">mix</span><span class="o">(</span><span class="nx">Attribute</span><span class="o">,</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">Event</span><span class="o">.</span><span class="nx">Target</span><span class="o">,</span> <span class="kc">false</span><span class="o">,</span> <span class="kc">null</span><span class="o">,</span> <span class="m">1</span><span class="o">);</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">Attribute</span> <span class="o">=</span> <span class="nx">Attribute</span><span class="o">;</span>
</pre></div>
</div>
</div>
</div>
<div class="yui-b">
<div class="nav">
<div class="module">
<h4>Modules</h4>
<ul class="content">
<li class=""><a href="module_anim.html">anim</a></li>
<li class="selected"><a href="module_attribute.html">attribute</a></li>
<li class=""><a href="module_base.html">base</a></li>
<li class=""><a href="module_dd.html">dd</a></li>
<li class=""><a href="module_dd-plugin.html">dd-plugin</a></li>
<li class=""><a href="module_dump.html">dump</a></li>
<li class=""><a href="module_event.html">event</a></li>
<li class=""><a href="module_io.html">io</a></li>
<li class=""><a href="module_node.html">node</a></li>
<li class=""><a href="module_oop.html">oop</a></li>
<li class=""><a href="module_queue.html">queue</a></li>
<li class=""><a href="module_substitute.html">substitute</a></li>
<li class=""><a href="module_yui.html">yui</a></li>
</ul>
</div>
<div class="module">
<h4>Classes</h4>
<ul class="content">
<li class=""><a href="Attribute.html">Attribute</a></li>
<li class=""><a href="State.html">State</a></li>
</ul>
</div>
<div class="module">
<h4>Files</h4>
<ul class="content">
<li class="selected"><a href="Attribute.js.html">Attribute.js</a></li>
<li class=""><a href="State.js.html">State.js</a></li>
</ul>
</div>
</div>
</div>
</div>
<div id="ft">
<hr />
Copyright &copy; 2008 Yahoo! Inc. All rights reserved.
</div>
</div>
</body>
</html>