<?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>JavaScriptly &#187; jQuery</title> <atom:link href="http://javascriptly.com/category/development-news/jquery/feed/" rel="self" type="application/rss+xml" /><link>http://javascriptly.com</link> <description>JavaScript Techniques, Tricks and News</description> <lastBuildDate>Tue, 06 Sep 2011 04:57:52 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.2.1</generator> <item><title>Something for Christmas: Snowfall in Picture</title><link>http://javascriptly.com/2009/12/something-for-christmas-snowfall-in-picture/</link> <comments>http://javascriptly.com/2009/12/something-for-christmas-snowfall-in-picture/#comments</comments> <pubDate>Wed, 23 Dec 2009 07:05:26 +0000</pubDate> <dc:creator>Jimmy Vu</dc:creator> <category><![CDATA[jQuery]]></category> <category><![CDATA[Misc]]></category> <category><![CDATA[effect]]></category> <category><![CDATA[snowfall]]></category><guid isPermaLink="false">http://javascriptly.com/?p=62</guid> <description><![CDATA[<p></p><p style="text-align: justify;">Now it is time for Christmas and if you want to add some snows to a picture like the below example, a cool jQuery plugin &#8212; created by <a href="http://www.somethinghitme.com/2009/12/20/snowfall-plugin-updated/" target="_blank">Jason Brown</a> &#8212; can come to help.&#8230;</p>]]></description> <content:encoded><![CDATA[<p></p><p style="text-align: justify;">Now it is time for Christmas and if you want to add some snows to a picture like the below example, a cool jQuery plugin &#8212; created by <a href="http://www.somethinghitme.com/2009/12/20/snowfall-plugin-updated/" target="_blank">Jason Brown</a> &#8212; can come to help.</p><p><a href="http://javascriptly.com/wp-content/uploads/2009/12/snow-fall-in-picture.png" rel="lightbox"><img src="http://javascriptly.com/wp-content/uploads/2009/12/snow-fall-in-picture-500x378.png" alt="" title="snow-fall-in-picture" width="500" height="378" class="aligncenter size-medium wp-image-141" /></a></p><ul><li><strong><a href="http://javascriptly.com/examples/jquery-snowfall/">View Live Demo</a></strong></li><li><strong><a href="http://javascriptly.com/examples/jquery-snowfall/snowfall.jquery.zip">Download Plugin</a></strong></li></ul><p><span id="more-62"></span></p><p style="text-align: justify;">Just include the plugin along with the latest version of jQuery (1.3.2 currently) and initiate it as the following code</p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#snow_window'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">snowfall</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
		flakeCount <span style="color: #339933;">:</span> <span style="color: #CC0000;">50</span><span style="color: #339933;">,</span>
		flakeColor <span style="color: #339933;">:</span> <span style="color: #3366CC;">'#ffffff'</span><span style="color: #339933;">,</span>
		flakeIndex<span style="color: #339933;">:</span> <span style="color: #CC0000;">999999</span><span style="color: #339933;">,</span>
		minSize <span style="color: #339933;">:</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span>
		maxSize <span style="color: #339933;">:</span> <span style="color: #CC0000;">4</span><span style="color: #339933;">,</span>
		minSpeed <span style="color: #339933;">:</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">,</span>
		maxSpeed <span style="color: #339933;">:</span> <span style="color: #CC0000;">5</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div><p style="text-align: justify;">where &#8220;<em>snow_window</em>&#8221; is the ID of target DIV in which snowflakes will fly. You can define number of snowflakes, their color, min/max sizes (just do not set too big sizes or they would look unnatural) and falling speed as parameters (<em>flakeCount</em>, <em>flakeColor</em> etc) in the initializing code.</p><p style="text-align: justify;">Of course, you can set the snowfall effect to the whole web page with</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">snowfall</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p style="text-align: justify;"><strong>Tip:</strong> It won&#8217;t work properly with fixed positioning and you must explicitly set the target DIV with &#8220;<em>position: relative</em>&#8221; or you&#8217;ll see snow falling on top corner of the page instead.</p><p style="text-align: justify;">I hope you enjoy this Christmas and can surprise your friends with the snowfall effect.</p><div id="crp_related"><h2>Related Posts:</h2><ul><li><a href="http://javascriptly.com/2009/12/best-ie6-png-fixes/" rel="bookmark">Best IE6 “PNG Alpha-Transparency” Fixes</a></li><li><a href="http://javascriptly.com/2008/09/quick-useful-jquery-plugins/" rel="bookmark">Quick & Useful jQuery Plugins</a></li><li><a href="http://javascriptly.com/2009/12/firequery-an-introduction/" rel="bookmark">FireQuery - An Introduction</a></li></ul></div>]]></content:encoded> <wfw:commentRss>http://javascriptly.com/2009/12/something-for-christmas-snowfall-in-picture/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>corMVC: An jQuery-based MVC Framework</title><link>http://javascriptly.com/2009/12/coremvc-an-jquery-based-mvc-framework/</link> <comments>http://javascriptly.com/2009/12/coremvc-an-jquery-based-mvc-framework/#comments</comments> <pubDate>Tue, 22 Dec 2009 10:16:28 +0000</pubDate> <dc:creator>Jimmy Vu</dc:creator> <category><![CDATA[jQuery]]></category> <category><![CDATA[Solution]]></category> <category><![CDATA[framework]]></category> <category><![CDATA[MVC]]></category><guid isPermaLink="false">http://javascriptly.com/?p=58</guid> <description><![CDATA[<p style="text-align: justify;">I know quite a few JavaScript MVC frameworks out there but <strong><a href="http://www.bennadel.com/resources/projects/cormvc/demo/index.htm#/" target="_blank">corMVC</a></strong> is what makes me exited at most for a few reasons.</p><p style="text-align: justify;"><strong>corMVC</strong> stands for &#8220;<strong>c</strong>lient-<strong>o</strong>nly-<strong>r</strong>equired&#8221; <strong>M</strong>odel-<strong>V</strong>iew-<strong>C</strong>ontroller and that means it does not depend on&#8230;</p>]]></description> <content:encoded><![CDATA[<p style="text-align: justify;">I know quite a few JavaScript MVC frameworks out there but <strong><a href="http://www.bennadel.com/resources/projects/cormvc/demo/index.htm#/" target="_blank">corMVC</a></strong> is what makes me exited at most for a few reasons.</p><p style="text-align: justify;"><strong>corMVC</strong> stands for &#8220;<strong>c</strong>lient-<strong>o</strong>nly-<strong>r</strong>equired&#8221; <strong>M</strong>odel-<strong>V</strong>iew-<strong>C</strong>ontroller and that means it does not depend on specific server-side technology. In case you want to demo something, it would be perfect if everything can be done on client side. Of course, you can save changes or load data from server (via Model) as the general illustration below.</p><div id="attachment_59" class="wp-caption alignnone" style="width: 510px"><a href="http://javascriptly.com/wp-content/uploads/2009/12/cormvc-overview.png" rel="lightbox"><img src="http://javascriptly.com/wp-content/uploads/2009/12/cormvc-overview-500x238.png" alt="corMVC Overview" title="cormvc-overview" width="500" height="238" class="size-medium wp-image-59" /></a><p class="wp-caption-text">corMVC Overview</p></div><p style="text-align: justify;">Not like other JavaScript MVC solutions, <strong>corMVC</strong> is very simple and has very small footprint. It also does not require you to build the application using scaffolding or any other command-line utilities.</p><p><span id="more-58"></span></p><p style="text-align: justify;">The whole framework is actually a 19KB JavaScript file (not minified yet) named <em>Application.js<strong>,</strong></em> you&#8217;ll have to define models, views and controllers by yourself following the guidelines. It&#8217;s not hard especially for those who are familiar with modern MVC frameworks like Rails, Django or CakePHP.</p><p style="text-align: justify;">Running application built on <strong>corMVC</strong>, you&#8217;ll have almost the same impression of running a server-side MVC application for the URIs (after the hash, however) are changed based on actions. The following diagram is about how the framework detects URL changes and handles events accordingly.</p><p><a href="http://javascriptly.com/wp-content/uploads/2009/12/mvc-workflow.png" rel="lightbox"><img src="http://javascriptly.com/wp-content/uploads/2009/12/mvc-workflow-500x462.png" alt="" title="mvc-workflow" width="500" height="462" class="alignnone size-medium wp-image-60" /></a></p><p style="text-align: justify;">To get an overview of how the framework works and the interaction of model-view-controller we are going to examine <a href="http://www.bennadel.com/resources/presentations/jquery2/demo/#/" target="_blank">the demo application</a> called &#8220;<strong>Contacts</strong>&#8221; provided by <a href="http://www.bennadel.com/" target="_blank">Ben Nadel</a> &#8212; the author of <strong>corMVC</strong>. The app, as its name tells, is a contact manager that has all basic functionalities like Search, View, Add and Delete contact info on a single web page.</p><div id="attachment_61" class="wp-caption alignnone" style="width: 510px"><a href="http://www.bennadel.com/resources/presentations/jquery2/demo/#/contacts" target="_blank"><img src="http://javascriptly.com/wp-content/uploads/2009/12/contacts-app-ui-500x290.png" alt="MVC Contacts application" title="contacts-app-ui" width="500" height="290" class="size-medium wp-image-61" /></a><p class="wp-caption-text">MVC Contacts application</p></div><p style="text-align: justify;">Let&#8217;s look at definition of a &#8220;contact&#8221; model in &#8220;<em>contact.js</em>&#8221; file.</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
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// Add model to the application.</span>
window.<span style="color: #660066;">application</span>.<span style="color: #660066;">addModel</span><span style="color: #009900;">&#40;</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: #339933;">,</span> application <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// I am the contact class.</span>
	<span style="color: #003366; font-weight: bold;">function</span> Contact<span style="color: #009900;">&#40;</span> id<span style="color: #339933;">,</span> <span style="color: #000066;">name</span><span style="color: #339933;">,</span> phone<span style="color: #339933;">,</span> email <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">id</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>id <span style="color: #339933;">||</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #000066;">name</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066;">name</span> <span style="color: #339933;">||</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">phone</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>phone <span style="color: #339933;">||</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">email</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>email <span style="color: #339933;">||</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// I validate the contact instance.</span>
	Contact.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">validate</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;">// For now, we are just goint to validate TRUE on the client and let</span>
		<span style="color: #006600; font-style: italic;">// the full validation happen on the model peristence.</span>
		<span style="color: #000066; font-weight: bold;">return</span><span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	<span style="color: #006600; font-style: italic;">// ----------------------------------------------------------------------- //</span>
	<span style="color: #006600; font-style: italic;">// ----------------------------------------------------------------------- //</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// Return a new model class.</span>
	<span style="color: #000066; font-weight: bold;">return</span><span style="color: #009900;">&#40;</span> Contact <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span> jQuery<span style="color: #339933;">,</span> window.<span style="color: #660066;">application</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div><p style="text-align: justify;">The code define a contact class with a few properties like ID, Name, Phone# and E-mail address and return the class as a model that will be used by Controllers/Views.</p><p style="text-align: justify;">The controller is more interesting and it&#8217;s not too difficult to understand though.</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
