<?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>jesal gadhia &#187; javascript</title>
	<atom:link href="http://jesal.us/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://jesal.us</link>
	<description></description>
	<lastBuildDate>Thu, 14 Jul 2011 18:51:24 +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>Parse Twitter &amp; Facebook feeds with jQuery</title>
		<link>http://jesal.us/2011/01/parse-twitter-facebook-feeds-with-jquery/</link>
		<comments>http://jesal.us/2011/01/parse-twitter-facebook-feeds-with-jquery/#comments</comments>
		<pubDate>Thu, 20 Jan 2011 22:29:26 +0000</pubDate>
		<dc:creator>J</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://jesal.us/?p=269</guid>
		<description><![CDATA[This post simply demonstrates how to parse Twitter and Facebook feeds using jQuery. I&#8217;m utilizing a JavaScript equivalent of C# prototype methods which I had talked about in one of my earlier posts. Also, you&#8217;ll note that I&#8217;m using two different date/time jQuery plugins to make Twitter and Facebook date parsing a little easier. One [...]]]></description>
			<content:encoded><![CDATA[<p>This post simply demonstrates how to parse Twitter and Facebook feeds using jQuery. I&#8217;m utilizing a JavaScript equivalent of C# prototype methods which I had talked about in one of my <a href="http://jesal.us/2009/05/how-to-parse-twitter-usernames-hashtags-and-urls-in-c-30/">earlier posts</a>. Also, you&#8217;ll note that I&#8217;m using two different date/time jQuery plugins to make Twitter and Facebook date parsing a little easier. One of them is <a href="http://timeago.yarp.com/">timeago</a> and the other one is <a href="http://blog.stevenlevithan.com/archives/date-time-format">dateFormat</a>. Although I had to put a condition to check if its IE as the dateFormat function was not playing nice with IE. Rest everything is pretty straight forward.</p>
<pre>
$(function () {
	$.ajax({
		url: 'http://api.twitter.com/1/statuses/user_timeline.json?screen_name=jesalg&#038;trim_user=1&#038;count=5&#038;include_rts=1&#038;callback=?',
		dataType: 'json',
		success: displayTwitterFeed
	});
	$.ajax({
		url: 'https://graph.facebook.com/calistolabs/feed?limit=5&#038;access_token=XXXXXXXXXXXX|XXXXXXXXXXXXX|XXXXXXXXXXXXXXX&#038;callback=?', //Replace with your own access token
		dataType: 'json',
		success: displayFacebookFeed
	});
});

function displayTwitterFeed(result) {
	var outputTemplate = "&lt;p&gt;{0}&lt;br /&gt; &lt;small&gt;&lt;a href=\"{1}\"&gt;{2} via {3}&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;";
	$.each(result, function (i, item) {
		var tweet = item.text.parseURL().parseUsername().parseHashtag();
		var createdAt = $.browser.msie ? item.created_at : $.timeago(dateFormat(item.created_at, "isoUtcDateTime"));
		var source = item.source;
		var tweetURL = "http://twitter.com/CalistoLabs/status/" + item.id_str;
		$("#TwitterFeed").append(outputTemplate.format(tweet, tweetURL, createdAt, source));
	});
}
function displayFacebookFeed(result) {
	var outputTemplate = "&lt;p&gt;&lt;strong&gt;&lt;a href=\"{0}\"&gt;{1}&lt;/a&gt;&lt;/strong&gt; {2}&lt;br /&gt;&lt;small&gt;{3}&lt;/small&gt;&lt;/p&gt;";
	$.each(result.data, function (i, item) {
		var username = item.from.name;
		var pageURL = "http://www.facebook.com/" + item.from.name.replace(/ /g, '');
		var date = $.browser.msie ? item.created_time : dateFormat(item.created_time.replace("+0000", ""), "dddd, mmmm dS, yyyy 'at' h:MM TT");
		var body = item.message;
		if (!body) {
			body = "&lt;a href='" + item.link + "'&gt;" + item.name + "&lt;/a&gt;&lt;br/&gt;" + item.description;
		}
		$("#FacebookFeed").append(outputTemplate.format(pageURL, username, body, date));
	});
}
String.prototype.parseURL = function () {
	return this.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&#038;\?\/.=]+/g, function (url) {
		return url.link(url);
	});
};
String.prototype.parseUsername = function () {
	return this.replace(/[@]+[A-Za-z0-9-_]+/g, function (u) {
		var username = u.replace("@", "")
		return u.link("http://twitter.com/" + username);
	});
};
String.prototype.parseHashtag = function () {
	return this.replace(/[#]+[A-Za-z0-9-_]+/g, function (t) {
		var tag = t.replace("#", "%23")
		return t.link("http://search.twitter.com/search?q=" + tag);
	});
};
String.prototype.format = function () {
	var s = this,
        i = arguments.length;
	while (i--) {
		s = s.replace(new RegExp('\\{' + i + '\\}', 'gm'), arguments[i]);
	}
	return s;
};
</pre>
<p><strong>Edit:</strong></p>
<p>As of Friday June 3rd Facebook Graph API now requires a valid app or user access_token to access feed data: <a href="https://developers.facebook.com/blog/post/509/">https://developers.facebook.com/blog/post/509/</a> You can get your access_token from from the <a href="https://developers.facebook.com/tools/explorer/?method=GET&#038;path=calistolabs%2Ffeed%3Flimit%3D5%26callback%3D%3F">Graph API Explorer</a> and append it to your URL as a query string parameter as shown above.</p>
]]></content:encoded>
			<wfw:commentRss>http://jesal.us/2011/01/parse-twitter-facebook-feeds-with-jquery/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Cross-Domain Communication with IFrames</title>
		<link>http://jesal.us/2010/12/cross-domain-communication-with-iframes/</link>
		<comments>http://jesal.us/2010/12/cross-domain-communication-with-iframes/#comments</comments>
		<pubDate>Tue, 21 Dec 2010 21:18:29 +0000</pubDate>
		<dc:creator>J</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://jesal.us/?p=259</guid>
		<description><![CDATA[Recently I encountered a situation where I had to communicate between an iframe located on a different domain and its parent. Due to the &#8220;same origin policy&#8221;, a security concept for browsers, which only permits scripts running on pages originating from the same site, this was not possible to do right out of the box. [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I encountered a situation where I had to communicate between an iframe located on a different domain and its parent. Due to the &#8220;same origin policy&#8221;, a security concept for browsers, which only permits scripts running on pages originating from the same site, this was not possible to do right out of the box. After some Googling, I learned there were a couple of workarounds for it. You could use dynamic script tags included from external domains aka JSONP or use postMessage or the IFrame URL technique. All of these solutions are quite hackish or complicated and not 100% secure. Luckily I found this nice little library called <a href="http://easyxdm.net/">easyXDM</a>.</p>
<blockquote><p>At the core easyXDM provides a transport stack capable of passing string based messages between two windows, a consumer (the main document) and a provider (a document included using an iframe). It does this by using one of several available techniques, always selecting the most efficient one for the current browser. For all implementations the transport stack offers bi-directionality, reliability, queueing and sender-verification.</p></blockquote>
<p>Here&#8217;s a small test I created. It calls a function to scroll the page up from the remote site. Local and remote directories represent the servers where the files will be residing on.</p>
<p><strong>local/methods.html</strong></p>
<pre>
&lt;!doctype html&gt;
&lt;html&gt;
    &lt;head&gt;
        &lt;title&gt;easyXDM&lt;/title&gt;
        &lt;script type="text/javascript" src="easyXDM.js"&gt;
        &lt;/script&gt;
        &lt;script type="text/javascript"&gt;
            var REMOTE = (function(){
                var remote = location.href;
                switch (location.host) {
                    case "jesal.us":
                        location.href = remote.replace("provider", "consumer");
                        break;
                    case "calistolabs.com":
                        remote = remote.replace("calistolabs.com", "jesal.us");
                        break;
                }
                return remote.substring(0, remote.lastIndexOf("/"));
            }());
            var remote = new easyXDM.Rpc(/** The channel configuration */{
                /**
                 * Register the url to hash.html, this must be an absolute path
                 * or a path relative to the root.
                 * @field
                 */
                local: "name.html",
                /**
                 * Register the url to the remote interface
                 * @field
                 */
                remote: REMOTE + "/../remote/remotemethods.html",
                remoteHelper: REMOTE + "/../remote/name.html",
                /**
                 * Register the DOMElement that the generated IFrame should be inserted into
                 */
                container: "embedded",
                props: {
                    style: {
                        border: "2px dotted red",
                        height: "1200px"
                    }
                }
            }, /** The interface configuration */ {
                local: {
                    triggerScrollUp: function(){
						scroll(0,0);
                    }
                }
            });
        &lt;/script&gt;
        &lt;style type="text/css"&gt;
            #embedded iframe {
                width: 100%;
                height: 100%;
            }
        &lt;/style&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;script type="text/javascript"&gt;
            document.write("Domain: " + location.host);
        &lt;/script&gt;
            &lt;br/&gt;
			&lt;br&gt;
			&lt;br&gt;
			&lt;br&gt;
			&lt;br&gt;
			&lt;br&gt;
			&lt;br&gt;
			&lt;br&gt;
			&lt;br&gt;
			&lt;br&gt;
			&lt;br&gt;
			&lt;br&gt;
			&lt;br&gt;
			&lt;br&gt;
			&lt;br&gt;
			&lt;br&gt;
			&lt;br&gt;
			&lt;br&gt;
			&lt;br&gt;
			&lt;div id="embedded"&gt;
			&lt;/div&gt;
    &lt;/body&gt;
&lt;/html&gt;
</pre>
<p><strong>remote/remotemethods.html</strong></p>
<pre>
&lt;!doctype html&gt;
&lt;html&gt;
    &lt;head&gt;
        &lt;title&gt;easyXDM&lt;/title&gt;
        &lt;script type="text/javascript" src="easyXDM.js"&gt;
        &lt;/script&gt;
        &lt;script type="text/javascript"&gt;
            var remote = new easyXDM.Rpc(/** The channel configuration*/{
                local: "name.html",
				onReady: function(){
                    /**
                     * Call a method on the other side
                     */
                    remote.triggerScrollUp();
                }
            }, /** The configuration */ {
                remote: {
                    triggerScrollUp: {}
                }
            });
        &lt;/script&gt;
    &lt;/head&gt;

    &lt;body&gt;
        &lt;script type="text/javascript"&gt;
            document.write("Domain: " + location.host);
        &lt;/script&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;input type="button" onclick="remote.triggerScrollUp();" value="Call to triggerScrollUp on mother ship"/&gt;
    &lt;/body&gt;
&lt;/html&gt;
</pre>
<p><strong>remote/name.html</strong></p>
<pre>
&lt;!doctype html&gt;
&lt;html&gt;
    &lt;head&gt;
        &lt;title&gt;&lt;/title&gt;
        &lt;meta http-equiv="CACHE-CONTROL" content="PUBLIC"/&gt;
        &lt;meta http-equiv="EXPIRES" content="Sat, 01 Jan 2050 00:00:00 GMT"/&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;script type="text/javascript"&gt;

        function sendMessage(message, url){
            window.setTimeout(function(){
                window.name = message;
                location.href = url + "," + encodeURIComponent(location.protocol + "//" + location.host + location.pathname);
            }, 0);
        }

        if (location.hash) {
            if (location.hash.substring(1, 2) === "_") {
                var channel, url, hash = location.href.substring(location.href.indexOf("#") + 3), indexOf = hash.indexOf(",");
                if (indexOf == -1) {
                    channel = hash;
                }
                else {
                    channel = hash.substring(0, indexOf);
                    url = decodeURIComponent(hash.substring(indexOf + 1));
                }
                switch (location.hash.substring(2, 3)) {
                    case "2":
                        // NameTransport local
                        window.parent.parent.easyXDM.Fn.get(channel)(window.name);
                        location.href = url + "#_4" + channel + ",";
                        break;
                    case "3":
                        // NameTransport remote
                        var guest = window.parent.frames["easyXDM_" + channel + "_provider"];
                        if (!guest) {
                            throw new Error("unable to reference window");
                        }
                        guest.easyXDM.Fn.get(channel)(window.name);
                        location.href = url + "#_4" + channel + ",";
                        break;
                    case "4":
                        // NameTransport idle
                        var fn = window.parent.easyXDM.Fn.get(channel + "_load");
                        if (fn) {
                            fn();
                        }
                        break;
                }
            }
        }
        &lt;/script&gt;
    &lt;/body&gt;
&lt;/html&gt;
</pre>
<p>You can find lot more examples and documentation on easyXDM&#8217;s <a href="http://easyxdm.net/wp/category/examples/">website</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://jesal.us/2010/12/cross-domain-communication-with-iframes/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>CSS Browser Selector</title>
		<link>http://jesal.us/2007/09/css-browser-selector/</link>
		<comments>http://jesal.us/2007/09/css-browser-selector/#comments</comments>
		<pubDate>Sun, 23 Sep 2007 04:04:45 +0000</pubDate>
		<dc:creator>J</dc:creator>
				<category><![CDATA[browser]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://jesal.us/blog/2007/09/22/css-browser-selector/</guid>
		<description><![CDATA[CSS Browser Selector is a lifesaver when it comes to creating cross-browser compatible layouts with CSS. Check it out here &#8211; http://rafael.adm.br/css_browser_selector/ Although its something people should avoid overusing, its an invaluable tool for fixing some of those stubborn CSS inconsistencies between different browsers.]]></description>
			<content:encoded><![CDATA[<p>CSS Browser Selector is a lifesaver when it comes to creating cross-browser compatible layouts with CSS. </p>
<p>Check it out here &#8211; <a href="http://rafael.adm.br/css_browser_selector/">http://rafael.adm.br/css_browser_selector/</a></p>
<p>Although its something people should avoid overusing, its an invaluable tool for fixing some of those stubborn CSS inconsistencies between different browsers.  </p>
]]></content:encoded>
			<wfw:commentRss>http://jesal.us/2007/09/css-browser-selector/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

