<?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>{ Code: Impossible } &#187; jquery</title>
	<atom:link href="http://codeimpossible.com/tag/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://codeimpossible.com</link>
	<description>this = HowI.Roll();</description>
	<lastBuildDate>Thu, 29 Jul 2010 02:58:45 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Using jQuery on an Iframe</title>
		<link>http://codeimpossible.com/2010/03/04/using-jquery-on-an-iframe/</link>
		<comments>http://codeimpossible.com/2010/03/04/using-jquery-on-an-iframe/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 01:10:39 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[jquery-extensions]]></category>

		<guid isPermaLink="false">http://codeimpossible.com/?p=803</guid>
		<description><![CDATA[The other day I had to alter the stylesheets in a child IFrame when a user selected an item from a drop-down. My first draft was pretty ugly, it ivolved getting the DOM from the child IFrame (by getting it&#8217;s contentWindow or contentDocument property) then getting the  of the DOM and looping over all [...]]]></description>
			<content:encoded><![CDATA[<p>The other day I had to alter the stylesheets in a child IFrame when a user selected an item from a drop-down. My first draft was pretty ugly, it ivolved getting the DOM from the child IFrame (by getting it&#8217;s <a href="http://www-archive.mozilla.org/docs/dom/domref/dom_frame_ref5.html">contentWindow</a> or <a href="http://www-archive.mozilla.org/docs/dom/domref/dom_frame_ref4.html">contentDocument</a> property) then getting the <head> of the DOM and looping over all the child items&#8230; yuck!</p>
<p>I coded up this jQuery extension method which will return a jQuery-wrapped DOM instance for any of the matched IFrames.</p>
<pre class="prettyprint"><code>
(function($) {
    $.fn.extend({
        dom: function () {
            var $this = $(this);
            var getDom = function(o) {
                if( !o || (!o.contentWindow &#038;&#038; !o.contentDocument) ) {
                    return null;
                }

                var doc = (o.contentWindow || o.contentDocument);

                return doc.document || doc;
            };

            var dom = getDom($this[0]);

            return dom === null ? $this : $(dom);
        }
    });
})(jQuery);
</code></pre>
<p>So with this, getting the styles for a child IFrame is as easy as:</p>
<pre class="prettyprint"><code>
$('iframe').dom().find('head link').each(function(index, item) {
    alert(item.href);
});
</code></pre>
<p><em>Unfortunately, this code will only work if your IFrame is hosting content that is on the same domain as its parent.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://codeimpossible.com/2010/03/04/using-jquery-on-an-iframe/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Solving &#8220;$(document).ready is not a function&#8221; and other problems</title>
		<link>http://codeimpossible.com/2010/01/13/solving-document-ready-is-not-a-function-and-other-problems/</link>
		<comments>http://codeimpossible.com/2010/01/13/solving-document-ready-is-not-a-function-and-other-problems/#comments</comments>
		<pubDate>Thu, 14 Jan 2010 01:29:29 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[code-style]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://codeimpossible.com/?p=767</guid>
		<description><![CDATA[Has this ever happened to you: you&#8217;ve been working on a customer&#8217;s site, writing some really awesome jQuery flashy, fadey, scrolly, interactivey thing, you deploy it, and everything is awesome. The customer rejoices and the customer&#8217;s customers rejoice. Rejoicing is had by everyone. 
And then you get an email one day:

&#8220;Everything is broken. We&#8217;ve kidnapped [...]]]></description>
			<content:encoded><![CDATA[<p>Has this ever happened to you: you&#8217;ve been working on a customer&#8217;s site, writing some really awesome jQuery flashy, fadey, scrolly, interactivey thing, you deploy it, and everything is awesome. The customer rejoices and the customer&#8217;s customers rejoice. Rejoicing is had by everyone. </p>
<p>And then you get an email one day:</p>
<blockquote><p>
&#8220;Everything is broken. We&#8217;ve kidnapped your dog. Fix our site or you&#8217;ll never see Spartacus again.&#8221;</p></blockquote>
<p>And before you have time to wonder why you ever named your dog &#8220;Spartacus&#8221; to begin with (i mean <strong>come. on.</strong>), you&#8217;re off in debug hell. You load the site and see all sorts of weird errors:</p>
<p><code>“$().ready is not a function”</code></p>
<p><code>“$(document) doesn’t support this property or method”</code></p>
<p>Or my personal favorite: </p>
<p><code>“null is null or not an object”</code></p>
<p>You open up FireFox, activate FireBug, load the console, and type “alert($)”, press run, and instead of seeing the expected jQuery function:</p>
<pre class="prettyprint"><code>
function (E, F) {
    return new (o.fn.init)(E, F);
}
</code></pre>
<p>You instead get:</p>
<pre class="prettyprint"><code>
function $(element) {
    if (arguments.length > 1) {
        for (var i = 0, elements = [], length = arguments.length; i < length; i++) {
            elements.push($(arguments[i]));
        }
        return elements;
    }
    if (Object.isString(element)) {
        element = document.getElementById(element);
    }
    return Element.extend(element);
}
</code></pre>
<p>Or even:</p>
<pre class="prettyprint"><code>
function $(id) {
    return document.getElementById(id);
}
</code></pre>
<p><strong>DOH!</strong> Looks like another javascript library has been loaded and has overwritten the <code>$()</code> shortcut for jQuery. Woe is I. Why can’t we all just get along?!? </p>
<p>Well, we can’t stop people from including their favorite javascript libraries, but what we can do is prevent our code from suffering as a result. We’ll need a nice, big beefy, bodyguard to make sure our code isn’t messed with while it’s out clubbing with Prototype, Scriptaculous or even MooTools (who invited <em>him</em>??!?).</p>
<p>Here’s what our bodyguard function will look like</p>
<pre class="prettyprint"><code>
( function($) {

} ) ( jQuery );
</code></pre>
<p>So what this does is call our anonymous function and pass the <code>jQuery</code> object. This will scope ‘$’ to within our little function so we won’t step on anyone else’s toes (and they won’t bump into us while we’re on the dance floor and spill our drink everywhere). Okay, I think I've taken the clubbing metaphor far enough.</p>
<p>Basically this will allow our code to run and use the <code>$</code> shortcut for JQuery as if it were loaded without any of these other libraries on the page. </p>
<p>Here is what the completed code would look like:</p>
<pre class="prettyprint"><code>
&lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js" type="text/javascript"&gt;
&lt;/script&gt;

&lt;script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js" type="text/javascript">
&lt;/script&gt;
&lt;script src="http://ajax.googleapis.com/ajax/libs/scriptaculous/1.8.3/scriptaculous.js" type="text/javascript">
&lt;/script&gt;

&lt;script type="text/javascript"&gt;
( function($) {
    // we can now rely on $ within the safety of our “bodyguard” function
    $(document).ready( function() { alert("nyah nyah! I’m able to use '$'!!!!");  } );
} ) ( jQuery );

//this will fail
$(document).ready( function() { alert('fail?'); } );
&lt;/script&gt;
</code></pre>
<p>I love using this simple self-calling anonymous function style when working with jQuery because it saves me from typing <code>jQuery()</code>, which really does look a lot more ugly than using the <code>$()</code> shortcut. It also protects my code from any scoping issues and lets the code function normally when <a href="http://docs.jquery.com/Core/jQuery.noConflict">jQuery is put into no conflict mode</a>. </p>
<p>My opinion, if you're doing work in jQuery on sites that you don't control 100%, you should be using this method to protect your code and your clients.</p>
<p><strong>Updated: changed link for jquery to use 1.4.1 at the google CDN (tsk, tsk, tsk I was using the googlecode.com link)</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://codeimpossible.com/2010/01/13/solving-document-ready-is-not-a-function-and-other-problems/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Jquery + MVC = Web Dev Heaven</title>
		<link>http://codeimpossible.com/2008/10/02/jquery_plus_mvc_equals_web_dev_heaven/</link>
		<comments>http://codeimpossible.com/2008/10/02/jquery_plus_mvc_equals_web_dev_heaven/#comments</comments>
		<pubDate>Fri, 03 Oct 2008 02:43:35 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://pistalwhipped.wordpress.com/?p=216</guid>
		<description><![CDATA[So Jquery is going to become part of Asp.net MVC. First off, congrats to the Jquery team. They&#8217;ve put out a really awesome product. Second, congrats to Microsoft for catching every .Net developer completely by surprise, proving, again, that they are listening to the community.
I never really got into the microsoft javascript libraries that shipped [...]]]></description>
			<content:encoded><![CDATA[<p>So <a href="http://www.hanselman.com/blog/jQueryToShipWithASPNETMVCAndVisualStudio.aspx" target="_blank">Jquery is going to become part of Asp.net MVC</a>. First off, congrats to <a href="http://jquery.com/" target="_blank">the Jquery team</a>. They&#8217;ve put out a really awesome product. Second, congrats to Microsoft for catching every .Net developer completely by surprise, proving, again, that they are listening to the community.</p>
<p>I never really got into the microsoft javascript libraries that shipped with the ajax control toolkit because I found that I could do things much faster using external javascript libraries .</p>
<p>It will be interesting to see what Microsoft contributes back to the Jquery community in later updates to the ASP MVC product.</p>
]]></content:encoded>
			<wfw:commentRss>http://codeimpossible.com/2008/10/02/jquery_plus_mvc_equals_web_dev_heaven/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
