<?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>Joe Maller &#187; web design</title>
	<atom:link href="http://joemaller.com/tag/web-design/feed/" rel="self" type="application/rss+xml" />
	<link>http://joemaller.com</link>
	<description>.com</description>
	<lastBuildDate>Fri, 27 Jan 2012 06:04:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>A web-focused Git workflow</title>
		<link>http://joemaller.com/990/a-web-focused-git-workflow/</link>
		<comments>http://joemaller.com/990/a-web-focused-git-workflow/#comments</comments>
		<pubDate>Tue, 25 Nov 2008 17:04:30 +0000</pubDate>
		<dc:creator>Joe Maller</dc:creator>
				<category><![CDATA[misc.]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[web design]]></category>
		<category><![CDATA[workflow]]></category>

		<guid isPermaLink="false">http://joemaller.com/?p=990</guid>
		<description><![CDATA[After months of looking, struggling through Git-SVN glitches and letting things roll around in my head, I&#8217;ve finally arrived at a web-focused Git workflow that&#8217;s simple, flexible and easy to use. Some key advantages: Pushing remote changes automatically updates the live site Server-based site edits won&#8217;t break history Simple, no special commit rules or requirements [...]]]></description>
			<content:encoded><![CDATA[<p>After months of looking, struggling through Git-SVN glitches and letting things roll around in my head, I&#8217;ve finally arrived at a web-focused Git workflow that&#8217;s simple, flexible and easy to use.</p>
<p>Some key advantages:</p>
<ul>
<li>Pushing remote changes automatically updates the live site</li>
<li>Server-based site edits won&#8217;t break history</li>
<li>Simple, no special commit rules or requirements</li>
<li>Works with existing sites, no need to redeploy or move files</li>
</ul>
<h3>Overview</h3>
<p>The key idea in this system is that the web site exists on the server as a pair of repositories; a bare repository alongside a conventional repository containing the live site. Two simple Git hooks link the pair, automatically pushing and pulling changes between them.</p>
<p><img src="http://joemaller.com/wordpress/wp-content/uploads/2008/11/hub-prime2.jpg" alt="" title="hub, prime, clones" width="500" height="247" /></p>
<p>The two repositories:</p>
<ul>
<li><strong>Hub</strong> is a bare repository. All other repositories will be cloned from this.</li>
<li><strong>Prime</strong> is a standard repository, the live web site is served from its working directory.</li>
</ul>
<p>Using the pair of repositories is simple and flexible. Remote clones with ssh-access can update the live site with a simple <strong>git push </strong>to Hub. Any files edited directly on the server are instantly mirrored into Hub upon commit. The whole thing pretty much just works &#8212; whichever way it&#8217;s used.</p>
<p><strong>Getting ready</strong></p>
<p>Obviously <a href="http://git.or.cz/">Git</a> is required on the server and any local machines. My shared web host doesn&#8217;t offer Git, but it&#8217;s easy enough to <a href="http://joemaller.com/2008/08/13/how-to-install-git-on-a-shared-host/">install Git yourself</a>.</p>
<p>If this is the first time running Git on your webserver, remember to <a href="http://rails.wincent.com/wiki/Git_quickstart ">setup your global configuration info</a>. I set a different Git user.name to help distinguish server-based changes in project history.</p>
<pre><code>$ git config --global user.name "Joe, working on the server"</code></pre>
<h3>Getting started</h3>
<p>The first step is to initialize a new Git repository in the live web site directory on the server, then to add and commit all the site&#8217;s files. This is the <strong>Prime</strong> repository and working copy. Even if history exists in other places, the contents of the live site will be the baseline onto which all other work is merged.</p>
<pre><code>$ cd ~/www
$ git init
$ git add .
$ git commit -m"initial import of pre-existing web files"</code></pre>
<p>Initializing in place also means there is no downtime or need to re-deploy the site, Git just builds a repository around everything that&#8217;s  already there.</p>
<p>With the live site now safely in Git, create a bare repository outside the web directory, this is <strong>Hub</strong>.</p>
<pre><code>$ cd; mkdir site_hub.git; cd site_hub.git
$ git --bare init
<span class="response">Initialized empty Git repository in /home/joe/site_hub.git</span></code></pre>
<p>Then, from inside Prime&#8217;s working directory, add Hub as a remote and push Prime&#8217;s master branch:</p>
<pre><code>$ cd ~/www
$ git remote add hub ~/site_hub.git
$ git remote show hub
<span class="response">* remote hub
  URL: /home/joe/site_hub.git</span>
$ git push hub master</code></pre>
<h3>Hooks</h3>
<p>Two simple Git hooks scripts keep Hub and Prime linked together.</p>
<p>An oft-repeated rule of Git is to <a href="http://git.or.cz/gitwiki/GitFaq#head-b96f48bc9c925074be9f95c0fce69bcece5f6e73">never push into a repository that has a work tree attached to it</a>. I tried it, and things do get weird fast. The hub repository exists for this reason. Instead of pushing changes to Prime from Hub, which wouldn&#8217;t affect the working copy anyway, Hub uses a hook script which tells Prime to pull changes from Hub.</p>
<h4>post-update &#8211; Hub repository</h4>
<p>This hook is called when Hub receives an update. The script changes directories to the Prime repository working copy then runs a pull from Prime. Pushing changes doesn&#8217;t update a repository&#8217;s working copy, so it&#8217;s necessary to execute this from inside the working copy itself.</p>
<pre><code>#!/bin/sh

echo
echo "**** Pulling changes into Prime [Hub's post-update hook]"
echo

cd $HOME/www || exit
unset GIT_DIR
git pull hub master

exec git-update-server-info</code></pre>
<h4>post-commit &#8211; Prime repository</h4>
<p>This hook is called after every commit to send the newly commited changes back up to Hub. Ideally, it&#8217;s not common to make changes live on the server, but automating this makes sure site history won&#8217;t diverge and create conflicts.</p>
<pre><code>#!/bin/sh

echo
echo "**** pushing changes to Hub [Prime's post-commit hook]"
echo

git push hub</code></pre>
<p>With this hook in place, all changes made to Prime&#8217;s master branch are immediately available from Hub. Other branches will also be cloned, but won&#8217;t affect the site. Because all remote repository access is via SSH urls, only users with shell access to the web server will be able to push and trigger a site update.</p>
<h3>Conflicts</h3>
<p>This repository-hook arrangement makes it very difficult to accidentally break the live site. Since every commit to Prime is automatically pushed to Hub, all conflicts will be immediately visible to the clones when pushing an update. </p>
<p>However there are a few situations where Prime can diverge from Hub which will require additional steps to fix. If an uncommitted edit leaves Prime in a dirty state, Hub&#8217;s post-update pull will fail with an &#8220;Entry &#8216;foo&#8217; not uptodate. Cannot merge.&#8221; warning. Committing changes will clean up Prime&#8217;s working directory, and the post-update hook will then merge the un-pulled changes. </p>
<p>If a conflict occurs where changes to Prime can&#8217;t be merged with Hub, I&#8217;ve found the best solution is to push the current state of Prime to a new branch on Hub. The following command, issued from inside Prime, will create a remote &#8220;fixme&#8221; branch based on the current contents of Prime:</p>
<pre><code>$ git push hub master:refs/heads/fixme</code></pre>
<p>Once that&#8217;s in Hub, any remote clone can pull down the new branch and resolve the merge. Trying to resolve a conflict on the server would almost certainly break the site due to Git&#8217;s conflict markers.</p>
<h3>Housekeeping</h3>
<p>Prime&#8217;s .git folder is at the root level of the web site, and is probably publicly accessible. To protect the folder and prevent unwanted clones of the repository, add the following to your top-level .htaccess file to forbid web access:</p>
<pre><code># deny access to the top-level git repository:
RewriteEngine On
RewriteRule \.git - [F,L]</code></pre>
<h3>Troubleshooting</h3>
<p>If you&#8217;re seeing this error when trying to push to a server repository:
<pre><code><span class="response nocode">git-receive-pack: command not found
fatal: The remote end hung up unexpectedly</span></code></pre>
<p>Add <code>export PATH=${PATH}:~/bin</code> to your .bashrc file on the server. Thanks to Robert for <a href="http://www.bluestatic.org/blog/2007/08/01/git-public-push-ing/">finding and posting the fix</a>.</p>
<h3>Links</h3>
<p>These didn&#8217;t fit in anywhere else:</p>
<ul>
<li>Toolman Tim has a very good introductory walkthrough of <a href="http://toolmantim.com/article/2007/12/5/setting_up_a_new_remote_git_repository">setting up a new remote git repository</a>.
</li>
<li>This ended up being somewhat similar to the <a href="http://ikiwiki.info/rcs/git/"> update mechanism in Ikiwiki</a>, wish I&#8217;d found that page earlier.</li>
<li><a href="http://www.linuxworld.com/community/?q=node/3057"> Getting a static web site organized with git </a> came up with a different solution, but calling <code>git reset --hard</code> from a hook on the server could cause a lot of trouble when committing server-side changes.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://joemaller.com/990/a-web-focused-git-workflow/feed/</wfw:commentRss>
		<slash:comments>82</slash:comments>
		</item>
		<item>
		<title>Web Syntax Coloring</title>
		<link>http://joemaller.com/743/web-syntax-coloring/</link>
		<comments>http://joemaller.com/743/web-syntax-coloring/#comments</comments>
		<pubDate>Thu, 05 Apr 2007 06:35:12 +0000</pubDate>
		<dc:creator>Joe</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[TextMate]]></category>
		<category><![CDATA[web design]]></category>

		<guid isPermaLink="false">http://joemaller.com/2007/04/05/web-syntax-coloring/</guid>
		<description><![CDATA[February 2011 Update: This post was originally published in 2007 and hasn&#8217;t aged well. For code snippet syntax coloring, I currently use Google&#8217;s Prettify script (prettify.js). The script is dynamically inserted by jQuery if there are code elements to style. Recently I&#8217;ve been experimenting with two very different methods of syntax coloring source code in [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p><strong>February 2011 Update:</strong> This post was originally published in 2007 and hasn&#8217;t aged well. For code snippet syntax coloring, I currently use <a href="http://code.google.com/p/google-code-prettify/">Google&#8217;s Prettify script</a> (<a href="http://code.google.com/p/google-code-prettify/">prettify.js</a>). The script is dynamically inserted by jQuery if there are code elements to style.
</p></blockquote>
<style>/* Stylesheet generated from TextMate theme
*
* Blackboard
* 
*
*/
/* Mostly to improve view within the TextMate HTML viewer */
pre.textmate-source{margin:0;padding:0 0 0 2px;font-family:Monaco,monospace;font-size:11px;line-height:1.3em;word-wrap:break-word;white-space:pre;white-space:pre-wrap;white-space:-moz-pre-wrap;white-space:-o-pre-wrap;}
pre.textmate-source.blackboard{color:#F8F8F8;background-color:#0C1021;}
pre.textmate-source .linenum{width:75px;padding:0.1em 1em 0.2em 0;color:#888;background-color:#eee;}
pre.textmate-source.blackboard span{padding-top:0.2em;padding-bottom:0.1em;}
pre.textmate-source.blackboard ::selection{background-color:#253B76;}
/* Comment */
pre.textmate-source.blackboard .comment{color:#AEAEAE;}
/* Constant */
pre.textmate-source.blackboard .constant{color:#D8FA3C;}
/* Entity */
pre.textmate-source.blackboard .entity{color:#FF6400;}
/* Keyword */
pre.textmate-source.blackboard .keyword{color:#FBDE2D;}
/* Storage */
pre.textmate-source.blackboard .storage{color:#FBDE2D;}
/* String */
pre.textmate-source.blackboard .string,pre.textmate-source.blackboard .meta_verbatim{color:#61CE3C;}
/* Support */
pre.textmate-source.blackboard .support{color:#8DA6CE;}
/* Variable */
pre.textmate-source.blackboard .variable{}
/* Invalid — Deprecated */
pre.textmate-source.blackboard .invalid_deprecated{color:#AB2A1D;font-style:italic;}
/* Invalid — Illegal */
pre.textmate-source.blackboard .invalid_illegal{color:#F8F8F8;background-color:#9D1E15;}
/* Superclass */
pre.textmate-source.blackboard .entity_other_inherited-class{color:#FF6400;font-style:italic;}
/* String interpolation */
pre.textmate-source.blackboard .string .constant_other_placeholder{color:#FF6400;}
/* meta.function-call.py */
pre.textmate-source.blackboard .meta_function-call_py{color:#BECDE6;}
/* meta.tag */
pre.textmate-source.blackboard .meta_tag,pre.textmate-source.blackboard .meta_tag .entity{color:#7F90AA;}
/* entity.name.section */
pre.textmate-source.blackboard .entity_name_section{color:#FFFFFF;}
/* OCaml variant */
pre.textmate-source.blackboard .keyword_type_variant{color:#D5E0F3;}
/* OCaml operator */
pre.textmate-source.blackboard .source_ocaml .keyword_operator_symbol{color:#F8F8F8;}
/* OCaml infix operator */
pre.textmate-source.blackboard .source_ocaml .keyword_operator_symbol_infix{color:#8DA6CE;}
/* OCaml prefix operator */
pre.textmate-source.blackboard .source_ocaml .keyword_operator_symbol_prefix{color:#8DA6CE;}
/* OCaml f-p infix operator */
pre.textmate-source.blackboard .source_ocaml .keyword_operator_symbol_infix_floating-point{text-decoration:underline;}
/* OCaml f-p prefix operator */
pre.textmate-source.blackboard .source_ocaml .keyword_operator_symbol_prefix_floating-point{text-decoration:underline;}
/* OCaml f-p constant */
pre.textmate-source.blackboard .source_ocaml .constant_numeric_floating-point{text-decoration:underline;}
/* LaTeX environment */
pre.textmate-source.blackboard .text_tex_latex .meta_function_environment{background-color:rgba(255,255,255,0.03);}
/* LaTeX environment (nested) */
pre.textmate-source.blackboard .text_tex_latex .meta_function_environment .meta_function_environment{background-color:rgba(122,150,250,0.03);}
/* Latex support */
pre.textmate-source.blackboard .text_tex_latex .support_function{color:#FBDE2D;}
/* PList unquoted string */
pre.textmate-source.blackboard .source_plist .string_unquoted,pre.textmate-source.blackboard .source_plist .keyword_operator{color:#FFFFFF;}
</style>
<p><script src="/js/code_highlighter.js" type="text/javascript"></script><script src="/js/css.js" type="text/javascript"></script>Recently I&#8217;ve been experimenting  with two very different methods of syntax coloring source code in web pages. The first method uses a Dan Webb&#8217;s <a href="http://jquery.com/demo/code/">CodeHighlighter JavaScript library</a> to convert appropriately tagged content into syntax colored code. It&#8217;s necessarily simple, but easily extensible. As an example, here are the CSS rules I&#8217;m using to style CodeHighlighter&#8217;s conversions:</p>
<pre><code class="css">code.html span.comment         { color: #999;}
code.html span.tag             { color: #07f;}
code.html span.string         { color: #080;}
code.html span.attribute     { color: #07f;}
code.html span.doctype         { color: #07f;}

code.css span.comment          {color: #999;}
code.css span.keywords         {color: #fd2;}
code.css span.selectors        {color: #0b0;}
code.css span.properties    {color: #66f;}
code.css span.units            {color: #33c;}
code.css span.urls            {color: #4a0;}

code.javascript span.comment     { color: #999; }
code.javascript span.brackets     { color: #07f; }
code.javascript span.string     { color: #4a0; }
code.javascript span.keywords     { color: #07f; }
code.javascript span.exp         { color: #808; }
code.javascript span.global     { color: #06e; }</code></pre>
<p>The second method uses two more fantastic <a href="http://macromates.com">TextMate</a> features, <em>Create HTML From Selection</em> and <em>Create CSS from Current Theme</em>. What these two commands do is translate exactly what I&#8217;m seeing in TextMate into very precise and valid XHTML with accompanying CSS rules. The main disadvantage of this is the weight of the code, the above 721 bytes of CSS converts to nearly 36k of HTML and CSS rules. It&#8217;s a seriously heavy pile of span tags, but the cost is immediately outweighed by <a href="http://macromates.com/svn/Bundles/trunk/Bundles/">148 very specific reasons</a>. And that&#8217;s just bundles, there are <a href="http://macromates.com/wiki/Themes/UserSubmittedThemes">dozens of great themes</a> too.</p>
<p>Aaron Quint also deservingly <a href="http://www.quirkey.com/blog/2006/07/13/highlight-me-baby/">gushes over these two commands</a>.</p>
<p>What these do is convert exactly what I&#8217;m seeing in TextMate into very precise and valid XHTML. Here&#8217;s the same CSS as above translated by TextMate:</p>
<pre class="textmate-source blackboard"><span class="source source_css"></span><span class="meta meta_selector meta_selector_css"></span><span class="entity entity_name entity_name_tag entity_name_tag_css">code</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>html <span class="entity entity_name entity_name_tag entity_name_tag_css">span</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>comment      <span class="meta meta_property-list meta_property-list_css"></span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">{</span> <span class="meta meta_property-name meta_property-name_css"></span><span class="support support_type support_type_property-name support_type_property-name_css">color</span><span class="meta meta_property-value meta_property-value_css"></span><span class="punctuation punctuation_separator punctuation_separator_key-value punctuation_separator_key-value_css">:</span> <span class="constant constant_other constant_other_color constant_other_color_rgb-value constant_other_color_rgb-value_css"></span><span class="punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_css">#</span>999<span class="punctuation punctuation_terminator punctuation_terminator_rule punctuation_terminator_rule_css">;</span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">}</span>
<span class="meta meta_selector meta_selector_css"></span><span class="entity entity_name entity_name_tag entity_name_tag_css">code</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>html <span class="entity entity_name entity_name_tag entity_name_tag_css">span</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>tag          <span class="meta meta_property-list meta_property-list_css"></span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">{</span> <span class="meta meta_property-name meta_property-name_css"></span><span class="support support_type support_type_property-name support_type_property-name_css">color</span><span class="meta meta_property-value meta_property-value_css"></span><span class="punctuation punctuation_separator punctuation_separator_key-value punctuation_separator_key-value_css">:</span> <span class="constant constant_other constant_other_color constant_other_color_rgb-value constant_other_color_rgb-value_css"></span><span class="punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_css">#</span>07f<span class="punctuation punctuation_terminator punctuation_terminator_rule punctuation_terminator_rule_css">;</span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">}</span>
<span class="meta meta_selector meta_selector_css"></span><span class="entity entity_name entity_name_tag entity_name_tag_css">code</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>html <span class="entity entity_name entity_name_tag entity_name_tag_css">span</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>string       <span class="meta meta_property-list meta_property-list_css"></span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">{</span> <span class="meta meta_property-name meta_property-name_css"></span><span class="support support_type support_type_property-name support_type_property-name_css">color</span><span class="meta meta_property-value meta_property-value_css"></span><span class="punctuation punctuation_separator punctuation_separator_key-value punctuation_separator_key-value_css">:</span> <span class="constant constant_other constant_other_color constant_other_color_rgb-value constant_other_color_rgb-value_css"></span><span class="punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_css">#</span>080<span class="punctuation punctuation_terminator punctuation_terminator_rule punctuation_terminator_rule_css">;</span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">}</span>
<span class="meta meta_selector meta_selector_css"></span><span class="entity entity_name entity_name_tag entity_name_tag_css">code</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>html <span class="entity entity_name entity_name_tag entity_name_tag_css">span</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>attribute    <span class="meta meta_property-list meta_property-list_css"></span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">{</span> <span class="meta meta_property-name meta_property-name_css"></span><span class="support support_type support_type_property-name support_type_property-name_css">color</span><span class="meta meta_property-value meta_property-value_css"></span><span class="punctuation punctuation_separator punctuation_separator_key-value punctuation_separator_key-value_css">:</span> <span class="constant constant_other constant_other_color constant_other_color_rgb-value constant_other_color_rgb-value_css"></span><span class="punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_css">#</span>07f<span class="punctuation punctuation_terminator punctuation_terminator_rule punctuation_terminator_rule_css">;</span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">}</span>
<span class="meta meta_selector meta_selector_css"></span><span class="entity entity_name entity_name_tag entity_name_tag_css">code</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>html <span class="entity entity_name entity_name_tag entity_name_tag_css">span</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>doctype      <span class="meta meta_property-list meta_property-list_css"></span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">{</span> <span class="meta meta_property-name meta_property-name_css"></span><span class="support support_type support_type_property-name support_type_property-name_css">color</span><span class="meta meta_property-value meta_property-value_css"></span><span class="punctuation punctuation_separator punctuation_separator_key-value punctuation_separator_key-value_css">:</span> <span class="constant constant_other constant_other_color constant_other_color_rgb-value constant_other_color_rgb-value_css"></span><span class="punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_css">#</span>07f<span class="punctuation punctuation_terminator punctuation_terminator_rule punctuation_terminator_rule_css">;</span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">}</span>

<span class="meta meta_selector meta_selector_css"></span><span class="entity entity_name entity_name_tag entity_name_tag_css">code</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>css <span class="entity entity_name entity_name_tag entity_name_tag_css">span</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>comment       <span class="meta meta_property-list meta_property-list_css"></span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">{</span> <span class="meta meta_property-name meta_property-name_css"></span><span class="support support_type support_type_property-name support_type_property-name_css">color</span><span class="meta meta_property-value meta_property-value_css"></span><span class="punctuation punctuation_separator punctuation_separator_key-value punctuation_separator_key-value_css">:</span> <span class="constant constant_other constant_other_color constant_other_color_rgb-value constant_other_color_rgb-value_css"></span><span class="punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_css">#</span>999<span class="punctuation punctuation_terminator punctuation_terminator_rule punctuation_terminator_rule_css">;</span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">}</span>
<span class="meta meta_selector meta_selector_css"></span><span class="entity entity_name entity_name_tag entity_name_tag_css">code</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>css <span class="entity entity_name entity_name_tag entity_name_tag_css">span</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>keywords      <span class="meta meta_property-list meta_property-list_css"></span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">{</span> <span class="meta meta_property-name meta_property-name_css"></span><span class="support support_type support_type_property-name support_type_property-name_css">color</span><span class="meta meta_property-value meta_property-value_css"></span><span class="punctuation punctuation_separator punctuation_separator_key-value punctuation_separator_key-value_css">:</span> <span class="constant constant_other constant_other_color constant_other_color_rgb-value constant_other_color_rgb-value_css"></span><span class="punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_css">#</span>fd2<span class="punctuation punctuation_terminator punctuation_terminator_rule punctuation_terminator_rule_css">;</span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">}</span>
<span class="meta meta_selector meta_selector_css"></span><span class="entity entity_name entity_name_tag entity_name_tag_css">code</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>css <span class="entity entity_name entity_name_tag entity_name_tag_css">span</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>selectors     <span class="meta meta_property-list meta_property-list_css"></span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">{</span> <span class="meta meta_property-name meta_property-name_css"></span><span class="support support_type support_type_property-name support_type_property-name_css">color</span><span class="meta meta_property-value meta_property-value_css"></span><span class="punctuation punctuation_separator punctuation_separator_key-value punctuation_separator_key-value_css">:</span> <span class="constant constant_other constant_other_color constant_other_color_rgb-value constant_other_color_rgb-value_css"></span><span class="punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_css">#</span>0b0<span class="punctuation punctuation_terminator punctuation_terminator_rule punctuation_terminator_rule_css">;</span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">}</span>
<span class="meta meta_selector meta_selector_css"></span><span class="entity entity_name entity_name_tag entity_name_tag_css">code</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>css <span class="entity entity_name entity_name_tag entity_name_tag_css">span</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>properties    <span class="meta meta_property-list meta_property-list_css"></span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">{</span> <span class="meta meta_property-name meta_property-name_css"></span><span class="support support_type support_type_property-name support_type_property-name_css">color</span><span class="meta meta_property-value meta_property-value_css"></span><span class="punctuation punctuation_separator punctuation_separator_key-value punctuation_separator_key-value_css">:</span> <span class="constant constant_other constant_other_color constant_other_color_rgb-value constant_other_color_rgb-value_css"></span><span class="punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_css">#</span>66f<span class="punctuation punctuation_terminator punctuation_terminator_rule punctuation_terminator_rule_css">;</span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">}</span>
<span class="meta meta_selector meta_selector_css"></span><span class="entity entity_name entity_name_tag entity_name_tag_css">code</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>css <span class="entity entity_name entity_name_tag entity_name_tag_css">span</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>units         <span class="meta meta_property-list meta_property-list_css"></span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">{</span> <span class="meta meta_property-name meta_property-name_css"></span><span class="support support_type support_type_property-name support_type_property-name_css">color</span><span class="meta meta_property-value meta_property-value_css"></span><span class="punctuation punctuation_separator punctuation_separator_key-value punctuation_separator_key-value_css">:</span> <span class="constant constant_other constant_other_color constant_other_color_rgb-value constant_other_color_rgb-value_css"></span><span class="punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_css">#</span>33c<span class="punctuation punctuation_terminator punctuation_terminator_rule punctuation_terminator_rule_css">;</span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">}</span>
<span class="meta meta_selector meta_selector_css"></span><span class="entity entity_name entity_name_tag entity_name_tag_css">code</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>css <span class="entity entity_name entity_name_tag entity_name_tag_css">span</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>urls          <span class="meta meta_property-list meta_property-list_css"></span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">{</span> <span class="meta meta_property-name meta_property-name_css"></span><span class="support support_type support_type_property-name support_type_property-name_css">color</span><span class="meta meta_property-value meta_property-value_css"></span><span class="punctuation punctuation_separator punctuation_separator_key-value punctuation_separator_key-value_css">:</span> <span class="constant constant_other constant_other_color constant_other_color_rgb-value constant_other_color_rgb-value_css"></span><span class="punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_css">#</span>4a0<span class="punctuation punctuation_terminator punctuation_terminator_rule punctuation_terminator_rule_css">;</span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">}</span> 

<span class="meta meta_selector meta_selector_css"></span><span class="entity entity_name entity_name_tag entity_name_tag_css">code</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>javascript <span class="entity entity_name entity_name_tag entity_name_tag_css">span</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>comment    <span class="meta meta_property-list meta_property-list_css"></span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">{</span> <span class="meta meta_property-name meta_property-name_css"></span><span class="support support_type support_type_property-name support_type_property-name_css">color</span><span class="meta meta_property-value meta_property-value_css"></span><span class="punctuation punctuation_separator punctuation_separator_key-value punctuation_separator_key-value_css">:</span> <span class="constant constant_other constant_other_color constant_other_color_rgb-value constant_other_color_rgb-value_css"></span><span class="punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_css">#</span>999<span class="punctuation punctuation_terminator punctuation_terminator_rule punctuation_terminator_rule_css">;</span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">}</span>
<span class="meta meta_selector meta_selector_css"></span><span class="entity entity_name entity_name_tag entity_name_tag_css">code</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>javascript <span class="entity entity_name entity_name_tag entity_name_tag_css">span</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>brackets   <span class="meta meta_property-list meta_property-list_css"></span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">{</span> <span class="meta meta_property-name meta_property-name_css"></span><span class="support support_type support_type_property-name support_type_property-name_css">color</span><span class="meta meta_property-value meta_property-value_css"></span><span class="punctuation punctuation_separator punctuation_separator_key-value punctuation_separator_key-value_css">:</span> <span class="constant constant_other constant_other_color constant_other_color_rgb-value constant_other_color_rgb-value_css"></span><span class="punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_css">#</span>07f<span class="punctuation punctuation_terminator punctuation_terminator_rule punctuation_terminator_rule_css">;</span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">}</span>
<span class="meta meta_selector meta_selector_css"></span><span class="entity entity_name entity_name_tag entity_name_tag_css">code</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>javascript <span class="entity entity_name entity_name_tag entity_name_tag_css">span</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>string     <span class="meta meta_property-list meta_property-list_css"></span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">{</span> <span class="meta meta_property-name meta_property-name_css"></span><span class="support support_type support_type_property-name support_type_property-name_css">color</span><span class="meta meta_property-value meta_property-value_css"></span><span class="punctuation punctuation_separator punctuation_separator_key-value punctuation_separator_key-value_css">:</span> <span class="constant constant_other constant_other_color constant_other_color_rgb-value constant_other_color_rgb-value_css"></span><span class="punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_css">#</span>4a0<span class="punctuation punctuation_terminator punctuation_terminator_rule punctuation_terminator_rule_css">;</span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">}</span>
<span class="meta meta_selector meta_selector_css"></span><span class="entity entity_name entity_name_tag entity_name_tag_css">code</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>javascript <span class="entity entity_name entity_name_tag entity_name_tag_css">span</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>keywords   <span class="meta meta_property-list meta_property-list_css"></span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">{</span> <span class="meta meta_property-name meta_property-name_css"></span><span class="support support_type support_type_property-name support_type_property-name_css">color</span><span class="meta meta_property-value meta_property-value_css"></span><span class="punctuation punctuation_separator punctuation_separator_key-value punctuation_separator_key-value_css">:</span> <span class="constant constant_other constant_other_color constant_other_color_rgb-value constant_other_color_rgb-value_css"></span><span class="punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_css">#</span>07f<span class="punctuation punctuation_terminator punctuation_terminator_rule punctuation_terminator_rule_css">;</span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">}</span>
<span class="meta meta_selector meta_selector_css"></span><span class="entity entity_name entity_name_tag entity_name_tag_css">code</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>javascript <span class="entity entity_name entity_name_tag entity_name_tag_css">span</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>exp        <span class="meta meta_property-list meta_property-list_css"></span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">{</span> <span class="meta meta_property-name meta_property-name_css"></span><span class="support support_type support_type_property-name support_type_property-name_css">color</span><span class="meta meta_property-value meta_property-value_css"></span><span class="punctuation punctuation_separator punctuation_separator_key-value punctuation_separator_key-value_css">:</span> <span class="constant constant_other constant_other_color constant_other_color_rgb-value constant_other_color_rgb-value_css"></span><span class="punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_css">#</span>808<span class="punctuation punctuation_terminator punctuation_terminator_rule punctuation_terminator_rule_css">;</span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">}</span>
<span class="meta meta_selector meta_selector_css"></span><span class="entity entity_name entity_name_tag entity_name_tag_css">code</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>javascript <span class="entity entity_name entity_name_tag entity_name_tag_css">span</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>global     <span class="meta meta_property-list meta_property-list_css"></span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">{</span> <span class="meta meta_property-name meta_property-name_css"></span><span class="support support_type support_type_property-name support_type_property-name_css">color</span><span class="meta meta_property-value meta_property-value_css"></span><span class="punctuation punctuation_separator punctuation_separator_key-value punctuation_separator_key-value_css">:</span> <span class="constant constant_other constant_other_color constant_other_color_rgb-value constant_other_color_rgb-value_css"></span><span class="punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_css">#</span>06e<span class="punctuation punctuation_terminator punctuation_terminator_rule punctuation_terminator_rule_css">;</span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">}</span>
</pre>
</p>
<p>Just for the sake of comparison, below is a screenshot of how my code looks in TextMate. It&#8217;s not a perfect translation, but it&#8217;s a very good start:</p>
<p><img src='http://joemaller.com/wordpress/wp-content/uploads/2007/04/textmate-css.png' alt='Syntax Coloring CSS in TextMate' /></p>
<p>One of the purported advantages of the JavaScript method is that the source code remains unchanged. That&#8217;s sort of true, but not really. The JavaScript functions work by inserting a bunch of spans, so by the time the user sees it the main difference between JavaScript converted code and pre-processed code from TextMate is the detail (and weight) of the TextMate result. Also, any HTML would need to have entities escaped which is another step and a further degradation of the original code.</p>
<p>The main advantage then becomes convenience. A simple block of code doesn&#8217;t need to be run through TextMate (on the off-chance I&#8217;m writing somewhere else), it can be entered directly and tagged for styling without breaking focus.</p>
]]></content:encoded>
			<wfw:commentRss>http://joemaller.com/743/web-syntax-coloring/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Two little MonoBook styling hacks for MediaWiki</title>
		<link>http://joemaller.com/703/two-little-monobook-styling-hacks-for-mediawiki/</link>
		<comments>http://joemaller.com/703/two-little-monobook-styling-hacks-for-mediawiki/#comments</comments>
		<pubDate>Sun, 19 Nov 2006 03:49:17 +0000</pubDate>
		<dc:creator>Joe</dc:creator>
				<category><![CDATA[misc.]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[MediaWiki]]></category>
		<category><![CDATA[MonoBook]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[web design]]></category>

		<guid isPermaLink="false">http://joemaller.com/2006/11/18/two-little-monobook-styling-hacks-for-mediawiki/</guid>
		<description><![CDATA[Recently, I&#8217;ve spent some time working with MediaWiki for Lila&#8217;s school&#8217;s web site. A small part of what I&#8217;ve been doing has been implementing an exisiting design onto the wiki backend. In an effort not to overcomplicate anything (think longevity) I built the entire design adaptation on the default MediaWiki MonoBook theme. Everyone who&#8217;s visited [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, I&#8217;ve spent some time working with <a href="http://www.mediawiki.org">MediaWiki</a> for Lila&#8217;s school&#8217;s web site. A small part of what I&#8217;ve been doing has been implementing an exisiting design onto the wiki backend. In an effort not to overcomplicate anything (think longevity) I built the entire design adaptation on the default MediaWiki MonoBook theme. Everyone who&#8217;s visited Wikipedia has seen what this looks like. Monobook is a very well constructed theme with clearly defined parts that degrade nicely without its stylesheets. So far, with the exception of  these two small changes, I&#8217;ve able to do everything I needed to with the default page structure. </p>
<h3>First change: Fixing bad portlet IDs</h3>
<p>Editing Mediawiki:Sidebar allows for nearly complete customization of the sidebar links. Custom sections automatically get custom IDs which can then be styled. There is one thing that seems like a bug however: If a section heading has a space in it, the portlet ID will have an illegal name. Classes can have spaces in their selectors, but IDs can&#8217;t. Here&#8217;s what I did:</p>
<pre><code>&lt;div class='portlet' id='p-&lt;?php echo htmlspecialchars($bar) ?&gt;'&gt;</code></pre>
<p>and the new one:</p>
<pre><code>&lt;div class='portlet' id='p-&lt;?php echo str_replace(' ', '_',htmlspecialchars($bar)) ?&gt;'&gt;</code>
</pre>
<p>Simple enough, PHP&#8217;s str_replace is used to swap underscores for spaces. I&#8217;m still feeling my way around the MediaWiki codebase, so this might not be the best solution to the problem, but it does what it needs to with a very lightweight function.</p>
<h3>Second change: Classes from page title</h3>
<p>I needed to change the background of the globalWrapper element depending on the page, the way I accomplished this was to use the page-title. This has one initial drawback, namely that colons are not allowed in CSS class names. However the workaround above can be recast here with added benefit. Switching colons for spaces results in multiple class names, so namespaces can be styled too. </p>
<p>Here&#8217;s the old code:</p>
<pre><code>&lt;div id="globalWrapper"&gt;</code>
</pre>
<p>And the new code: </p>
<pre><code>&lt;div id="globalWrapper" class="&lt;?php echo str_replace(':', ' ', $this-&gt;data['titleprefixeddbkey'])?&gt;"&gt;</code>
</pre>
<p>This method would seem preferrable to adding a CSS import rule which would look for a custom-named file. Even though CSS load errors don&#8217;t break pages with visible 404 errors, they would slow down page loads and litter the server logs. Checking that the CSS file exists is somewhat costly, and I suspect MediaWiki&#8217;s cacheing isn&#8217;t something that can be quickly skimmed over and implemented.</p>
<p>There appears to be a <a href="http://tools.wikimedia.de/~avar/cvs/html/all/module_extensions_PageCSS.html">pageCSS extension</a> somewhere, the hooks are even specified in MonoBook&#8217;s header, but I couldn&#8217;t find a working download and CVS repository doesn&#8217;t seem to be working anymore.</p>
]]></content:encoded>
			<wfw:commentRss>http://joemaller.com/703/two-little-monobook-styling-hacks-for-mediawiki/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>getSelection() Workaround for Safari 1.3, 2.0 and Firefox 1.0.3</title>
		<link>http://joemaller.com/503/getselection-workaround/</link>
		<comments>http://joemaller.com/503/getselection-workaround/#comments</comments>
		<pubDate>Sun, 24 Apr 2005 05:56:20 +0000</pubDate>
		<dc:creator>Joe</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[bookmarklet]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[safari]]></category>
		<category><![CDATA[web design]]></category>

		<guid isPermaLink="false">http://joemaller.com/2005/04/24/post503/503</guid>
		<description><![CDATA[A simple workaround for problems introduced by security-based changes to getSelection in Safari and Firefox.]]></description>
			<content:encoded><![CDATA[<p><b>update 2:</b> These workarounds also work with Safari 2.0 in Mac OS X v10.4 .<br />
<b>update:</b> There&#8217;s a simpler fix, <a href="#plusquotequote">jump to the bottom</a>.</p>
<p>Yesterday morning I noticed a change to the JavaScript/DOM getSelection() behavior in the new Safari 1.3 (in 10.3.9) and the most recent version of Firefox 1.0.3.</p>
<p>I&#8217;ve been using this method for years to pull selected text from web pages for several <a href="http://www.joemaller.com/translation_bookmarklets.shtml">of my bookmarklets</a>. The one I use most frequently generates a link from whatever text is selected. If nothing is selected, it grabs the document&#8217;s title. The change in getSelection() broke that bookmarklet, no selected text was recognized.</p>
<p>After a bit of research, I found Mozilla&#8217;s <a href='http://developer-test.mozilla.org/docs/Safely_accessing_content_DOM_from_chrome'>Safely accessing content DOM from chrome</a> page which describes the security fixes behind the modification and detailing other problems the changes had caused.  Based on <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=290777">Mozilla bug 290777</a> and this <a href="http://weblog.scifihifi.com/2005/04/18/cocoalicious-and-safari-13/">post by Buzz Anderson</a>, both browsers seem to have problems with the change. Despite those bugs, I managed to find the simple workaround as described below.</p>
<p>What Safari and Firefox now seem to be doing is creating a DOM selection object from getSelection() instead of treating it as a simple string. The result is that getSelection()  appear to be a string, but few of the string manipulation functions work without additional considerations.</p>
<p>The following examples are all intended to be tested as bookmarklets, drag them to your bookmarks bar for testing:</p>
<ul>
<li>
<a href="javascript:d=window.getSelection();alert(d);">getSelection() test 1</a><br />
<code>javascript:d=window.getSelection();<br />
alert(d);</code></p>
<p>Works as expected in Safari 1.2.4, Safari 1.3 and Firefox 1.03, popping an alert containing the selected text. Trying to measure that returned string fails in Safari 1.3 and Firefox 1.0.3 but works in Safari 1.2.4:
</li>
<li><a href="javascript:d=window.getSelection();alert(d.length);">getSelection() test 2</a><br />
<code>javascript:d=window.getSelection();alert(d.length);</code></p>
<p>The older version of Safari returns a character count for the string of selected text. Firefox and Safari 1.3 return &#8220;undefined&#8221;. There are quite a few other problems:</li>
<li><a href="javascript:d=window.getSelection();alert(d.toString());">getSelection() test  3</a><br />
<code>javascript:d=window.getSelection();<br />
alert(d.toString());</code></p>
<p>Works in Firefox and Safari 1.2.4 but not in Safari 1.3.</li>
<li><a href="javascript:d=window.getSelection();alert(d.toString().length);">getSelection() test 4</a><br />
<code>javascript:d=window.getSelection();<br />
alert(d.toString().length);</code></p>
<p>Getting the length after toString works in Safari 1.2.4 and Firefox.</li>
</ul>
<p>Further inconsistencies between Safari 1.3 and Firefox 1.0.3:</p>
<ul>
<li><a href="javascript:d=window.getSelection();alert(d.type);">getSelection() test 5</a><br />
<code>javascript:d=window.getSelection();alert(d.type);</code></p>
<p>Returns &#8220;Range&#8221; in Safari with a selection, returns &#8220;Caret&#8221; or &#8220;None&#8221; with nothing selected. Fails with &#8220;undefined&#8221; in Firefox. (I think the <a href='http://developer-test.mozilla.org/docs/index.php?title=Working_around_the_Firefox_1.0.3_DHTML_regression&#038;redirect=no'>Firefox 1.0.3 DHTML regression bug</a> might be preventing it from working in Firefox but I didn&#8217;t try any of the recent nightly builds.)</li>
<li><a href="javascript:d=window.getSelection();alert(d.getRangeAt(0));">getSelection() test  6</a><br />
<code>javascript:d=window.getSelection();<br />
alert(d.getRangeAt(0));</code></p>
<p>Fails silently in Safari, returns selected text in Firefox. Safari dumps this into the Console log:<br />
 <code>[5956] :TypeError - Value undefined (result of expression d.getRangeAt) is not object.</code></li>
<li>
<a href="javascript:d=window.getSelection();alert(d.typeDetail);">getSelection() test  7</a><br />
<code>javascript:d=window.getSelection();<br />
alert(d.typeDetail);</code></p>
<p>Fails with &#8220;undefined&#8221; in both.</li>
</ul>
<p>There is some good news:</p>
<ul>
<li>
<a href="javascript:d=window.getSelection();alert(d.isCollapsed);">getSelection() test 8</a><br />
<code>javascript:d=window.getSelection();<br />
alert(d.isCollapsed);</code></p>
<p>Works in both Firefox and Safari 1.3; fails in Safari 1.2.4 as &#8220;undefined&#8221;. This means (finally!) there is a workaround for my problem.</li>
</ul>
<p>I was using the length property to determine whether a selection was empty or not, then fetching the title of the window if that value was 0. Knowing that length no longer works in Firefox and Safari, isCollapsed can be used as a conditional switch.</p>
<ul>
<li><a href="javascript:d=window.getSelection();d=(d.isCollapsed||d.length==0)?document.title:d;alert(d);">getSelection() Workaround</a><br />
<code>javascript:d=window.getSelection();<br />
d=(d.isCollapsed||d.length==0)?document.title:d;<br />
alert(d);</code></p>
<p>That will return any selected text or the document title if there is no selection. Tested successfully in Safari 1.2.4, Safari 1.3, Firefox 1.0.3 and presumably Safari 2.0 as well.
</li>
</ul>
<p>Line breaks were added to visible code examples because my style-sheet choked on long lines and I can&#8217;t redo the CSS right now&#8230;</p>
<p><b><a name="plusquotequote"></a>Update:</b> After working through all of the above, I realized there is a far simpler solution: <code>+''</code>. The Safari problem seems to be that string methods do not work on the returned object from getSelection(). Forcing the result into a string by concatenating with an empty string fixes all of my bookmarklets. Concat() fails because it&#8217;s a method of string, use the <code>"+"</code> joining operator and an empty string <code>''</code> instead.</p>
<ul>
<li>
<a href="javascript:d=window.getSelection()+'';d=(d.length==0)?document.title:d;alert(d);">getSelection() Faster Fix</a><br />
<code>javascript:d=window.getSelection()+'';<br />
d=(d.length==0)?document.title:d;<br />
alert(d);</code>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://joemaller.com/503/getselection-workaround/feed/</wfw:commentRss>
		<slash:comments>32</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Database Caching 1/24 queries in 0.023 seconds using disk: basic
Object Caching 380/432 objects using disk: basic

Served from: joemaller.com @ 2012-02-08 13:26:41 -->

<!-- W3 Total Cache: Page cache debug info:
Engine:             disk: enhanced
Cache key:          tag/web-design/feed/_index.xml_gzip
Caching:            enabled
Status:             not cached
Creation Time:      0.632s
Header info:
Set-Cookie:         bb2_screener_=1328725601+38.107.179.218+38.107.179.218; path=/
X-Pingback:         http://joemaller.com/wordpress/xmlrpc.php
Content-Type:       text/xml; charset=UTF-8
Last-Modified:      Wed, 08 Feb 2012 18:26:41 GMT
Vary:               Accept-Encoding, Cookie
Expires:            Wed, 08 Feb 2012 19:26:41 GMT
Pragma:             public
Cache-Control:      public, must-revalidate, proxy-revalidate
Etag:               ebc39466e9c76e950fe8b18e3bae5130
X-Powered-By:       W3 Total Cache/0.9.2.4
Content-Encoding:   gzip
-->