82
83
84
85
86
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// Add a controller to the application.</span>
window.<span style="color: #660066;">application</span>.<span style="color: #660066;">addController</span><span style="color: #009900;">&#40;</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: #339933;">,</span> application <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// I am the controller class.</span>
	<span style="color: #003366; font-weight: bold;">function</span> Controller<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;">// Route URL events to the controller's event handlers.</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">route</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;/&quot;</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">index</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">route</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;/contacts/&quot;</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">index</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">route</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;/contacts/add/&quot;</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">addContact</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">route</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;/contacts/edit/:id&quot;</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">editContact</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">route</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;/contacts/delete/:id&quot;</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">deleteContact</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">// Set default properties.</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">currentView</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">contactListView</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">contactFormView</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// Extend the core application controller (required).</span>
	Controller.<span style="color: #660066;">prototype</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> application.<span style="color: #660066;">Controller</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	<span style="color: #006600; font-style: italic;">// I initialize the controller. I get called once the application starts</span>
	<span style="color: #006600; font-style: italic;">// running. At that point, the DOM is available and all the other model</span>
	<span style="color: #006600; font-style: italic;">// and view classes will have been added to the system.</span>
	Controller.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">init</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: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">contactListView</span> <span style="color: #339933;">=</span> application.<span style="color: #660066;">getView</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;ContactList&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">contactFormView</span> <span style="color: #339933;">=</span> application.<span style="color: #660066;">getView</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;ContactForm&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	<span style="color: #006600; font-style: italic;">// I am the add event for this controller.</span>
	Controller.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">addContact</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> event <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #006600; font-style: italic;">// Show the form view.</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">showView</span><span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">contactFormView</span><span style="color: #339933;">,</span> event <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	<span style="color: #006600; font-style: italic;">// I am the edit event for this controller.</span>
	Controller.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">editContact</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> event<span style="color: #339933;">,</span> id <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #006600; font-style: italic;">// Show the form view.</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">showView</span><span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">contactFormView</span><span style="color: #339933;">,</span> event <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	<span style="color: #006600; font-style: italic;">// I am the delete event for this controller.</span>
	Controller.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">deleteContact</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> event<span style="color: #339933;">,</span> id <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #006600; font-style: italic;">// Delete the contact.</span>
		application.<span style="color: #660066;">getModel</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;ContactService&quot;</span> <span style="color: #009900;">&#41;</span>.<span style="color: #660066;">deleteContact</span><span style="color: #009900;">&#40;</span>
			id<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>
				application.<span style="color: #660066;">relocateTo</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;contacts&quot;</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: #339933;">;</span>
