<?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>Scott Robbin &#187; Ubiquity</title>
	<atom:link href="http://srobbin.com/blog/category/ubiquity/feed/" rel="self" type="application/rss+xml" />
	<link>http://srobbin.com/blog</link>
	<description>A variety of articles, projects and by web developer, Scott Robbin.</description>
	<lastBuildDate>Mon, 30 Apr 2012 18:45:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Using Ubiquity to Replace alert()</title>
		<link>http://srobbin.com/blog/using-ubiquity-to-replace-alert/</link>
		<comments>http://srobbin.com/blog/using-ubiquity-to-replace-alert/#comments</comments>
		<pubDate>Tue, 30 Dec 2008 18:22:10 +0000</pubDate>
		<dc:creator>Scott Robbin</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Ubiquity]]></category>
		<category><![CDATA[UI]]></category>

		<guid isPermaLink="false">http://halobrite.com/blog/?p=32</guid>
		<description><![CDATA[Bad habits are hard to break, especially when they're your own, but what about other people's habits....impossible? Difficult, perhaps, but not insurmountable. By using Ubiquity's preLoad_ authoring tool, you can override Javascript's native functions, such as alert(), and replace them with useful interactions like Transparent Messages.]]></description>
			<content:encoded><![CDATA[<p>Bad habits are hard to break, especially when they&#8217;re your own, but what about other people&#8217;s habits&#8230;.impossible? Difficult, perhaps, but not insurmountable.</p>
<p>When we first encounter Javascript programming, the quintessential function that enamors us all is <a href="http://www.w3schools.com/JS/js_popup.asp" title="Javascript pop-up boxes">alert()</a>. Plunk that baby down into a page and, bam (or more accurately&#8230;thwunk!), a magical dialog box appears, grabbing the viewer&#8217;s attention and providing useful/useless information:</p>
<input type="button" onclick="alert('Aw, geez, you clicked me! Thanks.')" value="Click me, click me, click me" style="margin:15px 0 25px 0" id="demo" />
<p>But is this the best way to convey important information? Probably not. For one, the alert box is <a href="http://en.wikipedia.org/wiki/Modal_window" title="Wikipedia: Modal Windows">modal</a>; a user cannot continue with their task until they&#8217;ve clicked OK &mdash; their train of thought is broken.</p>
<p>One solution to this problem is to use transparent messaging. Rather than doing a disservice by re-explaining, I&#8217;ll refer you to read <a href="http://humanized.com/weblog/2006/09/11/monolog_boxes_and_transparent_messages/" title="Humanized: Monolog Boxes and Transparent Messages">Aza Raskin&#8217;s article on Monolog Boxes and Transparent Messages</a>. Or, if you&#8217;d like to see them in the wild, check out <a href="http://songza.com" title="Songza: The Music Search Engine and Internet Jukebox">Songza</a>: we utilize transparent messages to convey the state of media player (play a song, then press the space bar to Pause.)</p>
<p><a href="http://www.flickr.com/photos/srobbin/3151602178/"><img alt="" src="http://farm4.static.flickr.com/3146/3151602178_d8f20bf468.jpg" title="Transparent Message on Songza.com" class="alignnone" width="500" height="246" /></a></p>
<p>Now, that&#8217;s all well and good, you might say, but what about sites that I don&#8217;t have programmatic control over? As a user, I&#8217;m at the mercy of whatever features the site programmer chooses to implement. Not true. Enter <a href="http://labs.mozilla.com/projects/ubiquity/" title="Mozilla Labs: Ubiquity">Ubiquity</a>.</a></p>
<h2>Ubiquity and pageLoad_</h2>
<p>One of the goals of Ubiquity is to extend functionality across websites, regardless of whether or not the original programmer had coded that type of interaction (i.e. language translation, map insertion, word definition, etc). As such, <a href="http://labs.mozlla.com" title="Mozilla Labs">Mozilla Labs</a> has given programmers a bevy of <a href="https://wiki.mozilla.org/Labs/Ubiquity/Ubiquity_0.1_Author_Tutorial" title="Ubiquity: Author Tutorial">authoring tools</a>, including the <strong>pageLoad_</strong> prefix. If, in your command file, you create a function that starts with pageLoad_, Ubiquity will execute this code whenever a new page is loaded into the browser window. It is this functionality that allows users to override native Javascript functions, such as alert().</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"> <span style="color: #003366; font-weight: bold;">function</span> pageLoad_overrideNativeFunction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     CmdUtils.<span style="color: #660066;">getWindowInsecure</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">nativeFunction</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          <span style="color: #006600; font-style: italic;">// Your code here</span>
     <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>By using this pattern, the native function is auto-magically replaced with your customized code each time a new page is loaded. In my case, I&#8217;ve chosen to override alert() with a call to create and show a Transparent Message <em>(Note: I&#8217;ve used a Singleton with lazy instantiation to converse resources on pages that won&#8217;t call the command)</em>:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> pageLoad_overrideAlert<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     CmdUtils.<span style="color: #660066;">getWindowInsecure</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066;">alert</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>str<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          TransparentMessage.<span style="color: #660066;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span>str<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>To see a working example, simply <a href="https://ubiquity.mozilla.com/xpi/ubiquity-latest.xpi" title="Install Ubiquity">install the Ubiquity extension for Firefox</a> and <a href="http://halobrite.com/ubiquity/" title="Halobrite: Ubiquity Commands">subscribe to the transparent-message command</a>. From there, you can create a test message by issuing the &#8220;transparent-message&#8221; command, or see how it overrides alert() by revisiting this page and clicking the <a href="#demo">demo button located at the top of this article</a>.</p>
<p><em>Note: Many thanks to <a href="http://binarybonsai.com/" title="Binary Bonsai">Micheal Heilemann</a> for authoring the <a href="http://code.google.com/p/humanmsg/" title="jQuery: Humanized Messages plugin">jQuery Humanized Messages plugin</a>. It&#8217;s what we use on Songza, and was used as a reference to create the transparent-message command.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://srobbin.com/blog/using-ubiquity-to-replace-alert/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

