Remove util module, add event creation and triggering, remove some old/redundant in code checks, and greatly increase test coverage.

This commit is contained in:
Timothy Warren 2013-12-12 15:13:57 -05:00
parent 517fe203e7
commit 14b8a6c981
28 changed files with 573 additions and 1168 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -314,57 +314,43 @@
<span class='line'>307</span> */</span><span class="WHIT">
<span class='line'>308</span> </span><span class="WHIT"> </span><span class="NAME">append</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">htm</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>309</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>310</span> </span><span class="WHIT"> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">document.insertAdjacentHTML</span><span class="WHIT"> </span><span class="PUNC">!==</span><span class="WHIT"> </span><span class="NAME">undefined</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>311</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>312</span> </span><span class="WHIT"> </span><span class="NAME">this.el.insertAdjacentHTML</span><span class="PUNC">(</span><span class="STRN">'beforeend'</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">htm</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>313</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>314</span> </span><span class="WHIT"> </span><span class="KEYW">else</span><span class="WHIT">
<span class='line'>315</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>316</span> </span><span class="WHIT"> </span><span class="NAME">this.el.innerHTML</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">htm</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>317</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>318</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>319</span> </span><span class="WHIT"> </span><span class="COMM">/**
<span class='line'>320</span> * Adds to the innerHTML of the selected element, before the current children
<span class='line'>321</span> *
<span class='line'>322</span> * @name prepend
<span class='line'>323</span> * @memberOf $_.dom
<span class='line'>324</span> * @function
<span class='line'>325</span> * @param string htm
<span class='line'>326</span> */</span><span class="WHIT">
<span class='line'>327</span> </span><span class="WHIT"> </span><span class="NAME">prepend</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">htm</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>328</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>329</span> </span><span class="WHIT"> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">document.insertAdjacentHTML</span><span class="WHIT"> </span><span class="PUNC">!==</span><span class="WHIT"> </span><span class="NAME">undefined</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>330</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>331</span> </span><span class="WHIT"> </span><span class="NAME">this.el.insertAdjacentHTML</span><span class="PUNC">(</span><span class="STRN">'afterbegin'</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">htm</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>332</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>333</span> </span><span class="WHIT"> </span><span class="KEYW">else</span><span class="WHIT">
<span class='line'>334</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>335</span> </span><span class="WHIT"> </span><span class="NAME">this.el.innerHTML</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">htm</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">this.el.innerHTML</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>336</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>337</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>338</span> </span><span class="WHIT"> </span><span class="COMM">/**
<span class='line'>339</span> * Sets or gets the innerHTML propery of the element(s) passed
<span class='line'>340</span> *
<span class='line'>341</span> * @name html
<span class='line'>342</span> * @memberOf $_.dom
<span class='line'>343</span> * @function
<span class='line'>344</span> * @param [string] htm
<span class='line'>345</span> * @return string
<span class='line'>346</span> * @type string
<span class='line'>347</span> */</span><span class="WHIT">
<span class='line'>348</span> </span><span class="WHIT"> </span><span class="NAME">html</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">htm</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>349</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>350</span>
<span class='line'>351</span> </span><span class="WHIT"> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">htm</span><span class="WHIT"> </span><span class="PUNC">!==</span><span class="WHIT"> </span><span class="NAME">undefined</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>352</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>353</span> </span><span class="WHIT"> </span><span class="NAME">this.el.innerHTML</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">htm</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>354</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>355</span>
<span class='line'>356</span> </span><span class="WHIT"> </span><span class="COMM">//If the parameter is undefined, just return the current value</span><span class="WHIT">
<span class='line'>357</span> </span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">this.el.innerHTML</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>358</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>359</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>360</span>
<span class='line'>361</span> </span><span class="WHIT"> </span><span class="NAME">$_.ext</span><span class="PUNC">(</span><span class="STRN">'dom'</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">d</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>362</span>
<span class='line'>363</span> </span><span class="PUNC">}</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span></pre></body></html>
<span class='line'>310</span> </span><span class="WHIT"> </span><span class="NAME">this.el.insertAdjacentHTML</span><span class="PUNC">(</span><span class="STRN">'beforeend'</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">htm</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>311</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>312</span> </span><span class="WHIT"> </span><span class="COMM">/**
<span class='line'>313</span> * Adds to the innerHTML of the selected element, before the current children
<span class='line'>314</span> *
<span class='line'>315</span> * @name prepend
<span class='line'>316</span> * @memberOf $_.dom
<span class='line'>317</span> * @function
<span class='line'>318</span> * @param string htm
<span class='line'>319</span> */</span><span class="WHIT">
<span class='line'>320</span> </span><span class="WHIT"> </span><span class="NAME">prepend</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">htm</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>321</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>322</span> </span><span class="WHIT"> </span><span class="NAME">this.el.insertAdjacentHTML</span><span class="PUNC">(</span><span class="STRN">'afterbegin'</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">htm</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>323</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>324</span> </span><span class="WHIT"> </span><span class="COMM">/**
<span class='line'>325</span> * Sets or gets the innerHTML propery of the element(s) passed
<span class='line'>326</span> *
<span class='line'>327</span> * @name html
<span class='line'>328</span> * @memberOf $_.dom
<span class='line'>329</span> * @function
<span class='line'>330</span> * @param [string] htm
<span class='line'>331</span> * @return string
<span class='line'>332</span> * @type string
<span class='line'>333</span> */</span><span class="WHIT">
<span class='line'>334</span> </span><span class="WHIT"> </span><span class="NAME">html</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">htm</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>335</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>336</span>
<span class='line'>337</span> </span><span class="WHIT"> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">htm</span><span class="WHIT"> </span><span class="PUNC">!==</span><span class="WHIT"> </span><span class="NAME">undefined</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>338</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>339</span> </span><span class="WHIT"> </span><span class="NAME">this.el.innerHTML</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">htm</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>340</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>341</span>
<span class='line'>342</span> </span><span class="WHIT"> </span><span class="COMM">//If the parameter is undefined, just return the current value</span><span class="WHIT">
<span class='line'>343</span> </span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">this.el.innerHTML</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>344</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>345</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>346</span>
<span class='line'>347</span> </span><span class="WHIT"> </span><span class="NAME">$_.ext</span><span class="PUNC">(</span><span class="STRN">'dom'</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">d</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>348</span>
<span class='line'>349</span> </span><span class="PUNC">}</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span></pre></body></html>

View File

@ -76,7 +76,7 @@
<span class='line'> 69</span>
<span class='line'> 70</span> </span><span class="WHIT"> </span><span class="KEYW">for</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">name</span><span class="WHIT"> </span><span class="KEYW">in</span><span class="WHIT"> </span><span class="NAME">data</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 71</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 72</span> </span><span class="WHIT"> </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="WHIT"> </span><span class="PUNC">!</span><span class="WHIT"> </span><span class="NAME">data.hasOwnProperty</span><span class="PUNC">(</span><span class="NAME">name</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">data</span><span class="PUNC">[</span><span class="NAME">name</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">===</span><span class="WHIT"> </span><span class="STRN">"function"</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 72</span> </span><span class="WHIT"> </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="WHIT"> </span><span class="PUNC">!</span><span class="WHIT"> </span><span class="NAME">data.hasOwnProperty</span><span class="PUNC">(</span><span class="NAME">name</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NAME">$_.type</span><span class="PUNC">(</span><span class="NAME">data</span><span class="PUNC">[</span><span class="NAME">name</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">===</span><span class="WHIT"> </span><span class="STRN">"function"</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 73</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 74</span> </span><span class="WHIT"> </span><span class="KEYW">continue</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 75</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">

View File

@ -21,136 +21,176 @@
<span class='line'> 14</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 15</span> </span><span class="WHIT"> </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">i</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">len</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 16</span>
<span class='line'> 17</span> </span><span class="WHIT"> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">sel</span><span class="WHIT"> </span><span class="PUNC">===</span><span class="WHIT"> </span><span class="NAME">undefined</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 18</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 19</span> </span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 20</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 17</span> </span><span class="WHIT"> </span><span class="COMM">// Multiple events? Run recursively!</span><span class="WHIT">
<span class='line'> 18</span> </span><span class="WHIT"> </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="WHIT"> </span><span class="PUNC">!</span><span class="WHIT"> </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'> 19</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 20</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'> 21</span>
<span class='line'> 22</span> </span><span class="WHIT"> </span><span class="COMM">// Multiple events? Run recursively!</span><span class="WHIT">
<span class='line'> 23</span> </span><span class="WHIT"> </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="WHIT"> </span><span class="PUNC">!</span><span class="WHIT"> </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'> 24</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="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'> 26</span>
<span class='line'> 27</span> </span><span class="WHIT"> </span><span class="NAME">len</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">event.length</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 22</span> </span><span class="WHIT"> </span><span class="NAME">len</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">event.length</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 23</span>
<span class='line'> 24</span> </span><span class="WHIT"> </span><span class="KEYW">for</span><span class="WHIT"> </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">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'> 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="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="NAME">i</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">callback</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">add</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 27</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 28</span>
<span class='line'> 29</span> </span><span class="WHIT"> </span><span class="KEYW">for</span><span class="WHIT"> </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">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'> 30</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 31</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="NAME">i</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">callback</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">add</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 32</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 33</span>
<span class='line'> 34</span> </span><span class="WHIT"> </span><span class="KEYW">return</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 35</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 36</span>
<span class='line'> 37</span> </span><span class="WHIT"> </span><span class="COMM">// Bind the event</span><span class="WHIT">
<span class='line'> 38</span> </span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">add</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'> 39</span> </span><span class="WHIT"> </span><span class="PUNC">?</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="WHIT">
<span class='line'> 40</span> </span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">sel.removeEventListener</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'> 41</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="KEYW">return</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 30</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 31</span>
<span class='line'> 32</span> </span><span class="WHIT"> </span><span class="COMM">// Bind the event</span><span class="WHIT">
<span class='line'> 33</span> </span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">add</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'> 34</span> </span><span class="WHIT"> </span><span class="PUNC">?</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="WHIT">
<span class='line'> 35</span> </span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">sel.removeEventListener</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'> 36</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 37</span>
<span class='line'> 38</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'> 39</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="COMM">// attach the listener to the parent object</span><span class="WHIT">
<span class='line'> 41</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'> 42</span>
<span class='line'> 43</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'> 44</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 45</span> </span><span class="WHIT"> </span><span class="COMM">// attach the listener to the parent object</span><span class="WHIT">
<span class='line'> 46</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'> 43</span> </span><span class="WHIT"> </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 class='line'> 44</span>
<span class='line'> 45</span> </span><span class="WHIT"> </span><span class="COMM">// Get the live version of the target selector</span><span class="WHIT">
<span class='line'> 46</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="WHIT"> </span><span class="NAME">sel</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 47</span>
<span class='line'> 48</span> </span><span class="WHIT"> </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 class='line'> 49</span>
<span class='line'> 50</span> </span><span class="WHIT"> </span><span class="COMM">// Get the live version of the target selector</span><span class="WHIT">
<span class='line'> 51</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="WHIT"> </span><span class="NAME">sel</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 52</span>
<span class='line'> 53</span> </span><span class="WHIT"> </span><span class="COMM">// Check each element to see if it matches the target</span><span class="WHIT">
<span class='line'> 54</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'> 55</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 56</span> </span><span class="WHIT"> </span><span class="COMM">// Fire target callback when event bubbles from target</span><span class="WHIT">
<span class='line'> 57</span> </span><span class="WHIT"> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">e.target</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'> 58</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 59</span> </span><span class="WHIT"> </span><span class="COMM">// Trigger the event callback</span><span class="WHIT">
<span class='line'> 60</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'> 48</span> </span><span class="WHIT"> </span><span class="COMM">// Check each element to see if it matches the target</span><span class="WHIT">
<span class='line'> 49</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'> 50</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="COMM">// Fire target callback when event bubbles from target</span><span class="WHIT">
<span class='line'> 52</span> </span><span class="WHIT"> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">e.target</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'> 53</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 54</span> </span><span class="WHIT"> </span><span class="COMM">// Trigger the event callback</span><span class="WHIT">
<span class='line'> 55</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'> 56</span>
<span class='line'> 57</span> </span><span class="WHIT"> </span><span class="COMM">// Stop event propegation</span><span class="WHIT">
<span class='line'> 58</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'> 59</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 60</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 61</span>
<span class='line'> 62</span> </span><span class="WHIT"> </span><span class="COMM">// Stop event propegation</span><span class="WHIT">
<span class='line'> 63</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'> 64</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 65</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 62</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 63</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 64</span>
<span class='line'> 65</span> </span><span class="WHIT"> </span><span class="COMM">// --------------------------------------------------------------------------</span><span class="WHIT">
<span class='line'> 66</span>
<span class='line'> 67</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 68</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 69</span>
<span class='line'> 70</span> </span><span class="WHIT"> </span><span class="COMM">// --------------------------------------------------------------------------</span><span class="WHIT">
<span class='line'> 71</span>
<span class='line'> 72</span> </span><span class="WHIT"> </span><span class="COMM">/**
<span class='line'> 73</span> * Event Listener module
<span class='line'> 74</span> *
<span class='line'> 75</span> * @namespace
<span class='line'> 76</span> * @name event
<span class='line'> 77</span> * @memberOf $_
<span class='line'> 78</span> */</span><span class="WHIT">
<span class='line'> 79</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="PUNC">{</span><span class="WHIT">
<span class='line'> 80</span> </span><span class="WHIT"> </span><span class="COMM">/**
<span class='line'> 81</span> * Adds an event that returns a callback when triggered on the selected
<span class='line'> 82</span> * event and selector
<span class='line'> 83</span> *
<span class='line'> 84</span> * @memberOf $_.event
<span class='line'> 85</span> * @name add
<span class='line'> 86</span> * @function
<span class='line'> 87</span> * @example Eg. $_("#selector").event.add("click", do_something());
<span class='line'> 88</span> * @param string event
<span class='line'> 89</span> * @param function callback
<span class='line'> 90</span> */</span><span class="WHIT">
<span class='line'> 91</span> </span><span class="WHIT"> </span><span class="NAME">add</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">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'> 92</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 93</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'> 94</span> </span><span class="WHIT"> </span><span class="NAME">_add_remove</span><span class="PUNC">(</span><span class="NAME">e</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><span class="KEYW">true</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 95</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 96</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 97</span> </span><span class="WHIT"> </span><span class="COMM">/**
<span class='line'> 98</span> * Removes an event bound the the specified selector, event type, and callback
<span class='line'> 99</span> *
<span class='line'>100</span> * @memberOf $_.event
<span class='line'>101</span> * @name remove
<span class='line'>102</span> * @function
<span class='line'>103</span> * @example Eg. $_("#selector").event.remove("click", do_something());
<span class='line'>104</span> * @param string event
<span class='line'>105</span> * @param string callback
<span class='line'>106</span> */</span><span class="WHIT">
<span class='line'>107</span> </span><span class="WHIT"> </span><span class="NAME">remove</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">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'>108</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>109</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'>110</span> </span><span class="WHIT"> </span><span class="NAME">_add_remove</span><span class="PUNC">(</span><span class="NAME">e</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><span class="KEYW">false</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>111</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>112</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>113</span> </span><span class="WHIT"> </span><span class="COMM">/**
<span class='line'>114</span> * Binds a persistent event to the document
<span class='line'>115</span> *
<span class='line'>116</span> * @memberOf $_.event
<span class='line'>117</span> * @name live
<span class='line'>118</span> * @function
<span class='line'>119</span> * @example Eg. $_.event.live(".button", "click", do_something());
<span class='line'>120</span> * @param string target
<span class='line'>121</span> * @param string event
<span class='line'>122</span> * @param function callback
<span class='line'>123</span> */</span><span class="WHIT">
<span class='line'>124</span> </span><span class="WHIT"> </span><span class="NAME">live</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'>125</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>126</span> </span><span class="WHIT"> </span><span class="NAME">_attach_delegate</span><span class="PUNC">(</span><span class="NAME">document.documentElement</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'>127</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>128</span> </span><span class="WHIT"> </span><span class="COMM">/**
<span class='line'>129</span> * Binds an event to a parent object
<span class='line'>130</span> *
<span class='line'>131</span> * @memberOf $_.event
<span class='line'>132</span> * @name delegate
<span class='line'>133</span> * @function
<span class='line'>134</span> * @example Eg. $_("#parent").delegate(".button", "click", do_something());
<span class='line'>135</span> * @param string target
<span class='line'>136</span> * @param string event_type
<span class='line'>137</span> * @param function callback
<span class='line'>138</span> */</span><span class="WHIT">
<span class='line'>139</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'>140</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>141</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'>142</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'>143</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>144</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>145</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>146</span>
<span class='line'>147</span> </span><span class="WHIT"> </span><span class="NAME">$_.ext</span><span class="PUNC">(</span><span class="STRN">'event'</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'>148</span>
<span class='line'>149</span> </span><span class="PUNC">}</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span></pre></body></html>
<span class='line'> 67</span> </span><span class="WHIT"> </span><span class="COMM">/**
<span class='line'> 68</span> * Event Listener module
<span class='line'> 69</span> *
<span class='line'> 70</span> * @namespace
<span class='line'> 71</span> * @name event
<span class='line'> 72</span> * @memberOf $_
<span class='line'> 73</span> */</span><span class="WHIT">
<span class='line'> 74</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="PUNC">{</span><span class="WHIT">
<span class='line'> 75</span> </span><span class="WHIT"> </span><span class="COMM">/**
<span class='line'> 76</span> * Create a custom event
<span class='line'> 77</span> *
<span class='line'> 78</span> * @memberOf $_.event
<span class='line'> 79</span> * @name create
<span class='line'> 80</span> * @function
<span class='line'> 81</span> * @example Eg. var event = $_("#selector").event.create('foo', {});
<span class='line'> 82</span> * @param string name
<span class='line'> 83</span> * @param [object] data
<span class='line'> 84</span> * @return object
<span class='line'> 85</span> */</span><span class="WHIT">
<span class='line'> 86</span> </span><span class="WHIT"> </span><span class="NAME">create</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">name</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">data</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 87</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 88</span> </span><span class="WHIT"> </span><span class="COMM">// Do a terrible browser-sniffic hack because I don't know of a good </span><span class="WHIT">
<span class='line'> 89</span> </span><span class="WHIT"> </span><span class="COMM">// feature test</span><span class="WHIT">
<span class='line'> 90</span> </span><span class="WHIT"> </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="REGX">/MSIE|Trident/i</span><span class="PUNC">.</span><span class="NAME">test</span><span class="PUNC">(</span><span class="NAME">navigator.userAgent</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 91</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 92</span> </span><span class="WHIT"> </span><span class="COMM">// Okay, I guess we have to do this the hard way... :(</span><span class="WHIT">
<span class='line'> 93</span> </span><span class="WHIT"> </span><span class="COMM">// Microsoft, your browser still sucks</span><span class="WHIT">
<span class='line'> 94</span> </span><span class="WHIT"> </span><span class="KEYW">var</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">document.createEvent</span><span class="PUNC">(</span><span class="STRN">'CustomEvent'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 95</span> </span><span class="WHIT"> </span><span class="NAME">e.initCustomEvent</span><span class="PUNC">(</span><span class="NAME">name</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">data</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 96</span> </span><span class="WHIT">
<span class='line'> 97</span> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">e</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 98</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 99</span> </span><span class="WHIT"> </span><span class="KEYW">else</span><span class="WHIT">
<span class='line'>100</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>101</span> </span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">CustomEvent</span><span class="PUNC">(</span><span class="NAME">name</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">data</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>102</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>103</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>104</span> </span><span class="WHIT"> </span><span class="COMM">/**
<span class='line'>105</span> * Adds an event that returns a callback when triggered on the selected
<span class='line'>106</span> * event and selector
<span class='line'>107</span> *
<span class='line'>108</span> * @memberOf $_.event
<span class='line'>109</span> * @name add
<span class='line'>110</span> * @function
<span class='line'>111</span> * @example Eg. $_("#selector").event.add("click", do_something());
<span class='line'>112</span> * @param string event
<span class='line'>113</span> * @param function callback
<span class='line'>114</span> */</span><span class="WHIT">
<span class='line'>115</span> </span><span class="WHIT"> </span><span class="NAME">add</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">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'>116</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>117</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'>118</span> </span><span class="WHIT"> </span><span class="NAME">_add_remove</span><span class="PUNC">(</span><span class="NAME">e</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><span class="KEYW">true</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>119</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>120</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>121</span> </span><span class="WHIT"> </span><span class="COMM">/**
<span class='line'>122</span> * Removes an event bound the the specified selector, event type, and callback
<span class='line'>123</span> *
<span class='line'>124</span> * @memberOf $_.event
<span class='line'>125</span> * @name remove
<span class='line'>126</span> * @function
<span class='line'>127</span> * @example Eg. $_("#selector").event.remove("click", do_something());
<span class='line'>128</span> * @param string event
<span class='line'>129</span> * @param string callback
<span class='line'>130</span> */</span><span class="WHIT">
<span class='line'>131</span> </span><span class="WHIT"> </span><span class="NAME">remove</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">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'>132</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>133</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'>134</span> </span><span class="WHIT"> </span><span class="NAME">_add_remove</span><span class="PUNC">(</span><span class="NAME">e</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><span class="KEYW">false</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>135</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>136</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>137</span> </span><span class="WHIT"> </span><span class="COMM">/**
<span class='line'>138</span> * Binds a persistent event to the document
<span class='line'>139</span> *
<span class='line'>140</span> * @memberOf $_.event
<span class='line'>141</span> * @name live
<span class='line'>142</span> * @function
<span class='line'>143</span> * @example Eg. $_.event.live(".button", "click", do_something());
<span class='line'>144</span> * @param string target
<span class='line'>145</span> * @param string event
<span class='line'>146</span> * @param function callback
<span class='line'>147</span> */</span><span class="WHIT">
<span class='line'>148</span> </span><span class="WHIT"> </span><span class="NAME">live</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'>149</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>150</span> </span><span class="WHIT"> </span><span class="NAME">_attach_delegate</span><span class="PUNC">(</span><span class="NAME">document.documentElement</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'>151</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>152</span> </span><span class="WHIT"> </span><span class="COMM">/**
<span class='line'>153</span> * Binds an event to a parent object
<span class='line'>154</span> *
<span class='line'>155</span> * @memberOf $_.event
<span class='line'>156</span> * @name delegate
<span class='line'>157</span> * @function
<span class='line'>158</span> * @example Eg. $_("#parent").delegate(".button", "click", do_something());
<span class='line'>159</span> * @param string target
<span class='line'>160</span> * @param string event_type
<span class='line'>161</span> * @param function callback
<span class='line'>162</span> */</span><span class="WHIT">
<span class='line'>163</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'>164</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>165</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'>166</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'>167</span> </span><span class="WHIT"> </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="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>169</span> </span><span class="WHIT"> </span><span class="COMM">/**
<span class='line'>170</span> * Trigger an event to fire
<span class='line'>171</span> *
<span class='line'>172</span> * @memberOf $_.event
<span class='line'>173</span> * @name trigger
<span class='line'>174</span> * @function
<span class='line'>175</span> * @example Eg. $_("#my_id").trigger('click');
<span class='line'>176</span> * @param string target
<span class='line'>177</span> * @param object event
<span class='line'>178</span> * @return bool
<span class='line'>179</span> */</span><span class="WHIT">
<span class='line'>180</span> </span><span class="WHIT"> </span><span class="NAME">trigger</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">event</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>181</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>182</span> </span><span class="WHIT"> </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">target</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">this.el</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>183</span> </span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">target.dispatchEvent</span><span class="PUNC">(</span><span class="NAME">event</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>184</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>185</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>186</span>
<span class='line'>187</span> </span><span class="WHIT"> </span><span class="NAME">$_.ext</span><span class="PUNC">(</span><span class="STRN">'event'</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'>188</span>
<span class='line'>189</span> </span><span class="PUNC">}</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span></pre></body></html>

View File

@ -497,14 +497,7 @@ if(typeof document!=="undefined"&&!("classList" in document.createElement("a")))
*/
append: function(htm)
{
if(document.insertAdjacentHTML !== undefined)
{
this.el.insertAdjacentHTML('beforeend', htm);
}
else
{
this.el.innerHTML += htm;
}
this.el.insertAdjacentHTML('beforeend', htm);
},
/**
* Adds to the innerHTML of the selected element, before the current children
@ -516,14 +509,7 @@ if(typeof document!=="undefined"&&!("classList" in document.createElement("a")))
*/
prepend: function(htm)
{
if(document.insertAdjacentHTML !== undefined)
{
this.el.insertAdjacentHTML('afterbegin', htm);
}
else
{
this.el.innerHTML = htm + this.el.innerHTML;
}
this.el.insertAdjacentHTML('afterbegin', htm);
},
/**
* Sets or gets the innerHTML propery of the element(s) passed
@ -623,7 +609,7 @@ if(typeof document!=="undefined"&&!("classList" in document.createElement("a")))
for (name in data)
{
if ( ! data.hasOwnProperty(name) || typeof data[name] === "function")
if ( ! data.hasOwnProperty(name) || $_.type(data[name]) === "function")
{
continue;
}
@ -687,11 +673,6 @@ if(typeof document!=="undefined"&&!("classList" in document.createElement("a")))
{
var i, len;
if(sel === undefined)
{
return null;
}
// Multiple events? Run recursively!
if ( ! event.match(/^([\w\-]+)$/))
{
@ -750,6 +731,35 @@ if(typeof document!=="undefined"&&!("classList" in document.createElement("a")))
* @memberOf $_
*/
e = {
/**
* Create a custom event
*
* @memberOf $_.event
* @name create
* @function
* @example Eg. var event = $_("#selector").event.create('foo', {});
* @param string name
* @param [object] data
* @return object
*/
create: function(name, data)
{
// Do a terrible browser-sniffic hack because I don't know of a good
// feature test
if (/MSIE|Trident/i.test(navigator.userAgent))
{
// Okay, I guess we have to do this the hard way... :(
// Microsoft, your browser still sucks
var e = document.createEvent('CustomEvent');
e.initCustomEvent(name, true, true, data);
return e;
}
else
{
return new CustomEvent(name, data);
}
},
/**
* Adds an event that returns a callback when triggered on the selected
* event and selector
@ -814,6 +824,22 @@ if(typeof document!=="undefined"&&!("classList" in document.createElement("a")))
$_.each(function(e){
_attach_delegate(e, target, event, callback);
});
},
/**
* Trigger an event to fire
*
* @memberOf $_.event
* @name trigger
* @function
* @example Eg. $_("#my_id").trigger('click');
* @param string target
* @param object event
* @return bool
*/
trigger: function(event)
{
var target = this.el;
return target.dispatchEvent(event);
}
};
@ -940,364 +966,4 @@ if(typeof document!=="undefined"&&!("classList" in document.createElement("a")))
$_.ext('store', store);
// --------------------------------------------------------------------------
/**
* Util Object
*
* Various object and string manipulation functions
* Note: these are based on similar phpjs functions: http://phpjs.org
*/
var reverse_key_sort = function(o)
{
//Define some variables
var keys = [],
num_keys = 0,
new_o = {},
i;
//Extract the keys
keys = u.object_keys(o);
//Sort the keys
keys.sort(function (b, a) {
var aFloat = parseFloat(a),
bFloat = parseFloat(b),
aNumeric = aFloat + '' === a,
bNumeric = bFloat + '' === b;
if (aNumeric && bNumeric)
{
return aFloat > bFloat ? 1 : aFloat < bFloat ? -1 : 0;
}
else if (aNumeric && !bNumeric)
{
return 1;
}
else if (!aNumeric && bNumeric)
{
return -1;
}
return a > b ? 1 : a < b ? -1 : 0;
});
// cache object/array size
num_keys = keys.length;
// Recreate the object/array
for(i=0; i < num_keys; i++)
{
new_o[keys[i]] = o[keys[i]];
}
return new_o;
},
/**
* String and object manipulation utilities
*
* @namespace
* @name util
* @memberOf $_
*/
u = {
/**
* Retrieve the keys, or member names of an object
*
* @name object_keys
* @memberOf $_.util
* @function
* @param object
* @return array
* @type array
*/
object_keys: function(o)
{
var keys = [],
k;
for(k in o)
{
if(o.hasOwnProperty(k))
{
keys.push(k);
}
}
return keys;
},
/**
* Retrieves the values of an object, and returns
* them as an array
*
* @name object_values
* @memberOf $_.util
* @function
* @param object
* @return array
* @type array
*/
object_values: function(o)
{
var vals = [],
prop;
for(prop in o)
{
vals.push(o[prop]);
}
return vals;
},
/**
* Creates an object, with the property names of the first array,
* and the values of the second. If objects are passed, the values
* of the object are used. If the arrays or objects passed are
* not the same size, the function will return false.
*
* @name array_combine
* @memberOf $_.util
* @function
* @param array/object keys
* @param array/object vals
* @return object
* @type object
*/
array_combine: function(keys, vals)
{
var new_object = {},
num_keys,
i = 0;
// Extract the keys or values if needed
if($_.type(keys) !== "array")
{
keys = this.object_values(keys);
}
if($_.type(vals) !== "array")
{
vals = this.object_values(vals);
}
// cache the number of keys
num_keys = keys.length;
if(num_keys !== vals.length)
{
return false;
}
// Create and return the new object
for(i = 0; i < num_keys; i++)
{
new_object[keys[i]] = vals[i];
}
return new_object;
},
/**
* Combines two or more objects/arrays. If the keys are numeric, the outputted
* object will have re-indexed keys. If a key/value pair exists in both objects,
* indentical values will be droped, but if a key exists with a different value,
* with the same key, the value in the second array will replace the value in the
* first
*
* @name object_merge
* @memberOf $_.util
* @function
* @param object [as many as you wish to combine]
* @type object
* @return object
*/
object_merge: function()
{
var args = Array.prototype.slice.call(arguments),
arg_len = args.length,
new_obj = {},
arg,
iarg_len = 0,
i,
j,
x,
is_array = true;
// Check for an array in the arguments
for(i=0; i < arg_len; i++)
{
if($_.type(args[i]) !== "array")
{
is_array = false;
break;
}
}
// If all the arguments are javascript arrays
if(is_array)
{
new_obj = [];
// Let javascript do all the work!
for(i=0; i< arg_len; i++)
{
new_obj = new_obj.contact(args[i]);
}
// Return early
return new_obj;
}
// No, there's at least one object
for(i=0, x=0; i < arg_len; i++)
{
arg = args[i];
// If the argument is an array, add the array items as
// numeric object properties
if ($_.type(arg) == "array")
{
for (j=0, iarg_len= arg.length; j < iarg_len; j++)
{
new_obj[x++] = arg[j];
}
}
else
{
for (j in arg)
{
if(arg.hasOwnProperty(j))
{
// If the key is numeric, add the property with
// a numeric key
if(parseInt(j, 10) + '' === j)
{
new_obj[x++] = arg[j];
}
else
{
new_obj[j] = arg[j];
}
}
}
}
}
return new_obj;
},
/**
* Replaces sections of strings in a greedy fashion,
* starting with the longest replace pairs first. Accepts
* one replace pair as two parameters, or an object, with
* from => to replacements as key/value pairs
*
* @name str_trans
* @memberOf $_.util
* @function
* @param string input_string
* @param mixed from (string)/replace pairs (object)
* @param [string]
* @return string
* @type string
*/
str_trans: function(str, from, to)
{
var froms = [],
tos = [],
ret = '',
match = false,
from_len = 0,
str_len = 0,
to_len = 0,
to_is_str = '',
from_is_str = '',
strx = '',
strw = '',
stry = '',
from_strx = '',
new_str = '',
f,
i,
j;
//Replace pairs? add them to the internal arrays
if(typeof from === 'object')
{
// Sort the keys in descending order for better
// replacement functionality
from = reverse_key_sort(from);
for(f in from)
{
if(from.hasOwnProperty(f))
{
froms.push(f);
tos.push(from[f]);
}
}
from = froms;
to = tos;
}
//Go through the string, and replace characters as needed
str_len = str.length;
from_len = from.length;
to_len = to.length;
to_is_str = typeof to === 'string';
from_is_str = typeof from === 'string';
for(i=0; i < str_len; i++)
{
match = false;
if(from_is_str)
{
strw = str.charAt(i-1);
strx = str.charAt(i);
stry = str.charAt(i+1);
for(j=0; j < from_len; j++)
{
if(strx == from.charAt(j))
{
match = true;
break;
}
}
}
else
{
for(j=0; j < from_len; j++)
{
if(str.substr(i, from[j].length) == from[j])
{
match = true;
//Go past the current match
i = (i + from[j].length) -1;
break;
}
}
}
if(match)
{
new_str += (to_is_str) ? to.charAt(j) : to[j];
}
else
{
new_str += str.charAt(i);
}
}
return new_str;
}
};
//Add it to the $_ object
$_.ext('util', u);
}($_));

15
kis-lite-dom-min.js vendored
View File

@ -1,14 +1,13 @@
(function(d){var f,g,c;f=function(a){c=a===d?f.el!==d?f.el:document.documentElement:g(a);f.prototype.el=c;a=Object.create(f);for(var b in a)"object"===typeof a[b]&&(a[b].el=c);a.el=c;return a};g=function(a,b){var c;if("string"!=typeof a||a===d)return a;c=null!=b&&1===b.nodeType?b:document;if(a.match(/^#([\w\-]+$)/))return document.getElementById(a.split("#")[1]);c=c.querySelectorAll(a);return 1===c.length?c[0]:c};f.ext=function(a,b){b.el=c;f[a]=b};f.ext("each",function(a){c.length!==d&&c!==window?
[].forEach.call(c,a):a.call(c,c)});f.type=function(a){return function(){return a&&a!==this}.call(a)?(typeof a).toLowerCase():{}.toString.call(a).match(/\s([a-z|A-Z]+)/)[1].toLowerCase()};f=window.$_=window.$_||f;f.$=g})();"undefined"===typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^[\s\uFEFF]+|[\s\uFEFF]+$/g,"")});"undefined"===typeof Array.isArray&&(Array.isArray=function(d){return"[object Array]"===Object.prototype.toString.apply(d)});
(function(d){var f={_do:function(f,c,a,b,h){var e=new XMLHttpRequest;a===d&&(a=function(){});h=h?"POST":"GET";"GET"===h&&(f+=f.match(/\?/)?this._serialize(c):"?"+this._serialize(c));e.open(h,f);e.onreadystatechange=function(){4===e.readyState&&(200===e.status?a.call(e.responseText,e.responseText):b!==d&&b.call(e.status,e.status))};"POST"===h?(e.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),e.send(this._serialize(c))):e.send(null)},_serialize:function(d){var c,a,b=[];for(c in d)d.hasOwnProperty(c)&&
"function"!==typeof d[c]&&(a=d[c].toString(),c=encodeURIComponent(c),a=encodeURIComponent(a),b.push(c+"="+a));return b.join("&")}};$_.ext("get",function(d,c,a,b){f._do(d,c,a,b,!1)});$_.ext("post",function(d,c,a,b){f._do(d,c,a,b,!0)})})();
(function(d){var f,g;f=function(c,a,b,h){var e,k;if(c===d)return null;if(a.match(/^([\w\-]+)$/))!0===h?c.addEventListener(a,b,!1):c.removeEventListener(a,b,!1);else for(a=a.split(" "),k=a.length,e=0;e<k;e++)f(c,a[e],b,h)};g=function(c,a,b,d){f(c,b,function(b){var f,g;g=$_.$(a,c);for(f in g)b.target==g[f]&&(d.call(g[f],b),b.stopPropagation())},!0)};$_.ext("event",{add:function(c,a){$_.each(function(b){f(b,c,a,!0)})},remove:function(c,a){$_.each(function(b){f(b,c,a,!1)})},live:function(c,a,b){g(document.documentElement,
c,a,b)},delegate:function(c,a,b){$_.each(function(d){g(d,c,a,b)})}})})();
"undefined"===typeof document||"classList"in document.createElement("a")||function(d){if("HTMLElement"in d||"Element"in d){d=(d.HTMLElement||d.Element).prototype;var f=Object,g=String.prototype.trim||function(){return this.replace(/^\s+|\s+$/g,"")},c=Array.prototype.indexOf||function(a){for(var b=0,d=this.length;b<d;b++)if(b in this&&this[b]===a)return b;return-1},a=function(a,b){this.name=a;this.code=DOMException[a];this.message=b},b=function(b,d){if(""===d)throw new a("SYNTAX_ERR","An invalid or illegal string was specified");
if(/\s/.test(d))throw new a("INVALID_CHARACTER_ERR","String contains an invalid character");return c.call(b,d)},h=function(a){for(var b=g.call(a.className),b=b?b.split(/\s+/):[],d=0,c=b.length;d<c;d++)this.push(b[d]);this._updateClassName=function(){a.className=this.toString()}},e=h.prototype=[],k=function(){return new h(this)};a.prototype=Error.prototype;e.item=function(a){return this[a]||null};e.contains=function(a){return-1!==b(this,a+"")};e.add=function(){var a=arguments,d=0,c=a.length,e,f=!1;
do e=a[d]+"",-1===b(this,e)&&(this.push(e),f=!0);while(++d<c);f&&this._updateClassName()};e.remove=function(){var a=arguments,d=0,c=a.length,e,f=!1;do e=a[d]+"",e=b(this,e),-1!==e&&(this.splice(e,1),f=!0);while(++d<c);f&&this._updateClassName()};e.toggle=function(a,b){a+="";var d=this.contains(a),c=d?!0!==b&&"remove":!1!==b&&"add";if(c)this[c](a);return!d};e.toString=function(){return this.join(" ")};if(f.defineProperty){e={get:k,enumerable:!0,configurable:!0};try{f.defineProperty(d,"classList",e)}catch(l){-2146823252===
"function"!==$_.type(d[c])&&(a=d[c].toString(),c=encodeURIComponent(c),a=encodeURIComponent(a),b.push(c+"="+a));return b.join("&")}};$_.ext("get",function(d,c,a,b){f._do(d,c,a,b,!1)});$_.ext("post",function(d,c,a,b){f._do(d,c,a,b,!0)})})();
(function(d){var f,g;f=function(c,a,b,d){var e,k;if(a.match(/^([\w\-]+)$/))!0===d?c.addEventListener(a,b,!1):c.removeEventListener(a,b,!1);else for(a=a.split(" "),k=a.length,e=0;e<k;e++)f(c,a[e],b,d)};g=function(c,a,b,d){f(c,b,function(b){var f,g;g=$_.$(a,c);for(f in g)b.target==g[f]&&(d.call(g[f],b),b.stopPropagation())},!0)};$_.ext("event",{create:function(c,a){if(/MSIE|Trident/i.test(navigator.userAgent)){var b=document.createEvent("CustomEvent");b.initCustomEvent(c,!0,!0,a);return b}return new CustomEvent(c,
a)},add:function(c,a){$_.each(function(b){f(b,c,a,!0)})},remove:function(c,a){$_.each(function(b){f(b,c,a,!1)})},live:function(c,a,b){g(document.documentElement,c,a,b)},delegate:function(c,a,b){$_.each(function(d){g(d,c,a,b)})},trigger:function(c){return this.el.dispatchEvent(c)}})})();
"undefined"===typeof document||"classList"in document.createElement("a")||function(d){if("HTMLElement"in d||"Element"in d){d=(d.HTMLElement||d.Element).prototype;var f=Object,g=String.prototype.trim||function(){return this.replace(/^\s+|\s+$/g,"")},c=Array.prototype.indexOf||function(a){for(var b=0,c=this.length;b<c;b++)if(b in this&&this[b]===a)return b;return-1},a=function(a,b){this.name=a;this.code=DOMException[a];this.message=b},b=function(b,d){if(""===d)throw new a("SYNTAX_ERR","An invalid or illegal string was specified");
if(/\s/.test(d))throw new a("INVALID_CHARACTER_ERR","String contains an invalid character");return c.call(b,d)},h=function(a){for(var b=g.call(a.className),b=b?b.split(/\s+/):[],c=0,d=b.length;c<d;c++)this.push(b[c]);this._updateClassName=function(){a.className=this.toString()}},e=h.prototype=[],k=function(){return new h(this)};a.prototype=Error.prototype;e.item=function(a){return this[a]||null};e.contains=function(a){return-1!==b(this,a+"")};e.add=function(){var a=arguments,c=0,d=a.length,e,f=!1;
do e=a[c]+"",-1===b(this,e)&&(this.push(e),f=!0);while(++c<d);f&&this._updateClassName()};e.remove=function(){var a=arguments,c=0,d=a.length,e,f=!1;do e=a[c]+"",e=b(this,e),-1!==e&&(this.splice(e,1),f=!0);while(++c<d);f&&this._updateClassName()};e.toggle=function(a,b){a+="";var c=this.contains(a),d=c?!0!==b&&"remove":!1!==b&&"add";if(d)this[d](a);return!c};e.toString=function(){return this.join(" ")};if(f.defineProperty){e={get:k,enumerable:!0,configurable:!0};try{f.defineProperty(d,"classList",e)}catch(l){-2146823252===
l.number&&(e.enumerable=!1,f.defineProperty(d,"classList",e))}}else f.prototype.__defineGetter__&&d.__defineGetter__("classList",k)}}(self);
(function(d){function f(a,b,c){var e,f;a.hasAttribute!==d?(a.hasAttribute(b)&&(e=a.getAttribute(b)),f=!0):a[b]!==d?(e=a[b],f=!1):"class"===b&&a.className!==d&&(b="className",e=a.className,f=!1);if(e===d&&(c===d||null===c))return null;if(c===d)return e;c!==d&&null!==c?!0===f?a.setAttribute(b,c):a[b]=c:null===c&&(!0===f?a.removeAttribute(b):delete a[b]);return c!==d?c:e}function g(a){return a.replace(/(\-[a-z])/g,function(a){return a.toUpperCase().replace("-","")})}function c(a,b,c){var e;b=g(b);e=
{outerHeight:"offsetHeight",outerWidth:"offsetWidth",top:"posTop"};if(c===d&&a.style[b]!==d)return a.style[b];if(c===d&&a.style[e[b]]!==d)return a.style[e[b]];if(a.style[b]!==d)return a.style[b]=c,null;if(a.style[e[b]])return a.style[e[b]]=c,null}$_.ext("dom",{addClass:function(a){$_.each(function(b){b.classList.add(a)})},removeClass:function(a){$_.each(function(b){b.classList.remove(a)})},hide:function(){this.css("display","none")},show:function(a){a===d&&(a="block");this.css("display",a)},attr:function(a,
b){var c=this.el;if(1<c.length&&b===d)return null;if(1<c.length&&b!==d)$_.each(function(c){return f(c,a,b)});else return f(c,a,b)},text:function(a){var b,c,e;e=this.el;c=a!==d?!0:!1;b=e.textContent;return c?e.textContent=a:b},css:function(a,b){if(b===d)return c(this.el,a);$_.each(function(d){c(d,a,b)})},append:function(a){document.insertAdjacentHTML!==d?this.el.insertAdjacentHTML("beforeend",a):this.el.innerHTML+=a},prepend:function(a){document.insertAdjacentHTML!==d?this.el.insertAdjacentHTML("afterbegin",
a):this.el.innerHTML=a+this.el.innerHTML},html:function(a){a!==d&&(this.el.innerHTML=a);return this.el.innerHTML}})})();
b){var c=this.el;if(1<c.length&&b===d)return null;if(1<c.length&&b!==d)$_.each(function(c){return f(c,a,b)});else return f(c,a,b)},text:function(a){var b,c,e;e=this.el;c=a!==d?!0:!1;b=e.textContent;return c?e.textContent=a:b},css:function(a,b){if(b===d)return c(this.el,a);$_.each(function(d){c(d,a,b)})},append:function(a){this.el.insertAdjacentHTML("beforeend",a)},prepend:function(a){this.el.insertAdjacentHTML("afterbegin",a)},html:function(a){a!==d&&(this.el.innerHTML=a);return this.el.innerHTML}})})();