&nbsp;
&nbsp;
	<span style="color: #006600; font-style: italic;">// I am the default event for this controller.</span>
	Controller.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">index</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> event <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #006600; font-style: italic;">// Show the list view.</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">showView</span><span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">contactListView</span><span style="color: #339933;">,</span> event <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	<span style="color: #006600; font-style: italic;">// I show the given view; but first, I hide any existing view.</span>
	Controller.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">showView</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> view<span style="color: #339933;">,</span> event <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #006600; font-style: italic;">// Check to see if there is a current view. If so, then hide it.</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">currentView</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">currentView</span>.<span style="color: #660066;">hideView</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">currentView</span>.<span style="color: #660066;">hideView</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">// Show the given view.</span>
		view.<span style="color: #660066;">showView</span><span style="color: #009900;">&#40;</span> event.<span style="color: #660066;">parameters</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">// Store the given view as the current view.</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">currentView</span> <span style="color: #339933;">=</span> view<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	<span style="color: #006600; font-style: italic;">// ----------------------------------------------------------------------- //</span>
	<span style="color: #006600; font-style: italic;">// ----------------------------------------------------------------------- //</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// Return a new contoller instance.</span>
	<span style="color: #000066; font-weight: bold;">return</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">new</span> Controller<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span> jQuery<span style="color: #339933;">,</span> window.<span style="color: #660066;">application</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div><p style="text-align: justify;">Basically, the controller defines routes for events associated with handlers like <em>addContact</em>, <em>editContact</em>, <em>deleteContact</em>. In most of cases, the handlers are to show appropriated views or to send events to model for updates.</p><p style="text-align: justify;">There are a number of views required by the app such as &#8220;<em>Contact List</em>&#8220;, &#8220;<em>Contact Form</em>&#8221; and a simple view for progress notification. Here are excerpt codes from &#8220;<em>Contact List</em>&#8221; view that mostly to interact with user and send events to controller if necessary.</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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">&nbsp;
