<?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>Juliana Peña &#187; Programming</title>
	<atom:link href="http://julianapena.com/tag/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://julianapena.com</link>
	<description></description>
	<lastBuildDate>Mon, 07 May 2012 20:01:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Updating the badge in a Windows 8 JavaScript App</title>
		<link>http://julianapena.com/2011/09/updating-the-badge-in-a-windows-8-javascript-metro-app/</link>
		<comments>http://julianapena.com/2011/09/updating-the-badge-in-a-windows-8-javascript-metro-app/#comments</comments>
		<pubDate>Sun, 18 Sep 2011 09:07:29 +0000</pubDate>
		<dc:creator>Juliana Peña</dc:creator>
				<category><![CDATA[Windows 8]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[windows 8]]></category>

		<guid isPermaLink="false">http://julianapena.com/?p=1025</guid>
		<description><![CDATA[Windows 8 apps can have notification badges in the tiles. It&#8217;s easy to update the badge, but it&#8217;s still not well documented, so here is a small snippet to show you how it&#8217;s done: var Notifications = Windows.UI.Notifications; var updater = Notifications.BadgeUpdateManager.createBadgeUpdaterForApplication(); var xml = Notifications.BadgeUpdateManager.getTemplateContent( Notifications.BadgeTemplateType.badgeNumber ); xml.getElementsByTagName('badge')[0].setAttribute('value', 5); var notification = Notifications.BadgeNotification(xml); updater.update(notification); <a href="http://julianapena.com/2011/09/updating-the-badge-in-a-windows-8-javascript-metro-app/"> read more <span class="meta-nav">&#187;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Windows 8 apps can have notification badges in the tiles. It&#8217;s easy to update the badge, but it&#8217;s still not well documented, so here is a small snippet to show you how it&#8217;s done:</p>
<pre class="brush: js">var Notifications = Windows.UI.Notifications;
var updater = Notifications.BadgeUpdateManager.createBadgeUpdaterForApplication();
var xml = Notifications.BadgeUpdateManager.getTemplateContent(
    Notifications.BadgeTemplateType.badgeNumber
);

xml.getElementsByTagName('badge')[0].setAttribute('value', 5);

var notification = Notifications.BadgeNotification(xml);
updater.update(notification);</pre>
<p>Replace the 5 in line 7 with the number of your choice. The end result looks like this:</p>
<p style="text-align: center;"><img class="size-full wp-image-1032 aligncenter" title="badge" src="http://julianapena.com/wp-content/uploads/2011/09/badge.png" alt="Badge update example" width="509" height="256" /></p>
<p>More info on badge updates is available in the <a href="http://msdn.microsoft.com/en-us/library/windows/apps/br208661(v=VS.85).aspx">Windows.UI.Notifications namespace of the WinRT</a> and the <a href="http://msdn.microsoft.com/en-us/library/windows/apps/br212851(v=VS.85).aspx">Badge Update XML Schema</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://julianapena.com/2011/09/updating-the-badge-in-a-windows-8-javascript-metro-app/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Gchat now available in the Marketplace!</title>
		<link>http://julianapena.com/2011/09/gchat/</link>
		<comments>http://julianapena.com/2011/09/gchat/#comments</comments>
		<pubDate>Sat, 03 Sep 2011 23:36:31 +0000</pubDate>
		<dc:creator>Juliana Peña</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Windows Phone]]></category>
		<category><![CDATA[apps]]></category>
		<category><![CDATA[windows phone]]></category>

		<guid isPermaLink="false">http://julianapena.com/?p=1018</guid>
		<description><![CDATA[   Gchat, the awesome Google Talk client Luis and I built for Windows Phone, is now available in the Marketplace! We’ve been working on it for a long time and we’d love to know what you think. Click the button below to go to the Marketplace now and download it! We hope you enjoy using <a href="http://julianapena.com/2011/09/gchat/"> read more <span class="meta-nav">&#187;</span></a>]]></description>
			<content:encoded><![CDATA[<p align="center"><a href="http://julianapena.com/wp-content/uploads/2011/09/screen1.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="screen1" src="http://julianapena.com/wp-content/uploads/2011/09/screen1_thumb.png" alt="screen1" width="180" height="300" border="0" /></a> <a href="http://julianapena.com/wp-content/uploads/2011/09/screen4.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="screen4" src="http://julianapena.com/wp-content/uploads/2011/09/screen4_thumb.png" alt="screen4" width="180" height="300" border="0" /></a> <a href="http://julianapena.com/wp-content/uploads/2011/09/screen5.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="screen5" src="http://julianapena.com/wp-content/uploads/2011/09/screen5_thumb.png" alt="screen5" width="180" height="300" border="0" /></a></p>
<p><a href="https://github.com/lhchavez/gtalkchat">Gchat</a>, the awesome Google Talk client <a href="http://lhchavez.com/">Luis</a> and I built for Windows Phone, is now available in the Marketplace! We’ve been working on it for a long time and we’d love to know what you think.</p>
<p>Click the button below to go to the Marketplace now and download it!</p>
<p align="center"><a href="http://www.microsoft.com/windowsphone/s?appid=f9da43e4-9bbb-4a6d-842d-629bd6bdc84b"><img title="Download Gchat" src="http://julianapena.com/wp-content/uploads/c76feed4bd9b_7F78/Download-EN-Med.png" alt="Download Gchat" width="165" height="54" border="0" /></a></p>
<p>We hope you enjoy using Gchat! If you find a bug or want to suggest a new feature, please <a href="https://github.com/lhchavez/gtalkchat/issues">report it</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://julianapena.com/2011/09/gchat/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>StickyTiles: A Windows Phone app to pin sticky notes!</title>
		<link>http://julianapena.com/2011/09/stickytiles/</link>
		<comments>http://julianapena.com/2011/09/stickytiles/#comments</comments>
		<pubDate>Fri, 02 Sep 2011 17:46:28 +0000</pubDate>
		<dc:creator>Juliana Peña</dc:creator>
				<category><![CDATA[Windows Phone]]></category>
		<category><![CDATA[apps]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://julianapena.com/?p=1001</guid>
		<description><![CDATA[StickyTiles is a simple Windows Phone Mango app that lets you pin short sticky notes to your start screen! Choose text, color, and back side of the sticky tile. Pin all the sticky tiles you want. StickyTiles is open source, fork the code at GitHub! StickyTiles is now available in the Windows Phone Marketplace and <a href="http://julianapena.com/2011/09/stickytiles/"> read more <span class="meta-nav">&#187;</span></a>]]></description>
			<content:encoded><![CDATA[<p align="center"><a href="http://julianapena.com/wp-content/uploads/2011/09/chromescreen1.png"><img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="chromescreen1" src="http://julianapena.com/wp-content/uploads/2011/09/chromescreen1_thumb.png" alt="chromescreen1" width="176" height="320" border="0" /></a><a href="http://julianapena.com/wp-content/uploads/2011/09/chromescreen2.png"><img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="chromescreen2" src="http://julianapena.com/wp-content/uploads/2011/09/chromescreen2_thumb.png" alt="chromescreen2" width="176" height="320" border="0" /></a><a href="http://julianapena.com/wp-content/uploads/2011/09/chromescreen3.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="chromescreen3" src="http://julianapena.com/wp-content/uploads/2011/09/chromescreen3_thumb.png" alt="chromescreen3" width="176" height="320" border="0" /></a></p>
<p>StickyTiles is a simple Windows Phone Mango app that lets you pin short sticky notes to your start screen! Choose text, color, and back side of the sticky tile. Pin all the sticky tiles you want.</p>
<p>StickyTiles is open source, <a href="https://github.com/limitedmage/StickyTiles">fork the code at GitHub!</a></p>
<p align="left">StickyTiles is now available in the Windows Phone Marketplace and is compatible with all Mango phones. Click the button below to download it.</p>
<p><a href="http://windowsphone.com/s?appid=e082297e-5d5c-4685-9e7a-21c6c3c76b71"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; margin-right: auto; padding-top: 0px; border: 0px;" title="Download StickyTiles" src="http://julianapena.com/wp-content/uploads/2011/09/wp7_English_278x92_blue.png" alt="Download StickyTiles" width="240" height="79" border="0" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://julianapena.com/2011/09/stickytiles/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>Sierpinski&#8217;s Tetrahedron!</title>
		<link>http://julianapena.com/2011/08/sierpinskis-tetrahedron/</link>
		<comments>http://julianapena.com/2011/08/sierpinskis-tetrahedron/#comments</comments>
		<pubDate>Wed, 24 Aug 2011 16:52:51 +0000</pubDate>
		<dc:creator>Juliana Peña</dc:creator>
				<category><![CDATA[Code snippet]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[graphics]]></category>
		<category><![CDATA[opengl]]></category>
		<category><![CDATA[school]]></category>

		<guid isPermaLink="false">http://julianapena.com/2011/08/sierpinskis-tetrahedron/</guid>
		<description><![CDATA[For my Computer Graphics class we had to do Sierpinski’s Triangle in OpenGL. As optional extra credit, we could expand it to 3D. I took up the challenge, and this was the result. It’s not perfect, but it looks really cool! As always, grab the code at Gist. Comments, forks and improvements are appreciated. :)]]></description>
			<content:encoded><![CDATA[<p><a href="http://julianapena.com/wp-content/uploads/2011/08/pyr.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px; padding-top: 0px" title="pyr" border="0" alt="pyr" src="http://julianapena.com/wp-content/uploads/2011/08/pyr_thumb.png" width="396" height="409" /></a></p>
<p>For my Computer Graphics class we had to do Sierpinski’s Triangle in OpenGL. As optional extra credit, we could expand it to 3D. I took up the challenge, and this was the result. It’s not perfect, but it looks really cool!</p>
<p>As always, <a href="https://gist.github.com/1168494">grab the code at Gist</a>. Comments, forks and improvements are appreciated. :)</p>
]]></content:encoded>
			<wfw:commentRss>http://julianapena.com/2011/08/sierpinskis-tetrahedron/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>New versions of Postponer and ChromeMilk released</title>
		<link>http://julianapena.com/2010/03/new-versions-of-postponer-and-chromemilk-released/</link>
		<comments>http://julianapena.com/2010/03/new-versions-of-postponer-and-chromemilk-released/#comments</comments>
		<pubDate>Fri, 12 Mar 2010 01:23:01 +0000</pubDate>
		<dc:creator>Juliana Peña</dc:creator>
				<category><![CDATA[Chrome]]></category>
		<category><![CDATA[extension]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://julianapena.com/2010/03/new-versions-of-postponer-and-chromemilk-released/</guid>
		<description><![CDATA[I’ve released new versions of my Chrome extensions Postponer and ChromeMilk. Postponer 0.4 add a one-click add mode to Adder and customizable popup size to Manager, as well as a few bug fixes. ChromeMilk 0.9.6 features a brand new icon as well as numerous bug fixes. As always, you can get them from the Chrome <a href="http://julianapena.com/2010/03/new-versions-of-postponer-and-chromemilk-released/"> read more <span class="meta-nav">&#187;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://julianapena.com/wp-content/uploads/NewversionsofPostponerandChromeMilkrelea_11090/screengmail.png"><img style="display: inline; margin-left: 0px; margin-right: 0px; border: 0px;" title="screen-gmail" src="http://julianapena.com/wp-content/uploads/NewversionsofPostponerandChromeMilkrelea_11090/screengmail_thumb.png" border="0" alt="screen-gmail" width="225" height="235" align="right" /></a>I’ve released new versions of my Chrome extensions <a href="http://julianapena.com/projects/chrome-postponer/">Postponer</a> and <a href="http://julianapena.com/projects/chrome-rtm/">ChromeMilk</a>.</p>
<p>Postponer 0.4 add a one-click add mode to Adder and customizable popup size to Manager, as well as a few bug fixes.</p>
<p>ChromeMilk 0.9.6 features a brand new icon as well as numerous bug fixes.</p>
<p>As always, you can get them from the Chrome extensions gallery:</p>
<p><a href="https://chrome.google.com/extensions/detail/pggmlienkcoenodbjpkbidlmmedgonai">Postponer Adder</a></p>
<p><a href="https://chrome.google.com/extensions/detail/mmfblgljgoaokhbcjnddgcnaielcpjeb">Postponer Manager</a></p>
<p><a href="https://chrome.google.com/extensions/detail/chieodlkhimccchlojdmiondhiggkhmf">ChromeMilk</a></p>
<p>Thanks to everyone that reported bugs, and a special thanks to <a href="http://aconitehikaru.deviantart.com/">Camila González</a> for the new icon in ChromeMilk.</p>
<p>Please let me know of any bugs, issues, feature requests or just general comments you may have. Enjoy the extensions!</p>
]]></content:encoded>
			<wfw:commentRss>http://julianapena.com/2010/03/new-versions-of-postponer-and-chromemilk-released/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Code snippet: Get a weather condition using Python and Google Weather API</title>
		<link>http://julianapena.com/2010/02/code-snippet-get-a-weather-condition-using-python-and-google-weather-api/</link>
		<comments>http://julianapena.com/2010/02/code-snippet-get-a-weather-condition-using-python-and-google-weather-api/#comments</comments>
		<pubDate>Fri, 19 Feb 2010 17:09:17 +0000</pubDate>
		<dc:creator>Juliana Peña</dc:creator>
				<category><![CDATA[Code snippet]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://julianapena.com/2010/02/code-snippet-get-a-weather-condition-using-python-and-google-weather-api/</guid>
		<description><![CDATA[Here’s a simple Python code snippet for finding the weather condition of any given city using Google’s Weather API. It’s also published on GitHub if you want to clone it. import urllib2 def getWeather(city): #create google weather api url url = "http://www.google.com/ig/api?weather=" + urllib2.quote(city) try: # open google weather api url f = urllib2.urlopen(url) except: <a href="http://julianapena.com/2010/02/code-snippet-get-a-weather-condition-using-python-and-google-weather-api/"> read more <span class="meta-nav">&#187;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Here’s a simple Python code snippet for finding the weather condition of any given city using Google’s Weather API. It’s also <a href="http://gist.github.com/308912">published on GitHub</a> if you want to clone it.</p>
<div id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:8f6cfd24-50f5-4569-a63a-46d12fc1a212" class="wlWriterEditableSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;">
<pre class="brush: python;">import urllib2

def getWeather(city):

    #create google weather api url
    url = "http://www.google.com/ig/api?weather=" + urllib2.quote(city)

    try:
        # open google weather api url
        f = urllib2.urlopen(url)
    except:
        # if there was an error opening the url, return
        return "Error opening url"

    # read contents to a string
    s = f.read()

    # extract weather condition data from xml string
    weather = s.split("&lt;current_conditions&gt;&lt;condition data=\"")[-1].split("\"")[0]

    # if there was an error getting the condition, the city is invalid
    if weather == "&lt;?xml version=":
        return "Invalid city"

    #return the weather condition
    return weather

def main():
    while True:
        city = raw_input("Give me a city: ")
        weather = getWeather(city)
        print(weather)

if __name__ == "__main__":
    main()</pre>
</div>
<p><strong>Update: </strong>GitHub is awesome because it allows very easy forking. <a href="http://gist.github.com/beaumartinez">Beau Martínez</a> has made a <a href="http://gist.github.com/309222">fork</a> of my script that includes Python 3 support, XML parsing instead of RegEx searching, and temperature reporting.</p>
]]></content:encoded>
			<wfw:commentRss>http://julianapena.com/2010/02/code-snippet-get-a-weather-condition-using-python-and-google-weather-api/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>How to build a Chrome extension, Part 4: Background pages and scheduling requests</title>
		<link>http://julianapena.com/2010/01/how-to-build-a-chrome-extension-part-4-background-pages-and-scheduling-requests/</link>
		<comments>http://julianapena.com/2010/01/how-to-build-a-chrome-extension-part-4-background-pages-and-scheduling-requests/#comments</comments>
		<pubDate>Wed, 06 Jan 2010 03:45:24 +0000</pubDate>
		<dc:creator>Juliana Peña</dc:creator>
				<category><![CDATA[Chrome]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[extension]]></category>

		<guid isPermaLink="false">http://julianapena.com/?p=409</guid>
		<description><![CDATA[One of the most common uses for an extension is as a notifier. For example, the Google Gmail Checker, an official Google extension and the most popular one in the gallery, constantly checks your Gmail inbox for new unread mail. This functionality is easy to add into your own extension. You need to add a <a href="http://julianapena.com/2010/01/how-to-build-a-chrome-extension-part-4-background-pages-and-scheduling-requests/"> read more <span class="meta-nav">&#187;</span></a>]]></description>
			<content:encoded><![CDATA[<p>One of the most common uses for an extension is as a notifier. For example, the <a href="https://chrome.google.com/extensions/detail/mihcahmgecmbnbcchbopgniflfhgnkff">Google Gmail Checker</a>, an official Google extension and the most popular one in the gallery, constantly checks your Gmail inbox for new unread mail.</p>
<p>This functionality is easy to add into your own extension. You need to add a background page, which is easily added by adding the background_page option to your manifest.json:</p>
<div id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:08cde715-f4bd-49b2-a7d2-ad7ff4ca5738" class="wlWriterEditableSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;">
<pre class="brush: javascript;">{
	"name": "My Extension",
	...
	"background_page": "background.html",
	...
}</pre>
</div>
<p>Like almost every other component in a Chrome extension, background.html is a standard HTML file. However, it can also do things most web pages cannot, such as <a href="http://code.google.com/chrome/extensions/xhr.html">cross-origin requests</a> if permissions are correctly added to the manifest. For example, if your extension is a Gmail checker, it would need permissions to <a href="http://www.google.com">http://www.google.com</a> and <a href="https://www.google.com">https://www.google.com</a>. To add these permissions, the manifest.json would be edited to:</p>
<div id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:babaf12b-186f-4c66-a12c-a6ae946caef4" class="wlWriterEditableSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;">
<pre class="brush: javascript;">{
	"name": "My Extension",
	...
	"background_page": "background.html",
	"permissions": ["http://www.google.com/", "https://www.google.com/"],
	...
}</pre>
</div>
<p>A background page runs at all times when the extension is enabled. You cannot see it, but it can modify other aspects of the extension, like setting the browser action badge. For example, the following example would set the icon badge to the number of unread items in a hypothetical service:</p>
<div id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:44a4f7d6-b513-4ff9-9f16-df573150bdc6" class="wlWriterEditableSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;">
<pre class="brush: javascript;">function getUnreadItems(callback) {
	$.ajax(..., function(data) {
		process(data);
		callback(data);
	});
}

function updateBadge() {
	getUnreadItems(function(data) {
		chrome.browserAction.setBadgeText({text:data.unreadItems});
	});
}</pre>
</div>
<p>So now you can make a request, but how can you schedule it so the data is retrieved and processed regularly? Luckily, JavaScript has a method called window.setTimeout to do just that:</p>
<div id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:1b5ebf9b-6c9c-428e-96ef-deb92b76b987" class="wlWriterEditableSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;">
<pre class="brush: javascript;">var pollInterval = 1000 * 60; // 1 minute, in milliseconds

function startRequest() {
	updateBadge();
	window.setTimeout(startRequest, pollInterval);
}</pre>
</div>
<p>That was easy! Now just slap a</p>
<pre class="brush: html">onload='startRequest()'</pre>
<p>on the background page’s body tag and that should do it!</p>
<p>But what if you want to stop the request? That can easily be done as well, by chaging the startRequest function a little and adding a stopRequest function:</p>
<div id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:b44225b5-3eb1-438d-a29f-0c02c893b8c7" class="wlWriterEditableSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;">
<pre class="brush: javascript;">var pollInterval = 1000 * 60; // 1 minute, in milliseconds
var timerId;

function startRequest() {
	updateBadge();
	timerId = window.setTimeout(startRequest, pollInterval);
}

function stopRequest() {
	window.clearTimeout(timerId);
}</pre>
</div>
<p>And that’s about it on building background pages that can schedule requests. Now go! Make an awesome notifier! You can even make things like a timer with this (Facebook addiction control, anyone?). Just remember to leave a comment telling everyone of your awesomeness.</p>
]]></content:encoded>
			<wfw:commentRss>http://julianapena.com/2010/01/how-to-build-a-chrome-extension-part-4-background-pages-and-scheduling-requests/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>How to build a Chrome extension, Part 3: Loading any web page in a popup</title>
		<link>http://julianapena.com/2010/01/how-to-build-a-chrome-extension-part-3-loading-any-web-page-in-a-popup/</link>
		<comments>http://julianapena.com/2010/01/how-to-build-a-chrome-extension-part-3-loading-any-web-page-in-a-popup/#comments</comments>
		<pubDate>Mon, 04 Jan 2010 03:40:18 +0000</pubDate>
		<dc:creator>Juliana Peña</dc:creator>
				<category><![CDATA[Chrome]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[extension]]></category>

		<guid isPermaLink="false">http://julianapena.com/2010/01/how-to-build-a-chrome-extension-part-3-loading-any-web-page-in-a-popup/</guid>
		<description><![CDATA[Chrome allows extensions that use its page action or browser action API to show popups when clicked. To add this popup, you’d add a popup.html file to your extension and the following to the manifest.json for browser actions: { "name": "My Extension", ... "browser_action": { "default_icon": "myicon.png", "popup": "popup.html" } ... } Or for page <a href="http://julianapena.com/2010/01/how-to-build-a-chrome-extension-part-3-loading-any-web-page-in-a-popup/"> read more <span class="meta-nav">&#187;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Chrome allows extensions that use its <a href="http://code.google.com/chrome/extensions/pageAction.html">page action</a> or <a href="http://code.google.com/chrome/extensions/browserAction.html">browser action</a> API to show popups when clicked. To add this popup, you’d add a popup.html file to your extension and the following to the manifest.json for browser actions:</p>
<pre class="brush: js">{
	"name": "My Extension",
	...
	"browser_action": {
		"default_icon": "myicon.png",
		"popup": "popup.html"
	}
	...
}</pre>
<p>Or for page actions:</p>
<pre class="brush: js">{
	"name": "My Extension",
	...
	"page_action": {
		"default_icon": "myicon.png",
		"popup": "popup.html"
	}
	...
}</pre>
<p>However, the popup page is static and cannot be changed while the extension is running. Also, only a local extension page can be put into a popup; you can’t load an external page.</p>
<p>So how can you fix this? Using a relatively old web technique called an iframe. Inline frame, or iframe, is an HTML element that can load any web page inside another in a type of box. So, even though you can’t load an external web page as your popup, you can load it <em>within</em> it.</p>
<p>A simple example for a Bing search extension would be:</p>
<div id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:a5285258-32cb-435a-8157-9dbedd4ca7ff" class="wlWriterEditableSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;">
<pre class="brush: xml;">&lt;html&gt;
&lt;head&gt;
	&lt;style type="text/css"&gt;
	body {width:200; height:300;}
	&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
	&lt;iframe src="http://m.bing.com" width="100%" height="100%" frameborder="0"&gt;
	&lt;/iframe&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
</div>
<p>As you can see, I have loaded the mobile version of Bing, <a title="http://m.bing.com" href="http://m.bing.com">http://m.bing.com</a>. Because of the small amount of screen real estate available on the popups, loading mobile versions of a page is a good idea as they are minimalistic and require less space.</p>
<p>I’ve also explicitly declared the size of the page (200 by 300) and the iframe (100% of the page). You can change this to what fits your extension best.</p>
<p>(Yeah, I know it is ironic to build a Chrome extension centered on Bing, but I couldn’t get <a href="http://www.google.com/m">Google’s mobile search</a> to load correctly in an iframe.)</p>
<p>On Chrome, the Bing search extension would look like this:</p>
<p><a href="http://julianapena.com/wp-content/uploads/HowtobuildaChromeextensionPart3Loadingan_13EA3/image.png"><img style="margin: 0px auto 5px; display: block; float: none; border-width: 0px;" title="image" src="http://julianapena.com/wp-content/uploads/HowtobuildaChromeextensionPart3Loadingan_13EA3/image_thumb.png" border="0" alt="image" width="390" height="367" /></a></p>
<p>You can download the completed Bing extension from the <a href="https://chrome.google.com/extensions/detail/dkjkkandkknagonejgliebkekfkkofad">Chrome Extensions Gallery</a> and the source code (under the <a href="http://creativecommons.org/licenses/GPL/2.0/">GPLv2</a>) from <a href="http://mfi.re/?imwxngtdkhg">Mediafire</a>.</p>
<p>Now, what if you want to load a different page depending on an <a href="http://julianapena.com/2010/01/how-to-build-a-chrome-extension-part-2-options-and-localstorage/">extension option</a>? You can easily do this by constructing the iframe element dynamically when the page loads, like this code excerpt from <a href="http://julianapena.com/projects/chrome-rtm/">ChromeMilk</a>:</p>
<div id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:dc0221eb-6196-4a17-96b4-eb1d29d48b94" class="wlWriterEditableSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;">
<pre class="brush: javascript;">$(document).ready(function() {
	var popup = localStorage.popup || 'igoogle';

	var frame = document.createElement('iframe');

	frame.setAttribute('width', '100%');
	frame.setAttribute('height', '100%');
	frame.setAttribute('frameborder', '0');
	frame.setAttribute('id', 'rtmframe');

	if (popup == 'gmail') {
		// open gmail gadget
		$('body').height(300).width(200);
		frame.setAttribute('src', 'http://www.rememberthemilk.com/services/modules/gmail/');
	}
	else if (popup == 'iphone') {
		// open iphone web app
		$('body').height(480).width(320);
		frame.setAttribute('src', 'http://i.rememberthemilk.com/');
	}
	else if (popup == 'mobile') {
		// open mobile web app
		$('body').height(300).width(200);
		frame.setAttribute('src', 'http://m.rememberthemilk.com/');
	}
	else {
		// igoogle and default
		$('body').height(400).width(400);
		frame.setAttribute('src', 'http://www.rememberthemilk.com/services/modules/googleig/');
	}

	document.body.appendChild(frame);
});</pre>
</div>
<p>This way, the extension sets the popup size and the iframe location based on a setting saved by the user.</p>
<p>There are a few limitations of this method. Most importantly, you can’t manipulate the iframe once it is loaded, as this is <a href="http://en.wikipedia.org/wiki/Cross-site_scripting">cross-side scripting</a> and is prevented by the browser for security reasons.</p>
<p>That’s about it on loading external web sites in popups. You can use this for a number of things. I’ve mentioned mobile sites, but things like iGoogle widgets also work well.</p>
<p>Do you have any tips on building Chrome extensions based on popups? Or are you having trouble building your extension? Leave a comment!</p>
]]></content:encoded>
			<wfw:commentRss>http://julianapena.com/2010/01/how-to-build-a-chrome-extension-part-3-loading-any-web-page-in-a-popup/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>How to build a Chrome extension, Part 2: Options and localStorage</title>
		<link>http://julianapena.com/2010/01/how-to-build-a-chrome-extension-part-2-options-and-localstorage/</link>
		<comments>http://julianapena.com/2010/01/how-to-build-a-chrome-extension-part-2-options-and-localstorage/#comments</comments>
		<pubDate>Sun, 03 Jan 2010 20:57:39 +0000</pubDate>
		<dc:creator>Juliana Peña</dc:creator>
				<category><![CDATA[Chrome]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[extension]]></category>

		<guid isPermaLink="false">http://julianapena.com/?p=399</guid>
		<description><![CDATA[An important aspect of almost all extensions is being able to save user settings. This can be achieved in Chrome easily by using the localStorage object and Chrome’s extension API options page. Adding an options page To add an options page to your extension, make an options.html file in your extension’s folder and add the <a href="http://julianapena.com/2010/01/how-to-build-a-chrome-extension-part-2-options-and-localstorage/"> read more <span class="meta-nav">&#187;</span></a>]]></description>
			<content:encoded><![CDATA[<p>An important aspect of almost all extensions is being able to save user settings. This can be achieved in Chrome easily by using the localStorage object and Chrome’s extension API options page.</p>
<h3>Adding an options page</h3>
<p>To add an options page to your extension, make an options.html file in your extension’s folder and add the “options_page” line to your manifest.json like so:</p>
<pre class="brush: js">{
  "name": "My Extension",
  ...
  "options_page": "options.html"
  ...
}</pre>
<h3>localStorage</h3>
<p>localStorage is an HTML5 object used for storing web page data locally using JavaScript. Chrome gives extensions the option of using localStorage to save options and data.</p>
<h3>Saving options</h3>
<p>To save a string to localStorage, use the following code, replacing mysetting and myvalue with your own:</p>
<pre class="brush: js">localStorage["mysetting"] = "myvalue";</pre>
<p>Or, equivalently:</p>
<pre class="brush: js">localStorage.mysetting = "myvalue";</pre>
<h3>Loading options</h3>
<p>To load an option, just access the setting member in the localstorage object:</p>
<pre class="brush: js">myvar = localStorage["mysetting"];</pre>
<p>Or, equivalently:</p>
<pre class="brush: js">myvar = localStorage.mysetting;</pre>
<p>It’s always a good idea to make sure you’ve loaded a valid setting. For example, the following code loads a favorite color, but if the current color is not valid, it loads the default value:</p>
<pre class="brush: js">var defaultColor = "blue";

function loadFavColor() {
	var favColor = localStorage["favColor"];

	// valid colors are red, blue, green and yellow
	if (favColor == undefined || (favColor != "red" &amp;&amp; favColor != "blue" &amp;&amp; favColor != "green" &amp;&amp; favColor != "yellow")) {
		favColor = defaultColor;
	}

	return favColor;
}</pre>
<h3>Erasing options</h3>
<p>You can erase an option by removing it from the localstorage object, like so:</p>
<pre class="brush: js">localStorage.removeItem("mysetting");</pre>
<h3>Building an options page</h3>
<p>Continuing with the favorite color example, lets now build a complete options page for our color-choosing extension. The options.html page would look like this:</p>
<pre class="brush: xml;">&lt;html&gt;
&lt;head&gt;
	&lt;title&gt;Options for Color Chooser&lt;/title&gt;
	&lt;script type="text/javascript" src="options.js"&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body onload="loadOptions()"&gt;
	&lt;h1&gt;Favorite Color&lt;/h1&gt;
	&lt;select id="color"&gt;
		&lt;option value="blue"&gt;Blue&lt;/option&gt;
		&lt;option value="red"&gt;Red&lt;/option&gt;
		&lt;option value="green"&gt;Green&lt;/option&gt;
		&lt;option value="yellow"&gt;Yellow&lt;/option&gt;
	&lt;/select&gt;
	&lt;br /&gt;
	&lt;button onclick="saveOptions()"&gt;Save&lt;/button&gt;
	&lt;br /&gt;
	&lt;button onclick="eraseOptions()"&gt;Restore default&lt;/button&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<p>For the behavior of the page, options.js would look like this:</p>
<pre class="brush: javascript;">var defaultColor = "blue";

function loadOptions() {
	var favColor = localStorage["favColor"];

	// valid colors are red, blue, green and yellow
	if (favColor == undefined || (favColor != "red" &amp;&amp; favColor != "blue" &amp;&amp; favColor != "green" &amp;&amp; favColor != "yellow")) {
		favColor = defaultColor;
	}

	var select = document.getElementById("color");
	for (var i = 0; i &lt; select.children.length; i++) {
		var child = select.children[i];
			if (child.value == favColor) {
			child.selected = "true";
			break;
		}
	}
}

function saveOptions() {
	var select = document.getElementById("color");
	var color = select.children[select.selectedIndex].value;
	localStorage["favColor"] = color;
}

function eraseOptions() {
	localStorage.removeItem("favColor");
	location.reload();
}</pre>
<p>And that’s about it! You can also save and load localStorage data elsewhere in your extension, as the data is shared between all your extension’s files.</p>
<p>Any question, remark, or addition? Please leave a comment!</p>
]]></content:encoded>
			<wfw:commentRss>http://julianapena.com/2010/01/how-to-build-a-chrome-extension-part-2-options-and-localstorage/feed/</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>How to build a Chrome extension, Part 1: Basics</title>
		<link>http://julianapena.com/2010/01/how-to-build-a-chrome-extension-part-1-basics/</link>
		<comments>http://julianapena.com/2010/01/how-to-build-a-chrome-extension-part-1-basics/#comments</comments>
		<pubDate>Sun, 03 Jan 2010 17:21:08 +0000</pubDate>
		<dc:creator>Juliana Peña</dc:creator>
				<category><![CDATA[Chrome]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[extension]]></category>

		<guid isPermaLink="false">http://julianapena.com/2010/01/how-to-build-a-chrome-extension-part-1-basics/</guid>
		<description><![CDATA[Building Chrome extensions is super-easy. I’ve already made two: ChromeMilk and Postponer. I wanted so share my method of building extensions, so I’m going to write a series of posts. This one will cover the basics on how to set up a good development environment and how to begin writing the extensions. 1. Install Chrome <a href="http://julianapena.com/2010/01/how-to-build-a-chrome-extension-part-1-basics/"> read more <span class="meta-nav">&#187;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://julianapena.com/wp-content/uploads/HowtobuildaChromeextensionPart1Basics_ADA5/image.png"><img style="display: block; float: none; margin-left: auto; margin-right: auto; border-width: 0px;" title="image" src="http://julianapena.com/wp-content/uploads/HowtobuildaChromeextensionPart1Basics_ADA5/image_thumb.png" border="0" alt="image" width="442" height="353" /></a></p>
<p>Building Chrome extensions is super-easy. I’ve already made two: <a href="http://julianapena.com/projects/chrome-rtm/">ChromeMilk</a> and <a href="http://julianapena.com/projects/chrome-postponer/">Postponer</a>. I wanted so share my method of building extensions, so I’m going to write a series of posts. This one will cover the basics on how to set up a good development environment and how to begin writing the extensions.</p>
<h3>1. Install Chrome dev channel</h3>
<p>The <a href="http://dev.chromium.org/getting-involved/dev-channel">Chrome dev channel</a> has the latest technologies and the best developing tools. <a href="http://www.google.com/chrome/eula.html?extra=devchannel">Install it</a> and use it to debug extensions.</p>
<h3>2. Get a text editor to write the code in</h3>
<p>If you’re really Spartan you can use regular Notepad. I use <a href="http://www.flos-freeware.ch/notepad2.html">Notepad2</a> because it’s light but has syntax highlighting and other features. There are many available, so take your pick.</p>
<h3>3. Learn HTML, CSS and JavaScript</h3>
<p>Chrome extensions are made using the same techniques used to make web pages. HTML for content, CSS for presentation and JavaScript for behavior and interaction. I highly recommend the tutorials at <a href="http://w3schools.com/">W3Schools</a> if you are just starting out. If you’ve been building web pages for a while, you can probably skip this step.</p>
<h3>4. Follow the official Getting Started tutorial</h3>
<p>Google has a <a href="http://code.google.com/chrome/extensions/getstarted.html">very good tutorial for writing your first extension</a>. This tutorial shows you how to build a simple extension and test in on your browser. After this, you should be ready to build your own extension!</p>
<h3>5. Now what?</h3>
<p>Now that you know how to build a basic Chrome extension, it’s time to let your imagination run wild! Read the <a href="http://code.google.com/chrome/extensions/devguide.html">extension documentation</a> and see what you can build with it. Start small and don’t be afraid to be wrong. When your extension is ready, you can submit it to the <a href="https://chrome.google.com/extensions/">Chrome Extensions Gallery</a> so that everyone can use it!</p>
<p>I’ll be writing more posts on this, so stay tuned.</p>
<p>Do you have any tips for building Chrome extensions? Have your made an extension after following these steps? What other resources do you use to make extensions? Leave a comment and tell us all about it!</p>
]]></content:encoded>
			<wfw:commentRss>http://julianapena.com/2010/01/how-to-build-a-chrome-extension-part-1-basics/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
