<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>dev.enekoalonso.com &#187; global</title>
	<atom:link href="http://dev.enekoalonso.com/tag/global/feed/" rel="self" type="application/rss+xml" />
	<link>http://dev.enekoalonso.com</link>
	<description>having fun with code</description>
	<lastBuildDate>Wed, 12 Oct 2011 21:40:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Mooml.globalize(): Mooml template functions going global</title>
		<link>http://dev.enekoalonso.com/2010/02/01/mooml-globalize-mooml-template-functions-going-global/</link>
		<comments>http://dev.enekoalonso.com/2010/02/01/mooml-globalize-mooml-template-functions-going-global/#comments</comments>
		<pubDate>Mon, 01 Feb 2010 15:49:35 +0000</pubDate>
		<dc:creator>Eneko Alonso</dc:creator>
				<category><![CDATA[uncategorized]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[global]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[mooml]]></category>
		<category><![CDATA[mootools]]></category>
		<category><![CDATA[scope]]></category>
		<category><![CDATA[template]]></category>

		<guid isPermaLink="false">http://dev.enekoalonso.com/?p=448</guid>
		<description><![CDATA[Since version 1.0.9, Mooml includes a new feature: globalize. It maybe handy for some websites to globalize all the Mooml template functions (div, a, p, span&#8230;) to the window object scope, so they can be used anywhere in the code without the need of defining or evaluating a template. For example, in normal Mootools code [...]]]></description>
			<content:encoded><![CDATA[<p>Since version 1.0.9, <a href="http://github.com/eneko/mooml">Mooml</a> includes a new feature: <string>globalize</strong>. It maybe handy for some websites to globalize all the Mooml template functions (div, a, p, span&#8230;) to the window object scope, so they can be used anywhere in the code without the need of defining or evaluating a template.</p>
<p>For example, in normal Mootools code we would create a div like this:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1">&nbsp;<span class="co1">// options can have attributes, css, events and more</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">var</span> mydiv = <span class="kw2">new</span> Element<span class="br0">&#40;</span><span class="st0">&#39;div&#39;</span>, options<span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>With Mooml.globalize() we can do this:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1">Mooml.<span class="me1">globalize</span><span class="br0">&#40;</span><span class="br0">&#41;</span>; <span class="co1">// Only need to call this once</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">var</span> mydiv = div<span class="br0">&#40;</span>options<span class="br0">&#41;</span>; <span class="co1">// Same options as Mootools new Element()</span></div>
</li>
</ol>
</div>
<p>Mooml globalized functions can also have nested elements, which makes very easy to create dom elements:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> mydiv = div<span class="br0">&#40;</span>options, </div>
</li>
<li class="li1">
<div class="de1">&nbsp;p<span class="br0">&#40;</span><span class="st0">&#39;First paragraph&#39;</span><span class="br0">&#41;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp;p<span class="br0">&#40;</span><span class="st0">&#39;Second paragraph&#39;</span><span class="br0">&#41;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp;div<span class="br0">&#40;</span><span class="st0">&#39;Nested div:&#39;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; span<span class="br0">&#40;</span><span class="st0">&#39;div content&#39;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#41;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp;Mooml.<span class="me1">render</span><span class="br0">&#40;</span><span class="st0">&#39;nested_template&#39;</span><span class="br0">&#41;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="st0">&#39;Some &lt;b&gt;inline&lt;/b&gt; &lt;em&gt;html&lt;/em&gt; too&#39;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>Will generate the dom elements for this html:</p>
<div class="geshi no html">
<ol>
<li class="li1">
<div class="de1">&lt;div&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;&lt;p&gt;First paragraph&lt;/p&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;&lt;p&gt;Second paragraph&lt;/p&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;&lt;div&gt;Nested div:
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &lt;span&gt;div content&lt;/span&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;&lt;/div&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;&lt;!&#8211; nested template here &#8211;&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;Some &lt;b&gt;inline&lt;/b&gt; &lt;em&gt;html&lt;/em&gt; too
</div>
</li>
<li class="li1">
<div class="de1">&lt;/div&gt;</div>
</li>
</ol>
</div>
<p>Elements created by Mooml template functions are not automatically injected in the DOM. They are just created like when you use new Element().</p>
<p>Please be aware that using Mooml.globalize() feature will pollute the window object scope, overriding any methods with the same name and/or possibly conflicting with other Javascript libraries. As a tip, Mooml.tags can be edited before calling Mooml.globalize(), so only functions for those tags we are interested on will be created.</p>
<h3  class="related_post_title">Related Posts:</h3><ul class="related_post"><li>April 28, 2010 -- <a href="http://dev.enekoalonso.com/2010/04/28/mooml-1-2-3-bye-bye-with/" title="Mooml 1.2.3 &#8211; Bye, bye, with()">Mooml 1.2.3 &#8211; Bye, bye, with()</a> (3)</li><li>March 24, 2010 -- <a href="http://dev.enekoalonso.com/2010/03/24/mooml-1-1-no-more-eval-say-hi-to-mooml-template-and-mooml-templates/" title="Mooml 1.1 &#8211; No more eval(), say Hi to Mooml.Template and Mooml.Templates">Mooml 1.1 &#8211; No more eval(), say Hi to Mooml.Template and Mooml.Templates</a> (0)</li><li>February 19, 2010 -- <a href="http://dev.enekoalonso.com/2010/02/19/having-fun-with-mooml-and-twitter/" title="Having fun with Mooml &#038; Twitter">Having fun with Mooml &#038; Twitter</a> (0)</li><li>March 15, 2010 -- <a href="http://dev.enekoalonso.com/2010/03/15/more-updates-to-mooml-coming-soon/" title="More updates to Mooml coming soon">More updates to Mooml coming soon</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://dev.enekoalonso.com/2010/02/01/mooml-globalize-mooml-template-functions-going-global/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

