Added append and prepend methods to dom module

This commit is contained in:
Timothy Warren 2011-11-22 15:23:50 -05:00
parent b6f16a4758
commit e635925a6d
15 changed files with 311 additions and 229 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

File diff suppressed because one or more lines are too long

View File

@ -310,29 +310,54 @@
<span class='line'>303</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>304</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>305</span> </span><span class="WHIT"> </span><span class="COMM">/**
<span class='line'>306</span> * Sets or gets the innerHTML propery of the element(s) passed
<span class='line'>306</span> * Adds to the innerHTML of the current element, after the last child.
<span class='line'>307</span> *
<span class='line'>308</span> * @name html
<span class='line'>309</span> * @memberOf $_.dom
<span class='line'>310</span> * @function
<span class='line'>311</span> * @param [string] htm
<span class='line'>312</span> * @return string
<span class='line'>313</span> * @type string
<span class='line'>314</span> */</span><span class="WHIT">
<span class='line'>315</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'>316</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>317</span> </span><span class="WHIT">
<span class='line'>318</span> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">htm</span><span class="WHIT"> </span><span class="PUNC">!==</span><span class="WHIT"> </span><span class="STRN">"undefined"</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>319</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>320</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'>321</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>322</span> </span><span class="WHIT">
<span class='line'>323</span> </span><span class="COMM">//If the parameter is undefined, just return the current value</span><span class="WHIT">
<span class='line'>324</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'>325</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>326</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>327</span>
<span class='line'>328</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'>329</span> </span><span class="WHIT">
<span class='line'>330</span> </span><span class="PUNC">}</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>331</span> </span></pre></body></html>
<span class='line'>308</span> * @example $_("ul").dom.append("&lt;li&gt;&lt;/li&gt;") adds an li element to the end of the selected ul element
<span class='line'>309</span> * @name append
<span class='line'>310</span> * @memberOf $_.dom
<span class='line'>311</span> * @function
<span class='line'>312</span> * @param string htm
<span class='line'>313</span> */</span><span class="WHIT">
<span class='line'>314</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'>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.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'>317</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>318</span> </span><span class="WHIT"> </span><span class="COMM">/**
<span class='line'>319</span> * Adds to the innerHTML of the selected element, before the current children
<span class='line'>320</span> *
<span class='line'>321</span> * @name prepend
<span class='line'>322</span> * @memberOf $_.dom
<span class='line'>323</span> * @function
<span class='line'>324</span> * @param string htm
<span class='line'>325</span> */</span><span class="WHIT">
<span class='line'>326</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'>327</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>328</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'>329</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>330</span> </span><span class="WHIT"> </span><span class="COMM">/**
<span class='line'>331</span> * Sets or gets the innerHTML propery of the element(s) passed
<span class='line'>332</span> *
<span class='line'>333</span> * @name html
<span class='line'>334</span> * @memberOf $_.dom
<span class='line'>335</span> * @function
<span class='line'>336</span> * @param [string] htm
<span class='line'>337</span> * @return string
<span class='line'>338</span> * @type string
<span class='line'>339</span> */</span><span class="WHIT">
<span class='line'>340</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'>341</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>342</span> </span><span class="WHIT">
<span class='line'>343</span> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">htm</span><span class="WHIT"> </span><span class="PUNC">!==</span><span class="WHIT"> </span><span class="STRN">"undefined"</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>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="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'>346</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>347</span> </span><span class="WHIT">
<span class='line'>348</span> </span><span class="COMM">//If the parameter is undefined, just return the current value</span><span class="WHIT">
<span class='line'>349</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'>350</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>351</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>352</span>
<span class='line'>353</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'>354</span> </span><span class="WHIT">
<span class='line'>355</span> </span><span class="PUNC">}</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>356</span> </span></pre></body></html>

View File