View File

@ -253,7 +253,7 @@ if (typeof Array.isArray === "undefined")
for (name in data)
{
if ( ! data.hasOwnProperty(name) || typeof data[name] === "function")
if ( ! data.hasOwnProperty(name) || $_.type(data[name]) === "function")
{
continue;
}
@ -320,11 +320,6 @@ if (typeof Array.isArray === "undefined")
{
var i, len;
if(sel === undefined)
{
return null;
}
// Multiple events? Run recursively!
if ( ! event.match(/^([\w\-]+)$/))
{
@ -383,6 +378,35 @@ if (typeof Array.isArray === "undefined")
* @memberOf $_
*/
e = {
/**
* Create a custom event
*
* @memberOf $_.event
* @name create
* @function
* @example Eg. var event = $_("#selector").event.create('foo', {});
* @param string name
* @param [object] data
* @return object
*/
create: function(name, data)
{
// Do a terrible browser-sniffic hack because I don't know of a good
// feature test
if (/MSIE|Trident/i.test(navigator.userAgent))
{
// Okay, I guess we have to do this the hard way... :(
// Microsoft, your browser still sucks
var e = document.createEvent('CustomEvent');
e.initCustomEvent(name, true, true, data);
return e;
}
else
{
return new CustomEvent(name, data);
}
},
/**
* Adds an event that returns a callback when triggered on the selected
* event and selector
@ -447,6 +471,22 @@ if (typeof Array.isArray === "undefined")
$_.each(function(e){
_attach_delegate(e, target, event, callback);
});
},
/**
* Trigger an event to fire
*
* @memberOf $_.event
* @name trigger
* @function
* @example Eg. $_("#my_id").trigger('click');
* @param string target
* @param object event
* @return bool
*/
trigger: function(event)
{
var target = this.el;
return target.dispatchEvent(event);
}
};
@ -765,14 +805,7 @@ if(typeof document!=="undefined"&&!("classList" in document.createElement("a")))
*/
append: function(htm)
{
if(document.insertAdjacentHTML !== undefined)
{
this.el.insertAdjacentHTML('beforeend', htm);
}
else
{
this.el.innerHTML += htm;
}
this.el.insertAdjacentHTML('beforeend', htm);
},
/**
* Adds to the innerHTML of the selected element, before the current children
@ -784,14 +817,7 @@ if(typeof document!=="undefined"&&!("classList" in document.createElement("a")))
*/
prepend: function(htm)
{
if(document.insertAdjacentHTML !== undefined)
{
this.el.insertAdjacentHTML('afterbegin', htm);
}
else
{
this.el.innerHTML = htm + this.el.innerHTML;
}
this.el.insertAdjacentHTML('afterbegin', htm);
},
/**
* Sets or gets the innerHTML propery of the element(s) passed

12
kis-lite-min.js vendored
View File

@ -1,6 +1,6 @@
(function(e){var b,g,c;b=function(a){c=a===e?b.el!==e?b.el:document.documentElement:g(a);b.prototype.el=c;a=Object.create(b);for(var d in a)"object"===typeof a[d]&&(a[d].el=c);a.el=c;return a};g=function(a,c){var b;if("string"!=typeof a||a===e)return a;b=null!=c&&1===c.nodeType?c:document;if(a.match(/^#([\w\-]+$)/))return document.getElementById(a.split("#")[1]);b=b.querySelectorAll(a);return 1===b.length?b[0]:b};b.ext=function(a,d){d.el=c;b[a]=d};b.ext("each",function(a){c.length!==e&&c!==window?
[].forEach.call(c,a):a.call(c,c)});b.type=function(a){return function(){return a&&a!==this}.call(a)?(typeof a).toLowerCase():{}.toString.call(a).match(/\s([a-z|A-Z]+)/)[1].toLowerCase()};b=window.$_=window.$_||b;b.$=g})();"undefined"===typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^[\s\uFEFF]+|[\s\uFEFF]+$/g,"")});"undefined"===typeof Array.isArray&&(Array.isArray=function(e){return"[object Array]"===Object.prototype.toString.apply(e)});
(function(e){var b={_do:function(b,c,a,d,h){var f=new XMLHttpRequest;a===e&&(a=function(){});h=h?"POST":"GET";"GET"===h&&(b+=b.match(/\?/)?this._serialize(c):"?"+this._serialize(c));f.open(h,b);f.onreadystatechange=function(){4===f.readyState&&(200===f.status?a.call(f.responseText,f.responseText):d!==e&&d.call(f.status,f.status))};"POST"===h?(f.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),f.send(this._serialize(c))):f.send(null)},_serialize:function(b){var c,a,d=[];for(c in b)b.hasOwnProperty(c)&&
"function"!==typeof b[c]&&(a=b[c].toString(),c=encodeURIComponent(c),a=encodeURIComponent(a),d.push(c+"="+a));return d.join("&")}};$_.ext("get",function(e,c,a,d){b._do(e,c,a,d,!1)});$_.ext("post",function(e,c,a,d){b._do(e,c,a,d,!0)})})();
(function(e){var b,g;b=function(c,a,d,h){var f,g;if(c===e)return null;if(a.match(/^([\w\-]+)$/))!0===h?c.addEventListener(a,d,!1):c.removeEventListener(a,d,!1);else for(a=a.split(" "),g=a.length,f=0;f<g;f++)b(c,a[f],d,h)};g=function(c,a,d,e){b(c,d,function(b){var d,g;g=$_.$(a,c);for(d in g)b.target==g[d]&&(e.call(g[d],b),b.stopPropagation())},!0)};$_.ext("event",{add:function(c,a){$_.each(function(d){b(d,c,a,!0)})},remove:function(c,a){$_.each(function(d){b(d,c,a,!1)})},live:function(c,a,b){g(document.documentElement,
c,a,b)},delegate:function(c,a,b){$_.each(function(e){g(e,c,a,b)})}})})();
(function(e){var c,f,b;c=function(a){b=a===e?c.el!==e?c.el:document.documentElement:f(a);c.prototype.el=b;a=Object.create(c);for(var d in a)"object"===typeof a[d]&&(a[d].el=b);a.el=b;return a};f=function(a,b){var c;if("string"!=typeof a||a===e)return a;c=null!=b&&1===b.nodeType?b:document;if(a.match(/^#([\w\-]+$)/))return document.getElementById(a.split("#")[1]);c=c.querySelectorAll(a);return 1===c.length?c[0]:c};c.ext=function(a,d){d.el=b;c[a]=d};c.ext("each",function(a){b.length!==e&&b!==window?
[].forEach.call(b,a):a.call(b,b)});c.type=function(a){return function(){return a&&a!==this}.call(a)?(typeof a).toLowerCase():{}.toString.call(a).match(/\s([a-z|A-Z]+)/)[1].toLowerCase()};c=window.$_=window.$_||c;c.$=f})();"undefined"===typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^[\s\uFEFF]+|[\s\uFEFF]+$/g,"")});"undefined"===typeof Array.isArray&&(Array.isArray=function(e){return"[object Array]"===Object.prototype.toString.apply(e)});
(function(e){var c={_do:function(c,b,a,d,h){var g=new XMLHttpRequest;a===e&&(a=function(){});h=h?"POST":"GET";"GET"===h&&(c+=c.match(/\?/)?this._serialize(b):"?"+this._serialize(b));g.open(h,c);g.onreadystatechange=function(){4===g.readyState&&(200===g.status?a.call(g.responseText,g.responseText):d!==e&&d.call(g.status,g.status))};"POST"===h?(g.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),g.send(this._serialize(b))):g.send(null)},_serialize:function(c){var b,a,d=[];for(b in c)c.hasOwnProperty(b)&&
"function"!==$_.type(c[b])&&(a=c[b].toString(),b=encodeURIComponent(b),a=encodeURIComponent(a),d.push(b+"="+a));return d.join("&")}};$_.ext("get",function(f,b,a,d){c._do(f,b,a,d,!1)});$_.ext("post",function(f,b,a,d){c._do(f,b,a,d,!0)})})();
(function(e){var c,f;c=function(b,a,d,h){var g,f;if(a.match(/^([\w\-]+)$/))!0===h?b.addEventListener(a,d,!1):b.removeEventListener(a,d,!1);else for(a=a.split(" "),f=a.length,g=0;g<f;g++)c(b,a[g],d,h)};f=function(b,a,d,f){c(b,d,function(c){var d,e;e=$_.$(a,b);for(d in e)c.target==e[d]&&(f.call(e[d],c),c.stopPropagation())},!0)};$_.ext("event",{create:function(b,a){if(/MSIE|Trident/i.test(navigator.userAgent)){var c=document.createEvent("CustomEvent");c.initCustomEvent(b,!0,!0,a);return c}return new CustomEvent(b,
a)},add:function(b,a){$_.each(function(d){c(d,b,a,!0)})},remove:function(b,a){$_.each(function(d){c(d,b,a,!1)})},live:function(b,a,c){f(document.documentElement,b,a,c)},delegate:function(b,a,c){$_.each(function(e){f(e,b,a,c)})},trigger:function(b){return this.el.dispatchEvent(b)}})})();

View File

@ -253,7 +253,7 @@ if (typeof Array.isArray === "undefined")
for (name in data)
{
if ( ! data.hasOwnProperty(name) || typeof data[name] === "function")
if ( ! data.hasOwnProperty(name) || $_.type(data[name]) === "function")
{
continue;
}
@ -320,11 +320,6 @@ if (typeof Array.isArray === "undefined")
{
var i, len;
if(sel === undefined)
{
return null;
}
// Multiple events? Run recursively!
if ( ! event.match(/^([\w\-]+)$/))
{
@ -383,6 +378,35 @@ if (typeof Array.isArray === "undefined")
* @memberOf $_
*/
e = {
/**
* Create a custom event
*
* @memberOf $_.event
* @name create
* @function
* @example Eg. var event = $_("#selector").event.create('foo', {});
* @param string name
* @param [object] data
* @return object
*/
create: function(name, data)
{
// Do a terrible browser-sniffic hack because I don't know of a good
// feature test
if (/MSIE|Trident/i.test(navigator.userAgent))
{
// Okay, I guess we have to do this the hard way... :(
// Microsoft, your browser still sucks
var e = document.createEvent('CustomEvent');
e.initCustomEvent(name, true, true, data);
return e;
}
else
{
return new CustomEvent(name, data);
}
},
/**
* Adds an event that returns a callback when triggered on the selected
* event and selector
@ -447,6 +471,22 @@ if (typeof Array.isArray === "undefined")
$_.each(function(e){
_attach_delegate(e, target, event, callback);
});
},
/**
* Trigger an event to fire
*
* @memberOf $_.event
* @name trigger
* @function
* @example Eg. $_("#my_id").trigger('click');
* @param string target
* @param object event
* @return bool
*/
trigger: function(event)
{
var target = this.el;
return target.dispatchEvent(event);
}
};

27
kis-min.js vendored
View File

@ -1,15 +1,12 @@
(function(g){var d,s,h;d=function(m){h=m===g?d.el!==g?d.el:document.documentElement:s(m);d.prototype.el=h;m=Object.create(d);for(var p in m)"object"===typeof m[p]&&(m[p].el=h);m.el=h;return m};s=function(d,h){var l;if("string"!=typeof d||d===g)return d;l=null!=h&&1===h.nodeType?h:document;if(d.match(/^#([\w\-]+$)/))return document.getElementById(d.split("#")[1]);l=l.querySelectorAll(d);return 1===l.length?l[0]:l};d.ext=function(g,p){p.el=h;d[g]=p};d.ext("each",function(d){h.length!==g&&h!==window?
[].forEach.call(h,d):d.call(h,h)});d.type=function(d){return function(){return d&&d!==this}.call(d)?(typeof d).toLowerCase():{}.toString.call(d).match(/\s([a-z|A-Z]+)/)[1].toLowerCase()};d=window.$_=window.$_||d;d.$=s})();"undefined"===typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^[\s\uFEFF]+|[\s\uFEFF]+$/g,"")});"undefined"===typeof Array.isArray&&(Array.isArray=function(g){return"[object Array]"===Object.prototype.toString.apply(g)});
(function(g,d){function s(a,b,c){var e,f;a.hasAttribute!==d?(a.hasAttribute(b)&&(e=a.getAttribute(b)),f=!0):a[b]!==d?(e=a[b],f=!1):"class"===b&&a.className!==d&&(b="className",e=a.className,f=!1);if(e===d&&(c===d||null===c))return null;if(c===d)return e;c!==d&&null!==c?!0===f?a.setAttribute(b,c):a[b]=c:null===c&&(!0===f?a.removeAttribute(b):delete a[b]);return c!==d?c:e}function h(a){return a.replace(/(\-[a-z])/g,function(a){return a.toUpperCase().replace("-","")})}function m(a,b,c){var e;b=h(b);
e={outerHeight:"offsetHeight",outerWidth:"offsetWidth",top:"posTop"};if(c===d&&a.style[b]!==d)return a.style[b];if(c===d&&a.style[e[b]]!==d)return a.style[e[b]];if(a.style[b]!==d)return a.style[b]=c,null;if(a.style[e[b]])return a.style[e[b]]=c,null}"undefined"===typeof document||"classList"in document.createElement("a")||function(a){if("HTMLElement"in a||"Element"in a){a=(a.HTMLElement||a.Element).prototype;var b=Object,c=String.prototype.trim||function(){return this.replace(/^\s+|\s+$/g,"")},e=Array.prototype.indexOf||
function(a){for(var b=0,c=this.length;b<c;b++)if(b in this&&this[b]===a)return b;return-1},f=function(a,b){this.name=a;this.code=DOMException[a];this.message=b},d=function(a,b){if(""===b)throw new f("SYNTAX_ERR","An invalid or illegal string was specified");if(/\s/.test(b))throw new f("INVALID_CHARACTER_ERR","String contains an invalid character");return e.call(a,b)},k=function(a){for(var b=c.call(a.className),b=b?b.split(/\s+/):[],e=0,f=b.length;e<f;e++)this.push(b[e]);this._updateClassName=function(){a.className=
this.toString()}},g=k.prototype=[],h=function(){return new k(this)};f.prototype=Error.prototype;g.item=function(a){return this[a]||null};g.contains=function(a){return-1!==d(this,a+"")};g.add=function(){var a=arguments,b=0,c=a.length,e,f=!1;do e=a[b]+"",-1===d(this,e)&&(this.push(e),f=!0);while(++b<c);f&&this._updateClassName()};g.remove=function(){var a=arguments,b=0,c=a.length,e,f=!1;do e=a[b]+"",e=d(this,e),-1!==e&&(this.splice(e,1),f=!0);while(++b<c);f&&this._updateClassName()};g.toggle=function(a,
b){a+="";var c=this.contains(a),e=c?!0!==b&&"remove":!1!==b&&"add";if(e)this[e](a);return!c};g.toString=function(){return this.join(" ")};if(b.defineProperty){g={get:h,enumerable:!0,configurable:!0};try{b.defineProperty(a,"classList",g)}catch(l){-2146823252===l.number&&(g.enumerable=!1,b.defineProperty(a,"classList",g))}}else b.prototype.__defineGetter__&&a.__defineGetter__("classList",h)}}(self);g.ext("dom",{addClass:function(a){g.each(function(b){b.classList.add(a)})},removeClass:function(a){g.each(function(b){b.classList.remove(a)})},
hide:function(){this.css("display","none")},show:function(a){a===d&&(a="block");this.css("display",a)},attr:function(a,b){var c=this.el;if(1<c.length&&b===d)return null;if(1<c.length&&b!==d)g.each(function(c){return s(c,a,b)});else return s(c,a,b)},text:function(a){var b,c,e;e=this.el;c=a!==d?!0:!1;b=e.textContent;return c?e.textContent=a:b},css:function(a,b){if(b===d)return m(this.el,a);g.each(function(c){m(c,a,b)})},append:function(a){document.insertAdjacentHTML!==d?this.el.insertAdjacentHTML("beforeend",
a):this.el.innerHTML+=a},prepend:function(a){document.insertAdjacentHTML!==d?this.el.insertAdjacentHTML("afterbegin",a):this.el.innerHTML=a+this.el.innerHTML},html:function(a){a!==d&&(this.el.innerHTML=a);return this.el.innerHTML}});var p={_do:function(a,b,c,e,f){var n=new XMLHttpRequest;c===d&&(c=function(){});f=f?"POST":"GET";"GET"===f&&(a+=a.match(/\?/)?this._serialize(b):"?"+this._serialize(b));n.open(f,a);n.onreadystatechange=function(){4===n.readyState&&(200===n.status?c.call(n.responseText,
n.responseText):e!==d&&e.call(n.status,n.status))};"POST"===f?(n.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),n.send(this._serialize(b))):n.send(null)},_serialize:function(a){var b,c,e=[];for(b in a)a.hasOwnProperty(b)&&"function"!==typeof a[b]&&(c=a[b].toString(),b=encodeURIComponent(b),c=encodeURIComponent(c),e.push(b+"="+c));return e.join("&")}};g.ext("get",function(a,b,c,e){p._do(a,b,c,e,!1)});g.ext("post",function(a,b,c,e){p._do(a,b,c,e,!0)});var l,t;l=function(a,b,c,
e){var f,n;if(a===d)return null;if(b.match(/^([\w\-]+)$/))!0===e?a.addEventListener(b,c,!1):a.removeEventListener(b,c,!1);else for(b=b.split(" "),n=b.length,f=0;f<n;f++)l(a,b[f],c,e)};t=function(a,b,c,e){l(a,c,function(c){var d,k;k=g.$(b,a);for(d in k)c.target==k[d]&&(e.call(k[d],c),c.stopPropagation())},!0)};g.ext("event",{add:function(a,b){g.each(function(c){l(c,a,b,!0)})},remove:function(a,b){g.each(function(c){l(c,a,b,!1)})},live:function(a,b,c){t(document.documentElement,a,b,c)},delegate:function(a,
b,c){g.each(function(e){t(e,a,b,c)})}});var q=localStorage,r=sessionStorage;g.ext("store",{get:function(a,b){var c=b?r.getItem(a):q.getItem(a);return JSON.parse(c)},set:function(a,b,c){b=JSON.stringify(b);c?r.setItem(a,b):q.setItem(a,b)},remove:function(a,b){b?r.removeItem(a):q.removeItem(a)},getAll:function(a){var b,c={},e,f;f=a?q:r;b=f.length;for(a=0;a<b;a++)e=f.key(a),c[e]=f.getItem(e);return c},clear:function(a){a?r.clear():q.clear()}});var v=function(a){var b=[],c=0,e={},f,b=u.object_keys(a);
b.sort(function(a,b){var c=parseFloat(b),e=parseFloat(a),f=c+""===b,d=e+""===a;return f&&d?c>e?1:c<e?-1:0:f&&!d?1:!f&&d?-1:b>a?1:b<a?-1:0});c=b.length;for(f=0;f<c;f++)e[b[f]]=a[b[f]];return e},u={object_keys:function(a){var b=[],c;for(c in a)a.hasOwnProperty(c)&&b.push(c);return b},object_values:function(a){var b=[],c;for(c in a)b.push(a[c]);return b},array_combine:function(a,b){var c={},e,f=0;"array"!==g.type(a)&&(a=this.object_values(a));"array"!==g.type(b)&&(b=this.object_values(b));e=a.length;
if(e!==b.length)return!1;for(f=0;f<e;f++)c[a[f]]=b[f];return c},object_merge:function(){var a=Array.prototype.slice.call(arguments),b=a.length,c={},e,f=0,d,k,h;e=!0;for(d=0;d<b;d++)if("array"!==g.type(a[d])){e=!1;break}if(e){c=[];for(d=0;d<b;d++)c=c.contact(a[d]);return c}for(h=d=0;d<b;d++)if(e=a[d],"array"==g.type(e))for(k=0,f=e.length;k<f;k++)c[h++]=e[k];else for(k in e)e.hasOwnProperty(k)&&(parseInt(k,10)+""===k?c[h++]=e[k]:c[k]=e[k]);return c},str_trans:function(a,b,c){var e=[],d=[],g=!1,h=0,
l=0,m="",p="",s="",q="",r;if("object"===typeof b){b=v(b);for(r in b)b.hasOwnProperty(r)&&(e.push(r),d.push(b[r]));b=e;c=d}l=a.length;h=b.length;m="string"===typeof c;p="string"===typeof b;for(e=0;e<l;e++){g=!1;if(p)for(a.charAt(e-1),s=a.charAt(e),a.charAt(e+1),d=0;d<h;d++){if(s==b.charAt(d)){g=!0;break}}else for(d=0;d<h;d++)if(a.substr(e,b[d].length)==b[d]){g=!0;e=e+b[d].length-1;break}q=g?q+(m?c.charAt(d):c[d]):q+a.charAt(e)}return q}};g.ext("util",u)})($_);
(function(e){var c,m,k;c=function(f){k=f===e?c.el!==e?c.el:document.documentElement:m(f);c.prototype.el=k;f=Object.create(c);for(var n in f)"object"===typeof f[n]&&(f[n].el=k);f.el=k;return f};m=function(c,k){var l;if("string"!=typeof c||c===e)return c;l=null!=k&&1===k.nodeType?k:document;if(c.match(/^#([\w\-]+$)/))return document.getElementById(c.split("#")[1]);l=l.querySelectorAll(c);return 1===l.length?l[0]:l};c.ext=function(f,e){e.el=k;c[f]=e};c.ext("each",function(c){k.length!==e&&k!==window?
[].forEach.call(k,c):c.call(k,k)});c.type=function(c){return function(){return c&&c!==this}.call(c)?(typeof c).toLowerCase():{}.toString.call(c).match(/\s([a-z|A-Z]+)/)[1].toLowerCase()};c=window.$_=window.$_||c;c.$=m})();"undefined"===typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^[\s\uFEFF]+|[\s\uFEFF]+$/g,"")});"undefined"===typeof Array.isArray&&(Array.isArray=function(e){return"[object Array]"===Object.prototype.toString.apply(e)});
(function(e,c){function m(a,b,d){var g,h;a.hasAttribute!==c?(a.hasAttribute(b)&&(g=a.getAttribute(b)),h=!0):a[b]!==c?(g=a[b],h=!1):"class"===b&&a.className!==c&&(b="className",g=a.className,h=!1);if(g===c&&(d===c||null===d))return null;if(d===c)return g;d!==c&&null!==d?!0===h?a.setAttribute(b,d):a[b]=d:null===d&&(!0===h?a.removeAttribute(b):delete a[b]);return d!==c?d:g}function k(a){return a.replace(/(\-[a-z])/g,function(a){return a.toUpperCase().replace("-","")})}function f(a,b,d){var g;b=k(b);
g={outerHeight:"offsetHeight",outerWidth:"offsetWidth",top:"posTop"};if(d===c&&a.style[b]!==c)return a.style[b];if(d===c&&a.style[g[b]]!==c)return a.style[g[b]];if(a.style[b]!==c)return a.style[b]=d,null;if(a.style[g[b]])return a.style[g[b]]=d,null}"undefined"===typeof document||"classList"in document.createElement("a")||function(a){if("HTMLElement"in a||"Element"in a){a=(a.HTMLElement||a.Element).prototype;var b=Object,d=String.prototype.trim||function(){return this.replace(/^\s+|\s+$/g,"")},c=Array.prototype.indexOf||
function(a){for(var b=0,d=this.length;b<d;b++)if(b in this&&this[b]===a)return b;return-1},h=function(a,b){this.name=a;this.code=DOMException[a];this.message=b},e=function(a,b){if(""===b)throw new h("SYNTAX_ERR","An invalid or illegal string was specified");if(/\s/.test(b))throw new h("INVALID_CHARACTER_ERR","String contains an invalid character");return c.call(a,b)},k=function(a){for(var b=d.call(a.className),b=b?b.split(/\s+/):[],c=0,g=b.length;c<g;c++)this.push(b[c]);this._updateClassName=function(){a.className=
this.toString()}},f=k.prototype=[],l=function(){return new k(this)};h.prototype=Error.prototype;f.item=function(a){return this[a]||null};f.contains=function(a){return-1!==e(this,a+"")};f.add=function(){var a=arguments,b=0,d=a.length,c,g=!1;do c=a[b]+"",-1===e(this,c)&&(this.push(c),g=!0);while(++b<d);g&&this._updateClassName()};f.remove=function(){var a=arguments,b=0,d=a.length,c,g=!1;do c=a[b]+"",c=e(this,c),-1!==c&&(this.splice(c,1),g=!0);while(++b<d);g&&this._updateClassName()};f.toggle=function(a,
b){a+="";var d=this.contains(a),c=d?!0!==b&&"remove":!1!==b&&"add";if(c)this[c](a);return!d};f.toString=function(){return this.join(" ")};if(b.defineProperty){f={get:l,enumerable:!0,configurable:!0};try{b.defineProperty(a,"classList",f)}catch(m){-2146823252===m.number&&(f.enumerable=!1,b.defineProperty(a,"classList",f))}}else b.prototype.__defineGetter__&&a.__defineGetter__("classList",l)}}(self);e.ext("dom",{addClass:function(a){e.each(function(b){b.classList.add(a)})},removeClass:function(a){e.each(function(b){b.classList.remove(a)})},
hide:function(){this.css("display","none")},show:function(a){a===c&&(a="block");this.css("display",a)},attr:function(a,b){var d=this.el;if(1<d.length&&b===c)return null;if(1<d.length&&b!==c)e.each(function(d){return m(d,a,b)});else return m(d,a,b)},text:function(a){var b,d,g;g=this.el;d=a!==c?!0:!1;b=g.textContent;return d?g.textContent=a:b},css:function(a,b){if(b===c)return f(this.el,a);e.each(function(d){f(d,a,b)})},append:function(a){this.el.insertAdjacentHTML("beforeend",a)},prepend:function(a){this.el.insertAdjacentHTML("afterbegin",
a)},html:function(a){a!==c&&(this.el.innerHTML=a);return this.el.innerHTML}});var n={_do:function(a,b,d,g,h){var e=new XMLHttpRequest;d===c&&(d=function(){});h=h?"POST":"GET";"GET"===h&&(a+=a.match(/\?/)?this._serialize(b):"?"+this._serialize(b));e.open(h,a);e.onreadystatechange=function(){4===e.readyState&&(200===e.status?d.call(e.responseText,e.responseText):g!==c&&g.call(e.status,e.status))};"POST"===h?(e.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),e.send(this._serialize(b))):
e.send(null)},_serialize:function(a){var b,d,c=[];for(b in a)a.hasOwnProperty(b)&&"function"!==e.type(a[b])&&(d=a[b].toString(),b=encodeURIComponent(b),d=encodeURIComponent(d),c.push(b+"="+d));return c.join("&")}};e.ext("get",function(a,b,d,c){n._do(a,b,d,c,!1)});e.ext("post",function(a,b,c,e){n._do(a,b,c,e,!0)});var l,r;l=function(a,b,c,e){var h,f;if(b.match(/^([\w\-]+)$/))!0===e?a.addEventListener(b,c,!1):a.removeEventListener(b,c,!1);else for(b=b.split(" "),f=b.length,h=0;h<f;h++)l(a,b[h],c,e)};
r=function(a,b,c,g){l(a,c,function(c){var d,f;f=e.$(b,a);for(d in f)c.target==f[d]&&(g.call(f[d],c),c.stopPropagation())},!0)};e.ext("event",{create:function(a,b){if(/MSIE|Trident/i.test(navigator.userAgent)){var c=document.createEvent("CustomEvent");c.initCustomEvent(a,!0,!0,b);return c}return new CustomEvent(a,b)},add:function(a,b){e.each(function(c){l(c,a,b,!0)})},remove:function(a,b){e.each(function(c){l(c,a,b,!1)})},live:function(a,b,c){r(document.documentElement,a,b,c)},delegate:function(a,
b,c){e.each(function(e){r(e,a,b,c)})},trigger:function(a){return this.el.dispatchEvent(a)}});var p=localStorage,q=sessionStorage;e.ext("store",{get:function(a,b){var c=b?q.getItem(a):p.getItem(a);return JSON.parse(c)},set:function(a,b,c){b=JSON.stringify(b);c?q.setItem(a,b):p.setItem(a,b)},remove:function(a,b){b?q.removeItem(a):p.removeItem(a)},getAll:function(a){var b,c={},e,f;f=a?p:q;b=f.length;for(a=0;a<b;a++)e=f.key(a),c[e]=f.getItem(e);return c},clear:function(a){a?q.clear():p.clear()}})})($_);

