<?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>djsipe.com &#187; jQuery</title>
	<atom:link href="http://blog.djsipe.com/tag/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.djsipe.com</link>
	<description>Web Development</description>
	<lastBuildDate>Sat, 31 Dec 2011 16:25:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Why I Don&#8217;t Like ExtJS</title>
		<link>http://blog.djsipe.com/2011/07/07/why-i-dont-like-extjs/</link>
		<comments>http://blog.djsipe.com/2011/07/07/why-i-dont-like-extjs/#comments</comments>
		<pubDate>Fri, 08 Jul 2011 00:14:22 +0000</pubDate>
		<dc:creator>DJ</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[ExtJS]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[progressive enhancement]]></category>

		<guid isPermaLink="false">http://www.djsipe.com/?p=59</guid>
		<description><![CDATA[From time to time at work, I feel like the only person in the world who doesn&#8217;t have a big soft spot in their heart for ExtJS.  Each time it&#8217;s vaunted as the Swiss Army Knife of UI development I can&#8217;t help but object.  I will say that ExtJS is a top-notch library with tons [...]]]></description>
			<content:encoded><![CDATA[<p>From time to time at work, I feel like the only person in the world who doesn&#8217;t have a big soft spot in their heart for <a title="Why would you need this?" href="http://dev.sencha.com/deploy/ext-4.0.2a/examples/desktop/desktop.html" target="_blank">ExtJS</a>.  Each time it&#8217;s vaunted as the Swiss Army Knife of UI development I can&#8217;t help but object.  I will say that ExtJS is a top-notch library with tons of amazing features, but what I take issue with is when it&#8217;s implemented as a replacement for traditional UI design and markup.</p>
<p>When you are writing your UI entirely in JavaScript, something is wrong.  Not only are you pushing the browser to generate a daunting amount of HTML through code, you&#8217;re also completely depending on JavaScript for anything to work on your site.  It&#8217;s <a href="http://www.alistapart.com/articles/understandingprogressiveenhancement" target="_blank">Progressive Enhancement</a> cryptonite.</p>
<p>To be fair, there are some reasons why you might use ExtJS for your UI:  You can get projects up and running much faster and in some groups where there isn&#8217;t a strong designer you can actually improve the consistency and look and feel of your applications.  Outside of these scenarios, I much prefer libraries like<a href="http://jquery.com/" target="_blank"> jQuery</a> that focus on building upon the existing markup of the page rather than writing the markup for the page.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.djsipe.com/2011/07/07/why-i-dont-like-extjs/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Doing Pop-Ups the Right Way with jQuery</title>
		<link>http://blog.djsipe.com/2008/07/04/doing-pop-ups-the-right-way-with-jquery/</link>
		<comments>http://blog.djsipe.com/2008/07/04/doing-pop-ups-the-right-way-with-jquery/#comments</comments>
		<pubDate>Fri, 04 Jul 2008 18:57:17 +0000</pubDate>
		<dc:creator>DJ</dc:creator>
				<category><![CDATA[Front End]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[popup]]></category>

		<guid isPermaLink="false">http://www.djsipe.com/2008/07/04/doing-pop-ups-the-right-way-with-jquery/</guid>
		<description><![CDATA[We&#8217;ve all seen them, links that look like they go somewhere but when you roll your mouse over them you see something like &#8220;javascript:popupWindow();&#8221; in the status bar instead of a URL. Putting JavaScript into the href of links is just a horrible idea as it severely degrades the accessibility of your site (and ticks [...]]]></description>
			<content:encoded><![CDATA[<p>We&#8217;ve all seen them, links that look like they go somewhere but when you roll your mouse over them you see something like &#8220;javascript:popupWindow();&#8221; in the status bar instead of a URL. Putting JavaScript into the href of links is just a horrible idea as it severely degrades the accessibility of your site (and ticks off people like me who want to see where they&#8217;re about to be taken before they click). But rather than just complain about it, I thought I&#8217;d put together some code to help us all avoid this situation all together.</p>
<p>The ideal solution is one that will work for the greatest number of users. Given that, we need a solution that will use <a href="http://en.wikipedia.org/wiki/Unobtrusive_JavaScript" target="_blank">unobtrusive JavaScript</a> to enhance a standard HTML page with customizable popup windows&#8212;rather than rely solely on JavaScript. Since straight-up HTML supports opening links in new windows by <a href="http://wp.netscape.com/eng/mozilla/2.0/relnotes/demo/target.html" target="_blank">adding a target attribute to the link</a>, we start off with a link that looks like this:</p>
<pre class="brush: xml; title: ; notranslate">&lt;a href=&quot;/popup.html&quot; target=&quot;popupWindow&quot; class=&quot;popup&quot;&gt;Open new window&lt;/a&gt;</pre>
<p>Using this as a starting point, the next step is to create a simple popup window function that wraps the standard DOM method: <a href="http://developer.mozilla.org/en/docs/DOM:window.open" target="_blank">window.open()</a>.  I use this function to do a few things:</p>
<ol>
<li>Enforce default parameters rather than depend on the browser&#8217;s defaults</li>
<li>Provide defaults that favor greater accessibility, ie: scrollbars and resize</li>
<li>Allow a <a href="http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Guide:Literals#Object_Literals" target="_blank">JavaScript object literal</a> to be used instead of the standard configuration string</li>
</ol>
<p>Here&#8217;s the function:</p>
<pre class="brush: jscript; title: ; notranslate">
// Create a namespace for our utilities
var UTIL = UTIL || {};
UTIL.popup = UTIL.popup || {};

/**
 * Open popup window
 *
 * Opens a popup window using as little as a URL. An optional params object can
 * be passed.
 *
 * @param {String} href
 * @param {Object} params
 * @return {WindowObjectReference}
 */
UTIL.popup.open = function (href, params) {
	// Defaults (don't leave it to the browser)
	var defaultParams = {
		&quot;width&quot;:       &quot;800&quot;,   // Window width
		&quot;height&quot;:      &quot;600&quot;,   // Window height
		&quot;top&quot;:         &quot;0&quot;,     // Y offset (in pixels) from top of screen
		&quot;left&quot;:        &quot;0&quot;,     // X offset (in pixels) from left side of screen
		&quot;directories&quot;: &quot;no&quot;,    // Show directories/Links bar?
		&quot;location&quot;:    &quot;no&quot;,    // Show location/address bar?
		&quot;resizeable&quot;:  &quot;yes&quot;,   // Make the window resizable?
		&quot;menubar&quot;:     &quot;no&quot;,    // Show the menu bar?
		&quot;toolbar&quot;:     &quot;no&quot;,    // Show the tool (Back button etc.) bar?
		&quot;scrollbars&quot;:  &quot;yes&quot;,   // Show scrollbars?
		&quot;status&quot;:      &quot;no&quot;     // Show the status bar?
	};

	var windowName = params[&quot;windowName&quot;] || &quot;new_window&quot;;

	var i, useParams = &quot;&quot;;

	// Override defaults with custom values while we construct the params string
	for (i in defaultParams) {
		useParams += (useParams === &quot;&quot;) ? &quot;&quot; : &quot;,&quot;;
		useParams += i + &quot;=&quot;;
		useParams += params[i] || defaultParams[i];
	}

	return window.open(href, windowName, useParams);
};
</pre>
<p>Admittedly, this part isn&#8217;t rocket science and could probably be done in a more elegant way, but it&#8217;s needed to really open things up for the next part.  Now we get to the fun stuff.  Using <a title="jQuery" href="http://jquery.com/" target="_blank">jQuery</a>, we search the document for all links that have a CSS class of &#8220;popup&#8221;.  For each one we find, we add an <a href="http://developer.mozilla.org/en/docs/onclick" target="_blank">onClick handler</a>that disables the browser&#8217;s default onClick behavior for links and then opens up a popup window using the links href attribute.  Here&#8217;s the code:</p>
<pre class="brush: jscript; title: ; notranslate">
$(function(){ // Run this code when the document's done loading

    // Apply this code to each link with class=&quot;popup&quot;
    $(&quot;a.popup&quot;).each(function (i){

        // Add an onClick behavior to this link
        $(this).click(function(event) {

            // Prevent the browser's default onClick handler
            event.preventDefault();

            // Grab parameters using jQuery's data() method
            var params = $(this).data(&quot;popup&quot;) || {};

            // Use the target attribute as the window name
            if ($(this).attr(&quot;target&quot;)) {
               params.windowName = $(this).attr(&quot;target&quot;);
            }

            // Pop up the window
            var windowObject = UTIL.popup.open(this.href, params);

            // Save the window object for other code to use
            $(this).data(&quot;windowObject&quot;, windowObject);
        });
    });
});
</pre>
<p>One of the great features of jQuery that we utilize here is the <a title="jQuery's data() method" href="http://docs.jquery.com/Core/data" target="_blank">data method</a>.  This allows us to attach data to DOM elements without corrupting the HTML with non-standard attributes or tags.  Using jQuery&#8217;s ability to locate DOM elements using CSS selectors, we can bind the custom configuration object (used in our new popup function) to the links themselves.  Then, when a link is clicked, it can read it&#8217;s popup configuration and pass it to the popup window function.  In this way, we can keep our HTML standards compliant <em>and </em>completely separate from our JavaScript code.</p>
<p>Putting it all together, we can create an HTML page like this:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01//EN&quot; &quot;http://www.w3.org/TR/html4/strict.dtd&quot;&gt;
&lt;html&gt;
	&lt;head&gt;
		&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot; /&gt;
		&lt;title&gt;Popup Window Test&lt;/title&gt;
		&lt;script type=&quot;text/javascript&quot; src=&quot;jquery-1.2.6.pack.js&quot;&gt;&lt;/script&gt;
		&lt;script type=&quot;text/javascript&quot; src=&quot;utils.js&quot;&gt;&lt;/script&gt;
	&lt;/head&gt;
	&lt;body&gt;
		&lt;ul&gt;
			&lt;li&gt;
				This link uses defaults:
				&lt;a href=&quot;http://google.com&quot; target=&quot;google&quot; class=&quot;popup&quot;&gt;Google.com&lt;/a&gt;
			&lt;/li&gt;
			&lt;li&gt;
				This link uses custom parameters:
				&lt;a id=&quot;custom-popup&quot; href=&quot;http://yahoo.com&quot; target=&quot;yahoo&quot; class=&quot;popup&quot;&gt;Yahoo.com&lt;/a&gt;
			&lt;/li&gt;
		&lt;/ul&gt;
		&lt;script type=&quot;text/javascript&quot;&gt;

			// Add custom pop-up properties to the second link
			$(&quot;a#custom-popup&quot;).data(&quot;popup&quot;, {width:400,height:400, top:200, left:200});

		&lt;/script&gt;
	&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>If you would like to download this example, you can get it <a href="https://com.djsipe.s3.amazonaws.com/demos/popup-test.zip">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.djsipe.com/2008/07/04/doing-pop-ups-the-right-way-with-jquery/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>