@ -76,165 +76,167 @@
<span class='line'> 69</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 70</span> </span><span class="WHIT"> </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">tmp</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">name</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 71</span> </span><span class="WHIT"> </span><span class="NAME">pairs</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 72</span> </span><span class="WHIT"> </span><span class="NAME">pseudos</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 73</span> </span><span class="NAME">num_pairs</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 74</span> </span><span class="WHIT"> </span><span class="NAME">num_pseudos</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 75</span> </span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 76</span> </span><span class="WHIT"> </span><span class="NAME">j</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 77</span> </span><span class="WHIT"> </span><span class="NAME">var_name</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">''</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 78</span> </span><span class="WHIT"> </span><span class="NAME">rep_data</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 79</span> </span><span class="WHIT"> </span><span class="NAME">tmp_data</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">''</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 80</span> </span><span class="WHIT"> </span><span class="NAME">data_len</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 81</span> </span><span class="WHIT"> </span><span class="NAME">frag</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 82</span> </span><span class="WHIT"> </span><span class="NAME">frag_section</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 83</span> </span><span class="WHIT"> </span><span class="NAME">emptys</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 84</span> </span><span class="WHIT"> </span><span class="NAME">x</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 85</span> </span><span class="WHIT">
<span class='line'> 86</span> </span><span class="NAME">tmp</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">String</span><span class="PUNC">(</span><span class="NAME">tmp</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 72</span> </span><span class="WHIT"> </span><span class="NAME">pair_reg</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="REGX">/\{([A-Z0-9_\-]+)\}(.*)\{\/\1\}/gim</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 73</span> </span><span class="WHIT"> </span><span class="NAME">var_reg</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="REGX">/\{([A-Z0-9_\-]+)\}/gim</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 74</span> </span><span class="WHIT"> </span><span class="NAME">pseudos</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 75</span> </span><span class="NAME">num_pairs</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 76</span> </span><span class="WHIT"> </span><span class="NAME">num_pseudos</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 77</span> </span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 78</span> </span><span class="WHIT"> </span><span class="NAME">j</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 79</span> </span><span class="WHIT"> </span><span class="NAME">var_name</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">''</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 80</span> </span><span class="WHIT"> </span><span class="NAME">rep_data</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 81</span> </span><span class="WHIT"> </span><span class="NAME">tmp_data</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">''</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 82</span> </span><span class="WHIT"> </span><span class="NAME">data_len</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 83</span> </span><span class="WHIT"> </span><span class="NAME">frag</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 84</span> </span><span class="WHIT"> </span><span class="NAME">frag_section</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 85</span> </span><span class="WHIT"> </span><span class="NAME">emptys</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 86</span> </span><span class="WHIT"> </span><span class="NAME">x</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 87</span> </span><span class="WHIT">
<span class='line'> 88</span> </span><span class="COMM">//Remove newlines and tabs from template because</span><span class="WHIT">
<span class='line'> 89</span> </span><span class="WHIT"> </span><span class="COMM">//those whitespace characters are extra bandwidth</span><span class="WHIT">
<span class='line'> 90</span> </span><span class="WHIT"> </span><span class="NAME">tmp</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">tmp.replace</span><span class="PUNC">(</span><span class="REGX">/\s+/gim</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">" "</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 91</span> </span><span class="WHIT"> </span><span class="NAME">tmp</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">tmp.replace</span><span class="PUNC">(</span><span class="REGX">/>\s+&lt;/gim</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">">&lt;"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 92</span> </span><span class="WHIT"> </span><span class="NAME">tmp</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">tmp.replace</span><span class="PUNC">(</span><span class="REGX">/>\s+\{/gim</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">">{"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 93</span> </span><span class="WHIT"> </span><span class="NAME">tmp</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">tmp.replace</span><span class="PUNC">(</span><span class="REGX">/\}\s+&lt;/gim</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"}&lt;"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 94</span> </span><span class="WHIT">
<span class='line'> 95</span> </span><span class="COMM">//Match all the looped sections of content</span><span class="WHIT">
<span class='line'> 96</span> </span><span class="WHIT"> </span><span class="NAME">pairs</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">tmp.match</span><span class="PUNC">(</span><span class="REGX">/\{([A-Z0-9_\-]+)\}(.*)\{\/\1\}/gim</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 97</span> </span><span class="WHIT">
<span class='line'> 98</span> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">pairs</span><span class="WHIT"> </span><span class="PUNC">!=</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 99</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>100</span> </span><span class="WHIT"> </span><span class="NAME">num_pairs</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">pairs.length</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>101</span> </span><span class="WHIT">
<span class='line'>102</span> </span><span class="COMM">//Go through the template, and match the pairs</span><span class="WHIT">
<span class='line'>103</span> </span><span class="WHIT"> </span><span class="KEYW">for</span><span class="PUNC">(</span><span class="NAME">i</span><span class="PUNC">=</span><span class="NUMB">0</span><span class="PUNC">;</span><span class="NAME">i</span><span class="PUNC">&lt;</span><span class="NAME">num_pairs</span><span class="PUNC">;</span><span class="NAME">i</span><span class="PUNC">++</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>104</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>105</span> </span><span class="WHIT"> </span><span class="COMM">//Put the loop in a placeholder</span><span class="WHIT">
<span class='line'>106</span> </span><span class="WHIT"> </span><span class="NAME">tmp</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">tmp.replace</span><span class="PUNC">(</span><span class="NAME">pairs</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"{"</span><span class="PUNC">+</span><span class="NAME">i</span><span class="PUNC">+</span><span class="STRN">"}"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>107</span> </span><span class="WHIT">
<span class='line'>108</span> </span><span class="COMM">//Create a place to store looped data</span><span class="WHIT">
<span class='line'>109</span> </span><span class="WHIT"> </span><span class="NAME">tmp_data</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">""</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>110</span> </span><span class="WHIT">
<span class='line'>111</span> </span><span class="COMM">//The replace variable is the name of the tag</span><span class="WHIT">
<span class='line'>112</span> </span><span class="WHIT"> </span><span class="NAME">var_name</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">String</span><span class="PUNC">(</span><span class="NAME">pairs</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">match</span><span class="PUNC">(</span><span class="REGX">/^\{([A-Z0-9_\-]+)\}/i</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>113</span> </span><span class="WHIT"> </span><span class="NAME">rep_data</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">data</span><span class="PUNC">[</span><span class="NAME">var_name</span><span class="PUNC">[</span><span class="NUMB">1</span><span class="PUNC">]</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>114</span> </span><span class="WHIT">
<span class='line'>115</span> </span><span class="COMM">//Make sure there are loops</span><span class="WHIT">
<span class='line'>116</span> </span><span class="WHIT"> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">rep_data.length</span><span class="WHIT"> </span><span class="PUNC">></span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>117</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>118</span> </span><span class="WHIT"> </span><span class="NAME">data_len</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">rep_data.length</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>119</span> </span><span class="WHIT">
<span class='line'>120</span> </span><span class="COMM">//Get rid of the loop tags</span><span class="WHIT">
<span class='line'>121</span> </span><span class="WHIT"> </span><span class="NAME">pairs</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">pairs</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">.</span><span class="NAME">replace</span><span class="PUNC">(</span><span class="REGX">/\{([A-Z0-9_\-]+)\}(.*)\{\/\1\}/gim</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"$2"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>122</span> </span><span class="WHIT">
<span class='line'>123</span> </span><span class="COMM">//Replace psudovariables with data</span><span class="WHIT">
<span class='line'>124</span> </span><span class="WHIT"> </span><span class="KEYW">for</span><span class="PUNC">(</span><span class="NAME">j</span><span class="PUNC">=</span><span class="NUMB">0</span><span class="PUNC">;</span><span class="NAME">j</span><span class="PUNC">&lt;</span><span class="NAME">data_len</span><span class="PUNC">;</span><span class="NAME">j</span><span class="PUNC">++</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="COMM">//Is there a better way to do this, rather than an inline function?</span><span class="WHIT">
<span class='line'>127</span> </span><span class="WHIT"> </span><span class="NAME">tmp_data</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">pairs</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">.</span><span class="NAME">replace</span><span class="PUNC">(</span><span class="REGX">/\{([A-Z0-9 _\-]+)\}/gi</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">_</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">varName</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>128</span> </span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">rep_data</span><span class="PUNC">[</span><span class="NAME">j</span><span class="PUNC">]</span><span class="PUNC">[</span><span class="NAME">varName</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="NAME">rep_data</span><span class="PUNC">[</span><span class="NAME">j</span><span class="PUNC">]</span><span class="PUNC">[</span><span class="NAME">varName</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">""</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>129</span> </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>130</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>131</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>132</span> </span><span class="WHIT">
<span class='line'>133</span> </span><span class="COMM">//Replace the looped content</span><span class="WHIT">
<span class='line'>134</span> </span><span class="WHIT"> </span><span class="NAME">tmp</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">tmp.replace</span><span class="PUNC">(</span><span class="STRN">"{"</span><span class="PUNC">+</span><span class="NAME">i</span><span class="PUNC">+</span><span class="STRN">"}"</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">tmp_data</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="WHIT">
<span class='line'>136</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>137</span> </span><span class="WHIT">
<span class='line'>138</span> </span><span class="COMM">//Replace all the rest of the psudeovariables</span><span class="WHIT">
<span class='line'>139</span> </span><span class="WHIT"> </span><span class="NAME">pseudos</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">tmp.match</span><span class="PUNC">(</span><span class="REGX">/\{([A-Z0-9_\-]+)\}/gim</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>140</span> </span><span class="WHIT">
<span class='line'>141</span> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">pseudos</span><span class="WHIT"> </span><span class="PUNC">!=</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>142</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>143</span> </span><span class="WHIT"> </span><span class="NAME">num_pseudos</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">pseudos.length</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>144</span> </span><span class="WHIT">
<span class='line'>145</span> </span><span class="KEYW">for</span><span class="PUNC">(</span><span class="NAME">i</span><span class="PUNC">=</span><span class="NUMB">0</span><span class="PUNC">;</span><span class="NAME">i</span><span class="PUNC">&lt;</span><span class="NAME">num_pseudos</span><span class="PUNC">;</span><span class="NAME">i</span><span class="PUNC">++</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>146</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>147</span> </span><span class="WHIT"> </span><span class="COMM">//Remove the {} from the pseudos</span><span class="WHIT">
<span class='line'>148</span> </span><span class="WHIT"> </span><span class="NAME">var_name</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">pseudos</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">.</span><span class="NAME">replace</span><span class="PUNC">(</span><span class="STRN">'{'</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">''</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>149</span> </span><span class="WHIT"> </span><span class="NAME">var_name</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">var_name.replace</span><span class="PUNC">(</span><span class="STRN">'}'</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">''</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>150</span> </span><span class="WHIT">
<span class='line'>151</span> </span><span class="COMM">//Replace each pseudovariable with the value of the object</span><span class="WHIT">
<span class='line'>152</span> </span><span class="WHIT"> </span><span class="COMM">//property of the same name</span><span class="WHIT">
<span class='line'>153</span> </span><span class="WHIT"> </span><span class="NAME">tmp</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">tmp.replace</span><span class="PUNC">(</span><span class="NAME">pseudos</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">data</span><span class="PUNC">[</span><span class="NAME">var_name</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>154</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>155</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>156</span> </span><span class="WHIT">
<span class='line'>157</span> </span><span class="COMM">//Create an empty fragement</span><span class="WHIT">
<span class='line'>158</span> </span><span class="WHIT"> </span><span class="NAME">frag</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">document.createDocumentFragment</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>159</span> </span><span class="WHIT">
<span class='line'>160</span> </span><span class="COMM">//Insert the html</span><span class="WHIT">
<span class='line'>161</span> </span><span class="WHIT"> </span><span class="NAME">frag.appendChild</span><span class="PUNC">(</span><span class="NAME">document.createElement</span><span class="PUNC">(</span><span class="STRN">'section'</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>162</span> </span><span class="WHIT"> </span><span class="NAME">frag_section</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">frag.querySelectorAll</span><span class="PUNC">(</span><span class="STRN">'section'</span><span class="PUNC">)</span><span class="PUNC">[</span><span class="NUMB">0</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>163</span> </span><span class="WHIT"> </span><span class="NAME">frag_section.innerHTML</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">tmp</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>164</span> </span><span class="WHIT">
<span class='line'>165</span> </span><span class="COMM">//Remove bad elements in the fragment, should be faster than being done live</span><span class="WHIT">
<span class='line'>166</span> </span><span class="WHIT"> </span><span class="NAME">emptys</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">frag_section.querySelectorAll</span><span class="PUNC">(</span><span class="STRN">'[src=""], [href=""]'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>167</span> </span><span class="WHIT">
<span class='line'>168</span> </span><span class="KEYW">for</span><span class="PUNC">(</span><span class="NAME">x</span><span class="WHIT"> </span><span class="KEYW">in</span><span class="WHIT"> </span><span class="NAME">emptys</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>169</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>170</span> </span><span class="WHIT"> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">emptys</span><span class="PUNC">[</span><span class="NAME">x</span><span class="PUNC">]</span><span class="PUNC">.</span><span class="NAME">parentNode</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>171</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>172</span> </span><span class="WHIT"> </span><span class="NAME">emptys</span><span class="PUNC">[</span><span class="NAME">x</span><span class="PUNC">]</span><span class="PUNC">.</span><span class="NAME">parentNode.removeChild</span><span class="PUNC">(</span><span class="NAME">emptys</span><span class="PUNC">[</span><span class="NAME">x</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>173</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>174</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>175</span> </span><span class="WHIT">
<span class='line'>176</span> </span><span class="COMM">//Save the parsed template in an object for later retrieval</span><span class="WHIT">
<span class='line'>177</span> </span><span class="WHIT"> </span><span class="NAME">_p</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">tmp</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>178</span> </span><span class="WHIT">
<span class='line'>179</span> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">tmp</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>180</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>181</span> </span><span class="WHIT"> </span><span class="COMM">/**
<span class='line'>182</span> * Inserts the formatted template into the page. If the url and data parameters
<span class='line'>183</span> * are passed, it will retrieve a template file from the same domain, parse,
<span class='line'>184</span> * and insert the template into the page.
<span class='line'>185</span> *
<span class='line'>186</span> * @memberOf $_.template
<span class='line'>187</span> * @name apply
<span class='line'>188</span> * @function
<span class='line'>189</span> * @param string parsed_template/template_name
<span class='line'>190</span> * @param [string] url
<span class='line'>191</span> * @param [object] data
<span class='line'>192</span> */</span><span class="WHIT">
<span class='line'>193</span> </span><span class="WHIT"> </span><span class="NAME">apply</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">url</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">data</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>194</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>195</span> </span><span class="WHIT"> </span><span class="COMM">//If the parsed template is supplied, just apply it to the passed selector</span><span class="WHIT">
<span class='line'>196</span> </span><span class="WHIT"> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">url</span><span class="WHIT"> </span><span class="PUNC">===</span><span class="WHIT"> </span><span class="STRN">"undefined"</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="WHIT"> </span><span class="PUNC">===</span><span class="WHIT"> </span><span class="STRN">"undefined"</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>197</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>198</span> </span><span class="WHIT"> </span><span class="COMM">//If the "name" variable is in the _p object, set that</span><span class="WHIT">
<span class='line'>199</span> </span><span class="WHIT"> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">_p</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">"undefined"</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>200</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>201</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">_p</span><span class="PUNC">[</span><span class="NAME">name</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>202</span> </span><span class="WHIT"> </span><span class="KEYW">return</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>203</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>204</span> </span><span class="WHIT">
<span class='line'>205</span> </span><span class="COMM">//Otherwise, set the passed string to the current selector</span><span class="WHIT">
<span class='line'>206</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">name</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>207</span> </span><span class="WHIT"> </span><span class="KEYW">return</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>208</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>209</span> </span><span class="WHIT">
<span class='line'>210</span> </span><span class="COMM">//Otherwise, get the template, parse it, and apply it</span><span class="WHIT">
<span class='line'>211</span> </span><span class="WHIT"> </span><span class="NAME">$_.get</span><span class="PUNC">(</span><span class="NAME">url</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">res</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>212</span> </span><span class="WHIT"> </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">parsed</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>213</span> </span><span class="WHIT">
<span class='line'>214</span> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">res</span><span class="WHIT"> </span><span class="PUNC">===</span><span class="WHIT"> </span><span class="STRN">""</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>215</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>216</span> </span><span class="WHIT"> </span><span class="NAME">console.log</span><span class="PUNC">(</span><span class="STRN">"Template is empty or can not be found"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>217</span> </span><span class="WHIT"> </span><span class="KEYW">return</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>218</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>219</span> </span><span class="WHIT">
<span class='line'>220</span> </span><span class="COMM">//Cache the template in an object for later use</span><span class="WHIT">
<span class='line'>221</span> </span><span class="WHIT"> </span><span class="NAME">_t</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">res</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>222</span> </span><span class="WHIT"> </span><span class="NAME">parsed</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">this.parse</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'>223</span> </span><span class="WHIT"> </span><span class="NAME">_p</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">parsed</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>224</span> </span><span class="WHIT">
<span class='line'>225</span> </span><span class="NAME">this.el.innerHTML</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">parsed</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>226</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>227</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>228</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>229</span> </span><span class="WHIT">
<span class='line'>230</span> </span><span class="COMM">//Add the module to the library</span><span class="WHIT">
<span class='line'>231</span> </span><span class="WHIT"> </span><span class="NAME">$_.ext</span><span class="PUNC">(</span><span class="STRN">'template'</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">t</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>232</span> </span><span class="WHIT">
<span class='line'>233</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'> 88</span> </span><span class="NAME">tmp</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">String</span><span class="PUNC">(</span><span class="NAME">tmp</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 89</span> </span><span class="WHIT">
<span class='line'> 90</span> </span><span class="COMM">//Remove newlines and tabs from template because</span><span class="WHIT">
<span class='line'> 91</span> </span><span class="WHIT"> </span><span class="COMM">//those whitespace characters are extra bandwidth</span><span class="WHIT">
<span class='line'> 92</span> </span><span class="WHIT"> </span><span class="NAME">tmp</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">tmp.replace</span><span class="PUNC">(</span><span class="REGX">/\s+/gim</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">" "</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 93</span> </span><span class="WHIT"> </span><span class="NAME">tmp</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">tmp.replace</span><span class="PUNC">(</span><span class="REGX">/>\s+&lt;/gim</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">">&lt;"</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">tmp</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">tmp.replace</span><span class="PUNC">(</span><span class="REGX">/>\s+\{/gim</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">">{"</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">tmp</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">tmp.replace</span><span class="PUNC">(</span><span class="REGX">/\}\s+&lt;/gim</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"}&lt;"</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="COMM">//Match all the looped sections of content</span><span class="WHIT">
<span class='line'> 98</span> </span><span class="WHIT"> </span><span class="NAME">pairs</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">tmp.match</span><span class="PUNC">(</span><span class="NAME">pair_reg</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 99</span> </span><span class="WHIT">
<span class='line'>100</span> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">pairs</span><span class="WHIT"> </span><span class="PUNC">!=</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>101</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>102</span> </span><span class="WHIT"> </span><span class="NAME">num_pairs</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">pairs.length</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>103</span> </span><span class="WHIT">
<span class='line'>104</span> </span><span class="COMM">//Go through the template, and match the pairs</span><span class="WHIT">
<span class='line'>105</span> </span><span class="WHIT"> </span><span class="KEYW">for</span><span class="PUNC">(</span><span class="NAME">i</span><span class="PUNC">=</span><span class="NUMB">0</span><span class="PUNC">;</span><span class="NAME">i</span><span class="PUNC">&lt;</span><span class="NAME">num_pairs</span><span class="PUNC">;</span><span class="NAME">i</span><span class="PUNC">++</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>106</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>107</span> </span><span class="WHIT"> </span><span class="COMM">//Put the loop in a placeholder</span><span class="WHIT">
<span class='line'>108</span> </span><span class="WHIT"> </span><span class="NAME">tmp</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">tmp.replace</span><span class="PUNC">(</span><span class="NAME">pairs</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"{"</span><span class="PUNC">+</span><span class="NAME">i</span><span class="PUNC">+</span><span class="STRN">"}"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>109</span> </span><span class="WHIT">
<span class='line'>110</span> </span><span class="COMM">//Create a place to store looped data</span><span class="WHIT">
<span class='line'>111</span> </span><span class="WHIT"> </span><span class="NAME">tmp_data</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">""</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>112</span> </span><span class="WHIT">
<span class='line'>113</span> </span><span class="COMM">//The replace variable is the name of the tag</span><span class="WHIT">
<span class='line'>114</span> </span><span class="WHIT"> </span><span class="NAME">var_name</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">String</span><span class="PUNC">(</span><span class="NAME">pairs</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">match</span><span class="PUNC">(</span><span class="REGX">/^\{([A-Z0-9_\-]+)\}/i</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>115</span> </span><span class="WHIT"> </span><span class="NAME">rep_data</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">data</span><span class="PUNC">[</span><span class="NAME">var_name</span><span class="PUNC">[</span><span class="NUMB">1</span><span class="PUNC">]</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>116</span> </span><span class="WHIT">
<span class='line'>117</span> </span><span class="COMM">//Make sure there are loops</span><span class="WHIT">
<span class='line'>118</span> </span><span class="WHIT"> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">rep_data.length</span><span class="WHIT"> </span><span class="PUNC">></span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>119</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>120</span> </span><span class="WHIT"> </span><span class="NAME">data_len</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">rep_data.length</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>121</span> </span><span class="WHIT">
<span class='line'>122</span> </span><span class="COMM">//Get rid of the loop tags</span><span class="WHIT">
<span class='line'>123</span> </span><span class="WHIT"> </span><span class="NAME">pairs</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">pairs</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">.</span><span class="NAME">replace</span><span class="PUNC">(</span><span class="NAME">pair_reg</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"$2"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>124</span> </span><span class="WHIT">
<span class='line'>125</span> </span><span class="COMM">//Replace psudovariables with data</span><span class="WHIT">
<span class='line'>126</span> </span><span class="WHIT"> </span><span class="KEYW">for</span><span class="PUNC">(</span><span class="NAME">j</span><span class="PUNC">=</span><span class="NUMB">0</span><span class="PUNC">;</span><span class="NAME">j</span><span class="PUNC">&lt;</span><span class="NAME">data_len</span><span class="PUNC">;</span><span class="NAME">j</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="WHIT">
<span class='line'>128</span> </span><span class="WHIT"> </span><span class="COMM">//Is there a better way to do this, rather than an inline function?</span><span class="WHIT">
<span class='line'>129</span> </span><span class="WHIT"> </span><span class="NAME">tmp_data</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">pairs</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">.</span><span class="NAME">replace</span><span class="PUNC">(</span><span class="NAME">var_reg</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">_</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">varName</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>130</span> </span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">rep_data</span><span class="PUNC">[</span><span class="NAME">j</span><span class="PUNC">]</span><span class="PUNC">[</span><span class="NAME">varName</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="NAME">rep_data</span><span class="PUNC">[</span><span class="NAME">j</span><span class="PUNC">]</span><span class="PUNC">[</span><span class="NAME">varName</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">""</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>131</span> </span><span class="PUNC">}</span><span class="PUNC">)</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="PUNC">}</span><span class="WHIT">
<span class='line'>134</span> </span><span class="WHIT">
<span class='line'>135</span> </span><span class="COMM">//Replace the looped content</span><span class="WHIT">
<span class='line'>136</span> </span><span class="WHIT"> </span><span class="NAME">tmp</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">tmp.replace</span><span class="PUNC">(</span><span class="STRN">"{"</span><span class="PUNC">+</span><span class="NAME">i</span><span class="PUNC">+</span><span class="STRN">"}"</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">tmp_data</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>137</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>138</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>139</span> </span><span class="WHIT">
<span class='line'>140</span> </span><span class="COMM">//Replace all the rest of the psudeovariables</span><span class="WHIT">
<span class='line'>141</span> </span><span class="WHIT"> </span><span class="NAME">pseudos</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">tmp.match</span><span class="PUNC">(</span><span class="NAME">var_reg</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>142</span> </span><span class="WHIT">
<span class='line'>143</span> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">pseudos</span><span class="WHIT"> </span><span class="PUNC">!=</span><span class="WHIT"> </span><span class="KEYW">null</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="NAME">num_pseudos</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">pseudos.length</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>146</span> </span><span class="WHIT">
<span class='line'>147</span> </span><span class="KEYW">for</span><span class="PUNC">(</span><span class="NAME">i</span><span class="PUNC">=</span><span class="NUMB">0</span><span class="PUNC">;</span><span class="NAME">i</span><span class="PUNC">&lt;</span><span class="NAME">num_pseudos</span><span class="PUNC">;</span><span class="NAME">i</span><span class="PUNC">++</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>148</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>149</span> </span><span class="WHIT"> </span><span class="COMM">//Remove the {} from the pseudos</span><span class="WHIT">
<span class='line'>150</span> </span><span class="WHIT"> </span><span class="NAME">var_name</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">pseudos</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">.</span><span class="NAME">replace</span><span class="PUNC">(</span><span class="STRN">'{'</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">''</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>151</span> </span><span class="WHIT"> </span><span class="NAME">var_name</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">var_name.replace</span><span class="PUNC">(</span><span class="STRN">'}'</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">''</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>152</span> </span><span class="WHIT">
<span class='line'>153</span> </span><span class="COMM">//Replace each pseudovariable with the value of the object</span><span class="WHIT">
<span class='line'>154</span> </span><span class="WHIT"> </span><span class="COMM">//property of the same name</span><span class="WHIT">
<span class='line'>155</span> </span><span class="WHIT"> </span><span class="NAME">tmp</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">tmp.replace</span><span class="PUNC">(</span><span class="NAME">pseudos</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">data</span><span class="PUNC">[</span><span class="NAME">var_name</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>156</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>157</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>158</span> </span><span class="WHIT">
<span class='line'>159</span> </span><span class="COMM">//Create an empty fragement</span><span class="WHIT">
<span class='line'>160</span> </span><span class="WHIT"> </span><span class="NAME">frag</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">document.createDocumentFragment</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>161</span> </span><span class="WHIT">
<span class='line'>162</span> </span><span class="COMM">//Insert the html</span><span class="WHIT">
<span class='line'>163</span> </span><span class="WHIT"> </span><span class="NAME">frag.appendChild</span><span class="PUNC">(</span><span class="NAME">document.createElement</span><span class="PUNC">(</span><span class="STRN">'section'</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>164</span> </span><span class="WHIT"> </span><span class="NAME">frag_section</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">frag.querySelectorAll</span><span class="PUNC">(</span><span class="STRN">'section'</span><span class="PUNC">)</span><span class="PUNC">[</span><span class="NUMB">0</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>165</span> </span><span class="WHIT"> </span><span class="NAME">frag_section.innerHTML</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">tmp</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>166</span> </span><span class="WHIT">
<span class='line'>167</span> </span><span class="COMM">//Remove bad elements in the fragment, should be faster than being done live</span><span class="WHIT">
<span class='line'>168</span> </span><span class="WHIT"> </span><span class="NAME">emptys</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">frag_section.querySelectorAll</span><span class="PUNC">(</span><span class="STRN">'[src=""], [href=""]'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>169</span> </span><span class="WHIT">
<span class='line'>170</span> </span><span class="KEYW">for</span><span class="PUNC">(</span><span class="NAME">x</span><span class="WHIT"> </span><span class="KEYW">in</span><span class="WHIT"> </span><span class="NAME">emptys</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>171</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>172</span> </span><span class="WHIT"> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">emptys</span><span class="PUNC">[</span><span class="NAME">x</span><span class="PUNC">]</span><span class="PUNC">.</span><span class="NAME">parentNode</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>173</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>174</span> </span><span class="WHIT"> </span><span class="NAME">emptys</span><span class="PUNC">[</span><span class="NAME">x</span><span class="PUNC">]</span><span class="PUNC">.</span><span class="NAME">parentNode.removeChild</span><span class="PUNC">(</span><span class="NAME">emptys</span><span class="PUNC">[</span><span class="NAME">x</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>175</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>176</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>177</span> </span><span class="WHIT">
<span class='line'>178</span> </span><span class="COMM">//Save the parsed template in an object for later retrieval</span><span class="WHIT">
<span class='line'>179</span> </span><span class="WHIT"> </span><span class="NAME">_p</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">tmp</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>180</span> </span><span class="WHIT">
<span class='line'>181</span> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">tmp</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>182</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>183</span> </span><span class="WHIT"> </span><span class="COMM">/**
<span class='line'>184</span> * Inserts the formatted template into the page. If the url and data parameters
<span class='line'>185</span> * are passed, it will retrieve a template file from the same domain, parse,
<span class='line'>186</span> * and insert the template into the page.
<span class='line'>187</span> *
<span class='line'>188</span> * @memberOf $_.template
<span class='line'>189</span> * @name apply
<span class='line'>190</span> * @function
<span class='line'>191</span> * @param string parsed_template/template_name
<span class='line'>192</span> * @param [string] url
<span class='line'>193</span> * @param [object] data
<span class='line'>194</span> */</span><span class="WHIT">
<span class='line'>195</span> </span><span class="WHIT"> </span><span class="NAME">apply</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">url</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">data</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>196</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>197</span> </span><span class="WHIT"> </span><span class="COMM">//If the parsed template is supplied, just apply it to the passed selector</span><span class="WHIT">
<span class='line'>198</span> </span><span class="WHIT"> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">url</span><span class="WHIT"> </span><span class="PUNC">===</span><span class="WHIT"> </span><span class="STRN">"undefined"</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="WHIT"> </span><span class="PUNC">===</span><span class="WHIT"> </span><span class="STRN">"undefined"</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>199</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>200</span> </span><span class="WHIT"> </span><span class="COMM">//If the "name" variable is in the _p object, set that</span><span class="WHIT">
<span class='line'>201</span> </span><span class="WHIT"> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">_p</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">"undefined"</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>202</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>203</span> </span><span class="WHIT"> </span><span class="NAME">this.el.innerHTML</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">_p</span><span class="PUNC">[</span><span class="NAME">name</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>204</span> </span><span class="WHIT"> </span><span class="KEYW">return</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>205</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>206</span> </span><span class="WHIT">
<span class='line'>207</span> </span><span class="COMM">//Otherwise, set the passed string to the current selector</span><span class="WHIT">
<span class='line'>208</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">name</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>209</span> </span><span class="WHIT"> </span><span class="KEYW">return</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>210</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>211</span> </span><span class="WHIT">
<span class='line'>212</span> </span><span class="COMM">//Otherwise, get the template, parse it, and apply it</span><span class="WHIT">
<span class='line'>213</span> </span><span class="WHIT"> </span><span class="NAME">$_.get</span><span class="PUNC">(</span><span class="NAME">url</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">res</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>214</span> </span><span class="WHIT"> </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">parsed</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>215</span> </span><span class="WHIT">
<span class='line'>216</span> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">res</span><span class="WHIT"> </span><span class="PUNC">===</span><span class="WHIT"> </span><span class="STRN">""</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>217</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>218</span> </span><span class="WHIT"> </span><span class="NAME">console.log</span><span class="PUNC">(</span><span class="STRN">"Template is empty or can not be found"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>219</span> </span><span class="WHIT"> </span><span class="KEYW">return</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>220</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>221</span> </span><span class="WHIT">
<span class='line'>222</span> </span><span class="COMM">//Cache the template in an object for later use</span><span class="WHIT">
<span class='line'>223</span> </span><span class="WHIT"> </span><span class="NAME">_t</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">res</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>224</span> </span><span class="WHIT"> </span><span class="NAME">parsed</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">this.parse</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'>225</span> </span><span class="WHIT"> </span><span class="NAME">_p</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">parsed</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>226</span> </span><span class="WHIT">
<span class='line'>227</span> </span><span class="NAME">this.el.innerHTML</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">parsed</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>228</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>229</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>230</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>231</span> </span><span class="WHIT">
<span class='line'>232</span> </span><span class="COMM">//Add the module to the library</span><span class="WHIT">
<span class='line'>233</span> </span><span class="WHIT"> </span><span class="NAME">$_.ext</span><span class="PUNC">(</span><span class="STRN">'template'</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">t</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>234</span> </span><span class="WHIT">
<span class='line'>235</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

@ -738,6 +738,31 @@
_css(e, prop, val);
});
},
/**
* Adds to the innerHTML of the current element, after the last child.
*
* @example $_("ul").dom.append("&lt;li&gt;&lt;/li&gt;") adds an li element to the end of the selected ul element
* @name append
* @memberOf $_.dom
* @function
* @param string htm
*/
append: function(htm)
{
this.el.insertAdjacentHTML('beforeend', htm);
},
/**
* Adds to the innerHTML of the selected element, before the current children
*
* @name prepend
* @memberOf $_.dom
* @function
* @param string htm
*/
prepend: function(htm)
{
this.el.insertAdjacentHTML('afterbegin', htm);
},
/**
* Sets or gets the innerHTML propery of the element(s) passed
*
@ -1702,6 +1727,8 @@
{
var tmp = _t[name],
pairs = [],
pair_reg = /\{([A-Z0-9_\-]+)\}(.*)\{\/\1\}/gim,
var_reg = /\{([A-Z0-9_\-]+)\}/gim,
pseudos = [],
num_pairs = 0,
num_pseudos = 0,
@ -1726,7 +1753,7 @@
tmp = tmp.replace(/\}\s+</gim, "}<");
//Match all the looped sections of content
pairs = tmp.match(/\{([A-Z0-9_\-]+)\}(.*)\{\/\1\}/gim);
pairs = tmp.match(pair_reg);
if(pairs != null)
{
@ -1751,13 +1778,13 @@
data_len = rep_data.length;
//Get rid of the loop tags
pairs[i] = pairs[i].replace(/\{([A-Z0-9_\-]+)\}(.*)\{\/\1\}/gim, "$2");
pairs[i] = pairs[i].replace(pair_reg, "$2");
//Replace psudovariables with data
for(j=0;j<data_len;j++)
{
//Is there a better way to do this, rather than an inline function?
tmp_data += pairs[i].replace(/\{([A-Z0-9 _\-]+)\}/gi, function(_, varName){
tmp_data += pairs[i].replace(var_reg, function(_, varName){
return (rep_data[j][varName]) ? rep_data[j][varName] : "";
});
}
@ -1769,7 +1796,7 @@
}
//Replace all the rest of the psudeovariables
pseudos = tmp.match(/\{([A-Z0-9_\-]+)\}/gim);
pseudos = tmp.match(var_reg);
if(pseudos != null)
{

49
kis-min.js vendored
View File

@ -1,24 +1,25 @@
(function(){if(typeof document.querySelector!=="undefined"){var g,h,d,c;g=function(a){c=typeof a==="undefined"?typeof g.el!=="undefined"?g.el:document.documentElement:typeof a!=="object"?h(a):a;g.prototype.el=c;var a=d(g),b;for(b in a)if(typeof a[b]==="object")a[b].el=c;a.el=c;return a};h=function(a,b){var c;if(typeof a!="string"||typeof a==="undefined")return a;c=b!=null&&b.nodeType===1?b:document;if(a.match(/^#([\w\-]+$)/))return document.getElementById(a.split("#")[1]);else c=c.querySelectorAll(a);
return c.length===1?c[0]:c};d=function(a){var b;if(typeof a!=="undefined"){if(typeof Object.create!=="undefined")return Object.create(a);b=typeof a;if(!(b!=="object"&&b!=="function"))return b=function(){},b.prototype=a,new b}};g.ext=function(a,b){b.el=c;g[a]=b};g.ext("each",function(a){if(typeof c.length!=="undefined"&&c!==window){var b=c.length;if(b!==0)for(var e,f=0;f<b;f++)e=c.item(f)?c.item(f):c[f],a.call(e,e)}else a.call(c,c)});g.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()};g=window.$_=window.$_||g;g.$=h}})();
(function(){if(typeof window.console==="undefined")window.console={log:function(){}};if(typeof String.prototype.trim==="undefined")String.prototype.trim=function(){return this.replace(/^[\s\uFEFF]+|[\s\uFEFF]+$/g,"")};typeof document!=="undefined"&&!("classList"in document.createElement("a"))&&function(g){var g=(g.HTMLElement||g.Element).prototype,h=Object,d=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,e){if(e==="")throw new a("SYNTAX_ERR","An invalid or illegal string was specified");if(/\s/.test(e))throw new a("INVALID_CHARACTER_ERR","String contains an invalid character");return c.call(b,e)},e=function(a){for(var b=d.call(a.className),b=b?b.split(/\s+/):[],c=0,e=b.length;c<e;c++)this.push(b[c]);this._updateClassName=function(){a.className=this.toString()}},f=e.prototype=[],
k=function(){return new e(this)};a.prototype=Error.prototype;f.item=function(a){return this[a]||null};f.contains=function(a){a+="";return b(this,a)!==-1};f.add=function(a){a+="";b(this,a)===-1&&(this.push(a),this._updateClassName())};f.remove=function(a){a+="";a=b(this,a);a!==-1&&(this.splice(a,1),this._updateClassName())};f.toggle=function(a){a+="";b(this,a)===-1?this.add(a):this.remove(a)};f.toString=function(){return this.join(" ")};if(h.defineProperty){f={get:k,enumerable:true,configurable:true};
try{h.defineProperty(g,"classList",f)}catch(i){if(i.number===-2146823252)f.enumerable=false,h.defineProperty(g,"classList",f)}}else h.prototype.__defineGetter__&&g.__defineGetter__("classList",k)}(self);if(typeof Event.preventDefault==="undefined"&&typeof window.event!=="undefined")Event.prototype.preventDefault=function(){window.event.stop()},Event.prototype.stopPropagation=function(){window.event.returnValue=false}})();
(function(){function g(c,a,b){var e,f;if(typeof c.hasAttribute!=="undefined")c.hasAttribute(a)&&(e=c.getAttribute(a)),f=true;else if(typeof c[a]!=="undefined")e=c[a],f=false;else if(a==="class"&&typeof c.className!=="undefined")a="className",e=c.className,f=false;if(typeof e==="undefined"&&(typeof b==="undefined"||b===null))console.log(b),console.log(c),console.log("Element does not have the selected attribute");else{if(typeof b==="undefined")return e;typeof b!=="undefined"&&b!==null?f===true?c.setAttribute(a,
b):c[a]=b:b===null&&(f===true?c.removeAttribute(a):delete c[a]);return typeof b!=="undefined"?b:e}}function h(c){return c.replace(/(\-[a-z])/g,function(a){return a.toUpperCase().replace("-","")})}function d(c,a,b){var e,a=h(a);e={outerHeight:"offsetHeight",outerWidth:"offsetWidth",top:"posTop"};if(typeof b==="undefined"&&c.style[a]!=="undefined")return c.style[a];else if(typeof b==="undefined"&&c.style[e[a]]!=="undefined")return c.style[e[a]];typeof c.style[a]!=="undefined"?c.style[a]=b:c.style[e[a]]?
c.style[e[a]]=b:console.log("Property "+a+" nor an equivalent seems to exist")}$_.ext("dom",{addClass:function(c){$_.each(function(a){a.classList.add(c)})},removeClass:function(c){$_.each(function(a){a.classList.remove(c)})},hide:function(){this.css("display","none")},show:function(c){typeof c==="undefined"&&(c="block");this.css("display",c)},attr:function(c,a){var b=this.el;if(b.length>1&&typeof a==="undefined")console.log(b),console.log("Must be a singular element");else if(b.length>1&&typeof a!==
"undefined")$_.each(function(b){return g(b,c,a)});else return g(b,c,a)},text:function(c){var a,b,e;e=this.el;b=typeof e.innerText!=="undefined"?"innerText":typeof e.textContent!=="undefined"?"textContent":"innerHTML";a=e[b];return typeof c!=="undefined"?e[b]=c:a},css:function(c,a){if(typeof a==="undefined")return d(this.el,c);$_.each(function(b){d(b,c,a)})},html:function(c){if(typeof c!=="undefined")this.el.innerHTML=c;return this.el.innerHTML}})})();
(function(){if(!(typeof localStorage==="undefined"||typeof JSON==="undefined")){var g=localStorage,h=sessionStorage;$_.ext("store",{get:function(d,c){var a=c?h.getItem(d):g.getItem(d);return JSON.parse(a)},set:function(d,c,a){c=JSON.stringify(c);a?h.setItem(d,c):g.setItem(d,c)},remove:function(d,c){c?h.removeItem(d):g.removeItem(d)},getAll:function(d){var c,a={},b,e;e=d?g:h;c=e.length;for(d=0;d<c;d++)b=e.key(d),a[b]=e.getItem(b);return a},clear:function(d){d?h.clear():g.clear()}})}})();
(function(){if(typeof window.XMLHttpRequest!=="undefined"){var g={_do:function(g,d,c,a){var b=new XMLHttpRequest;typeof c==="undefined"&&(c=function(){});a=a?"POST":"GET";g+=a==="GET"?"?"+this._serialize(d):"";b.open(a,g);b.onreadystatechange=function(){b.readyState===4&&c(b.responseText)};a==="POST"?(b.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),b.send(this._serialize(d))):b.send(null)},_serialize:function(g){var d,c,a=[];for(d in g)g.hasOwnProperty(d)&&typeof g[d]!=="function"&&
(c=g[d].toString(),d=encodeURIComponent(d),c=encodeURIComponent(c),a.push(d+"="+c));return a.join("&")}};$_.ext("get",function(h,d,c){g._do(h,d,c,false)});$_.ext("post",function(h,d,c){g._do(h,d,c,true)})}})();
(function(){var g=function(d){var c=[],a=0,b={},e,c=h.object_keys(d);c.sort(function(a,b){var c=parseFloat(b),e=parseFloat(a),d=c+""===b,g=e+""===a;if(d&&g)return c>e?1:c<e?-1:0;else if(d&&!g)return 1;else if(!d&&g)return-1;return b>a?1:b<a?-1:0});a=c.length;for(e=0;e<a;e++)b[c[e]]=d[c[e]];return b},h={object_keys:function(d){var c=[],a;for(a in d)d.hasOwnProperty(a)&&c.push(a);return c},object_values:function(d){var c=[],a;for(a in d)c.push(d[a]);return c},array_combine:function(d,c){var a={},b,
e=0;$_.type(d)!=="array"&&(d=this.object_values(d));$_.type(c)!=="array"&&(c=this.object_values(c));b=d.length;if(b!==c.length)return console.log("Object combine requires two arrays of the same size"),false;for(e=0;e<b;e++)a[d[e]]=c[e];return a},object_merge:function(){var d=Array.prototype.slice.call(arguments),c=d.length,a={},b,e=0,f,g,h;b=true;for(f=0;f<c;f++)if($_.type(d[f])!=="array"){b=false;break}if(b){a=[];for(f=0;f<c;f++)a=a.contact(d[f]);return a}for(f=0,h=0;f<c;f++)if(b=d[f],$_.type(b)==
"array")for(g=0,e=b.length;g<e;g++)a[h++]=b[g];else for(g in b)b.hasOwnProperty(g)&&(parseInt(g,10)+""===g?a[h++]=b[g]:a[g]=b[g]);return a},str_trans:function(d,c,a){var b=[],e=[],f=false,h=0,i=0,j="",m="",l="",o="",n;if(typeof c==="object"){c=g(c);for(n in c)c.hasOwnProperty(n)&&(b.push(n),e.push(c[n]));c=b;a=e}i=d.length;h=c.length;j=typeof a==="string";m=typeof c==="string";for(b=0;b<i;b++){f=false;if(m){d.charAt(b-1);l=d.charAt(b);d.charAt(b+1);for(e=0;e<h;e++)if(l==c.charAt(e)){f=true;break}}else for(e=
0;e<h;e++)if(d.substr(b,c[e].length)==c[e]){f=true;b=b+c[e].length-1;break}o+=f?j?a.charAt(e):a[e]:d.charAt(b)}return o}};$_.ext("util",h)})();
(function(){var g,h,d,c;typeof document.addEventListener!=="undefined"?(g=function(a,b,c){typeof a.addEventListener!=="undefined"&&a.addEventListener(b,c,false)},h=function(a,b,c){typeof a.removeEventListener!=="undefined"&&a.removeEventListener(b,c,false)}):typeof document.attachEvent!=="undefined"&&(g=function(a,b,c){var e;function d(a){c.apply(a)}typeof a.attachEvent!=="undefined"?(h(b,c),a.attachEvent("on"+b,d),e=a.KIS_0_5_0=a.KIS_0_5_0||{},a=e,a.listeners=a.listeners||{},a.listeners[b]=a.listeners[b]||
[],a.listeners[b].push({callback:c,_listener:d})):console.log("Failed to _attach event:"+b+" on "+a)},h=function(a,b,c){if(typeof a.detachEvent!=="undefined"){var d=a.KIS_0_5_0;if(d&&d.listeners&&d.listeners[b])for(var g=d.listeners[b],h=g.length,j=0;j<h;j++)if(g[j].callback===c){a.detachEvent("on"+b,g[j]._listener);g.splice(j,1);g.length===0&&delete d.listeners[b];break}}});d=function(a,b,c,f){var k,i;if(typeof a==="undefined")return console.log(arguments),console.log(b),false;if(b.match(/^([\w\-]+)$/))f===
true?g(a,b,c):h(a,b,c);else{b=b.split(" ");i=b.length;for(k=0;k<i;k++)d(a,b[k],c,f)}};c=function(a,b,c,f){d(a,c,function(a){var c,d,e,a=a||window.event;d=$_.$(b);for(c in d)e=a.target||a.srcElement,e==d[c]&&(f.call(d[c],a),a.stopPropagation())},true)};$_.ext("event",{add:function(a,b){$_.each(function(c){d(c,a,b,true)})},remove:function(a,b){$_.each(function(c){d(c,a,b,false)})},live:function(a,b,d){c(document.documentElement,a,b,d)},delegate:function(a,b,d){$_.each(function(f){c(f,a,b,d)})}})})();
(function(){if($_.ajax!=="undefined"){var g,h;g={};h={};$_.ext("template",{get:function(d){var c;c=this.el.innerHTML;if(c==="")console.log("Template is empty or cannot be found");else return g[d]=c},parse:function(d,c){var a=g[d],b=[],b=[],e=0,f=e=0,k=0,i="",j={},m="",l,a=String(a).replace(/\s+/gim," "),a=a.replace(/>\s+</gim,"><"),a=a.replace(/>\s+\{/gim,">{"),a=a.replace(/\}\s+</gim,"}<"),b=a.match(/\{([A-Z0-9_\-]+)\}(.*)\{\/\1\}/gim);if(b!=null){e=b.length;for(f=0;f<e;f++){a=a.replace(b[f],"{"+
f+"}");m="";i=String(b[f]).match(/^\{([A-Z0-9_\-]+)\}/i);j=c[i[1]];if(j.length>0){i=j.length;b[f]=b[f].replace(/\{([A-Z0-9_\-]+)\}(.*)\{\/\1\}/gim,"$2");for(k=0;k<i;k++)m+=b[f].replace(/\{([A-Z0-9 _\-]+)\}/gi,function(a,b){return j[k][b]?j[k][b]:""})}a=a.replace("{"+f+"}",m)}}b=a.match(/\{([A-Z0-9_\-]+)\}/gim);if(b!=null){e=b.length;for(f=0;f<e;f++)i=b[f].replace("{",""),i=i.replace("}",""),a=a.replace(b[f],c[i])}f=document.createDocumentFragment();f.appendChild(document.createElement("section"));
f=f.querySelectorAll("section")[0];f.innerHTML=a;f=f.querySelectorAll('[src=""], [href=""]');for(l in f)f[l].parentNode&&f[l].parentNode.removeChild(f[l]);return h[d]=a},apply:function(d,c,a){typeof c==="undefined"&&typeof a==="undefined"?this.el.innerHTML=typeof h[d]!=="undefined"?h[d]:d:$_.get(c,{},function(b){b===""?console.log("Template is empty or can not be found"):(g[d]=b,b=this.parse(d,a),h[d]=b,this.el.innerHTML=b)})}})}})();
(function(){if("undefined"!==typeof document.querySelector){var g,f,d,b;g=function(a){b="undefined"===typeof a?"undefined"!==typeof g.el?g.el:document.documentElement:"object"!==typeof a?f(a):a;g.prototype.el=b;var a=d(g),c;for(c in a)if("object"===typeof a[c])a[c].el=b;a.el=b;return a};f=function(a,c){var b;if("string"!=typeof a||"undefined"===typeof a)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};d=function(a){var c;if("undefined"!==typeof a){if("undefined"!==typeof Object.create)return Object.create(a);c=typeof a;if(!("object"!==c&&"function"!==c))return c=function(){},c.prototype=a,new c}};g.ext=function(a,c){c.el=b;g[a]=c};g.ext("each",function(a){if("undefined"!==typeof b.length&&b!==window){var c=b.length;if(0!==c)for(var e,d=0;d<c;d++)e=b.item(d)?b.item(d):b[d],a.call(e,e)}else a.call(b,b)});g.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()};g=window.$_=window.$_||g;g.$=f}})();
(function(){if("undefined"===typeof window.console)window.console={log:function(){}};if("undefined"===typeof String.prototype.trim)String.prototype.trim=function(){return this.replace(/^[\s\uFEFF]+|[\s\uFEFF]+$/g,"")};"undefined"!==typeof document&&!("classList"in document.createElement("a"))&&function(g){var g=(g.HTMLElement||g.Element).prototype,f=Object,d=String.prototype.trim||function(){return this.replace(/^\s+|\s+$/g,"")},b=Array.prototype.indexOf||function(a){for(var c=0,b=this.length;c<b;c++)if(c in
this&&this[c]===a)return c;return-1},a=function(a,c){this.name=a;this.code=DOMException[a];this.message=c},c=function(c,e){if(""===e)throw new a("SYNTAX_ERR","An invalid or illegal string was specified");if(/\s/.test(e))throw new a("INVALID_CHARACTER_ERR","String contains an invalid character");return b.call(c,e)},e=function(a){for(var c=d.call(a.className),c=c?c.split(/\s+/):[],b=0,e=c.length;b<e;b++)this.push(c[b]);this._updateClassName=function(){a.className=this.toString()}},j=e.prototype=[],
h=function(){return new e(this)};a.prototype=Error.prototype;j.item=function(a){return this[a]||null};j.contains=function(a){return-1!==c(this,a+"")};j.add=function(a){a+="";-1===c(this,a)&&(this.push(a),this._updateClassName())};j.remove=function(a){a=c(this,a+"");-1!==a&&(this.splice(a,1),this._updateClassName())};j.toggle=function(a){a+="";-1===c(this,a)?this.add(a):this.remove(a)};j.toString=function(){return this.join(" ")};if(f.defineProperty){j={get:h,enumerable:!0,configurable:!0};try{f.defineProperty(g,
"classList",j)}catch(i){if(-2146823252===i.number)j.enumerable=!1,f.defineProperty(g,"classList",j)}}else f.prototype.__defineGetter__&&g.__defineGetter__("classList",h)}(self);if("undefined"===typeof Event.preventDefault&&"undefined"!==typeof window.event)Event.prototype.preventDefault=function(){window.event.stop()},Event.prototype.stopPropagation=function(){window.event.returnValue=!1}})();
(function(){function g(b,a,c){var e,d;if("undefined"!==typeof b.hasAttribute)b.hasAttribute(a)&&(e=b.getAttribute(a)),d=!0;else if("undefined"!==typeof b[a])e=b[a],d=!1;else if("class"===a&&"undefined"!==typeof b.className)a="className",e=b.className,d=!1;if("undefined"===typeof e&&("undefined"===typeof c||null===c))console.log(c),console.log(b),console.log("Element does not have the selected attribute");else{if("undefined"===typeof c)return e;"undefined"!==typeof c&&null!==c?!0===d?b.setAttribute(a,
c):b[a]=c:null===c&&(!0===d?b.removeAttribute(a):delete b[a]);return"undefined"!==typeof c?c:e}}function f(b){return b.replace(/(\-[a-z])/g,function(a){return a.toUpperCase().replace("-","")})}function d(b,a,c){var e,a=f(a);e={outerHeight:"offsetHeight",outerWidth:"offsetWidth",top:"posTop"};if("undefined"===typeof c&&"undefined"!==b.style[a])return b.style[a];if("undefined"===typeof c&&"undefined"!==b.style[e[a]])return b.style[e[a]];"undefined"!==typeof b.style[a]?b.style[a]=c:b.style[e[a]]?b.style[e[a]]=
c:console.log("Property "+a+" nor an equivalent seems to exist")}$_.ext("dom",{addClass:function(b){$_.each(function(a){a.classList.add(b)})},removeClass:function(b){$_.each(function(a){a.classList.remove(b)})},hide:function(){this.css("display","none")},show:function(b){"undefined"===typeof b&&(b="block");this.css("display",b)},attr:function(b,a){var c=this.el;if(1<c.length&&"undefined"===typeof a)console.log(c),console.log("Must be a singular element");else if(1<c.length&&"undefined"!==typeof a)$_.each(function(c){return g(c,
b,a)});else return g(c,b,a)},text:function(b){var a,c,e;e=this.el;c="undefined"!==typeof e.innerText?"innerText":"undefined"!==typeof e.textContent?"textContent":"innerHTML";a=e[c];return"undefined"!==typeof b?e[c]=b:a},css:function(b,a){if("undefined"===typeof a)return d(this.el,b);$_.each(function(c){d(c,b,a)})},append:function(b){this.el.insertAdjacentHTML("beforeend",b)},prepend:function(b){this.el.insertAdjacentHTML("afterbegin",b)},html:function(b){if("undefined"!==typeof b)this.el.innerHTML=
b;return this.el.innerHTML}})})();
(function(){if(!("undefined"===typeof localStorage||"undefined"===typeof JSON)){var g=localStorage,f=sessionStorage;$_.ext("store",{get:function(d,b){var a=b?f.getItem(d):g.getItem(d);return JSON.parse(a)},set:function(d,b,a){b=JSON.stringify(b);a?f.setItem(d,b):g.setItem(d,b)},remove:function(d,b){b?f.removeItem(d):g.removeItem(d)},getAll:function(d){var b,a={},c,e;e=d?g:f;b=e.length;for(d=0;d<b;d++)c=e.key(d),a[c]=e.getItem(c);return a},clear:function(d){d?f.clear():g.clear()}})}})();
(function(){if("undefined"!==typeof window.XMLHttpRequest){var g={_do:function(f,d,b,a){var c=new XMLHttpRequest;"undefined"===typeof b&&(b=function(){});a=a?"POST":"GET";f+="GET"===a?"?"+this._serialize(d):"";c.open(a,f);c.onreadystatechange=function(){4===c.readyState&&b(c.responseText)};"POST"===a?(c.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),c.send(this._serialize(d))):c.send(null)},_serialize:function(f){var d,b,a=[];for(d in f)f.hasOwnProperty(d)&&"function"!==typeof f[d]&&
(b=f[d].toString(),d=encodeURIComponent(d),b=encodeURIComponent(b),a.push(d+"="+b));return a.join("&")}};$_.ext("get",function(f,d,b){g._do(f,d,b,!1)});$_.ext("post",function(f,d,b){g._do(f,d,b,!0)})}})();
(function(){var g=function(d){var b=[],a=0,c={},e,b=f.object_keys(d);b.sort(function(a,c){var b=parseFloat(c),e=parseFloat(a),d=b+""===c,f=e+""===a;return d&&f?b>e?1:b<e?-1:0:d&&!f?1:!d&&f?-1:c>a?1:c<a?-1:0});a=b.length;for(e=0;e<a;e++)c[b[e]]=d[b[e]];return c},f={object_keys:function(d){var b=[],a;for(a in d)d.hasOwnProperty(a)&&b.push(a);return b},object_values:function(d){var b=[],a;for(a in d)b.push(d[a]);return b},array_combine:function(d,b){var a={},c,e=0;"array"!==$_.type(d)&&(d=this.object_values(d));
"array"!==$_.type(b)&&(b=this.object_values(b));c=d.length;if(c!==b.length)return console.log("Object combine requires two arrays of the same size"),!1;for(e=0;e<c;e++)a[d[e]]=b[e];return a},object_merge:function(){var d=Array.prototype.slice.call(arguments),b=d.length,a={},c,e=0,f,h,g;c=!0;for(f=0;f<b;f++)if("array"!==$_.type(d[f])){c=!1;break}if(c){a=[];for(f=0;f<b;f++)a=a.contact(d[f]);return a}for(f=0,g=0;f<b;f++)if(c=d[f],"array"==$_.type(c))for(h=0,e=c.length;h<e;h++)a[g++]=c[h];else for(h in c)c.hasOwnProperty(h)&&
(parseInt(h,10)+""===h?a[g++]=c[h]:a[h]=c[h]);return a},str_trans:function(d,b,a){var c=[],e=[],f=!1,h=0,i=0,k="",l="",o="",m="",n;if("object"===typeof b){b=g(b);for(n in b)b.hasOwnProperty(n)&&(c.push(n),e.push(b[n]));b=c;a=e}i=d.length;h=b.length;k="string"===typeof a;l="string"===typeof b;for(c=0;c<i;c++){f=!1;if(l){d.charAt(c-1);o=d.charAt(c);d.charAt(c+1);for(e=0;e<h;e++)if(o==b.charAt(e)){f=!0;break}}else for(e=0;e<h;e++)if(d.substr(c,b[e].length)==b[e]){f=!0;c=c+b[e].length-1;break}m=f?m+(k?
a.charAt(e):a[e]):m+d.charAt(c)}return m}};$_.ext("util",f)})();
(function(){var g,f,d,b;"undefined"!==typeof document.addEventListener?(g=function(a,c,b){"undefined"!==typeof a.addEventListener&&a.addEventListener(c,b,!1)},f=function(a,c,b){"undefined"!==typeof a.removeEventListener&&a.removeEventListener(c,b,!1)}):"undefined"!==typeof document.attachEvent&&(g=function(a,c,b){var e;function d(a){b.apply(a)}"undefined"!==typeof a.attachEvent?(f(c,b),a.attachEvent("on"+c,d),e=a.KIS_0_5_0=a.KIS_0_5_0||{},a=e,a.listeners=a.listeners||{},a.listeners[c]=a.listeners[c]||
[],a.listeners[c].push({callback:b,_listener:d})):console.log("Failed to _attach event:"+c+" on "+a)},f=function(a,c,b){if("undefined"!==typeof a.detachEvent){var d=a.KIS_0_5_0;if(d&&d.listeners&&d.listeners[c])for(var f=d.listeners[c],g=f.length,k=0;k<g;k++)if(f[k].callback===b){a.detachEvent("on"+c,f[k]._listener);f.splice(k,1);0===f.length&&delete d.listeners[c];break}}});d=function(a,c,b,j){var h,i;if("undefined"===typeof a)return console.log(arguments),console.log(c),!1;if(c.match(/^([\w\-]+)$/))!0===
j?g(a,c,b):f(a,c,b);else{c=c.split(" ");i=c.length;for(h=0;h<i;h++)d(a,c[h],b,j)}};b=function(a,c,b,f){d(a,b,function(a){var b,d,e,a=a||window.event;d=$_.$(c);for(b in d)e=a.target||a.srcElement,e==d[b]&&(f.call(d[b],a),a.stopPropagation())},!0)};$_.ext("event",{add:function(a,c){$_.each(function(b){d(b,a,c,!0)})},remove:function(a,b){$_.each(function(e){d(e,a,b,!1)})},live:function(a,c,d){b(document.documentElement,a,c,d)},delegate:function(a,c,d){$_.each(function(f){b(f,a,c,d)})}})})();
(function(){if("undefined"!==$_.ajax){var g,f;g={};f={};$_.ext("template",{get:function(d){var b;b=this.el.innerHTML;if(""===b)console.log("Template is empty or cannot be found");else return g[d]=b},parse:function(d,b){var a=g[d],c=[],e=/\{([A-Z0-9_\-]+)\}(.*)\{\/\1\}/gim,j=/\{([A-Z0-9_\-]+)\}/gim,c=[],h=0,i=h=0,k=0,l="",o={},m="",n,a=(""+a).replace(/\s+/gim," "),a=a.replace(/>\s+</gim,"><"),a=a.replace(/>\s+\{/gim,">{"),a=a.replace(/\}\s+</gim,"}<"),c=a.match(e);if(null!=c){h=c.length;for(i=0;i<
h;i++){a=a.replace(c[i],"{"+i+"}");m="";l=(""+c[i]).match(/^\{([A-Z0-9_\-]+)\}/i);o=b[l[1]];if(0<o.length){l=o.length;c[i]=c[i].replace(e,"$2");for(k=0;k<l;k++)m+=c[i].replace(j,function(a,b){return o[k][b]?o[k][b]:""})}a=a.replace("{"+i+"}",m)}}c=a.match(j);if(null!=c){h=c.length;for(i=0;i<h;i++)l=c[i].replace("{",""),l=l.replace("}",""),a=a.replace(c[i],b[l])}e=document.createDocumentFragment();e.appendChild(document.createElement("section"));e=e.querySelectorAll("section")[0];e.innerHTML=a;e=e.querySelectorAll('[src=""], [href=""]');
for(n in e)e[n].parentNode&&e[n].parentNode.removeChild(e[n]);return f[d]=a},apply:function(d,b,a){"undefined"===typeof b&&"undefined"===typeof a?this.el.innerHTML="undefined"!==typeof f[d]?f[d]:d:$_.get(b,{},function(b){""===b?console.log("Template is empty or can not be found"):(g[d]=b,b=this.parse(d,a),f[d]=b,this.el.innerHTML=b)})}})}})();

View File

@ -302,6 +302,31 @@
_css(e, prop, val);
});
},
/**
* Adds to the innerHTML of the current element, after the last child.
*
* @example $_("ul").dom.append("&lt;li&gt;&lt;/li&gt;") adds an li element to the end of the selected ul element
* @name append
* @memberOf $_.dom
* @function
* @param string htm
*/
append: function(htm)
{
this.el.insertAdjacentHTML('beforeend', htm);
},
/**
* Adds to the innerHTML of the selected element, before the current children
*
* @name prepend
* @memberOf $_.dom
* @function
* @param string htm
*/
prepend: function(htm)
{
this.el.insertAdjacentHTML('afterbegin', htm);
},
/**
* Sets or gets the innerHTML propery of the element(s) passed
*

View File

@ -69,6 +69,8 @@
{
var tmp = _t[name],
pairs = [],
pair_reg = /\{([A-Z0-9_\-]+)\}(.*)\{\/\1\}/gim,
var_reg = /\{([A-Z0-9_\-]+)\}/gim,
pseudos = [],
num_pairs = 0,
num_pseudos = 0,
@ -93,7 +95,7 @@
tmp = tmp.replace(/\}\s+</gim, "}<");
//Match all the looped sections of content
pairs = tmp.match(/\{([A-Z0-9_\-]+)\}(.*)\{\/\1\}/gim);
pairs = tmp.match(pair_reg);
if(pairs != null)
{
@ -118,13 +120,13 @@
data_len = rep_data.length;
//Get rid of the loop tags
pairs[i] = pairs[i].replace(/\{([A-Z0-9_\-]+)\}(.*)\{\/\1\}/gim, "$2");
pairs[i] = pairs[i].replace(pair_reg, "$2");
//Replace psudovariables with data
for(j=0;j<data_len;j++)
{
//Is there a better way to do this, rather than an inline function?
tmp_data += pairs[i].replace(/\{([A-Z0-9 _\-]+)\}/gi, function(_, varName){
tmp_data += pairs[i].replace(var_reg, function(_, varName){
return (rep_data[j][varName]) ? rep_data[j][varName] : "";
});
}
@ -136,7 +138,7 @@
}
//Replace all the rest of the psudeovariables
pseudos = tmp.match(/\{([A-Z0-9_\-]+)\}/gim);
pseudos = tmp.match(var_reg);
if(pseudos != null)
{