View File

@ -307,14 +307,7 @@ if(typeof document!=="undefined"&&!("classList" in document.createElement("a")))
*/
append: function(htm)
{
if(document.insertAdjacentHTML !== undefined)
{
this.el.insertAdjacentHTML('beforeend', htm);
}
else
{
this.el.innerHTML += htm;
}
this.el.insertAdjacentHTML('beforeend', htm);
},
/**
* Adds to the innerHTML of the selected element, before the current children
@ -326,14 +319,7 @@ if(typeof document!=="undefined"&&!("classList" in document.createElement("a")))
*/
prepend: function(htm)
{
if(document.insertAdjacentHTML !== undefined)
{
this.el.insertAdjacentHTML('afterbegin', htm);
}
else
{
this.el.innerHTML = htm + this.el.innerHTML;
}
this.el.insertAdjacentHTML('afterbegin', htm);
},
/**
* Sets or gets the innerHTML propery of the element(s) passed

View File

@ -69,7 +69,7 @@
for (name in data)
{
if ( ! data.hasOwnProperty(name) || typeof data[name] === "function")
if ( ! data.hasOwnProperty(name) || $_.type(data[name]) === "function")
{
continue;
}

View File

@ -14,11 +14,6 @@
{
var i, len;
if(sel === undefined)
{
return null;
}
// Multiple events? Run recursively!
if ( ! event.match(/^([\w\-]+)$/))
{
@ -77,6 +72,35 @@
* @memberOf $_
*/
e = {
/**
* Create a custom event
*
* @memberOf $_.event
* @name create
* @function
* @example Eg. var event = $_("#selector").event.create('foo', {});
* @param string name
* @param [object] data
* @return object
*/
create: function(name, data)
{
// Do a terrible browser-sniffic hack because I don't know of a good
// feature test
if (/MSIE|Trident/i.test(navigator.userAgent))
{
// Okay, I guess we have to do this the hard way... :(
// Microsoft, your browser still sucks
var e = document.createEvent('CustomEvent');
e.initCustomEvent(name, true, true, data);
return e;
}
else
{
return new CustomEvent(name, data);
}
},
/**
* Adds an event that returns a callback when triggered on the selected
* event and selector
@ -141,6 +165,22 @@
$_.each(function(e){
_attach_delegate(e, target, event, callback);
});
},
/**
* Trigger an event to fire
*
* @memberOf $_.event
* @name trigger
* @function
* @example Eg. $_("#my_id").trigger('click');
* @param string target
* @param object event
* @return bool
*/
trigger: function(event)
{
var target = this.el;
return target.dispatchEvent(event);
}
};

