<?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>Earnest Apathy &#187; JavaScript</title>
	<atom:link href="http://blog.pyrolupus.com/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.pyrolupus.com</link>
	<description>The meaning of one life</description>
	<lastBuildDate>Wed, 29 Jun 2011 17:33:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>Multiple jQueryUI Themerolled Themes inside ASP.Net App_Themes</title>
		<link>http://blog.pyrolupus.com/2009/03/multiple-jqueryui-themerolled-themes-inside-aspnet-app_themes/</link>
		<comments>http://blog.pyrolupus.com/2009/03/multiple-jqueryui-themerolled-themes-inside-aspnet-app_themes/#comments</comments>
		<pubDate>Thu, 26 Mar 2009 22:49:48 +0000</pubDate>
		<dc:creator>pyrolupus</dc:creator>
				<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[jQueryUI]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[themes]]></category>
		<category><![CDATA[workaround]]></category>

		<guid isPermaLink="false">http://blog.pyrolupus.com/?p=106</guid>
		<description><![CDATA[One of the things I love about jQueryUI is the fact that it can generate a download based upon one of several great-looking themes. This rolls up all the images and CSS into a single zip along with a customized &#8230; <a href="http://blog.pyrolupus.com/2009/03/multiple-jqueryui-themerolled-themes-inside-aspnet-app_themes/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>One of the things I love about <a href="http://jqueryui.com/">jQueryUI</a> is the fact that it can generate a download based upon one of several <a title="jQueryUI ThemeRoller" href="http://jqueryui.com/themeroller/">great-looking themes</a>.  This rolls up all the images and CSS into a single zip along with a customized JavaScript file.  This is awesome, but what happens if I want to grab multiple themes, drop them into an ASP.Net website, and be able to switch between them?<br />
<span id="more-106"></span><br />
After downloading a couple of themes and renaming the unzipped directories, we can see that there are several things included in our zip:</p>
<p><img class="size-full wp-image-107 alignnone" title="jQueryUI Theme Directories" src="http://blog.pyrolupus.com/wp-content/uploads/2009/03/uitheme_dirs.png" alt="jQueryUI Theme Directories" width="197" height="223" /></p>
<p><img class="size-full wp-image-108 alignright" title="App_Theme Directories" src="http://blog.pyrolupus.com/wp-content/uploads/2009/03/apptheme_dirs.png" alt="App_Theme Directories" width="131" height="113" align="right" />The aforementioned CSS and images are inside that <code>/css</code> directory, plus some other goodies, like example code for using each of UI&#8217;s widgets. When I want to use a jQueryUI theme in an ASP.Net, I just copy the <code>theme-name</code> subdirectory from <code>/css</code> into the App_Themes .Net solution folder.  From there, it&#8217;s a simple matter of letting the web app know to use the one of the themes in Web.config:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pages</span> <span style="color: #000066;">styleSheetTheme</span>=<span style="color: #ff0000;">&quot;start&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p>I used <a href="http://weblogs.asp.net/vimodi/articles/WhatIs_StyleSheetTheme.aspx">StyleSheetTheme over Theme</a>, because a) StyleSheetTheme is processed earlier in the page lifecycle&#8211;before page control properties applied&#8211;and b) since these are style-only themes (meaning no .Net-specific .skin files that contain server-processed control properties), StyleSheetTheme just makes more sense.</p>
<p>Now that I have a couple of Themerolled themes, how the heck do I get the right customized JavaScript file to load?  Glad you (er, I) asked!</p>
<p>When you download a themerolled theme, the included JavaScript file is named <code>jquery-ui-1.7.1.custom.min.js</code> (with the appropriate version number if you are reading this a while after I write it).  The first thing I do is change that &#8220;custom&#8221; into the name of the theme:  <code>jquery-ui-1.7.1.south-street.min.js</code> &#8212; and drop it into my site&#8217;s <code>/js</code> directory..  Now it&#8217;s time to crack open my Master page&#8217;s code-behind:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">partial</span> <span style="color: #6666cc; font-weight: bold;">class</span> MasterPage 
 <span style="color: #008000;">:</span> <span style="color: #000000;">System.<span style="color: #0000FF;">Web</span><span style="color: #008000;">.</span><span style="color: #0000FF;">UI</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">MasterPage</span> <span style="color: #008000;">&#123;</span>
  <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #6666cc; font-weight: bold;">void</span> Page_Init<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, EventArgs e<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">//prefer StyleSheetTheme, but use Theme if</span>
    <span style="color: #008080; font-style: italic;">//  no StyleSheetTheme is present</span>
    <span style="color: #6666cc; font-weight: bold;">string</span> themeName <span style="color: #008000;">=</span> Page<span style="color: #008000;">.</span><span style="color: #0000FF;">StyleSheetTheme</span> <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span> 
     <span style="color: #008000;">?</span> Page<span style="color: #008000;">.</span><span style="color: #0000FF;">StyleSheetTheme</span> 
     <span style="color: #008000;">:</span> Page<span style="color: #008000;">.</span><span style="color: #0000FF;">Theme</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #6666cc; font-weight: bold;">string</span> uiScriptPath <span style="color: #008000;">=</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Format</span><span style="color: #008000;">&#40;</span>
     <span style="color: #666666;">&quot;~/js/jquery-ui-1.7.1.{0}.min&quot;</span>, 
     themeName<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    ScriptManager1<span style="color: #008000;">.</span><span style="color: #0000FF;">Scripts</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>
     <span style="color: #008000;">new</span> ScriptReference<span style="color: #008000;">&#40;</span>uiScriptPath<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>Not using ASP.Net AJAX?  Then replace that last statement with:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Page<span style="color: #008000;">.</span><span style="color: #0000FF;">ClientScript</span><span style="color: #008000;">.</span><span style="color: #0000FF;">RegisterClientScriptInclude</span><span style="color: #008000;">&#40;</span>
 <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetType</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, <span style="color: #666666;">&quot;jqueryui&quot;</span>, uiScriptPath<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>Now, if you want to provide a way for users of your site to switch between themes, the right customized jQueryUI file gets picked up!</p>
<p>On a related note, the <a href="http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=103654">MasterPage class has no PreInit event</a>, so we cannot <b>globally</b> (<i>i.e.</i>, just one time) do the following:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">//no such thing as a MasterPage.PreInit event :-(</span>
<span style="color: #008080; font-style: italic;">//  so, only works on content, i.e., aspx pages</span>
<span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #6666cc; font-weight: bold;">void</span> Page_PreInit<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, EventArgs e<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
  <span style="color: #008080; font-style: italic;">//grab from profile or session or cookie, etc.</span>
  Page<span style="color: #008000;">.</span><span style="color: #0000FF;">StyleSheetTheme</span> <span style="color: #008000;">=</span> Profile<span style="color: #008000;">.</span><span style="color: #0000FF;">Theme</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>So how can we easily pick up our JavaScript file across the whole site if I want users to be able to switch between themes?  (Microsoft suggested doing so in Global.asax in the above linked suggestion&#8230;but how the blazes can you access the Page.(StyleSheet)Theme inside Global.asax?!)</p>
<p>It just so happens that <a href="http://www.edream.org/">Sue Googe</a> <a href="http://www.edream.org/BlogArticle.aspx?RecordID=103">blogged about solving that very problem</a> and also <a href="http://www.codeproject.com/KB/aspnet/dynamicThemes.aspx">posted her solution to CodeProject</a>.  In brief, she created a <code>BasePage</code> class (which inherits from <code>Page</code>) in the <code>/App_Code</code> folder that sets the theme, and then all your site pages inherit from <code>BasePage</code>.  Less than ideal for a pre-existing site with many pages, but I have yet to find or come up with a better globally-available solution.  (Thanks, Sue! ^_^)</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.pyrolupus.com/2009/03/multiple-jqueryui-themerolled-themes-inside-aspnet-app_themes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery Detector Overkill</title>
		<link>http://blog.pyrolupus.com/2008/07/jquery-detector-overkill/</link>
		<comments>http://blog.pyrolupus.com/2008/07/jquery-detector-overkill/#comments</comments>
		<pubDate>Thu, 31 Jul 2008 02:28:10 +0000</pubDate>
		<dc:creator>pyrolupus</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[userscripts]]></category>

		<guid isPermaLink="false">http://blog.pyrolupus.com/?p=10</guid>
		<description><![CDATA[With the ideas, help, and suggestions of some very smart folks, I&#8217;ve been able to put together a userscript that displays whether jQuery is used on the current page&#8212;along with version&#8212;and can also load jQuery into the current page by &#8230; <a href="http://blog.pyrolupus.com/2008/07/jquery-detector-overkill/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>With the ideas, help, and suggestions of some very smart folks, I&#8217;ve been able to put together a userscript that displays whether jQuery is used on the current page&#8212;along with version&#8212;and can also load jQuery into the current page by clicking the indicator if jQuery is not already present.<br />
<span id="more-12"></span><br />
In early 2007, Paul Bakaus wrote a <a href="http://paul.jquery.com/jquerydetector.user.js">nifty userscript</a> that displays the jQuery icon (<img src='http://jquery.com/images/favicon.png' width='14' height='14' alt='jQuery Logo' class='alignnone' style='border:0;margin:0;padding:0 2px;vertical-align: middle;' />) at the bottom right hand side of the browser window when the page contains <a href="http://jquery.com">jQuery</a>.  (You need either <a href="http://opera.com/">Opera</a> or the <a href="http://www.greasespot.net/">Greasemonkey</a> plugin for <a href="http://getfirefox.com/">Firefox</a> to run userscripts.)</p>
<p>In a thread on the <a href="http://groups.google.com/group/jquery-en">jQuery discussion group</a> that (re)announced Paul&#8217;s userscript, <a href="http://groups.google.com/group/jquery-en/browse_thread/thread/2439fc066ea47d9a/5c4b95261f8206bd#dcbc48cfe398cf9f">Karl Swedberg suggested</a> putting the version of jQuery in the image&#8217;s title attribute so it would show as a tooltip when you hover over it. As I am curious about when each site started using jQuery and what capabilities they have available on their site, I thought that was a fantastic idea. So, I copied <a href="http://paul.jquery.com/jquerydetector.js">Paul&#8217;s detector script</a> to my own server, and added in Karl&#8217;s suggestion (modifying my userscript to point to my modded detector script).</p>
<p>I had been (and am still) having some problems with the version tooltip showing on my home browser&#8211;some plug-in or configuration issue, no doubt&#8211;so I cobbled together something that would display the <a href="http://pyrolupus.com/js/jquerydetector.version.js">page&#8217;s jQuery version</a> in a div when I clicked on the icon.</p>
<p>Now, on a separate track, Karl had talked about how to create a <a href="http://www.learningjquery.com/2006/12/jquerify-bookmarklet">jQuery bookmarklet</a> that would insert jQuery into pages that do not have it, in order to have jQuery&#8217;s power on the console in <a href="http://getfirebug.com/">Firebug</a> or <a href="http://opera.com/products/dragonfly/">Dragonfly</a>&#8211;or slightly more painstakingly with &#8220;javascript:&#8221; statements in the address bar for <a href="http://www.microsoft.com/windows/products/winfamily/ie/default.mspx">Internet Exploder</a> and <a href="http://www.apple.com/safari/">Safari</a> (does Safari have its own console?).  I&#8217;ve been using and loving it ever since I found it.</p>
<p>Karl recently wrote about an <a href="http://www.learningjquery.com/2008/06/updated-jquery-bookmarklet">updated jQuery bookmarklet</a> that has things like a spiffy div that pops up and tells you what it&#8217;s doing.  When I saw that and thought about the display-on-click that I&#8217;d added to my jQuery Detector, I just knew that these were two great tastes that had to, er, play golf together.</p>
<p>So, here is the &#8220;debug&#8221; version of the script, <i>i.e.</i>, with line breaks and long(er) variables names:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> version<span style="color: #339933;">=</span><span style="color: #CC0000;">0.3</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">//cheaply find version when compressed</span>
    b<span style="color: #339933;">=</span>document.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'body'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    el<span style="color: #339933;">=</span>document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    img <span style="color: #339933;">=</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'img'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    els <span style="color: #339933;">=</span> el.<span style="color: #660066;">style</span><span style="color: #339933;">,</span> ims <span style="color: #339933;">=</span> img.<span style="color: #660066;">style</span><span style="color: #339933;">,</span>
    <span style="color: #006600; font-style: italic;">//&quot;jquery is present&quot; image</span>
    jqimg<span style="color: #339933;">=</span><span style="color: #3366CC;">'http://jquery.com/images/favicon.png'</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">// style info div</span>
  els.<span style="color: #660066;">position</span><span style="color: #339933;">=</span><span style="color: #3366CC;">'fixed'</span><span style="color: #339933;">;</span>
  els.<span style="color: #660066;">bottom</span><span style="color: #339933;">=</span><span style="color: #3366CC;">'2px'</span><span style="color: #339933;">;</span>
  els.<span style="color: #660066;">right</span><span style="color: #339933;">=</span><span style="color: #3366CC;">'20px'</span><span style="color: #339933;">;</span>
  els.<span style="color: #660066;">width</span><span style="color: #339933;">=</span><span style="color: #3366CC;">'200px'</span><span style="color: #339933;">;</span>
  els.<span style="color: #660066;">height</span><span style="color: #339933;">=</span><span style="color: #3366CC;">'24px'</span><span style="color: #339933;">;</span>
  els.<span style="color: #660066;">margin</span><span style="color: #339933;">=</span><span style="color: #3366CC;">'0 auto 0 auto'</span><span style="color: #339933;">;</span>
  els.<span style="color: #660066;">padding</span><span style="color: #339933;">=</span><span style="color: #3366CC;">'5px 10px 5px 10px'</span><span style="color: #339933;">;</span>
  els.<span style="color: #660066;">backgroundColor</span><span style="color: #339933;">=</span><span style="color: #3366CC;">'#c33'</span><span style="color: #339933;">;</span>
  els.<span style="color: #660066;">color</span><span style="color: #339933;">=</span><span style="color: #3366CC;">'#fff'</span><span style="color: #339933;">;</span>
  els.<span style="color: #660066;">fontSize</span><span style="color: #339933;">=</span><span style="color: #3366CC;">'8pt'</span><span style="color: #339933;">;</span>
  els.<span style="color: #660066;">textAlign</span><span style="color: #339933;">=</span><span style="color: #3366CC;">'center'</span><span style="color: #339933;">;</span>
  els.<span style="color: #660066;">display</span><span style="color: #339933;">=</span><span style="color: #3366CC;">'none'</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">// style jquery detector icon</span>
  ims.<span style="color: #660066;">position</span><span style="color: #339933;">=</span><span style="color: #3366CC;">'fixed'</span><span style="color: #339933;">;</span>
  ims.<span style="color: #660066;">bottom</span><span style="color: #339933;">=</span><span style="color: #3366CC;">'2px'</span><span style="color: #339933;">;</span>
  ims.<span style="color: #660066;">right</span><span style="color: #339933;">=</span><span style="color: #3366CC;">'2px'</span><span style="color: #339933;">;</span>
  ims.<span style="color: #660066;">zIndex</span><span style="color: #339933;">=</span><span style="color: #3366CC;">'5'</span><span style="color: #339933;">;</span>
  ims.<span style="color: #660066;">cursor</span><span style="color: #339933;">=</span><span style="color: #3366CC;">'pointer'</span><span style="color: #339933;">;</span>
  ims.<span style="color: #660066;">border</span><span style="color: #339933;">=</span><span style="color: #3366CC;">'0'</span><span style="color: #339933;">;</span>
&nbsp;
  b.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>img<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  b.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">// function overhead in order to rebind click event after loading jQuery</span>
  <span style="color: #006600; font-style: italic;">// showJq(): img.click = display version of jQuery currently loaded</span>
  <span style="color: #003366; font-weight: bold;">function</span> showJq<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> jq<span style="color: #339933;">=</span>jQuery<span style="color: #339933;">,</span> v <span style="color: #339933;">=</span> jq.<span style="color: #660066;">fn</span>.<span style="color: #660066;">jquery</span><span style="color: #339933;">;</span>
    <span style="color: #006600; font-style: italic;">//&quot;if&quot; protects jquery.com from needless rechecking</span>
    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>img.<span style="color: #660066;">src</span><span style="color: #339933;">!=</span>jqimg<span style="color: #009900;">&#41;</span> img.<span style="color: #660066;">src</span><span style="color: #339933;">=</span>jqimg<span style="color: #339933;">;</span>
    img.<span style="color: #660066;">title</span><span style="color: #339933;">=</span>v<span style="color: #339933;">;</span>
    el.<span style="color: #660066;">innerHTML</span><span style="color: #339933;">=</span><span style="color: #3366CC;">'Using jQuery v'</span><span style="color: #339933;">+</span>v<span style="color: #339933;">;</span>
    jq<span style="color: #009900;">&#40;</span>img<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      els.<span style="color: #660066;">display</span><span style="color: #339933;">=</span><span style="color: #3366CC;">'block'</span><span style="color: #339933;">;</span>
      window.<span style="color: #660066;">setTimeout</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        jq<span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeOut</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'slow'</span><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: #CC0000;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #006600; font-style: italic;">//jquery exists; display version on icon click</span>
  <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> jQuery <span style="color: #339933;">!=</span> <span style="color: #3366CC;">'undefined'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    showJq<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #006600; font-style: italic;">//no jquery; show bland icon and load jquery on click</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
    img.<span style="color: #660066;">src</span><span style="color: #339933;">=</span><span style="color: #3366CC;">'http://jquery.com/images/ics.png'</span><span style="color: #339933;">;</span>
    img.<span style="color: #660066;">title</span><span style="color: #339933;">=</span><span style="color: #3366CC;">'Load jQuery'</span><span style="color: #339933;">;</span>
    img.<span style="color: #660066;">onclick</span><span style="color: #339933;">=</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">//todo: rebind click event to above</span>
      <span style="color: #003366; font-weight: bold;">var</span> s<span style="color: #339933;">=</span>document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'script'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      s.<span style="color: #660066;">setAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'src'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      document.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'head'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>s<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
      <span style="color: #006600; font-style: italic;">// loadJQuery(): recursive calls until jQuery finishes loading</span>
      <span style="color: #003366; font-weight: bold;">function</span> loadJQuery<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        el.<span style="color: #660066;">innerHTML</span><span style="color: #339933;">=</span><span style="color: #3366CC;">'jQuery Loading...'</span><span style="color: #339933;">;</span>els.<span style="color: #660066;">display</span><span style="color: #339933;">=</span><span style="color: #3366CC;">'block'</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">++</span>i <span style="color: #339933;">&lt;</span> <span style="color: #CC0000;">10</span> <span style="color: #339933;">&amp;</span>#038<span style="color: #339933;">;&amp;</span> <span style="color: #000066; font-weight: bold;">typeof</span> jQuery <span style="color: #339933;">==</span> <span style="color: #3366CC;">'undefined'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          window.<span style="color: #660066;">setTimeout</span><span style="color: #009900;">&#40;</span>loadJQuery<span style="color: #339933;">,</span> <span style="color: #CC0000;">50</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #006600; font-style: italic;">//recheck every x milliseconds</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">&gt;=</span> <span style="color: #CC0000;">10</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>    <span style="color: #006600; font-style: italic;">//don't try rechecking more than y times</span>
          el.<span style="color: #660066;">innerHTML</span><span style="color: #339933;">=</span><span style="color: #3366CC;">'Load jQuery failed&lt;br/&gt;(try again?)'</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>    <span style="color: #006600; font-style: italic;">//finished loading; show version and fade out</span>
          img.<span style="color: #660066;">onclick</span><span style="color: #339933;">=</span>showJq<span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//rebind to just show version</span>
          el.<span style="color: #660066;">innerHTML</span><span style="color: #339933;">=</span><span style="color: #3366CC;">'jQuery loaded, v'</span><span style="color: #339933;">+</span>jQuery.<span style="color: #660066;">fn</span>.<span style="color: #660066;">jquery</span><span style="color: #339933;">;</span>
          img.<span style="color: #660066;">src</span><span style="color: #339933;">=</span>jqimg<span style="color: #339933;">;</span>  <span style="color: #006600; font-style: italic;">//reset img url to jquery icon</span>
          window.<span style="color: #660066;">setTimeout</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            jQuery<span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeOut</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'slow'</span><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: #CC0000;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span>
      loadJQuery<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   <span style="color: #006600; font-style: italic;">//start loading jquery</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Once that&#8217;s done, all that&#8217;s left is to churn this (much heavier than Paul&#8217;s original) script through the <a href="http://developer.yahoo.com/yui/compressor/">YUI Compressor</a> to cut its size down a bit.  I also turned on compression for my scripts directory to get even more mileage out of it.</p>
<p>I have not yet gotten this working in Opera 9.5x, though Paul&#8217;s original script worked fine in 9.2x.</p>
<p>Each of the resulting scripts are available below:</p>
<ul>
<li><a href="http://pyrolupus.com/js/jquerydetector.user.js">jQuery Detector userscript</a> (for Greasemonkey/user scripts)</li>
<li><a href="http://pyrolupus.com/js/jqd.js">jQuery Detector Script</a> (referenced by the userscript)</li>
<li><a href="http://pyrolupus.com/js/jqd.debug.js">jQuery Detector Script &#8211; debug</a> (verbose)</li>
</ul>
<p>Can you find problems or think of improvements&#8212;or give me tips on why I&#8217;ve broken it in Opera?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.pyrolupus.com/2008/07/jquery-detector-overkill/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Email Validation RegExp</title>
		<link>http://blog.pyrolupus.com/2007/11/email-validation-regexp/</link>
		<comments>http://blog.pyrolupus.com/2007/11/email-validation-regexp/#comments</comments>
		<pubDate>Fri, 02 Nov 2007 21:40:34 +0000</pubDate>
		<dc:creator>pyrolupus</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Regular Expressions]]></category>

		<guid isPermaLink="false">http://blog.pyrolupus.com/archives/5/email-validation-regexp/</guid>
		<description><![CDATA[I had to search my desktop files and email history for forty minutes before I turned this up: var rfc2822 = /^&#91;\w!#$%&#38;'*+/=?^`{&#124;}~-]+(?:\.[\w!#$%&#38;'*+/=?^`&#123;&#124;&#125;~-&#93;+&#41;*@&#40;?:&#91;a-z0-9&#93;&#40;?:&#91;a-z0-9-&#93;*&#91;a-z0-9&#93;&#41;*&#41;+\.&#40;?:&#91;a-z&#93;&#123;2,4&#125;&#124;museum&#124;travel&#41;$/i; That&#8217;s a JavaScript variable declaration, but the RegExp is valid for Perl and can be quickly translated for &#8230; <a href="http://blog.pyrolupus.com/2007/11/email-validation-regexp/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I had to search my desktop files and email history for forty minutes before I turned this up:<br />
<font size="-1"></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> rfc2822 <span style="color: #339933;">=</span>
<span style="color: #339933;">/^</span><span style="color: #009900;">&#91;</span>\w<span style="color: #339933;">!</span>#$<span style="color: #339933;">%&amp;</span><span style="color: #3366CC;">'*+/=?^`{|}~-]+(?:<span style="color: #000099; font-weight: bold;">\.</span>[<span style="color: #000099; font-weight: bold;">\w</span>!#$%&amp;'</span><span style="color: #339933;">*+/=?^</span>`<span style="color: #009900;">&#123;</span><span style="color: #339933;">|</span><span style="color: #009900;">&#125;</span>~<span style="color: #339933;">-</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*@</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">?:</span><span style="color: #009900;">&#91;</span>a<span style="color: #339933;">-</span>z0<span style="color: #339933;">-</span><span style="color: #CC0000;">9</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">?:</span><span style="color: #009900;">&#91;</span>a<span style="color: #339933;">-</span>z0<span style="color: #339933;">-</span><span style="color: #CC0000;">9</span><span style="color: #339933;">-</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">*</span><span style="color: #009900;">&#91;</span>a<span style="color: #339933;">-</span>z0<span style="color: #339933;">-</span><span style="color: #CC0000;">9</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span>\.<span style="color: #009900;">&#40;</span><span style="color: #339933;">?:</span><span style="color: #009900;">&#91;</span>a<span style="color: #339933;">-</span>z<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span><span style="color: #CC0000;">2</span><span style="color: #339933;">,</span><span style="color: #CC0000;">4</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">|</span>museum<span style="color: #339933;">|</span>travel<span style="color: #009900;">&#41;</span>$<span style="color: #339933;">/</span>i<span style="color: #339933;">;</span></pre></div></div>

<p></font><br />
That&#8217;s a JavaScript  variable declaration, but the RegExp is valid for Perl and can be quickly translated for other languages.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.pyrolupus.com/2007/11/email-validation-regexp/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

