<?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>Frank Fiedler</title>
	<atom:link href="http://www.frankfiedler.de/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.frankfiedler.de</link>
	<description>Musician &#38; Software Developer</description>
	<lastBuildDate>Mon, 27 Dec 2010 19:52:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>iPhone &#8220;view source&#8221; bookmarklet with syntax highlighting</title>
		<link>http://www.frankfiedler.de/2010/12/iphone-show-source/</link>
		<comments>http://www.frankfiedler.de/2010/12/iphone-show-source/#comments</comments>
		<pubDate>Wed, 15 Dec 2010 17:30:33 +0000</pubDate>
		<dc:creator>frank</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[ipad]]></category>
		<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">http://blog.frank-fiedler.de/?p=195</guid>
		<description><![CDATA[A slight modification of the 'show source' bookmarklet by Dustin Caruso, adding color coding.]]></description>
			<content:encoded><![CDATA[<p>When surfing with mobile safari I sometimes miss a <em>show source</em> function to see the source code of websites.</p>
<p>Some solutions are described <a href="http://iphoneized.com/2009/05/8-ways-view-page-source-code-iphone/" target="_blank">here</a>. I like the &#8216;pure bookmarklet&#8217; approach most, as it is quite fast and uses the <em>real source</em>, which is actually loaded by mobile safari. The solutions using a redirect are sending the url to another website, causing the other page to load the source again. So, the page is loaded by <em>another client</em>and you cannot be sure if this is really the source which is loaded by mobile safari.<br /> Therefore I used the <a href="http://dustincaruso.com/javascript/view-source-on-iphone/" target="_blank">bookmarklet from Dustin Caruso</a> and added syntax highlighting by calling a prettifiy script from google.</p>
<p>This is the source of my bookmarklet:</p>
<pre class="brush: jscript; title: ;">javascript:(function(){
  var w = window.open('about:blank'),
  doc = w.document;
  doc.write('&lt;!DOCTYPE html&gt;&lt;html&gt;&lt;head&gt;&lt;title&gt;Source of ' + location.href +
    '&lt;/title&gt;&lt;meta name=\'viewport\' content=\'width=device-width\' /&gt;' +
    '&lt;link rel=\'stylesheet\''+
    ' href=\'http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.css\''+
    ' type=\'text/css\'/&gt;' +
    '&lt;/head&gt;&lt;body&gt;&lt;/body&gt;&lt;/html&gt;');
  doc.close();
  var pre = doc.body.appendChild(doc.createElement('pre'));
  pre.style.overflow = 'auto';
  pre.style.whiteSpace = 'pre-wrap';
  pre.style.border = 'none';
  pre.className = 'prettyprint';
  pre.appendChild(doc.createTextNode(document.documentElement.innerHTML));
  var lib = doc.createElement('script');
  lib.setAttribute('type','text/javascript');
  lib.setAttribute('src','http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.js');
  doc.getElementsByTagName('head')[0].appendChild(lib);
  var call = doc.createElement('script');
  call.setAttribute('type','text/javascript');
  var txt = doc.createTextNode('window.setTimeout(function () {prettyPrint();},600);');
  call.appendChild(txt);
  doc.body.appendChild(call);
}());</pre>
<p>You can try it the usual way: Copy the code to the clipboard, then create a link. Right click on the link and choose &#8216;Edit Address&#8217; and paste the code as link address. Save the link. Don&#8217;t be confused if the code does not appear as expected (this happened to me when I started working with bookmarklets; it is due to the fact that the litte input fields for the link address are not made for lengthy code).</p>
<p>The easiest way to get the link on the iOS device is to create it in desktop safari and syncronize it via iTunes.</p>
<p>The call to <code>prettyPrint()</code> has a timeout. The timeout needed depends on the length of the page. For small pages, a shorter timeout is sufficient (like 200ms), the given timeout of 600ms was enough even for big pages.</p>
<p>The result should look somewhat like this:</p>
<p><a href="/wp-content/uploads/IMG_0347.png"><img class="alignright size-full wp-image-238" title="iphone show source" src="http://www.frankfiedler.de/wp-content/uploads/IMG_0347.png" alt="iphone show source" width="320" height="480" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.frankfiedler.de/2010/12/iphone-show-source/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