<span style="color: #006600; font-style: italic;">// Add view to the application.</span>
window.<span style="color: #660066;">application</span>.<span style="color: #660066;">addView</span><span style="color: #009900;">&#40;</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: #339933;">,</span> application <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// I am the contact list view class.</span>
	<span style="color: #003366; font-weight: bold;">function</span> ContactList<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">layout</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">searchForm</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">searchCriteria</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">addLink</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">contactList</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">contactTemplate</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	<span style="color: #006600; font-style: italic;">// I initialize the view. I get called once the application starts</span>
	<span style="color: #006600; font-style: italic;">// running. At that point, the DOM is available and all the other model</span>
	<span style="color: #006600; font-style: italic;">// and view classes will have been added to the system.</span>
	ContactList.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">init</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: #003366; font-weight: bold;">var</span> self <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">// Initialize properties.</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">layout</span> <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;#contact-list-layout&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">searchForm</span> <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;#contact-list-header form&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">searchCriteria</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">searchForm</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;input&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">addLink</span> <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;#contact-list-header a&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">contactList</span> <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;#contact-list&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">contactTemplate</span> <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;#contact-list-item-template&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">// Bind the search form submit.</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">searchForm</span>.<span style="color: #660066;">submit</span><span style="color: #009900;">&#40;</span>
			<span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> event <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				<span style="color: #006600; font-style: italic;">// Hand of to the search form handler.</span>
				self.<span style="color: #660066;">searchFormHandler</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #006600; font-style: italic;">// Cancel the default event.</span>
				<span style="color: #000066; font-weight: bold;">return</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">false</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>
&nbsp;
		<span style="color: #006600; font-style: italic;">// Bind the keypress event on the search criteria.</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">searchCriteria</span>.<span style="color: #660066;">keyup</span><span style="color: #009900;">&#40;</span>
			<span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> event <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				<span style="color: #006600; font-style: italic;">// Filter the contact list.</span>
				self.<span style="color: #660066;">filterList</span><span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">value</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>
&nbsp;
		<span style="color: #006600; font-style: italic;">// Bind the keypress event to the search criteria so we can track </span>
		<span style="color: #006600; font-style: italic;">// the use of the special keys presses.</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">searchCriteria</span>.<span style="color: #660066;">keypress</span><span style="color: #009900;">&#40;</span>
			<span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> event <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				<span style="color: #006600; font-style: italic;">// Store the SHIFT and ALT key status of the current click.</span>
				self.<span style="color: #660066;">searchCriteria</span>.<span style="color: #660066;">data</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;shift&quot;</span><span style="color: #339933;">,</span> event.<span style="color: #660066;">shiftKey</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				self.<span style="color: #660066;">searchCriteria</span>.<span style="color: #660066;">data</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;alt&quot;</span><span style="color: #339933;">,</span> event.<span style="color: #660066;">altKey</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>
&nbsp;
		<span style="color: #006600; font-style: italic;">// Bind the list-level clicking (to avoid setting to many </span>
		<span style="color: #006600; font-style: italic;">// event handlers).</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">contactList</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> event <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				<span style="color: #003366; font-weight: bold;">var</span> target <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span> event.<span style="color: #660066;">target</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #006600; font-style: italic;">// Check to see if the target is the &quot;more&quot; link.</span>
				<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>target.<span style="color: #000066; font-weight: bold;">is</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;a.more&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
					<span style="color: #006600; font-style: italic;">// Toggle the list item details.</span>
					self.<span style="color: #660066;">toggleDetails</span><span style="color: #009900;">&#40;</span> target.<span style="color: #660066;">parents</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;li&quot;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
					<span style="color: #006600; font-style: italic;">// Blur the current link.</span>
					target.<span style="color: #000066;">blur</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
					<span style="color: #006600; font-style: italic;">// Prevent default event.</span>
					<span style="color: #000066; font-weight: bold;">return</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">false</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #006600; font-style: italic;">// Check to see if the target is a the &quot;delete&quot; link.</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>target.<span style="color: #000066; font-weight: bold;">is</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;a.delete&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
					<span style="color: #006600; font-style: italic;">// Blur the current link.</span>
					target.<span style="color: #000066;">blur</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
					<span style="color: #006600; font-style: italic;">// Confirm that the user wants to delete the contact.</span>
					<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066;">confirm</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;Delete this contact?&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
						<span style="color: #006600; font-style: italic;">// This is a *hack* that we have to do since jQuery click() </span>
						<span style="color: #006600; font-style: italic;">// event won't trigger the default action of the link.</span>
						application.<span style="color: #660066;">setLocation</span><span style="color: #009900;">&#40;</span> target.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;href&quot;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
					<span style="color: #009900;">&#125;</span>
&nbsp;
					<span style="color: #006600; font-style: italic;">// Return false to cancel default event.</span>
					<span style="color: #000066; font-weight: bold;">return</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">false</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>		
&nbsp;
				<span style="color: #009900;">&#125;</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: #339933;">;</span>
&nbsp;
	....
