Added IE event.preventDefault polyfill

This commit is contained in:
Timothy Warren 2011-11-06 17:11:34 -05:00
parent 9205532e79
commit 69fb63a983
7 changed files with 115 additions and 74 deletions

View File

@ -30,7 +30,7 @@
<span class='line'> 23</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> <span class='line'> 23</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 24</span> </span><span class="WHIT"> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">sel.addEventListener</span><span class="WHIT"> </span><span class="PUNC">!==</span><span class="WHIT"> </span><span class="STRN">"undefined"</span><span class="PUNC">)</span><span class="WHIT"> <span class='line'> 24</span> </span><span class="WHIT"> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">sel.addEventListener</span><span class="WHIT"> </span><span class="PUNC">!==</span><span class="WHIT"> </span><span class="STRN">"undefined"</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 25</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> <span class='line'> 25</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 26</span> </span><span class="WHIT"> </span><span class="COMM">//Duplicated events are dropped, per the specification</span><span class="WHIT"> <span class='line'> 26</span> </span><span class="WHIT"> </span><span class="COMM">// Duplicated events are dropped, per the specification</span><span class="WHIT">
<span class='line'> 27</span> </span><span class="WHIT"> </span><span class="NAME">sel.addEventListener</span><span class="PUNC">(</span><span class="NAME">event</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">callback</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT"> <span class='line'> 27</span> </span><span class="WHIT"> </span><span class="NAME">sel.addEventListener</span><span class="PUNC">(</span><span class="NAME">event</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">callback</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 28</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT"> <span class='line'> 28</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 29</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT"> <span class='line'> 29</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
@ -45,7 +45,7 @@
<span class='line'> 38</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT"> <span class='line'> 38</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 39</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT"> <span class='line'> 39</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 40</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT"> <span class='line'> 40</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 41</span> </span><span class="WHIT"> </span><span class="COMM">//typeof function doesn't work in IE where attachEvent is available: brute force it</span><span class="WHIT"> <span class='line'> 41</span> </span><span class="WHIT"> </span><span class="COMM">// typeof function doesn't work in IE where attachEvent is available: brute force it</span><span class="WHIT">
<span class='line'> 42</span> </span><span class="WHIT"> </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">document.attachEvent</span><span class="WHIT"> </span><span class="PUNC">!==</span><span class="WHIT"> </span><span class="STRN">"undefined"</span><span class="PUNC">)</span><span class="WHIT"> <span class='line'> 42</span> </span><span class="WHIT"> </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">document.attachEvent</span><span class="WHIT"> </span><span class="PUNC">!==</span><span class="WHIT"> </span><span class="STRN">"undefined"</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 43</span> </span><span class="PUNC">{</span><span class="WHIT"> <span class='line'> 43</span> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 44</span> </span><span class="WHIT"> </span><span class="COMM">/** <span class='line'> 44</span> </span><span class="WHIT"> </span><span class="COMM">/**
@ -120,7 +120,7 @@
<span class='line'>113</span> </span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT"> <span class='line'>113</span> </span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>114</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT"> <span class='line'>114</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>115</span> <span class='line'>115</span>
<span class='line'>116</span> </span><span class="WHIT"> </span><span class="COMM">//Multiple events? Run recursively!</span><span class="WHIT"> <span class='line'>116</span> </span><span class="WHIT"> </span><span class="COMM">// Multiple events? Run recursively!</span><span class="WHIT">
<span class='line'>117</span> </span><span class="WHIT"> </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">event.match</span><span class="PUNC">(</span><span class="REGX">/^([\w\-]+)$/</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> <span class='line'>117</span> </span><span class="WHIT"> </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">event.match</span><span class="PUNC">(</span><span class="REGX">/^([\w\-]+)$/</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>118</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> <span class='line'>118</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>119</span> </span><span class="WHIT"> </span><span class="NAME">event</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">event.split</span><span class="PUNC">(</span><span class="STRN">" "</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT"> <span class='line'>119</span> </span><span class="WHIT"> </span><span class="NAME">event</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">event.split</span><span class="PUNC">(</span><span class="STRN">" "</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
@ -148,30 +148,30 @@
<span class='line'>141</span> <span class='line'>141</span>
<span class='line'>142</span> </span><span class="WHIT"> </span><span class="NAME">_attach_delegate</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">sel</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">target</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">event</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">callback</span><span class="PUNC">)</span><span class="WHIT"> <span class='line'>142</span> </span><span class="WHIT"> </span><span class="NAME">_attach_delegate</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">sel</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">target</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">event</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">callback</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>143</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> <span class='line'>143</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>144</span> </span><span class="WHIT"> </span><span class="COMM">//_attach the _listener to the parent object</span><span class="WHIT"> <span class='line'>144</span> </span><span class="WHIT"> </span><span class="COMM">// attach the listener to the parent object</span><span class="WHIT">
<span class='line'>145</span> </span><span class="WHIT"> </span><span class="NAME">_add_remove</span><span class="PUNC">(</span><span class="NAME">sel</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">event</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">e</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT"> <span class='line'>145</span> </span><span class="WHIT"> </span><span class="NAME">_add_remove</span><span class="PUNC">(</span><span class="NAME">sel</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">event</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">e</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>146</span> </span><span class="WHIT"> <span class='line'>146</span> </span><span class="WHIT">
<span class='line'>147</span> </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">elem</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">t</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">tar</span><span class="PUNC">;</span><span class="WHIT"> <span class='line'>147</span> </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">elem</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">t</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">tar</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>148</span> </span><span class="WHIT"> <span class='line'>148</span> </span><span class="WHIT">
<span class='line'>149</span> </span><span class="COMM">//IE 8 doesn't have event bound to element</span><span class="WHIT"> <span class='line'>149</span> </span><span class="COMM">// IE 8 doesn't have event bound to element</span><span class="WHIT">
<span class='line'>150</span> </span><span class="WHIT"> </span><span class="NAME">e</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">e</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NAME">window.event</span><span class="PUNC">;</span><span class="WHIT"> <span class='line'>150</span> </span><span class="WHIT"> </span><span class="NAME">e</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">e</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NAME">window.event</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>151</span> </span><span class="WHIT"> <span class='line'>151</span> </span><span class="WHIT">
<span class='line'>152</span> </span><span class="COMM">//Get the live version of the target selector</span><span class="WHIT"> <span class='line'>152</span> </span><span class="COMM">// Get the live version of the target selector</span><span class="WHIT">
<span class='line'>153</span> </span><span class="WHIT"> </span><span class="NAME">t</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">$_.$</span><span class="PUNC">(</span><span class="NAME">target</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT"> <span class='line'>153</span> </span><span class="WHIT"> </span><span class="NAME">t</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">$_.$</span><span class="PUNC">(</span><span class="NAME">target</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>154</span> </span><span class="WHIT"> <span class='line'>154</span> </span><span class="WHIT">
<span class='line'>155</span> </span><span class="COMM">//Check each element to see if it matches the target</span><span class="WHIT"> <span class='line'>155</span> </span><span class="COMM">// Check each element to see if it matches the target</span><span class="WHIT">
<span class='line'>156</span> </span><span class="WHIT"> </span><span class="KEYW">for</span><span class="PUNC">(</span><span class="NAME">elem</span><span class="WHIT"> </span><span class="KEYW">in</span><span class="WHIT"> </span><span class="NAME">t</span><span class="PUNC">)</span><span class="WHIT"> <span class='line'>156</span> </span><span class="WHIT"> </span><span class="KEYW">for</span><span class="PUNC">(</span><span class="NAME">elem</span><span class="WHIT"> </span><span class="KEYW">in</span><span class="WHIT"> </span><span class="NAME">t</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>157</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> <span class='line'>157</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>158</span> </span><span class="WHIT"> </span><span class="COMM">//IE 8 doesn't have target in the event object</span><span class="WHIT"> <span class='line'>158</span> </span><span class="WHIT"> </span><span class="COMM">// IE 8 doesn't have target in the event object</span><span class="WHIT">
<span class='line'>159</span> </span><span class="WHIT"> </span><span class="NAME">tar</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">e.target</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NAME">e.srcElement</span><span class="PUNC">;</span><span class="WHIT"> <span class='line'>159</span> </span><span class="WHIT"> </span><span class="NAME">tar</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">e.target</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NAME">e.srcElement</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>160</span> </span><span class="WHIT"> <span class='line'>160</span> </span><span class="WHIT">
<span class='line'>161</span> </span><span class="COMM">//Fire target callback when event bubbles from target</span><span class="WHIT"> <span class='line'>161</span> </span><span class="COMM">// Fire target callback when event bubbles from target</span><span class="WHIT">
<span class='line'>162</span> </span><span class="WHIT"> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">tar</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="NAME">t</span><span class="PUNC">[</span><span class="NAME">elem</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="WHIT"> <span class='line'>162</span> </span><span class="WHIT"> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">tar</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="NAME">t</span><span class="PUNC">[</span><span class="NAME">elem</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>163</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> <span class='line'>163</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>164</span> </span><span class="WHIT"> </span><span class="COMM">//Trigger the event callback</span><span class="WHIT"> <span class='line'>164</span> </span><span class="WHIT"> </span><span class="COMM">// Trigger the event callback</span><span class="WHIT">
<span class='line'>165</span> </span><span class="WHIT"> </span><span class="NAME">callback.call</span><span class="PUNC">(</span><span class="NAME">t</span><span class="PUNC">[</span><span class="NAME">elem</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">e</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT"> <span class='line'>165</span> </span><span class="WHIT"> </span><span class="NAME">callback.call</span><span class="PUNC">(</span><span class="NAME">t</span><span class="PUNC">[</span><span class="NAME">elem</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">e</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>166</span> </span><span class="WHIT"> <span class='line'>166</span> </span><span class="WHIT">
<span class='line'>167</span> </span><span class="COMM">//Stop event propegation</span><span class="WHIT"> <span class='line'>167</span> </span><span class="COMM">// Stop event propegation</span><span class="WHIT">
<span class='line'>168</span> </span><span class="WHIT"> </span><span class="NAME">e.stopPropagation</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT"> <span class='line'>168</span> </span><span class="WHIT"> </span><span class="NAME">e.stopPropagation</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>169</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT"> <span class='line'>169</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>170</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT"> <span class='line'>170</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
@ -250,7 +250,7 @@
<span class='line'>243</span> * @param string event_type <span class='line'>243</span> * @param string event_type
<span class='line'>244</span> * @param function callback <span class='line'>244</span> * @param function callback
<span class='line'>245</span> */</span><span class="WHIT"> <span class='line'>245</span> */</span><span class="WHIT">
<span class='line'>246</span> </span><span class="WHIT"> </span><span class="NAME">delegate</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">target</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">event</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">callback</span><span class="PUNC">)</span><span class="WHIT"> <span class='line'>246</span> </span><span class="WHIT"> </span><span class="NAME">delegate</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">target</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">event</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">callback</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>247</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> <span class='line'>247</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>248</span> </span><span class="WHIT"> </span><span class="NAME">$_.each</span><span class="PUNC">(</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">e</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT"> <span class='line'>248</span> </span><span class="WHIT"> </span><span class="NAME">$_.each</span><span class="PUNC">(</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">e</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>249</span> </span><span class="WHIT"> </span><span class="NAME">_attach_delegate</span><span class="PUNC">(</span><span class="NAME">e</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">target</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">event</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">callback</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT"> <span class='line'>249</span> </span><span class="WHIT"> </span><span class="NAME">_attach_delegate</span><span class="PUNC">(</span><span class="NAME">e</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">target</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">event</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">callback</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">

View File

@ -50,10 +50,10 @@
<span class='line'> 43</span> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">a</span><span class="WHIT"> </span><span class="PUNC">></span><span class="WHIT"> </span><span class="NAME">b</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">a</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">b</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="NUMB">1</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT"> <span class='line'> 43</span> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">a</span><span class="WHIT"> </span><span class="PUNC">></span><span class="WHIT"> </span><span class="NAME">b</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">a</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">b</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="NUMB">1</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 44</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT"> <span class='line'> 44</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 45</span> </span><span class="WHIT"> <span class='line'> 45</span> </span><span class="WHIT">
<span class='line'> 46</span> </span><span class="COMM">//cache object/array size</span><span class="WHIT"> <span class='line'> 46</span> </span><span class="COMM">// cache object/array size</span><span class="WHIT">
<span class='line'> 47</span> </span><span class="WHIT"> </span><span class="NAME">num_keys</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">keys.length</span><span class="PUNC">;</span><span class="WHIT"> <span class='line'> 47</span> </span><span class="WHIT"> </span><span class="NAME">num_keys</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">keys.length</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 48</span> </span><span class="WHIT"> <span class='line'> 48</span> </span><span class="WHIT">
<span class='line'> 49</span> </span><span class="COMM">//Recreate the object/array</span><span class="WHIT"> <span class='line'> 49</span> </span><span class="COMM">// Recreate the object/array</span><span class="WHIT">
<span class='line'> 50</span> </span><span class="WHIT"> </span><span class="KEYW">for</span><span class="PUNC">(</span><span class="NAME">i</span><span class="PUNC">=</span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">num_keys</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="PUNC">++</span><span class="PUNC">)</span><span class="WHIT"> <span class='line'> 50</span> </span><span class="WHIT"> </span><span class="KEYW">for</span><span class="PUNC">(</span><span class="NAME">i</span><span class="PUNC">=</span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">num_keys</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="PUNC">++</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 51</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> <span class='line'> 51</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 52</span> </span><span class="WHIT"> </span><span class="NAME">new_o</span><span class="PUNC">[</span><span class="NAME">keys</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">o</span><span class="PUNC">[</span><span class="NAME">keys</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT"> <span class='line'> 52</span> </span><span class="WHIT"> </span><span class="NAME">new_o</span><span class="PUNC">[</span><span class="NAME">keys</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">o</span><span class="PUNC">[</span><span class="NAME">keys</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
@ -138,7 +138,7 @@
<span class='line'>131</span> </span><span class="WHIT"> </span><span class="NAME">num_keys</span><span class="PUNC">,</span><span class="WHIT"> <span class='line'>131</span> </span><span class="WHIT"> </span><span class="NAME">num_keys</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>132</span> </span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT"> <span class='line'>132</span> </span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>133</span> </span><span class="WHIT"> <span class='line'>133</span> </span><span class="WHIT">
<span class='line'>134</span> </span><span class="COMM">//Extract the keys or values if needed</span><span class="WHIT"> <span class='line'>134</span> </span><span class="COMM">// Extract the keys or values if needed</span><span class="WHIT">
<span class='line'>135</span> </span><span class="WHIT"> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">$_.type</span><span class="PUNC">(</span><span class="NAME">keys</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">!==</span><span class="WHIT"> </span><span class="STRN">"array"</span><span class="PUNC">)</span><span class="WHIT"> <span class='line'>135</span> </span><span class="WHIT"> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">$_.type</span><span class="PUNC">(</span><span class="NAME">keys</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">!==</span><span class="WHIT"> </span><span class="STRN">"array"</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>136</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> <span class='line'>136</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>137</span> </span><span class="WHIT"> </span><span class="NAME">keys</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">this.object_values</span><span class="PUNC">(</span><span class="NAME">keys</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT"> <span class='line'>137</span> </span><span class="WHIT"> </span><span class="NAME">keys</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">this.object_values</span><span class="PUNC">(</span><span class="NAME">keys</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
@ -148,7 +148,7 @@
<span class='line'>141</span> </span><span class="WHIT"> </span><span class="NAME">vals</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">this.object_values</span><span class="PUNC">(</span><span class="NAME">vals</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT"> <span class='line'>141</span> </span><span class="WHIT"> </span><span class="NAME">vals</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">this.object_values</span><span class="PUNC">(</span><span class="NAME">vals</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>142</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT"> <span class='line'>142</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>143</span> </span><span class="WHIT"> <span class='line'>143</span> </span><span class="WHIT">
<span class='line'>144</span> </span><span class="COMM">//cache the number of keys</span><span class="WHIT"> <span class='line'>144</span> </span><span class="COMM">// cache the number of keys</span><span class="WHIT">
<span class='line'>145</span> </span><span class="WHIT"> </span><span class="NAME">num_keys</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">keys.length</span><span class="PUNC">;</span><span class="WHIT"> <span class='line'>145</span> </span><span class="WHIT"> </span><span class="NAME">num_keys</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">keys.length</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>146</span> </span><span class="WHIT"> <span class='line'>146</span> </span><span class="WHIT">
<span class='line'>147</span> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">num_keys</span><span class="WHIT"> </span><span class="PUNC">!==</span><span class="WHIT"> </span><span class="NAME">vals.length</span><span class="PUNC">)</span><span class="WHIT"> <span class='line'>147</span> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">num_keys</span><span class="WHIT"> </span><span class="PUNC">!==</span><span class="WHIT"> </span><span class="NAME">vals.length</span><span class="PUNC">)</span><span class="WHIT">
@ -157,7 +157,7 @@
<span class='line'>150</span> </span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT"> <span class='line'>150</span> </span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>151</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT"> <span class='line'>151</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>152</span> </span><span class="WHIT"> <span class='line'>152</span> </span><span class="WHIT">
<span class='line'>153</span> </span><span class="COMM">//Create and return the new object</span><span class="WHIT"> <span class='line'>153</span> </span><span class="COMM">// Create and return the new object</span><span class="WHIT">
<span class='line'>154</span> </span><span class="WHIT"> </span><span class="KEYW">for</span><span class="PUNC">(</span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">num_keys</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="PUNC">++</span><span class="PUNC">)</span><span class="WHIT"> <span class='line'>154</span> </span><span class="WHIT"> </span><span class="KEYW">for</span><span class="PUNC">(</span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">num_keys</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="PUNC">++</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>155</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> <span class='line'>155</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>156</span> </span><span class="WHIT"> </span><span class="NAME">new_object</span><span class="PUNC">[</span><span class="NAME">keys</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">vals</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT"> <span class='line'>156</span> </span><span class="WHIT"> </span><span class="NAME">new_object</span><span class="PUNC">[</span><span class="NAME">keys</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">vals</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
@ -191,7 +191,7 @@
<span class='line'>184</span> </span><span class="WHIT"> </span><span class="NAME">x</span><span class="PUNC">,</span><span class="WHIT"> <span class='line'>184</span> </span><span class="WHIT"> </span><span class="NAME">x</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>185</span> </span><span class="WHIT"> </span><span class="NAME">is_array</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">;</span><span class="WHIT"> <span class='line'>185</span> </span><span class="WHIT"> </span><span class="NAME">is_array</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>186</span> </span><span class="WHIT"> <span class='line'>186</span> </span><span class="WHIT">
<span class='line'>187</span> </span><span class="COMM">//Check for an array in the arguments</span><span class="WHIT"> <span class='line'>187</span> </span><span class="COMM">// Check for an array in the arguments</span><span class="WHIT">
<span class='line'>188</span> </span><span class="WHIT"> </span><span class="KEYW">for</span><span class="PUNC">(</span><span class="NAME">i</span><span class="PUNC">=</span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">arg_len</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="PUNC">++</span><span class="PUNC">)</span><span class="WHIT"> <span class='line'>188</span> </span><span class="WHIT"> </span><span class="KEYW">for</span><span class="PUNC">(</span><span class="NAME">i</span><span class="PUNC">=</span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">arg_len</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="PUNC">++</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>189</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> <span class='line'>189</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>190</span> </span><span class="WHIT"> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">$_.type</span><span class="PUNC">(</span><span class="NAME">args</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">!==</span><span class="WHIT"> </span><span class="STRN">"array"</span><span class="PUNC">)</span><span class="WHIT"> <span class='line'>190</span> </span><span class="WHIT"> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">$_.type</span><span class="PUNC">(</span><span class="NAME">args</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">!==</span><span class="WHIT"> </span><span class="STRN">"array"</span><span class="PUNC">)</span><span class="WHIT">
@ -201,21 +201,21 @@
<span class='line'>194</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT"> <span class='line'>194</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>195</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT"> <span class='line'>195</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>196</span> </span><span class="WHIT"> <span class='line'>196</span> </span><span class="WHIT">
<span class='line'>197</span> </span><span class="COMM">//If all the arguments are javascript arrays</span><span class="WHIT"> <span class='line'>197</span> </span><span class="COMM">// If all the arguments are javascript arrays</span><span class="WHIT">
<span class='line'>198</span> </span><span class="WHIT"> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">is_array</span><span class="PUNC">)</span><span class="WHIT"> <span class='line'>198</span> </span><span class="WHIT"> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">is_array</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>199</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> <span class='line'>199</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>200</span> </span><span class="WHIT"> </span><span class="NAME">new_obj</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT"> <span class='line'>200</span> </span><span class="WHIT"> </span><span class="NAME">new_obj</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>201</span> </span><span class="WHIT"> </span><span class="COMM">//Let javascript do all the work!</span><span class="WHIT"> <span class='line'>201</span> </span><span class="WHIT"> </span><span class="COMM">// Let javascript do all the work!</span><span class="WHIT">
<span class='line'>202</span> </span><span class="WHIT"> </span><span class="KEYW">for</span><span class="PUNC">(</span><span class="NAME">i</span><span class="PUNC">=</span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">arg_len</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="PUNC">++</span><span class="PUNC">)</span><span class="WHIT"> <span class='line'>202</span> </span><span class="WHIT"> </span><span class="KEYW">for</span><span class="PUNC">(</span><span class="NAME">i</span><span class="PUNC">=</span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">arg_len</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="PUNC">++</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>203</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> <span class='line'>203</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>204</span> </span><span class="WHIT"> </span><span class="NAME">new_obj</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">new_obj.contact</span><span class="PUNC">(</span><span class="NAME">args</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT"> <span class='line'>204</span> </span><span class="WHIT"> </span><span class="NAME">new_obj</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">new_obj.contact</span><span class="PUNC">(</span><span class="NAME">args</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>205</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT"> <span class='line'>205</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>206</span> </span><span class="WHIT"> <span class='line'>206</span> </span><span class="WHIT">
<span class='line'>207</span> </span><span class="COMM">//Return early</span><span class="WHIT"> <span class='line'>207</span> </span><span class="COMM">// Return early</span><span class="WHIT">
<span class='line'>208</span> </span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">new_obj</span><span class="PUNC">;</span><span class="WHIT"> <span class='line'>208</span> </span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">new_obj</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>209</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT"> <span class='line'>209</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>210</span> </span><span class="WHIT"> <span class='line'>210</span> </span><span class="WHIT">
<span class='line'>211</span> </span><span class="COMM">//No, there's at least one object</span><span class="WHIT"> <span class='line'>211</span> </span><span class="COMM">// No, there's at least one object</span><span class="WHIT">
<span class='line'>212</span> </span><span class="WHIT"> </span><span class="KEYW">for</span><span class="PUNC">(</span><span class="NAME">i</span><span class="PUNC">=</span><span class="NUMB">0</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">x</span><span class="PUNC">=</span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">arg_len</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="PUNC">++</span><span class="PUNC">)</span><span class="WHIT"> <span class='line'>212</span> </span><span class="WHIT"> </span><span class="KEYW">for</span><span class="PUNC">(</span><span class="NAME">i</span><span class="PUNC">=</span><span class="NUMB">0</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">x</span><span class="PUNC">=</span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">arg_len</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="PUNC">++</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>213</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> <span class='line'>213</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>214</span> </span><span class="WHIT"> </span><span class="NAME">arg</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">args</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT"> <span class='line'>214</span> </span><span class="WHIT"> </span><span class="NAME">arg</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">args</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
@ -360,10 +360,11 @@
<span class='line'>353</span> </span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">new_str</span><span class="PUNC">;</span><span class="WHIT"> <span class='line'>353</span> </span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">new_str</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>354</span> </span><span class="WHIT"> <span class='line'>354</span> </span><span class="WHIT">
<span class='line'>355</span> </span><span class="PUNC">}</span><span class="WHIT"> <span class='line'>355</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>356</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT"> <span class='line'>356</span> </span><span class="WHIT">
<span class='line'>357</span> <span class='line'>357</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>358</span> </span><span class="WHIT"> </span><span class="COMM">//Add it to the $_ object</span><span class="WHIT"> <span class='line'>358</span>
<span class='line'>359</span> </span><span class="WHIT"> </span><span class="NAME">$_.ext</span><span class="PUNC">(</span><span class="STRN">'util'</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">u</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT"> <span class='line'>359</span> </span><span class="WHIT"> </span><span class="COMM">//Add it to the $_ object</span><span class="WHIT">
<span class='line'>360</span> </span><span class="PUNC">}</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT"> <span class='line'>360</span> </span><span class="WHIT"> </span><span class="NAME">$_.ext</span><span class="PUNC">(</span><span class="STRN">'util'</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">u</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>361</span> <span class='line'>361</span> </span><span class="PUNC">}</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>362</span> </span></pre></body></html> <span class='line'>362</span>
<span class='line'>363</span> </span></pre></body></html>

View File

@ -411,6 +411,25 @@
}(self)); }(self));
} }
// --------------------------------------------------------------------------
/**
* event.preventDefault/e.stopPropagation polyfill
* @private
*/
if(typeof Event.preventDefault === "undefined" && typeof window.event !== "undefined")
{
Event.prototype.preventDefault = function()
{
window.event.stop();
},
Event.prototype.stopPropagation = function()
{
window.event.returnValue = false;
}
}
}()); }());
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
@ -1028,10 +1047,10 @@
return a > b ? 1 : a < b ? -1 : 0; return a > b ? 1 : a < b ? -1 : 0;
}); });
//cache object/array size // cache object/array size
num_keys = keys.length; num_keys = keys.length;
//Recreate the object/array // Recreate the object/array
for(i=0; i < num_keys; i++) for(i=0; i < num_keys; i++)
{ {
new_o[keys[i]] = o[keys[i]]; new_o[keys[i]] = o[keys[i]];
@ -1116,7 +1135,7 @@
num_keys, num_keys,
i = 0; i = 0;
//Extract the keys or values if needed // Extract the keys or values if needed
if($_.type(keys) !== "array") if($_.type(keys) !== "array")
{ {
keys = this.object_values(keys); keys = this.object_values(keys);
@ -1126,7 +1145,7 @@
vals = this.object_values(vals); vals = this.object_values(vals);
} }
//cache the number of keys // cache the number of keys
num_keys = keys.length; num_keys = keys.length;
if(num_keys !== vals.length) if(num_keys !== vals.length)
@ -1135,7 +1154,7 @@
return false; return false;
} }
//Create and return the new object // Create and return the new object
for(i = 0; i < num_keys; i++) for(i = 0; i < num_keys; i++)
{ {
new_object[keys[i]] = vals[i]; new_object[keys[i]] = vals[i];
@ -1169,7 +1188,7 @@
x, x,
is_array = true; is_array = true;
//Check for an array in the arguments // Check for an array in the arguments
for(i=0; i < arg_len; i++) for(i=0; i < arg_len; i++)
{ {
if($_.type(args[i]) !== "array") if($_.type(args[i]) !== "array")
@ -1179,21 +1198,21 @@
} }
} }
//If all the arguments are javascript arrays // If all the arguments are javascript arrays
if(is_array) if(is_array)
{ {
new_obj = []; new_obj = [];
//Let javascript do all the work! // Let javascript do all the work!
for(i=0; i< arg_len; i++) for(i=0; i< arg_len; i++)
{ {
new_obj = new_obj.contact(args[i]); new_obj = new_obj.contact(args[i]);
} }
//Return early // Return early
return new_obj; return new_obj;
} }
//No, there's at least one object // No, there's at least one object
for(i=0, x=0; i < arg_len; i++) for(i=0, x=0; i < arg_len; i++)
{ {
arg = args[i]; arg = args[i];
@ -1338,6 +1357,7 @@
return new_str; return new_str;
} }
}; };
//Add it to the $_ object //Add it to the $_ object
@ -1372,7 +1392,7 @@
{ {
if(typeof sel.addEventListener !== "undefined") if(typeof sel.addEventListener !== "undefined")
{ {
//Duplicated events are dropped, per the specification // Duplicated events are dropped, per the specification
sel.addEventListener(event, callback, false); sel.addEventListener(event, callback, false);
} }
}; };
@ -1387,7 +1407,7 @@
} }
}; };
} }
//typeof function doesn't work in IE where attachEvent is available: brute force it // typeof function doesn't work in IE where attachEvent is available: brute force it
else if(typeof document.attachEvent !== "undefined") else if(typeof document.attachEvent !== "undefined")
{ {
/** /**
@ -1462,7 +1482,7 @@
return false; return false;
} }
//Multiple events? Run recursively! // Multiple events? Run recursively!
if (!event.match(/^([\w\-]+)$/)) if (!event.match(/^([\w\-]+)$/))
{ {
event = event.split(" "); event = event.split(" ");
@ -1490,30 +1510,30 @@
_attach_delegate = function(sel, target, event, callback) _attach_delegate = function(sel, target, event, callback)
{ {
//_attach the _listener to the parent object // attach the listener to the parent object
_add_remove(sel, event, function(e){ _add_remove(sel, event, function(e){
var elem, t, tar; var elem, t, tar;
//IE 8 doesn't have event bound to element // IE 8 doesn't have event bound to element
e = e || window.event; e = e || window.event;
//Get the live version of the target selector // Get the live version of the target selector
t = $_.$(target); t = $_.$(target);
//Check each element to see if it matches the target // Check each element to see if it matches the target
for(elem in t) for(elem in t)
{ {
//IE 8 doesn't have target in the event object // IE 8 doesn't have target in the event object
tar = e.target || e.srcElement; tar = e.target || e.srcElement;
//Fire target callback when event bubbles from target // Fire target callback when event bubbles from target
if(tar == t[elem]) if(tar == t[elem])
{ {
//Trigger the event callback // Trigger the event callback
callback.call(t[elem], e); callback.call(t[elem], e);
//Stop event propegation // Stop event propegation
e.stopPropagation(); e.stopPropagation();
} }
} }
@ -1592,7 +1612,7 @@
* @param string event_type * @param string event_type
* @param function callback * @param function callback
*/ */
delegate: function(target, event, callback) delegate: function (target, event, callback)
{ {
$_.each(function(e){ $_.each(function(e){
_attach_delegate(e, target, event, callback); _attach_delegate(e, target, event, callback);

2
kis-min.js vendored
View File

@ -4,7 +4,7 @@ return b.length===1?b[0]:b};d=function(a){var c;if(typeof a!=="undefined"){if(ty
(function(){if(typeof window.console==="undefined")window.console={log:function(){}};if(typeof String.prototype.trim==="undefined")String.prototype.trim=function(){return this.replace(/^[\s\uFEFF]+|[\s\uFEFF]+$/g,"")};typeof document!=="undefined"&&!("classList"in document.createElement("a"))&&function(f){var f=(f.HTMLElement||f.Element).prototype,g=Object,d=String.prototype.trim||function(){return this.replace(/^\s+|\s+$/g,"")},b=Array.prototype.indexOf||function(a){for(var c=0,b=this.length;c<b;c++)if(c in (function(){if(typeof window.console==="undefined")window.console={log:function(){}};if(typeof String.prototype.trim==="undefined")String.prototype.trim=function(){return this.replace(/^[\s\uFEFF]+|[\s\uFEFF]+$/g,"")};typeof document!=="undefined"&&!("classList"in document.createElement("a"))&&function(f){var f=(f.HTMLElement||f.Element).prototype,g=Object,d=String.prototype.trim||function(){return this.replace(/^\s+|\s+$/g,"")},b=Array.prototype.indexOf||function(a){for(var c=0,b=this.length;c<b;c++)if(c in
this&&this[c]===a)return c;return-1},a=function(a,c){this.name=a;this.code=DOMException[a];this.message=c},c=function(c,e){if(e==="")throw new a("SYNTAX_ERR","An invalid or illegal string was specified");if(/\s/.test(e))throw new a("INVALID_CHARACTER_ERR","String contains an invalid character");return b.call(c,e)},e=function(a){for(var c=d.call(a.className),c=c?c.split(/\s+/):[],b=0,e=c.length;b<e;b++)this.push(c[b]);this._updateClassName=function(){a.className=this.toString()}},i=e.prototype=[], this&&this[c]===a)return c;return-1},a=function(a,c){this.name=a;this.code=DOMException[a];this.message=c},c=function(c,e){if(e==="")throw new a("SYNTAX_ERR","An invalid or illegal string was specified");if(/\s/.test(e))throw new a("INVALID_CHARACTER_ERR","String contains an invalid character");return b.call(c,e)},e=function(a){for(var c=d.call(a.className),c=c?c.split(/\s+/):[],b=0,e=c.length;b<e;b++)this.push(c[b]);this._updateClassName=function(){a.className=this.toString()}},i=e.prototype=[],
h=function(){return new e(this)};a.prototype=Error.prototype;i.item=function(a){return this[a]||null};i.contains=function(a){a+="";return c(this,a)!==-1};i.add=function(a){a+="";c(this,a)===-1&&(this.push(a),this._updateClassName())};i.remove=function(a){a+="";a=c(this,a);a!==-1&&(this.splice(a,1),this._updateClassName())};i.toggle=function(a){a+="";c(this,a)===-1?this.add(a):this.remove(a)};i.toString=function(){return this.join(" ")};if(g.defineProperty){i={get:h,enumerable:true,configurable:true}; h=function(){return new e(this)};a.prototype=Error.prototype;i.item=function(a){return this[a]||null};i.contains=function(a){a+="";return c(this,a)!==-1};i.add=function(a){a+="";c(this,a)===-1&&(this.push(a),this._updateClassName())};i.remove=function(a){a+="";a=c(this,a);a!==-1&&(this.splice(a,1),this._updateClassName())};i.toggle=function(a){a+="";c(this,a)===-1?this.add(a):this.remove(a)};i.toString=function(){return this.join(" ")};if(g.defineProperty){i={get:h,enumerable:true,configurable:true};
try{g.defineProperty(f,"classList",i)}catch(k){if(k.number===-2146823252)i.enumerable=false,g.defineProperty(f,"classList",i)}}else g.prototype.__defineGetter__&&f.__defineGetter__("classList",h)}(self)})(); try{g.defineProperty(f,"classList",i)}catch(k){if(k.number===-2146823252)i.enumerable=false,g.defineProperty(f,"classList",i)}}else g.prototype.__defineGetter__&&f.__defineGetter__("classList",h)}(self);if(typeof Event.preventDefault==="undefined"&&typeof window.event!=="undefined")Event.prototype.preventDefault=function(){window.event.stop()},Event.prototype.stopPropagation=function(){window.event.returnValue=false}})();
(function(){function f(b,a,c){var e,d;if(typeof b.hasAttribute!=="undefined")b.hasAttribute(a)&&(e=b.getAttribute(a)),d=true;else if(typeof b[a]!=="undefined")e=b[a],d=false;else if(a==="class"&&typeof b.className!=="undefined")a="className",e=b.className,d=false;if(typeof e==="undefined"&&(typeof c==="undefined"||c===null))console.log(c),console.log(b),console.log("Element does not have the selected attribute");else{if(typeof c==="undefined")return e;typeof c!=="undefined"&&c!==null?d===true?b.setAttribute(a, (function(){function f(b,a,c){var e,d;if(typeof b.hasAttribute!=="undefined")b.hasAttribute(a)&&(e=b.getAttribute(a)),d=true;else if(typeof b[a]!=="undefined")e=b[a],d=false;else if(a==="class"&&typeof b.className!=="undefined")a="className",e=b.className,d=false;if(typeof e==="undefined"&&(typeof c==="undefined"||c===null))console.log(c),console.log(b),console.log("Element does not have the selected attribute");else{if(typeof c==="undefined")return e;typeof c!=="undefined"&&c!==null?d===true?b.setAttribute(a,
c):b[a]=c:c===null&&(d===true?b.removeAttribute(a):delete b[a]);return typeof c!=="undefined"?c:e}}function g(b){return b.replace(/(\-[a-z])/g,function(a){return a.toUpperCase().replace("-","")})}function d(b,a,c){var e,a=g(a);e={outerHeight:"offsetHeight",outerWidth:"offsetWidth",top:"posTop"};if(typeof c==="undefined"&&b.style[a]!=="undefined")return b.style[a];else if(typeof c==="undefined"&&b.style[e[a]]!=="undefined")return b.style[e[a]];typeof b.style[a]!=="undefined"?b.style[a]=c:b.style[e[a]]? c):b[a]=c:c===null&&(d===true?b.removeAttribute(a):delete b[a]);return typeof c!=="undefined"?c:e}}function g(b){return b.replace(/(\-[a-z])/g,function(a){return a.toUpperCase().replace("-","")})}function d(b,a,c){var e,a=g(a);e={outerHeight:"offsetHeight",outerWidth:"offsetWidth",top:"posTop"};if(typeof c==="undefined"&&b.style[a]!=="undefined")return b.style[a];else if(typeof c==="undefined"&&b.style[e[a]]!=="undefined")return b.style[e[a]];typeof b.style[a]!=="undefined"?b.style[a]=c:b.style[e[a]]?
b.style[e[a]]=c:console.log("Property "+a+" nor an equivalent seems to exist")}$_.ext("dom",{addClass:function(b){$_.each(function(a){a.classList.add(b)})},removeClass:function(b){$_.each(function(a){a.classList.remove(b)})},hide:function(){this.css("display","none")},show:function(b){typeof b==="undefined"&&(b="block");this.css("display",b)},attr:function(b,a){var c=this.el;if(c.length>1&&typeof a==="undefined")console.log(c),console.log("Must be a singular element");else if(c.length>1&&typeof a!== b.style[e[a]]=c:console.log("Property "+a+" nor an equivalent seems to exist")}$_.ext("dom",{addClass:function(b){$_.each(function(a){a.classList.add(b)})},removeClass:function(b){$_.each(function(a){a.classList.remove(b)})},hide:function(){this.css("display","none")},show:function(b){typeof b==="undefined"&&(b="block");this.css("display",b)},attr:function(b,a){var c=this.el;if(c.length>1&&typeof a==="undefined")console.log(c),console.log("Must be a singular element");else if(c.length>1&&typeof a!==

View File

@ -23,7 +23,7 @@
{ {
if(typeof sel.addEventListener !== "undefined") if(typeof sel.addEventListener !== "undefined")
{ {
//Duplicated events are dropped, per the specification // Duplicated events are dropped, per the specification
sel.addEventListener(event, callback, false); sel.addEventListener(event, callback, false);
} }
}; };
@ -38,7 +38,7 @@
} }
}; };
} }
//typeof function doesn't work in IE where attachEvent is available: brute force it // typeof function doesn't work in IE where attachEvent is available: brute force it
else if(typeof document.attachEvent !== "undefined") else if(typeof document.attachEvent !== "undefined")
{ {
/** /**
@ -113,7 +113,7 @@
return false; return false;
} }
//Multiple events? Run recursively! // Multiple events? Run recursively!
if (!event.match(/^([\w\-]+)$/)) if (!event.match(/^([\w\-]+)$/))
{ {
event = event.split(" "); event = event.split(" ");
@ -141,30 +141,30 @@
_attach_delegate = function(sel, target, event, callback) _attach_delegate = function(sel, target, event, callback)
{ {
//_attach the _listener to the parent object // attach the listener to the parent object
_add_remove(sel, event, function(e){ _add_remove(sel, event, function(e){
var elem, t, tar; var elem, t, tar;
//IE 8 doesn't have event bound to element // IE 8 doesn't have event bound to element
e = e || window.event; e = e || window.event;
//Get the live version of the target selector // Get the live version of the target selector
t = $_.$(target); t = $_.$(target);
//Check each element to see if it matches the target // Check each element to see if it matches the target
for(elem in t) for(elem in t)
{ {
//IE 8 doesn't have target in the event object // IE 8 doesn't have target in the event object
tar = e.target || e.srcElement; tar = e.target || e.srcElement;
//Fire target callback when event bubbles from target // Fire target callback when event bubbles from target
if(tar == t[elem]) if(tar == t[elem])
{ {
//Trigger the event callback // Trigger the event callback
callback.call(t[elem], e); callback.call(t[elem], e);
//Stop event propegation // Stop event propegation
e.stopPropagation(); e.stopPropagation();
} }
} }
@ -243,7 +243,7 @@
* @param string event_type * @param string event_type
* @param function callback * @param function callback
*/ */
delegate: function(target, event, callback) delegate: function (target, event, callback)
{ {
$_.each(function(e){ $_.each(function(e){
_attach_delegate(e, target, event, callback); _attach_delegate(e, target, event, callback);

View File

@ -43,10 +43,10 @@
return a > b ? 1 : a < b ? -1 : 0; return a > b ? 1 : a < b ? -1 : 0;
}); });
//cache object/array size // cache object/array size
num_keys = keys.length; num_keys = keys.length;
//Recreate the object/array // Recreate the object/array
for(i=0; i < num_keys; i++) for(i=0; i < num_keys; i++)
{ {
new_o[keys[i]] = o[keys[i]]; new_o[keys[i]] = o[keys[i]];
@ -131,7 +131,7 @@
num_keys, num_keys,
i = 0; i = 0;
//Extract the keys or values if needed // Extract the keys or values if needed
if($_.type(keys) !== "array") if($_.type(keys) !== "array")
{ {
keys = this.object_values(keys); keys = this.object_values(keys);
@ -141,7 +141,7 @@
vals = this.object_values(vals); vals = this.object_values(vals);
} }
//cache the number of keys // cache the number of keys
num_keys = keys.length; num_keys = keys.length;
if(num_keys !== vals.length) if(num_keys !== vals.length)
@ -150,7 +150,7 @@
return false; return false;
} }
//Create and return the new object // Create and return the new object
for(i = 0; i < num_keys; i++) for(i = 0; i < num_keys; i++)
{ {
new_object[keys[i]] = vals[i]; new_object[keys[i]] = vals[i];
@ -184,7 +184,7 @@
x, x,
is_array = true; is_array = true;
//Check for an array in the arguments // Check for an array in the arguments
for(i=0; i < arg_len; i++) for(i=0; i < arg_len; i++)
{ {
if($_.type(args[i]) !== "array") if($_.type(args[i]) !== "array")
@ -194,21 +194,21 @@
} }
} }
//If all the arguments are javascript arrays // If all the arguments are javascript arrays
if(is_array) if(is_array)
{ {
new_obj = []; new_obj = [];
//Let javascript do all the work! // Let javascript do all the work!
for(i=0; i< arg_len; i++) for(i=0; i< arg_len; i++)
{ {
new_obj = new_obj.contact(args[i]); new_obj = new_obj.contact(args[i]);
} }
//Return early // Return early
return new_obj; return new_obj;
} }
//No, there's at least one object // No, there's at least one object
for(i=0, x=0; i < arg_len; i++) for(i=0, x=0; i < arg_len; i++)
{ {
arg = args[i]; arg = args[i];
@ -353,6 +353,7 @@
return new_str; return new_str;
} }
}; };
//Add it to the $_ object //Add it to the $_ object

View File

@ -198,4 +198,23 @@
}(self)); }(self));
} }
// --------------------------------------------------------------------------
/**
* event.preventDefault/e.stopPropagation polyfill
* @private
*/
if(typeof Event.preventDefault === "undefined" && typeof window.event !== "undefined")
{
Event.prototype.preventDefault = function()
{
window.event.stop();
},
Event.prototype.stopPropagation = function()
{
window.event.returnValue = false;
}
}
}()); }());