View File

@ -1,359 +0,0 @@
/**
* Util Object
*
* Various object and string manipulation functions
* Note: these are based on similar phpjs functions: http://phpjs.org
*/
(function (undefined){
"use strict";
var reverse_key_sort = function(o)
{
//Define some variables
var keys = [],
num_keys = 0,
new_o = {},
i;
//Extract the keys
keys = u.object_keys(o);
//Sort the keys
keys.sort(function (b, a) {
var aFloat = parseFloat(a),
bFloat = parseFloat(b),
aNumeric = aFloat + '' === a,
bNumeric = bFloat + '' === b;
if (aNumeric && bNumeric)
{
return aFloat > bFloat ? 1 : aFloat < bFloat ? -1 : 0;
}
else if (aNumeric && !bNumeric)
{
return 1;
}
else if (!aNumeric && bNumeric)
{
return -1;
}
return a > b ? 1 : a < b ? -1 : 0;
});
// cache object/array size
num_keys = keys.length;
// Recreate the object/array
for(i=0; i < num_keys; i++)
{
new_o[keys[i]] = o[keys[i]];
}
return new_o;
},
/**
* String and object manipulation utilities
*
* @namespace
* @name util
* @memberOf $_
*/
u = {
/**
* Retrieve the keys, or member names of an object
*
* @name object_keys
* @memberOf $_.util
* @function
* @param object
* @return array
* @type array
*/
object_keys: function(o)
{
var keys = [],
k;
for(k in o)
{
if(o.hasOwnProperty(k))
{
keys.push(k);
}
}
return keys;
},
/**
* Retrieves the values of an object, and returns
* them as an array
*
* @name object_values
* @memberOf $_.util
* @function
* @param object
* @return array
* @type array
*/
object_values: function(o)
{
var vals = [],
prop;
for(prop in o)
{
vals.push(o[prop]);
}
return vals;
},
/**
* Creates an object, with the property names of the first array,
* and the values of the second. If objects are passed, the values
* of the object are used. If the arrays or objects passed are
* not the same size, the function will return false.
*
* @name array_combine
* @memberOf $_.util
* @function
* @param array/object keys
* @param array/object vals
* @return object
* @type object
*/
array_combine: function(keys, vals)
{
var new_object = {},
num_keys,
i = 0;
// Extract the keys or values if needed
if($_.type(keys) !== "array")
{
keys = this.object_values(keys);
}
if($_.type(vals) !== "array")
{
vals = this.object_values(vals);
}
// cache the number of keys
num_keys = keys.length;
if(num_keys !== vals.length)
{
return false;
}
// Create and return the new object
for(i = 0; i < num_keys; i++)
{
new_object[keys[i]] = vals[i];
}
return new_object;
},
/**
* Combines two or more objects/arrays. If the keys are numeric, the outputted
* object will have re-indexed keys. If a key/value pair exists in both objects,
* indentical values will be droped, but if a key exists with a different value,
* with the same key, the value in the second array will replace the value in the
* first
*
* @name object_merge
* @memberOf $_.util
* @function
* @param object [as many as you wish to combine]
* @type object
* @return object
*/
object_merge: function()
{
var args = Array.prototype.slice.call(arguments),
arg_len = args.length,
new_obj = {},
arg,
iarg_len = 0,
i,
j,
x,
is_array = true;
// Check for an array in the arguments
for(i=0; i < arg_len; i++)
{
if($_.type(args[i]) !== "array")
{
is_array = false;
break;
}
}
// If all the arguments are javascript arrays
if(is_array)
{
new_obj = [];
// Let javascript do all the work!
for(i=0; i< arg_len; i++)
{
new_obj = new_obj.contact(args[i]);
}
// Return early
return new_obj;
}
// No, there's at least one object
for(i=0, x=0; i < arg_len; i++)
{
arg = args[i];
// If the argument is an array, add the array items as
// numeric object properties
if ($_.type(arg) == "array")
{
for (j=0, iarg_len= arg.length; j < iarg_len; j++)
{
new_obj[x++] = arg[j];
}
}
else
{
for (j in arg)
{
if(arg.hasOwnProperty(j))
{
// If the key is numeric, add the property with
// a numeric key
if(parseInt(j, 10) + '' === j)
{
new_obj[x++] = arg[j];
}
else
{
new_obj[j] = arg[j];
}
}
}
}
}
return new_obj;
},
/**
* Replaces sections of strings in a greedy fashion,
* starting with the longest replace pairs first. Accepts
* one replace pair as two parameters, or an object, with
* from => to replacements as key/value pairs
*
* @name str_trans
* @memberOf $_.util
* @function
* @param string input_string
* @param mixed from (string)/replace pairs (object)
* @param [string]
* @return string
* @type string
*/
str_trans: function(str, from, to)
{
var froms = [],
tos = [],
ret = '',
match = false,
from_len = 0,
str_len = 0,
to_len = 0,
to_is_str = '',
from_is_str = '',
strx = '',
strw = '',
stry = '',
from_strx = '',
new_str = '',
f,
i,
j;
//Replace pairs? add them to the internal arrays
if(typeof from === 'object')
{
// Sort the keys in descending order for better
// replacement functionality
from = reverse_key_sort(from);
for(f in from)
{
if(from.hasOwnProperty(f))
{
froms.push(f);
tos.push(from[f]);
}
}
from = froms;
to = tos;
}
//Go through the string, and replace characters as needed
str_len = str.length;
from_len = from.length;
to_len = to.length;
to_is_str = typeof to === 'string';
from_is_str = typeof from === 'string';
for(i=0; i < str_len; i++)
{
match = false;
if(from_is_str)
{
strw = str.charAt(i-1);
strx = str.charAt(i);
stry = str.charAt(i+1);
for(j=0; j < from_len; j++)
{
if(strx == from.charAt(j))
{
match = true;
break;
}
}
}
else
{
for(j=0; j < from_len; j++)
{
if(str.substr(i, from[j].length) == from[j])
{
match = true;
//Go past the current match
i = (i + from[j].length) -1;
break;
}
}
}
if(match)
{
new_str += (to_is_str) ? to.charAt(j) : to[j];
}
else
{
new_str += str.charAt(i);
}
}
return new_str;
}
};
//Add it to the $_ object
$_.ext('util', u);
}());

