<?xml version="1.0" encoding="utf-8" ?>

<rss version="2.0" 
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:admin="http://webns.net/mvcb/"
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
   xmlns:wfw="http://wellformedweb.org/CommentAPI/"
   xmlns:content="http://purl.org/rss/1.0/modules/content/"
   >
<channel>
    
    <title>mysiteonline™ - Web Development</title>
    <link>http://life.mysiteonline.org/</link>
    <description>Brendon Kozlowski's Home on the Web.</description>
    <dc:language>en</dc:language>
    <generator>Serendipity 1.5.4 - http://www.s9y.org/</generator>
    <pubDate>Mon, 20 Dec 2010 15:53:19 GMT</pubDate>

    <image>
        <url>http://life.mysiteonline.org/templates/default/img/s9y_banner_small.png</url>
        <title>RSS: mysiteonline™ - Web Development - Brendon Kozlowski's Home on the Web.</title>
        <link>http://life.mysiteonline.org/</link>
        <width>100</width>
        <height>21</height>
    </image>

<item>
    <title>jQuery Printed Footer Links</title>
    <link>http://life.mysiteonline.org/archives/191-jQuery-Printed-Footer-Links.html</link>
            <category>Web Development</category>
    
    <comments>http://life.mysiteonline.org/archives/191-jQuery-Printed-Footer-Links.html#comments</comments>
    <wfw:comment>http://life.mysiteonline.org/wfwcomment.php?cid=191</wfw:comment>

    <slash:comments>8</slash:comments>
    <wfw:commentRss>http://life.mysiteonline.org/rss.php?version=2.0&amp;type=comments&amp;cid=191</wfw:commentRss>
    

    <author>nospam@example.com (Brendon Kozlowski)</author>
    <content:encoded>
    I was randomly perusing the web and stumbled across an older interesting &lt;a href=&quot;http://www.alistapart.com/articles/improvingprint/&quot;&gt;List Apart article&lt;/a&gt; (September 19, 2005 to be exact).  In it, the author used JavaScript to create a list of all links found on the page, and then create a footer with a footnote-like list. I was using simple CSS to display the URL of the hyperlink in print display media, but that doesn&#039;t work in some browsers (IE), and worse off it can really mess up the visual order of the page.&lt;br /&gt;
&lt;br /&gt;
Inspired by the article&#039;s intentions, I decided to use some jQuery to whip up a similar solution &lt;em&gt;and I took the opportunity to use jQuery 1.4&#039;s new syntax for object creation&lt;/em&gt; (so this is 1.4 code only - see comments for a 1.3.x solution).  Differences? I exclude hyperlinks set to the hash symbol (#) which shouldn&#039;t be found anyway (graceful degredation people!), &quot;mailto&quot; links, and I don&#039;t find link element&#039;s citations (blockquote &quot;cite&quot; property).  I also believe his script would grab image information, but I&#039;m not entirely sure, mine only searches hyperlinks.  I also opted not to exclude listings of duplicate hyperlink values. If it&#039;s found twice, it lists it in the footer twice. Less JS processing, and more clear to the visitor (in my opinion).&lt;br /&gt;
&lt;br /&gt;
Expected Issues: It requires JavaScript (and the jQuery library included on your page). If JavaScript is enabled but CSS is disabled, the hidden content will be visible to the user.&lt;br /&gt;
&lt;br /&gt;
On to the code!&lt;br /&gt;
&lt;br /&gt;
First thing&#039;s first, we should find the links in our code that we&#039;d like to target.  For &lt;strong&gt;my&lt;/strong&gt; situation, I have a content class defined on my page for all content, and the column that contains the actual body is called &quot;.col2_right&quot; (yes, I know, ignore the fact of the poor naming scheme).  So, in jQuery, we&#039;re going to target all hyperlinks found in the col2_right and content classes, but we don&#039;t want to include links to hashes or mailto links. I&#039;ve also removed listing to nofollow links, but that is my choice (probably not a good one, but I digress).&lt;br /&gt;
&lt;br /&gt;
&lt;textarea name=&quot;code&quot; class=&quot;javascript&quot;&gt;var links = $(&#039;.col2_right.content a[href]:not([href^=#],[href^=mailto],[rel=nofollow])&#039;);&lt;/textarea&gt;&lt;br /&gt;
We&#039;ll also need some sort of container to keep these found links wrapped in.  I chose to use a fieldset and legend, you could just as easily create a DIV and a H2 or other tags for your own purposes. I also want to create an ordered list to match the found hyperlinks.&lt;br /&gt;
&lt;textarea name=&quot;code&quot; class=&quot;javascript&quot;&gt;var footnotesWrapper = $(&#039;&lt;fieldset&gt;&#039;, {
	css: {
		clear: &#039;both&#039;
	}
}).addClass(&#039;print_only&#039;);
var footnotesLabel = $(&#039;&lt;legend&gt;&#039;, {
	text: &#039;Website Addresses Used in the Document&#039;
}).appendTo(footnotesWrapper);

