<?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 &#187; jQuery</title>
	<atom:link href="http://roosteronacid.com/blog/index.php/category/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://roosteronacid.com/blog</link>
	<description></description>
	<lastBuildDate>Sat, 23 Jan 2010 17:49:32 +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>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>4</slash:comments>
		</item>
	</channel>
</rss>