37
tests/ajax.php Normal file
View File

@ -0,0 +1,37 @@
<?php
$verb = strtolower($_SERVER['REQUEST_METHOD']);
// Send request method if nothing else is specified
if (empty($_GET))
{
echo $verb;
}
else if (isset($_GET['data']))
{
$var =& $_GET;
switch($verb)
{
case "get":
$var =& $_GET;
break;
case "post":
$var =& $_POST;
break;
}
header('Content-type: application/json');
echo json_encode($var);
}
else if (isset($_GET['bad']))
{
http_response_code('401');
}

View File

@ -25,7 +25,6 @@
<script src='../src/modules/event.js' data-cover></script>
<script src='../src/modules/DOM.js' data-cover></script>
<script src='../src/modules/store.js' data-cover></script>
<script src='../src/modules/util.js' data-cover></script>
<script src="blanket.js"></script>
<script src="qunit/test_funcs.js"></script>
<script src="tests/core.js"></script>
@ -33,6 +32,5 @@
<script src="tests/event.js"></script>
<script src="tests/dom.js"></script>
<script src="tests/store.js"></script>
<script src="tests/util.js"></script>
</body>
</html>

View File

@ -9,4 +9,44 @@
ok($_.post, "AJAX post method");
});
asyncTest("Get", function() {
$_.get("ajax.php", {}, function(res) {
ok(res, "Get Response recieved");
equal(res, 'get', "Appropriate request type");
start();
}, function(res) {
ok(false, "Response failed");
});
});
asyncTest("Post", function() {
$_.post("ajax.php", {}, function(res) {
ok(res, "Post Response recieved");
equal(res, 'post', "Appropriate request type");
start();
}, function(res) {
ok(false, "Post Response failed");
});
});
asyncTest("Post with data", function() {
$_.post("ajax.php?data", {foo:'data', bar:function(){}}, function(res) {
ok(res, "Data post Response received");
equal(res, '{"foo":"data"}', "JSON received");
start();
});
});
asyncTest("Bad request", function() {
$_.get("ajax.php?bad", {}, undefined, function(res) {
ok(res, "Bad response");
equal(res, 401, "Passed value is error code");
start();
});
});
}());