//create an OL to hold the footnotes
var footnoteList = $(&#039;&lt;ol&gt;&#039;).appendTo(footnotesWrapper);&lt;/textarea&gt;&lt;br /&gt;
Here comes the real center, meaty goodness of the script: looping through our list of found hyperlinks, creating a little notification text next to the hyperlink&#039;s text, and add the hyperlink URL itself to the footnote section in the ordered list as a list item.&lt;br /&gt;
&lt;br /&gt;
We use jQuery&#039;s each() method to loop through the items in the array, grab the link&#039;s URL so that we can do some testing on it, and modify it&#039;s value for inclusion in to the footnotes. Some links may be relative URLs, but that doesn&#039;t mean much to someone who doesn&#039;t know what a relative URL is. In fact, it would probably confuse me too at first. I then create a span tag to hold the associated footnote number (the ListApart article used a superscript tag, I found regular text is more easily readable), add a class to it so it&#039;s only visible when printed, and create my list item element with the URL from our link, and place those elements in to the document in the appropriate places with the appendTo jQuery function.&lt;br /&gt;
&lt;textarea name=&quot;code&quot; class=&quot;javascript&quot;&gt;$.each(links, function(i){
	var linkText = $(this).text();
	var linkValue = $(this).attr(&#039;href&#039;);
	if(linkValue.substring(0,1) === &#039;/&#039;){
		linkValue = &#039;http://&#039;+document.location.host + linkValue;
	}
	//create element to hold span with class to hide except on print
	var newElement = $(&#039;&lt;span&gt;&#039;, {
		text: &#039; [&#039;+ ++i +&#039;]&#039;
	}).addClass(&#039;print_only&#039;).appendTo($(this));

	var listEntry = $(&#039;&lt;li&gt;&#039;, {
		text: linkValue
	}).appendTo(footnoteList);
});&lt;/textarea&gt;&lt;br /&gt;
Last but not least, we append our entire footnote to the end of our content body section.  The full code is below.&lt;br /&gt;
&lt;textarea name=&quot;code&quot; class=&quot;javascript&quot;&gt;$(document).ready(function(){
	//get the container and target
	var links = $(&#039;.col2_right.content a[href]:not([href^=#],[href^=mailto],[rel=nofollow])&#039;);

	if($(links).length){
		//create a container and heading for the footnotes
		var footnotesWrapper = $(&#039;&lt;fieldset&gt;&#039;, {
			css: {
				clear: &#039;both&#039;
			}
		}).addClass(&#039;print_only&#039;);
		var footnotesLabel = $(&#039;&lt;legend&gt;&#039;, {
			text: &#039;Website Addresses Used in the Document&#039;
		}).appendTo(footnotesWrapper);

		//create an OL to hold the footnotes
		var footnoteList = $(&#039;&lt;ol&gt;&#039;).appendTo(footnotesWrapper);

		$.each(links, function(i){
			var linkText = $(this).text();
			var linkValue = $(this).attr(&#039;href&#039;);
			if(linkValue.substring(0,1) === &#039;/&#039;){
				linkValue = &#039;http://&#039;+document.location.host + linkValue;
			}
			//create element to hold span with class to hide except on print
			var newElement = $(&#039;&lt;span&gt;&#039;, {
				text: &#039; [&#039;+ ++i +&#039;]&#039;
			}).addClass(&#039;print_only&#039;).appendTo($(this));

			var listEntry = $(&#039;&lt;li&gt;&#039;, {
				text: linkValue
			}).appendTo(footnoteList);
		});

		// append the heading and &lt;ol&gt; to the target
		$(&#039;.col2_right.content&#039;).append(footnotesWrapper);
	}
});&lt;/textarea&gt;&lt;br /&gt;
&lt;br /&gt;
Note the added &quot;if&quot; statement to check the length of the links variable. If it is empty, we did not find any links and don&#039;t want to create any extra markup when printing the page.&lt;br /&gt;
&lt;br /&gt;
Oh, and the CSS: &quot;.print_only { display:none; }&quot; This should be placed in your normal style sheet, and leave it out from your print style sheet. If you don&#039;t have a print style sheet, extend it a bit: @media print { .print_only { display:none; } }&lt;br /&gt;
&lt;br /&gt;
Note: Thanks to Stiles to provide some fixes and compatibility changes for jQuery 1.3.x. 
    </content:encoded>

    <pubDate>Mon, 08 Mar 2010 11:52:51 -0800</pubDate>
    <guid isPermaLink="false">http://life.mysiteonline.org/archives/191-guid.html</guid>
    
</item>
<item>
    <title>Style Switcher with jQuery</title>
    <link>http://life.mysiteonline.org/archives/194-Style-Switcher-with-jQuery.html</link>
            <category>Web Development</category>
    
    <comments>http://life.mysiteonline.org/archives/194-Style-Switcher-with-jQuery.html#comments</comments>
    <wfw:comment>http://life.mysiteonline.org/wfwcomment.php?cid=194</wfw:comment>

    <slash:comments>1</slash:comments>
    <wfw:commentRss>http://life.mysiteonline.org/rss.php?version=2.0&amp;type=comments&amp;cid=194</wfw:commentRss>
    

    <author>nospam@example.com (Brendon Kozlowski)</author>
    <content:encoded>
    While developing an Adobe AIR application using CSS/HTML/JS, I decided I wanted to allow for templating of the application. The default template has the ability to switch view states (horizontal, or vertical). Since I&#039;m building the application with CSS, HTML and JavaScript (with jQuery), I thought that in order to create this effect, I&#039;d use a style switcher.&lt;br /&gt;
&lt;br /&gt;
I then thought...hey, I wonder if this would work in browsers other than the WebKit version I&#039;ve been testing under?!&lt;br /&gt;
&lt;br /&gt;
It worked in Firefox 3.6.3, Opera 10.51, Chrome 5.0.342.8 beta, and Internet Explorer 6 (although my test CSS was broken in IE6). Opera 10.50 (tested first) had an issue with loading the secondary CSS on first attempt, but had it cached after that. 10.51 loaded everything just fine, but I can&#039;t be sure if it was still cached from the attempt with 10.50, or if 10.51 fixed an unknown issue to help fix it.&lt;br /&gt;
&lt;br /&gt;
So, how did I do it?&lt;br /&gt;
&lt;br /&gt;
Back in the day, Firefox had a little-known and not-often-used feature that allowed web-designers to incorporate multiple CSS layouts/designs right in the site, and the users could choose on-the-fly which UI they&#039;d like to use (on each session) by going to &lt;u&gt;V&lt;/u&gt;iew, Page St&lt;u&gt;y&lt;/u&gt;le, and then choose the style you wanted - if more than a single style was available from within the code. To give users this option, you include secondary stylesheets after the first, but in the link element, you specify that it&#039;s an &lt;strong&gt;alternative&lt;/strong&gt; stylesheet, as so:&lt;br /&gt;
&lt;textarea name=&quot;code&quot; class=&quot;html&quot;&gt;&lt;link media=&quot;screen&quot; title=&quot;horizontal&quot; href=&quot;http://life.mysiteonline.org/css/horiz-style.css&quot; type=&quot;text/css&quot; rel=&quot;stylesheet&quot; /&gt;
&lt;link media=&quot;screen&quot; title=&quot;horizontal&quot; href=&quot;http://life.mysiteonline.org/css/vert-style.css&quot; type=&quot;text/css&quot; rel=&quot;alternative stylesheet&quot; /&gt;&lt;/textarea&gt;&lt;br /&gt;
&lt;br /&gt;
I originally started with this concept and tried swapping out the primary for the secondary and vice versa.  Unfortunately this had some issues during development that may have been related to some other problems, but I dropped this attempt (but if Opera has a problem with caching, this route would solve that).  Instead, I simply changed the &lt;strong&gt;href&lt;/strong&gt; property of the link element. It was easier to target with jQuery without using URL matching/REGEX, or arbitrary naming of the &lt;strong&gt;rel&lt;/strong&gt; property.&lt;br /&gt;
&lt;br /&gt;
Anyhow, here&#039;s the code that I used (in this example, I am clicking on a button with ID of &quot;switch&quot;):&lt;br /&gt;
&lt;textarea name=&quot;code&quot; class=&quot;javascript&quot;&gt;//do the CSS style toggle change
$(&#039;#switch&#039;).bind(&#039;click&#039;, function(e){
	$(&#039;#application&#039;).fadeOut(200,function(){
		var cssStyle = $(&quot;link[media=&#039;screen&#039;][href]&quot;).attr(&#039;href&#039;);
		if(cssStyle == &#039;/css/vert-style.css&#039;){
			$(&quot;link[media=&#039;screen&#039;]&quot;).attr(&#039;href&#039;, &#039;/css/horiz-style.css&#039;);
		}else{
			$(&quot;link[media=&#039;screen&#039;]&quot;).attr(&#039;href&#039;, &#039;/css/vert-style.css&#039;);
		}
		$(&#039;#application&#039;).fadeIn(200);
	});
});&lt;/textarea&gt;&lt;br /&gt;
&lt;br /&gt;
What this is doing:&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;Bind an onClick event to the element with an id of &quot;switch&quot;&lt;/li&gt;
&lt;li&gt;find the LINK element of a media type of screen that contains an href property and assign it to the variable &quot;cssStyle&quot;&lt;/li&gt;
&lt;li&gt;fade out the application (or a website wrapper?)&lt;/li&gt;
&lt;li&gt;swap the CSS style for another (inline), depending on what&#039;s currently loaded&lt;/li&gt;
&lt;li&gt;fade the application (or website wrapper) back in with new style&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
...and we now have our style swapped out (quickly and easily) for an entirely new style. 
    </content:encoded>

    <pubDate>Wed, 07 Apr 2010 07:41:52 -0700</pubDate>
    <guid isPermaLink="false">http://life.mysiteonline.org/archives/194-guid.html</guid>
    
</item>

</channel>
</rss>
