<?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>rooster on acid – webblog</title>
	<atom:link href="http://roosteronacid.com/blog/index.php/feed/" rel="self" type="application/rss+xml" />
	<link>http://roosteronacid.com/blog</link>
	<description></description>
	<lastBuildDate>Fri, 18 Feb 2011 11:17:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>What if&#8230;</title>
		<link>http://roosteronacid.com/blog/index.php/2011/02/10/what-if/</link>
		<comments>http://roosteronacid.com/blog/index.php/2011/02/10/what-if/#comments</comments>
		<pubDate>Thu, 10 Feb 2011 22:25:29 +0000</pubDate>
		<dc:creator>roosteronacid</dc:creator>
				<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://roosteronacid.com/blog/?p=140</guid>
		<description><![CDATA[What if you we&#8217;re able to construct complex HTML fragments in C# with the same ease and readability as you are, using jQuery? Stuff like&#8230; var list = new cQuery ( tag: "ul", id: "tags", controls: new [] { new cQuery(tag: "li", text: "C#"), new cQuery(tag: "li", text: "JavaScript"), new cQuery(tag: "li", text: "Markup languages").Append [...]]]></description>
			<content:encoded><![CDATA[<p>What if you we&#8217;re able to construct complex HTML fragments in C# with the same ease and readability as you are, using <a href="http://jquery.com">jQuery</a>?</p>
<p>Stuff like&#8230;</p>
<pre name="code" class="c-sharp:nogutter:nocontrols">

var list = new cQuery
(
    tag: "ul",
    id: "tags",
    controls: new []
    {
        new cQuery(tag: "li", text: "C#"),
        new cQuery(tag: "li", text: "JavaScript"),

        new cQuery(tag: "li", text: "Markup languages").Append
        (
            new cQuery("ul").Append(new []
            {
                new cQuery("li", text: "XHTML"),
                new cQuery("li", text: "HTML 4"),
                new cQuery("li", text: "HTML 5")
            })
        ),

        new cQuery(tag: "li", text: "CSS")
    }
);

list.Wrap
(
    new cQuery("div").AddClass("horizontal").Append
    (
        new cQuery(new LinkButton { ID = "hidelist", Text = "Hide" }).AddClass("small")
    )
);

PlaceHolder.Controls.Add(list);
</pre>
<p>I will be releasing my cQuery class shortly. Stay tuned.</p>
]]></content:encoded>
			<wfw:commentRss>http://roosteronacid.com/blog/index.php/2011/02/10/what-if/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Syntatic sugar: a different way to do if-statements</title>
		<link>http://roosteronacid.com/blog/index.php/2011/02/10/syntatic-sugar-a-different-way-to-do-if-statements/</link>
		<comments>http://roosteronacid.com/blog/index.php/2011/02/10/syntatic-sugar-a-different-way-to-do-if-statements/#comments</comments>
		<pubDate>Thu, 10 Feb 2011 21:45:57 +0000</pubDate>
		<dc:creator>roosteronacid</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://roosteronacid.com/blog/?p=132</guid>
		<description><![CDATA[Try this one out for size. var value = "no"; if ({ foo: true, bar: true, yes: true, maybe: true }[value]) // will return false var value = "bar"; if ({ foo: true, bar: true, yes: true, maybe: true }[value]) // will return true var validValues = { foo: true, bar: true, yes: true, maybe: [...]]]></description>
			<content:encoded><![CDATA[<p>Try this one out for size.</p>
<pre name="code" class="js:nogutter:nocontrols">

var value = "no";

if ({ foo: true, bar: true, yes: true, maybe: true }[value]) // will return false
</pre>
<pre name="code" class="js:nogutter:nocontrols">

var value = "bar";

if ({ foo: true, bar: true, yes: true, maybe: true }[value]) // will return true
</pre>
<pre name="code" class="js:nogutter:nocontrols">

var validValues = {
    foo: true,
    bar: true,
    yes: true,
    maybe: true
};

if (validValues["bar"]) // will return true
</pre>
<p>C# you say?</p>
<pre name="code" class="c-sharp:nogutter:nocontrols">

if (new [] { "foo", "bar", "yes", "maybe" }.Contains("bar")) // returns true
</pre>
<pre name="code" class="c-sharp:nogutter:nocontrols">

var validValues = new []
{
    "foo",
    "bar",
    "yes",
    "maybe"
};

if (validValues.Contains("bar")) // returns true
</pre>
]]></content:encoded>
			<wfw:commentRss>http://roosteronacid.com/blog/index.php/2011/02/10/syntatic-sugar-a-different-way-to-do-if-statements/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The jQuery template plug-in: implementing complex logic using render-functions</title>
		<link>http://roosteronacid.com/blog/index.php/2011/02/10/the-jquery-template-plug-in-implementing-complex-logic-using-render-functions/</link>
		<comments>http://roosteronacid.com/blog/index.php/2011/02/10/the-jquery-template-plug-in-implementing-complex-logic-using-render-functions/#comments</comments>
		<pubDate>Thu, 10 Feb 2011 19:10:43 +0000</pubDate>
		<dc:creator>roosteronacid</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://roosteronacid.com/blog/?p=73</guid>
		<description><![CDATA[The new jQuery template plug-in is awesome. That being said, the double-curly brace template-tags are not exactly my cup of tea. In a more complex template the tags obscure the markup contained in the template, and implementing logic past simple if/else statements is a pain. After messing around with the plug-in for a few hours, [...]]]></description>
			<content:encoded><![CDATA[<p>The new jQuery <a href="http://api.jquery.com/category/plugins/templates/">template plug-in</a> is awesome. That being said, the double-curly brace template-tags are not exactly my cup of tea. In a more complex template the tags obscure the markup contained in the template, and implementing logic past simple if/else statements is a pain.</p>
<p>After messing around with the plug-in for a few hours, my head began to hurt from trying to distinguish the markup in my template from the millions of double curly braces.</p>
<p>So I popped an aspirin and began work on an alternative. And here it is…</p>
<p>&nbsp;</p>
<p><strong>The template</strong></p>
<pre name="code" class="html:nogutter:nocontrols">

<script id="animals_template" type="text/x-jquery-tmpl">

<!-- This is as clean as it gets -->
<!-- Execute render function, passing current entity as the first argument -->
<li>{{html this.render(this.data) }}</li>

</script>
</pre>
<p>&nbsp;</p>
<p><strong>The JavaScript</strong></p>
<pre name="code" class="js:nogutter:nocontrols">
$(function ()
{
    // Define an array of animals to be rendered out by the template
    var animals = [
        { species: "Moose", strength: 8, dexterity: 4 },
        { species: "Sloth", strength: 2, dexterity: 0 },
        { species: "Alpaca", strength: 6, dexterity: 9 },
        { species: "Blobfish", strength: 1, dexterity: 2 },
        { species: "Squirrel", strength: 10, dexterity: 10 }, // Squirrels... crazy dangerous!
        { species: "Badger", strength: 4, dexterity: 6 },
        { species: "Emu", strength: 2, dexterity: 8 }
    ];

    // Compile and cache the template
    $.template("animals_template_compiled", $("#animals_template"));

    // Create a render-function which implements complex logic
    function renderer(animal)
    {
        // If an animals strength is rated higher than 5 and if it's dexterity is rated
        // higher than 3... or if the animal is the insanely dangerous squirrel; return
        // it's name in bold
        if ((animal.strength > 5 &#038;&#038; animal.dexterity > 3) || animal.species === "Squirrel")
        return "<strong>" + animal.species + "</strong>";

        // If not; return it's name without the bold tags
        return animal.species;
    }

    // Render the template
    var output = $.tmpl("animals_template_compiled", animals, { render: renderer });

    // Append the rendered template to the DOM
    $("#animals_template_output").append(output);
});
</pre>
<p>&nbsp;</p>
<p><strong>The markup in which to place the output of the template</strong></p>
<pre name="code" class="html:nogutter:nocontrols">
<div>
<h1>Be warned!</h1>
<h4>The animals highlighted will probably tear off your arms</h4>
<h4>It would be a bad idea to try and pet them</h4>
<ul id="animals_template_output"></ul>
</div>
</pre>
<p>&nbsp;</p>
<p><strong>The result</strong></p>
<div><img src="http://roosteronacid.com/animals.jpg" /></div>
<p>&nbsp;</p>
<p><strong>&#8230; But you get the point</strong></p>
<p>I know that the logic contained in the render function is not <strong>that</strong> complex. But you get the point: complex logic is best expressed in JavaScript and not by using hard-to-read syntax, plastered into HTML.</p>
<p>&nbsp;</p>
<p><strong>For the purists</strong></p>
<p>I am aware that I&#8217;m breaking the whole model/view/controller concept by using a function to render out part of the template. But enabling full separation of logic and markup is possible. All you have to do is return a boolean value in the renderer function and update your template a tiny bit.</p>
<div style="margin-left: 40px;">
<p><em><strong>Note:</strong> the name &#8220;renderer&#8221; no longer applies since the function is now returning a boolean value. It&#8217;s been renamed to &#8220;isDangerous&#8221; in the following code-examples.</em></p>
</div>
<p>&nbsp;</p>
<p><strong>The updated template</strong></p>
<pre name="code" class="html:nogutter:nocontrols">

<script id="animals_template" type="text/x-jquery-tmpl">

<!-- if the animal is dangerous; make its name bold -->
<li>
    {{if this.isDangerous(this.data) }}
        <strong>${species}</strong>
    {{else}}
        ${species}
    {{/if}}
</li>

</script>
</pre>
<p>&nbsp;</p>
<p><strong>The updated JavaScript</strong></p>
<pre name="code" class="js:nogutter:nocontrols">

function isDangerous(animal)
{
    if ((animal.strength > 5 &#038;&#038; animal.dexterity > 3) || animal.species === "Squirrel")
    return true;
}

var output = $.tmpl("animals_template_compiled", animals, { isDangerous: isDangerous });
</pre>
]]></content:encoded>
			<wfw:commentRss>http://roosteronacid.com/blog/index.php/2011/02/10/the-jquery-template-plug-in-implementing-complex-logic-using-render-functions/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>altAlert, a jQuery plug-in for personalized alert messages without the need to change existing code</title>
		<link>http://roosteronacid.com/blog/index.php/2010/01/20/jquery-plug-in-personalized-alert-messages/</link>
		<comments>http://roosteronacid.com/blog/index.php/2010/01/20/jquery-plug-in-personalized-alert-messages/#comments</comments>
		<pubDate>Wed, 20 Jan 2010 21:11:17 +0000</pubDate>
		<dc:creator>roosteronacid</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://roosteronacid.com/blog/?p=26</guid>
		<description><![CDATA[I&#8217;ve wanted to write a jQuery plug-in for a long time, but I didn&#8217;t want to write one just for the exercise. Last night I was messing around with overriding native JavaScript functions &#8211; among those the alert-function &#8211; and it hit me: why not write a plug-in for jQuery which overrides and personalizes alert [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve wanted to write a jQuery plug-in for a long time, but I didn&#8217;t want to write one just for the exercise.</p>
<p>Last night I was messing around with overriding native JavaScript functions &#8211; among those the alert-function &#8211; and it hit me: why not write a plug-in for jQuery which overrides and personalizes alert messages without the need to change any existing code? And while I was at it, integrate the plug-in with jQuery UI and leverage the functionality of the Dialog widget?</p>
<p>&nbsp;</p>
<p><strong>So I did. And here’s what I came up with</strong></p>
<div style="padding-left: 40px;">
<a href="javascript: alert('In-line call to alert!');" id="tryme" title="Try me!"><img src="http://roosteronacid.com/button.png" alt="Try me!" /></a></p>
<p style="margin: 0;"><em><strong>Note:</strong> my WordPress theme seems to be interfering with the jQuery UI theme; breaking the styles on the close-button in the dialog.</em></p>
</div>
<p>&nbsp;</p>
<p><strong>The plug-in code</strong></p>
<pre name="code" class="js:nogutter:nocontrols">
jQuery.altAlert = function (options)
{
    var defaults = {
        title: "Alert",
        buttons: {
            "Ok": function()
            {
                jQuery(this).dialog("close");
            }
        }
    };

    jQuery.extend(defaults, options);

    delete defaults.autoOpen;

    window.alert = function ()
    {
        jQuery("&lt;div /&gt;", { html: arguments[0].replace(/\n/, "&lt;br /&gt;") }).dialog(defaults);
    };
};
</pre>
<p>&nbsp;</p>
<p><strong>And here&#8217;s how you use it&#8230; it&#8217;s pretty simple, really</strong></p>
<pre name="code" class="js:nogutter:nocontrols">
$(function ()
{
    $.altAlert();
});
</pre>
<p>After calling the plug-in constructor, all calls to the native alert-function will pop up a jQuery UI dialog instead of the boring standard dialog. Neat, huh?</p>
<p>&nbsp;</p>
<p><strong>My plug-in leverages the jQuery UI Dialog widget</strong></p>
<p>And because my plug-in leverages jQuery UI, my plug-in&#8230;</p>
<ul>
<li>inherits solid code that has undergone rigorous testing</li>
<li>generates solid markup that has been tested and looks the same in all A-grade browsers</li>
<li>fully supports the jQuery UI Themeroller</li>
</ul>
<p>On top of that: all the functionality available in the jQuery UI Dialog widget is available in my plug-in. This means that you can override the standard functionality of my plug-in &#8211; just like you would, using the jQuery UI Dialog widget &#8211; and change it&#8217;s default behavior:</p>
<pre name="code" class="js:nogutter:nocontrols">
$(function ()
{
    $.altAlert(
    {
        modal: true,
        closeOnEscape: false,
        title: "Dang!... Stuff happend!",
        buttons: {
            "Ok": function()
            {
                window.location = "error.html";
            }
        }
    });
});
</pre>
<p>In the above example, the code effectively locks down a page, preventing user-input, while the browser loads an error page.</p>
<p>&nbsp;</p>
<p><strong>In a few days time&#8230;</strong></p>
<p>I will create a project on Google Code, and put up some live usage-examples&#8230; In the meantime; feel free to leave comment and tell me what you think.</p>
<p>&nbsp;</p>
<p><strong>Update&#8230;</strong></p>
<p>I&#8217;ve added my plug-in to the endless list on the jQuery website. <a href="http://plugins.jquery.com/project/altAlert" title="altAlert, a jQuery plug-in for personalized alert messages without the need to change existing code"/>Here&#8217;s a direct link.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://roosteronacid.com/blog/index.php/2010/01/20/jquery-plug-in-personalized-alert-messages/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
	</channel>
</rss>