View File

@ -82,6 +82,6 @@
ok($_().event, "Event module");
ok($_.store, "Local Storage module");
ok($_().dom, "Dom manipulation module");
ok($_.util, "Utilities module");
ok($_.get, "Ajaz module");
});
}());

View File

@ -53,7 +53,7 @@
});
test("Attr", function(){
expect(2);
expect(3);
var $test = $_("section");
var ele = $test.el;
@ -63,6 +63,8 @@
equal($test.dom.attr('id'), "testing", "Getting attribute");
equal(ele.id, "testing", "Setting attribute");
equal($_("div").dom.attr('id'), null, "Trying to get an attribute for multiple elements");
});
test("CSS", function(){

View File

@ -1,18 +1,75 @@
(function(){
"use strict";
module("events");
module("events", {
setup: function() {
this.foo = $_.event.create('foo');
ok(this.foo, "Event foo created");
this.bar = $_.event.create('bar');
ok(this.bar, "Event bar created");
},
teardown: function() {
}
});
test("Events defined", function(){
expect(4);
expect(8);
ok($_.event.create, "Create Method Exists");
ok($_.event.add, "Add Method Exists");
ok($_.event.remove, "Remove Method Exists");
ok($_.event.live, "Live Method Exists");
ok($_.event.delegate, "Delegate Method Exists");
ok($_.event.trigger, "Trigger Method Exists");
});
test("Adding Events", function() {
expect(0);
asyncTest("Adding/Triggering Event Listener", function() {
expect(5);
var callback = function(e) {
ok(e, "Event was added");
ok(e, "Event was triggered");
start();
};
$_("#qunit").event.add('foo', callback);
var x = $_("#qunit").event.trigger(this.foo);
ok(x, "Event was not canceled");
});
asyncTest("Delegated Event", function() {
var callback = function(e) {
ok(e, "Delegated event was triggered");
start();
}
$_.event.delegate('.nephew', 'foo', callback);
var x = $_.event.trigger(this.foo);
ok(x, "Event was not canceled");
});
asyncTest("Live Event", function() {
var callback = function(e) {
ok(e, "Live event was triggered");
start();
}
$_.event.live('.child', 'foo', callback);
$_.event.trigger(this.foo);
});
asyncTest("Multiple Events", function() {
var callback = function(e) {
ok(e, "An event was triggered");
start();
}
$_("#qunit").event.add('foo bar', callback);
$_.event.trigger(this.bar);
});
}());

View File

@ -1,150 +0,0 @@
(function(){
"use strict";
module("util");
test("Object keys", function(){
expect(1);
var test_o = {
"x": 2,
"a": 4,
"q": 3,
"r": 6
};
var test_keys = ["x", "a", "q", "r"];
deepEqual($_.util.object_keys(test_o), test_keys, "Retrieves object keys correctly");
});
test("Object values", function(){
expect(1);
var test_o = {
"x": 2,
"a": 4,
"q": 3,
"r": 6,
"p": "q"
};
var test_values = [2,4,3,6,"q"];
deepEqual($_.util.object_values(test_o), test_values, "Retrieves object values correctly");
});
test("Array combine", function(){
expect(3);
var keys_5 = ["a", "u", "i", "e", "o"];
var keys_obj = {
"x": 2,
"a": 4,
"q": 3,
"r": 1,
"p": "q"
};
var vals_5 = [1, 5, 3, 2, 4];
var vals_4 = [3, 6, 2, 7];
var obj_combined = {
2:1,
4:5,
3:3,
1:2,
"q":4
};
var combined = {
"a":1,
"u":5,
"i":3,
"e":2,
"o":4
};
equal($_.util.array_combine(keys_5, vals_4), false, "Can't combine arrays of different sizes");
deepEqual($_.util.array_combine(keys_obj, vals_5), obj_combined, "Combine with keys as object");
deepEqual($_.util.array_combine(keys_5, vals_5), combined, "Properly combines arrays");
});
/*test("Reverse Key Sort", function(){
expect(2);
var test_o = {
"x": 2,
"a": 4,
"q": 3,
"r": 6
};
var test_sorted = {
"x": 2,
"r": 6,
"q": 3,
"a": 4
};
var test_array = [7, 2, 6, 3];
var test_array_sorted = [3, 6, 2, 7];
deepEqual($_.util.reverse_key_sort(test_o), test_sorted, "Object sort");
deepEqual($_.util.object_values($_.util.reverse_key_sort(test_array)), test_array_sorted, "Array Sort");
});*/
test("Object Merge", function(){
expect(2);
var arr1 = {
"color": "red",
0: 2,
1: 4
},
arr2 = {
0: "a",
1: "b",
"color": "green",
"shape": "trapezoid",
2: 4
},
res1 = {
"color": "green",
0: 2,
1: 4,
2: "a",
3: "b",
"shape": "trapezoid",
4: 4
},
arr3 = [],
arr4 = {
1:'value',
},
res2 = {0:'value'};
deepEqual($_.util.object_merge(arr1, arr2), res1, "Merge objects with numeric and test keys");
deepEqual($_.util.object_merge(arr3, arr4), res2, "Merged object has reordered keys");
});
test("String translate", function(){
var test_str = "chotto",
test_replace = {
cho: 'ちょ',
to: 'と'
},
test_res = "ちょtと",
$trans = {'hello' : 'hi', 'hi' : 'hello'};
equal($_.util.str_trans(test_str, test_replace), test_res, "Correctly replaces substrings from replace pairs");
equal($_.util.str_trans("hi all, I said hello", $trans), 'hello all, I said hi', "Correctly replaces substrings from scalar pair");
});
}());