&nbsp;
	<span style="color: #006600; font-style: italic;">// Return a new view class.</span>
	<span style="color: #000066; font-weight: bold;">return</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">new</span> ContactList<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span> jQuery<span style="color: #339933;">,</span> window.<span style="color: #660066;">application</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div><p style="text-align: justify;">Up till now, you may have had the overall knowledge of the framework and how to create a pure JavaScript MVC application. Yet, to get full understanding of <strong>corMVC</strong>, please see this great <a href="http://www.bennadel.com/resources/presentations/jquery2/video/">video presentation</a> in which Ben Nadel explains why he came to the framework, how the JavaScript/jQuery were used, step-by-step application building etc. (this is a multiple-part video and a bit lengthy but I&#8217;m sure it&#8217;ll pay off.)</p><ul><li><strong><a href="http://www.bennadel.com/resources/presentations/jquery2/code.zip">Download Demo Application Code</a></strong></li></ul><div id="crp_related"><h2>Related Posts:</h2><ul><li><a href="http://javascriptly.com/2008/09/10-alternative-javascript-frameworks/" rel="bookmark">10 Alternative JavaScript Frameworks</a></li><li><a href="http://javascriptly.com/2008/09/chainjs-02-updated-examples/" rel="bookmark">Chain.js v0.2 – Updated Examples</a></li><li><a href="http://javascriptly.com/2008/09/comet-chat-app-meteor-server/" rel="bookmark">Simple Web Chat with Meteor Comet Server</a></li></ul></div>]]></content:encoded> <wfw:commentRss>http://javascriptly.com/2009/12/coremvc-an-jquery-based-mvc-framework/feed/</wfw:commentRss> <slash:comments>5</slash:comments> </item> <item><title>FireQuery &#8211; An Introduction</title><link>http://javascriptly.com/2009/12/firequery-an-introduction/</link> <comments>http://javascriptly.com/2009/12/firequery-an-introduction/#comments</comments> <pubDate>Mon, 21 Dec 2009 06:41:37 +0000</pubDate> <dc:creator>Jimmy Vu</dc:creator> <category><![CDATA[jQuery]]></category> <category><![CDATA[Firebug]]></category> <category><![CDATA[FireQuery]]></category><guid isPermaLink="false">http://javascriptly.com/?p=51</guid> <description><![CDATA[<h2 style="text-align: justify;">Installation</h2><p style="text-align: justify;">FireQuery is an extension of Firebug created by <a href="http://www.binaryage.com/" target="_blank">BinaryAge</a> to help developers to keep track with jQuery expressions, data and collections as expressed on tool <a href="http://firequery.binaryage.com/" target="_blank">website</a>:</p><blockquote><ul><li> Query expressions</li></ul></blockquote><p>&#8230;</p>]]></description> <content:encoded><![CDATA[<h2 style="text-align: justify;">Installation</h2><p style="text-align: justify;">FireQuery is an extension of Firebug created by <a href="http://www.binaryage.com/" target="_blank">BinaryAge</a> to help developers to keep track with jQuery expressions, data and collections as expressed on tool <a href="http://firequery.binaryage.com/" target="_blank">website</a>:</p><blockquote><ul><li> Query expressions are intelligently presented in Firebug Console and DOM inspector</li><li> attached jQuery data are first class citizens</li><li> elements in jQuery collections are highlighted on hover</li><li> jQuerify: enables you to inject jQuery into any web page</li></ul></blockquote><p style="text-align: justify;">You can install the tool from <a href="https://addons.mozilla.org/en-US/firefox/addon/12632" target="_blank">official Mozilla add-on page</a> (it requires Firebug 1.3+ already existed.) One note: You may have to find <a href="https://addons.mozilla.org/en-US/firefox/addons/versions/12632" target="_blank">an older version</a> (v0.3) to make it work with current official Firebug release (v1.4) as my experience on Windows.</p><h2 style="text-align: justify;">In Action</h2><p style="text-align: justify;">After installing the add-on and restarting Firefox, just go to <a href="http://firequery.binaryage.com/test/index.html" target="_blank">the test page</a> to see how FireQuery tracks embedded jQuery data on FireBug&#8217;s &#8220;<strong>HTML</strong>&#8221; tab. The image below illustrates the data embedded in accordance with the jQuery codes to inject them to the page.</p><p><span id="more-51"></span><br /><div id="attachment_53" class="wp-caption alignnone" style="width: 510px"><a href="http://javascriptly.com/wp-content/uploads/2009/12/firequery-embedded-data.png" rel="lightbox"><img class="size-full wp-image-53" title="firequery-embedded-data" src="http://javascriptly.com/wp-content/uploads/2009/12/firequery-embedded-data.png" alt="FireQuery shows embedded data by jQuery" width="500" height="305" /></a><p class="wp-caption-text">FireQuery shows embedded data by jQuery</p></div></p><p style="text-align: justify;">Now, we&#8217;ll dig into cooler features. One of them is the ability to &#8220;jQuerify&#8221; any web page without jQuery support like <a href="http://www.google.com" target="_blank">Google.com</a> for example. This can be done simply by clicking &#8220;<strong>jQuerify</strong>&#8221; button on FireBug&#8217;s &#8220;<strong>Console</strong>&#8221; tab.</p><div id="attachment_54" class="wp-caption alignnone" style="width: 509px"><a href="http://javascriptly.com/wp-content/uploads/2009/12/firequery-jquerify-google-dot-com.png" rel="lightbox"><img class="size-medium wp-image-54" title="firequery-jquerify-google-dot-com" src="http://javascriptly.com/wp-content/uploads/2009/12/firequery-jquerify-google-dot-com-499x319.png" alt="jQuerify Google.com with FireQuery" width="499" height="319" /></a><p class="wp-caption-text">jQuerify Google.com with FireQuery</p></div><p style="text-align: justify;">Wow, now you can execute any jQuery codes in the Google home page. Normally, there is nothing happen when you click on Google logo but you just want it to say hello instead. Paste the following code snippet to Firebug command window and run it.</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#logo'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'click'</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: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Hello, I'm Google!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><div id="attachment_55" class="wp-caption alignnone" style="width: 509px"><a href="http://javascriptly.com/wp-content/uploads/2009/12/firequery-running-jquery-snippet.png" rel="lightbox"><img class="size-medium wp-image-55" title="firequery-running-jquery-snippet" src="http://javascriptly.com/wp-content/uploads/2009/12/firequery-running-jquery-snippet-499x130.png" alt="Running jQuery snippet on Google.com" width="499" height="130" /></a><p class="wp-caption-text">Running jQuery snippet on Google.com</p></div><p style="text-align: justify;">Now, click on Google&#8217;s logo and you&#8217;ll see the alert dialog appears to say hello to you (no surprise) and the FireBug&#8217;s console also shows the jQuery command executed.</p><div id="attachment_57" class="wp-caption alignnone" style="width: 510px"><a href="http://javascriptly.com/wp-content/uploads/2009/12/google-dot-com-saying-hello.png" rel="lightbox"><img class="size-medium wp-image-57" title="google-dot-com-saying-hello" src="http://javascriptly.com/wp-content/uploads/2009/12/google-dot-com-saying-hello-500x292.png" alt="Google.com to say hello" width="500" height="292" /></a><p class="wp-caption-text">Google.com to say hello</p></div><h2>Conclusion</h2><p>FireQuery is a great tool for those who commit to jQuery as main JavaScript library or is going to write a jQuery plug-in. Also, It&#8217;s especially useful for developers, theme designers to see the jQuery&#8217;s data and effects in action without loading the library and writing codes in the templates.</p><div id="crp_related"><h2>Related Posts:</h2><ul><li><a href="http://javascriptly.com/2010/01/why-do-we-need-google-closure/" rel="bookmark">Why Do We Need Google Closure?</a></li><li><a href="http://javascriptly.com/2008/09/javascript-in-google-chrome/" rel="bookmark">JavaScript in Google Chrome Not So That Fast</a></li><li><a href="http://javascriptly.com/2008/09/javascript-to-detect-google-chrome/" rel="bookmark">JavaScript to Detect Google Chrome</a></li></ul></div>]]></content:encoded> <wfw:commentRss>http://javascriptly.com/2009/12/firequery-an-introduction/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>jQuery Code Content Assistance for Eclipse WTP</title><link>http://javascriptly.com/2008/10/jquery-eclipse-wtp/</link> <comments>http://javascriptly.com/2008/10/jquery-eclipse-wtp/#comments</comments> <pubDate>Tue, 14 Oct 2008 03:16:23 +0000</pubDate> <dc:creator>Jimmy Vu</dc:creator> <category><![CDATA[jQuery]]></category> <category><![CDATA[Eclipse]]></category> <category><![CDATA[WTP]]></category><guid isPermaLink="false">http://javascriptly.com/?p=48</guid> <description><![CDATA[<p style="text-align: justify;">JavaScript code content assistance built in Eclipse WTP does very good job that I found even better than the same functionality in some commercial solutions, however, jQuery&#8217;s syntax is not supported (no surprise). That&#8217;s why jQueryWTP tool comes&#8230;</p>]]></description> <content:encoded><![CDATA[<p style="text-align: justify;">JavaScript code content assistance built in Eclipse WTP does very good job that I found even better than the same functionality in some commercial solutions, however, jQuery&#8217;s syntax is not supported (no surprise). That&#8217;s why jQueryWTP tool comes to help adding jQuery support to Eclipse WTP (and Eclipse PDT, MyEclipse which are based on WTP too.)</p><p style="text-align: justify;">This is not an Eclipse plugin instead a tool to patch the existing plugin and inject jQuery&#8217;s syntax support into it. First <a href="http://sourceforge.net/project/showfiles.php?group_id=202840&amp;package_id=241633&amp;release_id=631407">download the tool from SourceForce</a>; it&#8217;s a Java executable JAR so you can double-click to it or run it from command line:</p><div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">java <span style="color: #660033;">-jar</span> jqueryWTP0.2forJQuery1.2.6.jar</pre></div></div><p style="text-align: justify;">Now browse to plugin file</p><p style="text-align: justify;"><code>org.eclipse.wst.javascript.ui_xxxxxxx.jar</code></p><p style="text-align: justify;">and set output directory to generate the patch. Please backup the original file and set output directory different from source one.</p><p>&nbsp;</p><p style="text-align: justify;"><img class="alignnone size-full wp-image-49" title="jquery-eclipse-wtp-ui" src="http://javascriptly.com/wp-content/uploads/2008/10/jquery-eclipse-wtp-ui.gif" alt="jquery-eclipse-wtp-ui.gif" width="492" height="138" /></p><p>&nbsp;</p><p style="text-align: justify;">Select &#8220;<strong>Generate</strong>&#8221; button to get the patched file then copy over original file. Start Eclipse and open a HTML or script file to see jQuery&#8217;s functions listed on code assistance like image below.</p><p><span id="more-48"></span></p><p>&nbsp;</p><p style="text-align: justify;"><img class="alignnone size-full wp-image-50" title="jquery-eclipse-wtp-code-assistance" src="http://javascriptly.com/wp-content/uploads/2008/10/jquery-eclipse-wtp-code-assistance.gif" alt="wtp-code-assistance.gif" width="500" height="429" /></p><p>&nbsp;</p><p style="text-align: justify;">Find more info about jQueryWTP and donate for project <a href="http://www.langtags.com/jquerywtp/index.html" target="_blank">here</a>.</p><div id="crp_related"><h2>Related Posts:</h2><ul><li><a href="http://javascriptly.com/2010/01/why-do-we-need-google-closure/" rel="bookmark">Why Do We Need Google Closure?</a></li><li><a href="http://javascriptly.com/2009/12/best-ie6-png-fixes/" rel="bookmark">Best IE6 “PNG Alpha-Transparency” Fixes</a></li><li><a href="http://javascriptly.com/2009/12/firequery-an-introduction/" rel="bookmark">FireQuery - An Introduction</a></li></ul></div>]]></content:encoded> <wfw:commentRss>http://javascriptly.com/2008/10/jquery-eclipse-wtp/feed/</wfw:commentRss> <slash:comments>13</slash:comments> </item> <item><title>JavaScript to Detect Google Chrome</title><link>http://javascriptly.com/2008/09/javascript-to-detect-google-chrome/</link> <comments>http://javascriptly.com/2008/09/javascript-to-detect-google-chrome/#comments</comments> <pubDate>Fri, 05 Sep 2008 07:04:22 +0000</pubDate> <dc:creator>Jimmy Vu</dc:creator> <category><![CDATA[jQuery]]></category> <category><![CDATA[Solution]]></category> <category><![CDATA[Google Chrome]]></category><guid isPermaLink="false">http://javascriptly.com/?p=26</guid> <description><![CDATA[<p style="text-align: justify;">The negative side of having a new (and promisingly become popular) browser, no matter how good it can be, is you&#8217;ll have to test your web apps with it among many others.</p><p style="text-align: justify;">Probably, the first step&#8230;</p>]]></description> <content:encoded><![CDATA[<p style="text-align: justify;">The negative side of having a new (and promisingly become popular) browser, no matter how good it can be, is you&#8217;ll have to test your web apps with it among many others.</p><p style="text-align: justify;">Probably, the first step is to detect the browser from JavaScript code by parsing browser&#8217;s user agent, and here is what of Google Chrome.</p><div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US)
AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.2.149.27 Safari/525.13</pre></div></div><p style="text-align: justify;">I guess old JavaScript codes can mistakenly tell it Safari like when running the code snippet below using JQuery&#8217;s browser utility.</p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span>$.<span style="color: #660066;">browser</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">,</span> val<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	 $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&lt;div&gt;&quot;</span> <span style="color: #339933;">+</span> i <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; : &lt;span&gt;&quot;</span> <span style="color: #339933;">+</span> val <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;&lt;/span&gt;&lt;/div&gt;&quot;</span><span style="color: #009900;">&#41;</span>
		.<span style="color: #660066;">appendTo</span><span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">body</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></pre></td></tr></table></div><p><img class="size-full wp-image-27" title="jquery-browser-detection" src="http://javascriptly.com/wp-content/uploads/2008/09/jquery-browser-detection.gif" alt="" width="279" height="206" /></p><p style="text-align: justify;">It may be no problem until you find something wrong when your apps running on Chrome only. So, here is the code line to detect Chrome generally:</p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> is_chrome <span style="color: #339933;">=</span> <span style="color: #009966; font-style: italic;">/chrome/</span>.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span> navigator.<span style="color: #660066;">userAgent</span>.<span style="color: #660066;">toLowerCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div><p style="text-align: justify;">We&#8217;ll have to change the JQuery browser utility to support Chrome detection as follows:</p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> userAgent <span style="color: #339933;">=</span> navigator.<span style="color: #660066;">userAgent</span>.<span style="color: #660066;">toLowerCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Figure out what browser is being used</span>
jQuery.<span style="color: #660066;">browser</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
	version<span style="color: #339933;">:</span> <span style="color: #009900;">&#40;</span>userAgent.<span style="color: #660066;">match</span><span style="color: #009900;">&#40;</span> <span style="color: #009966; font-style: italic;">/.+(?:rv|it|ra|ie|me)[\/: ]([\d.]+)/</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
	chrome<span style="color: #339933;">:</span> <span style="color: #009966; font-style: italic;">/chrome/</span>.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span> userAgent <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	safari<span style="color: #339933;">:</span> <span style="color: #009966; font-style: italic;">/webkit/</span>.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span> userAgent <span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!/</span>chrome<span style="color: #339933;">/</span>.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span> userAgent <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	opera<span style="color: #339933;">:</span> <span style="color: #009966; font-style: italic;">/opera/</span>.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span> userAgent <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	msie<span style="color: #339933;">:</span> <span style="color: #009966; font-style: italic;">/msie/</span>.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span> userAgent <span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!/</span>opera<span style="color: #339933;">/</span>.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span> userAgent <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	mozilla<span style="color: #339933;">:</span> <span style="color: #009966; font-style: italic;">/mozilla/</span>.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span> userAgent <span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!/</span><span style="color: #009900;">&#40;</span>compatible<span style="color: #339933;">|</span>webkit<span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span>.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span> userAgent <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></td></tr></table></div><p style="text-align: justify;">Now, correct result shows on test screen:</p><p><img class="alignnone size-full wp-image-28" title="jquery-browser-detection2" src="http://javascriptly.com/wp-content/uploads/2008/09/jquery-browser-detection2.gif" alt="" width="280" height="234" /></p><p style="text-align: justify;">Just one notice: Current version of JQuery (1.2.6) is treating Chrome as if it was Safari and basically no serious problem has been found yet. Modifying browser detection can cause the lib render pages/elements incorrectly for it has no knowledge of Chrome&#8217;s rendering engine. To keep compatibility, you can change line 7 back to:</p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>7
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">	safari<span style="color: #339933;">:</span> <span style="color: #009966; font-style: italic;">/webkit/</span>.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span> userAgent <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span></pre></td></tr></table></div><p><span id="more-26"></span></p><p>But in this case the browser will be detected as both Chrome and Safari &#8212; not nice solution, I accept.</p><p style="text-align: justify;">Anyway, it&#8217;s very likely that JQuery and other JavaScript frameworks will include Chrome to browser list for detection in next versions.</p><div id="crp_related"><h2>Related Posts:</h2><ul><li><a href="http://javascriptly.com/2008/09/javascript-in-google-chrome/" rel="bookmark">JavaScript in Google Chrome Not So That Fast</a></li><li><a href="http://javascriptly.com/2008/09/lightningdom-to-balance-dom-vs-innerhtml/" rel="bookmark">LightningDOM to Balance DOM vs innerHTML</a></li><li><a href="http://javascriptly.com/2008/08/turn-on-javascript-jit-in-firefox-31/" rel="bookmark">Turn on JavaScript JIT in Firefox 3.1</a></li></ul></div>]]></content:encoded> <wfw:commentRss>http://javascriptly.com/2008/09/javascript-to-detect-google-chrome/feed/</wfw:commentRss> <slash:comments>4</slash:comments> </item> <item><title>JQuery Site Re-redesign</title><link>http://javascriptly.com/2008/08/jquery-site-re-redesign/</link> <comments>http://javascriptly.com/2008/08/jquery-site-re-redesign/#comments</comments> <pubDate>Thu, 28 Aug 2008 18:00:14 +0000</pubDate> <dc:creator>Jimmy Vu</dc:creator> <category><![CDATA[Development News]]></category> <category><![CDATA[jQuery]]></category><guid isPermaLink="false">http://javascriptly.com/?p=15</guid> <description><![CDATA[<p style="text-align: justify;">The redesign of JQuery DOT COM site recently <a href="http://jquery.com/blog/2008/08/29/jquerycom-site-redesign/">gained a huge amount of comments</a>; unfortunately most of them were not positive. Developers who have come along with the library feel unhappy with new slogan &#8220;<strong>Be a Javascript</strong>&#8230;</p>]]></description> <content:encoded><![CDATA[<p style="text-align: justify;">The redesign of JQuery DOT COM site recently <a href="http://jquery.com/blog/2008/08/29/jquerycom-site-redesign/">gained a huge amount of comments</a>; unfortunately most of them were not positive. Developers who have come along with the library feel unhappy with new slogan &#8220;<strong>Be a Javascript Rockstar</strong>&#8221; that, said, makes them look unprofessional.</p><p><img class="aligncenter size-full wp-image-16" title="Jquery Site Redesign" src="http://javascriptly.com/wp-content/uploads/2008/08/jquerycom1.png" alt="" width="362" height="410" /></p><p style="text-align: left;">Response to <a href="http://ajaxian.com/archives/jquerycom-redesigned-with-a-rock-star">a post on Ajaxian</a>, <em>shypht</em> commented:</p><blockquote><p style="text-align: justify;">Hate to say it, but image is everything. If I was trying to sell my manager on using jQuery, Prototype, Mootools or Dojo, and sent them to those sites, I think based on look alone jQuery would be at a disadvantage. &#8220;Write less, do more&#8221; is a great slogan, &#8220;Be a Javascript Rockstar&#8221;, not so much.</p><p>Strikes me as being an amateur, and more focused on flashy effects than functionality. I love jQuery, it&#8217;s helped me loads on my most recent project, but that header just makes me cringe a bit on the inside when I see it.</p></blockquote><p style="text-align: left;">While <em>Glen Lipka</em> described his feeling in more colorful words on <a href="http://commadot.com/the-ux-of-the-new-jquery-website/">his blog post</a>:</p><blockquote><p style="text-align: justify;">Truthfully, I feel alienated by it.  It doesn&#8217;t resonate with me.  It makes me feel old and lame.  My hair is not long and flowing. The rockstar isn&#8217;t me.  jQuery is me.  It&#8217;s different.</p></blockquote><p style="text-align: justify;">Obviously John Resig &amp; team did listen to the community and <a href="http://jquery.com/blog/2008/08/29/death-to-javascript-rock-stars/">decided to kill the &#8220;JavaScript RockStar&#8221;</a> on JQuery site.</p><p><span id="more-15"></span><br /> <img class="aligncenter size-full wp-image-17" title="JQuery Site Without The Rockstar" src="http://javascriptly.com/wp-content/uploads/2008/08/jquerycom2.png" alt="" width="410" height="505" /></p><p style="text-align: justify;">Apart from the new glossy UI, the best of JQuey site&#8217;s new design is to organize documentation for the library itself separately from hundreds of plugins and extentions. The new search functionality allows user to fine tune query to specific documents or keywords.</p><p style="text-align: justify;">Well, however, please keep in mind that nobody want to be a JavaScript rocktar! <img src='http://javascriptly.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p><div id="crp_related"><h2>Related Posts:</h2><ul><li><a href="http://javascriptly.com/2008/09/zend-16-comes-dojo-firephp-integrated/" rel="bookmark">Zend Framework 1.6 Comes with Dojo and FirePHP Integrated</a></li><li><a href="http://javascriptly.com/2008/08/yui-30-changes-from-the-root/" rel="bookmark">YUI 3.0 – Changes From the Root</a></li><li><a href="http://javascriptly.com/2008/09/comet-chat-app-meteor-server/" rel="bookmark">Simple Web Chat with Meteor Comet Server</a></li></ul></div>]]></content:encoded> <wfw:commentRss>http://javascriptly.com/2008/08/jquery-site-re-redesign/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: basic (User agent is rejected)
Database Caching using disk: basic

Served from: javascriptly.com @ 2012-05-18 02:38:02 -->
