<?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>CoffeeBear.net &#187; javascript</title>
	<atom:link href="http://coffeebear.net/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://coffeebear.net</link>
	<description></description>
	<lastBuildDate>Mon, 14 May 2012 02:58:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Brain Dump 01</title>
		<link>http://coffeebear.net/2012/01/19/brain-dump-01/</link>
		<comments>http://coffeebear.net/2012/01/19/brain-dump-01/#comments</comments>
		<pubDate>Fri, 20 Jan 2012 02:29:55 +0000</pubDate>
		<dc:creator>Mark</dc:creator>
				<category><![CDATA[Life]]></category>
		<category><![CDATA[Rants]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[driving]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://coffeebear.net/?p=2966</guid>
		<description><![CDATA[One of my goals for this year is to write more here; so while I don’t have a single idea that feels worthy of a full post, here’s a dump of various things floating around/through my skull today. Is today stupid driving day or something? I’ll grant I left for work a few minutes later [...]]]></description>
			<content:encoded><![CDATA[<p>One of my goals for this year <a class="simple-footnote" title="I don&#039;t really do new year resolutions, but I do occasionally set personal goals for the new year around January 1st." id="return-note-2966-1" href="#note-2966-1"><sup>1</sup></a> is to write more here; so while I don’t have a single idea that feels worthy of a full post, here’s a dump of various things floating around/through my skull today.</p>
<ul>
<li>Is today stupid driving day or something? I’ll grant I left for work a few minutes later than usual, but it seems odd that so many people would continually be pulling out into moving traffic (from driveways and side streets) and then going so slowly <a class="simple-footnote" title="Example in a 40mph zone, a car pulled out of a driveway less than half a block ahead of me, pulled across the lane I was driving in into the other lane and then just as I caught up to them they pulled right back in front of me." id="return-note-2966-2" href="#note-2966-2"><sup>2</sup></a>. Fortunately the roads were relatively clean this morning, so I was able to stop before plowing into any of those idiots, but still.…</li>
<li>Back in the day when Javascript was new to the web, many sites used it to frequently touch my browser in the bad way. So I quickly grew to hate it and pretty much ignored/disabled it for years. In more recent times, Javascript usage has grown up/cleaned up its act. To the point where I’m actually interested in learning to use it. So I’ve been searching around for some decent tutorials but haven’t had a lot of luck. Most tutorials either assume you already know quite a bit about Javascript or are so extremely dated that they’re useless. I did run across 2 sites with tutorials that don’t seem to be too awful: <a title="Learn to Code | Codecademy" href="http://codeacademy.com">Codecademy</a> <a class="simple-footnote" title="Codecademy gives a decent general knowledge of Javascrip. Though the site is far from perfect, with bugs in the lessons that prevent you from completing them or with questions that unclear in what they are looking for and hints that can be utterly useless" id="return-note-2966-3" href="#note-2966-3"><sup>3</sup></a> and <a title="In the Woods &amp;#8211; &amp;#8220;jQuery for Absolute Beginners&amp;#8221; Video Series | ThemeForest.net" href="http://blog.themeforest.net/tutorials/jquery-for-absolute-beginners-video-series/">jQuery for Absolute Beginners</a> <a class="simple-footnote" title="While technically these tutorials cover jQuery (a Javascript library) rather than &quot;pure&quot; Javascript and while covering an older version of jQuery (1.2.6), it still has been very interesting to go over so far." id="return-note-2966-4" href="#note-2966-4"><sup>4</sup></a></li>
<li>I’ve been thinking about about redesigning this site, but I’m trouble deciding what to do. I’ve got some ideas floating around in my skull, but I might hold off until I can look into working up a logo.</li>
</ul>
<p><small><a href="http://coffeebear.net/2012/01/19/brain-dump-01/">Brain Dump 01</a> © <a href="http://coffeebear.net" rel="cc:attributionURL">Mark McKibben</a>, <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/us/">Creative Commons Attribution-NonCommercial-ShareAlike 3.0 United States</a>.</small></p><div class="simple-footnotes"><p class="notes">Notes:</p><ol><li id="note-2966-1">I don’t really do new year resolutions, but I do occasionally set personal goals for the new year around January 1st. <a href="#return-note-2966-1">↩</a></li><li id="note-2966-2">Example in a 40mph zone, a car pulled out of a driveway less than half a block ahead of me, pulled across the lane I was driving in into the other lane and then just as I caught up to them they pulled right back in front of me. <a href="#return-note-2966-2">↩</a></li><li id="note-2966-3">Codecademy gives a decent general knowledge of Javascrip. Though the site is far from perfect, with bugs in the lessons that prevent you from completing them or with questions that unclear in what they are looking for and hints that can be utterly useless <a href="#return-note-2966-3">↩</a></li><li id="note-2966-4">While technically these tutorials cover jQuery (a Javascript library) rather than “pure” Javascript and while covering an older version of jQuery (1.2.6), it still has been very interesting to go over so far. <a href="#return-note-2966-4">↩</a></li></ol></div>]]></content:encoded>
			<wfw:commentRss>http://coffeebear.net/2012/01/19/brain-dump-01/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Author Pages with hCard &amp; jQuery</title>
		<link>http://coffeebear.net/2010/01/18/author-pages-with-hcard-jquery/</link>
		<comments>http://coffeebear.net/2010/01/18/author-pages-with-hcard-jquery/#comments</comments>
		<pubDate>Tue, 19 Jan 2010 05:00:48 +0000</pubDate>
		<dc:creator>Mark</dc:creator>
				<category><![CDATA[Web Design]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[hCard]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[microformats]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Theme]]></category>

		<guid isPermaLink="false">http://coffeebear.net/?p=972</guid>
		<description><![CDATA[While I’m definitely not the designer that any of the people who created these beautiful hCards, I was greatly impressed by them. In particular, I liked the personal hCard created by Tim Van Damme and decided to make my own version of it. Only since I’m using WordPress rather; than a static site, I wanted [...]]]></description>
			<content:encoded><![CDATA[<p>While I’m definitely not the designer that any of the people who created these <a title="hCard Examples in the wild" href="http://microformats.org/wiki/hcard-examples-in-wild">beautiful hCards</a>, I was greatly impressed by them. In particular, I liked the personal hCard created by <a href="http://timvandamme.com/">Tim Van Damme</a> and decided to make my own version of it. Only since I’m using WordPress rather; than a static site, I wanted the page to be generated automatically from info stored with my user profile within WordPress. Unfortunately WordPress does not by default store all the information I wanted to display as part of the user profile.</p>
<p>Initially when I setup the author page, I used the <a title="WordPress &amp;#8250; Cimy User Extra Fields &amp;laquo; WordPress Plugins" href="http://wordpress.org/extend/plugins/cimy-user-extra-fields/">Cimy User Extra Fields</a> plugin to get those extra fields; however in the words of Lord Downey, “It, uh … lacked elegance.” Don’t get me wrong, Marco Cimmino has created a very powerful and useful plugin. My problem is that it’s too complicated for what I want to do. Then almost as though the WordPress developers read my mind, the release of WordPress 2.9 included a new filter making it simple to add/remove new fields to the user profile page.  So easy in fact that the following bit of PHP code added to my theme’s function.php file was all that was required to add the fields I needed.</p>
<pre class="brush: php; title: ; notranslate">function vl2_contactmethods( $contactmethods ) {
 // Add Twitter
 $contactmethods['twitter'] = 'Twitter';
 //add Facebook
 $contactmethods['facebook'] = 'Facebook';
 //add flickr
 $contactmethods['flickr'] = 'Flickr';
 //add linkedin
 $contactmethods['linkedin'] = 'LinkedIn';
 //add delicious
 $contactmethods['delicious'] = 'Delicious';
 //add phone
 $contactmethods['phone'] = 'Phone';
 //add phone-type
 $contactmethods['phonetype'] = 'Phone Type';
 //add locality
 $contactmethods['locality'] = 'Locality';
 //add region
 $contactmethods['region'] = 'Region';
 //add postalcode
 $contactmethods['postalcode'] = 'Postal Code';
 //add country
 $contactmethods['country'] = 'Country';

 return $contactmethods;
 }
 add_filter('user_contactmethods','vl2_contactmethods',10,1);</pre>
<p>Of course just storing the info with the user’s profile isn’t enough; we also need to be able to pull it back out. This can be done using either the_author_meta or get_the_author_meta. I ended up using get_the_author_meta for two reasons:</p>
<p>1. I’m pulling the author’s meta info outside of the Loop.<br />
2. I wanted to return, not echo the values, so I can manipulate them before displaying them.</p>
<p>But that still wasn’t complicated enough, after all I started this project wanting to generate an hCard, using some jQuery UI to give it a fancy accordion effect. First we load the javascript for that accordion effect, by adding the following to our author.php file.</p>
<pre class="brush: jscript; title: ; notranslate">&lt;script type=&quot;text/javascript&quot;&gt;
 $(function() {
 $(&quot;#accordion&quot;).accordion();
 });
 &lt;/script&gt;</pre>
<p>Next we get all the user fields by:</p>
<pre class="brush: php; title: ; notranslate">&lt;?php if(isset($_GET['author_name'])) :
 // NOTE: 2.0 bug requires: get_userdatabylogin(get_the_author_login());
 $curauth = get_userdatabylogin($author_name);
 $id = $curauth-&gt;ID;
 else :
 $curauth = get_userdata(intval($author));
 $id = $curauth-&gt;ID;
 endif;

 $twitter = get_the_author_meta('twitter', $id);
 $flickr = get_the_author_meta('flickr', $id);
 $linkedin = get_the_author_meta('linkedin', $id);
 $delicious = get_the_author_meta('delicious', $id);
 $lastfm = get_the_author_meta('lastfm', $id);
 $phone = get_the_author_meta('phone', $id);
 $ptype = get_the_author_meta('phone-type', $id);
 $addr = get_the_author_meta('addr', $id);
 $locality = get_the_author_meta('locality', $id);
 $region = get_the_author_meta('region', $id);
 $postalcode = get_the_author_meta('postalcode', $id);
 $country = get_the_author_meta('country', $id);
 ?&gt;</pre>
<p>Now that we’ve got the data and the JavaScript; we need to combine it</p>
<pre class="brush: php; title: ; notranslate">&lt;div id=&quot;authorbox&quot;&gt;
 &lt;?php if (function_exists('get_avatar')) { echo get_avatar((get_the_author_meta('user_email', $id)), '120'); }?&gt;
 &lt;div id=&quot;accordion&quot;&gt;
 &lt;h3&gt;&lt;a href=&quot;#&quot;&gt;About&lt;/a&gt; &lt;span&gt;&lt;span&gt;&lt;?php echo $curauth-&gt;first_name; ?&gt;&lt;/span&gt; &lt;span&gt;&lt;?php echo $curauth-&gt;last_name; ?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
 &lt;div id=&quot;about&quot;&gt;
 &lt;p&gt;&lt;?php echo $curauth-&gt;description; ?&gt;&lt;/p&gt;
 &lt;/div&gt; &lt;!-- #about --&gt;
 &lt;h3&gt;&lt;a href=&quot;#&quot;&gt;Contact&lt;/a&gt;&lt;/h3&gt;
 &lt;div id=&quot;contact&quot;&gt;
 &lt;p&gt;&lt;span&gt;&lt;span&gt;&lt;?php echo $ptype; ?&gt;&lt;/span&gt;&lt;a href=&quot;callto:&lt;?php echo $phone; ?&gt;&quot;&gt;&lt;?php echo $phone; ?&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
 &lt;p&quot;&gt;&lt;a href=&quot;&lt;?php echo get_the_author_meta('user_url', $id); ?&gt;&quot; rel=&quot;me&quot;&gt;&lt;?php echo get_the_author_meta('user_url', $id); ?&gt;&lt;/a&gt;&lt;/p&gt;
 &lt;p&gt;&lt;span&gt;&lt;?php echo $addr; ?&gt;&lt;/span&gt;&lt;br/&gt;
 &lt;span&gt;&lt;?php echo $locality; ?&gt;&lt;/span&gt;, &lt;span&gt;&lt;?php echo $region; ?&gt;&lt;/span&gt; &lt;span&gt;&lt;?php echo $postalcode; ?&gt;&lt;/span&gt;&lt;br/&gt;&lt;span&gt;&lt;?php echo $country; ?&gt;&lt;/span&gt;&lt;/p&gt;
 &lt;/div&gt; &lt;!-- #contact --&gt;
 &lt;h3&gt;&lt;a href=&quot;#&quot;&gt;Networks&lt;/a&gt;&lt;/h3&gt;
 &lt;div id=&quot;social-networks&quot;&gt;
 &lt;ul&gt;
 &lt;li&gt;&lt;a title=&quot;View &lt;?php echo $curauth-&gt;first_name; ?&gt; &lt;?php echo $curauth-&gt;last_name; ?&gt;'s Profile&quot; href=&quot;http://www.linkedin.com/in/&lt;?php echo $linkedin ?&gt;&quot;&gt;&lt;img src=&quot;&lt;?php bloginfo('template_directory'); ?&gt;/images/linkedin.png&quot; alt=&quot;LinkedIn&quot; width=&quot;48&quot; height=&quot;48&quot; /&gt;&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;&lt;a title=&quot;Follow &lt;?php echo $twitter ?&gt; on Twitter&quot; href=&quot;http://twitter.com/&lt;?php echo $twitter ?&gt;&quot;&gt;&lt;img src=&quot;&lt;?php bloginfo('template_directory'); ?&gt;/images/twitter.png&quot; width=&quot;48&quot; height=&quot;48&quot; alt=&quot;Twitter&quot; /&gt;&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;&lt;a title=&quot;See &lt;?php echo $flickr ?&gt;'s photostream&quot; href=&quot;http://www.flickr.com/photos/&lt;?php echo $flickr ?&gt;&quot;&gt;&lt;img src=&quot;&lt;?php bloginfo('template_directory'); ?&gt;/images/flickr.png&quot; alt=&quot;Flickr&quot; width=&quot;48&quot; height=&quot;48&quot; /&gt;&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;&lt;a title=&quot;&lt;?php echo $delicious ?&gt;'s Bookmarks&quot; href=&quot;http://delicious.com/&lt;?php echo $delicious ?&gt;&quot;&gt;&lt;img src=&quot;&lt;?php bloginfo('template_directory'); ?&gt;/images/delicious.png&quot; alt=&quot;Delicious&quot; width=&quot;48&quot; height=&quot;48&quot; /&gt;&lt;/a&gt;&lt;/li&gt;
 &lt;/ul&gt;
 &lt;/div&gt; &lt;!-- #social-networks --&gt;
 &lt;h3&gt;&lt;a href=&quot;#&quot;&gt;&lt;?php echo $curauth-&gt;first_name; ?&gt;'s Last 5 Posts&lt;/a&gt;&lt;/h3&gt;
 &lt;?php $my_query = new WP_Query('showposts=5&amp;author='.$id); ?&gt;
 &lt;div id=&quot;5posts&quot;&gt;
 &lt;ul&gt;
 &lt;?php if ($my_query-&gt;have_posts()) : while ($my_query-&gt;have_posts()) : $my_query-&gt;the_post(); ?&gt;
 &lt;li&gt;&lt;a href=&quot;&lt;?php the_permalink(); ?&gt;&quot; rel=&quot;bookmark&quot; title=&quot;Permanent Link to &lt;?php the_title_attribute(); ?&gt;&quot;&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt; &lt;?php the_time('j F Y'); ?&gt;&lt;/li&gt;
 &lt;?php endwhile; ?&gt;
 &lt;/ul&gt;
 &lt;/div&gt; &lt;!-- #5posts --&gt;
 &lt;/div&gt;&lt;!-- #accordion --&gt;
 &lt;/div&gt;&lt;!-- #authorbox --&gt;
 &lt;?php else : ?&gt;
 &lt;h2&gt;Not Found&lt;/h2&gt;
 &lt;p&gt;Sorry, but you are looking for something that isn't here.&lt;/p&gt;
 &lt;?php endif; ?&gt;</pre>
<p>Oops, I almost forgot to mention; we need to make sure we’re loading jQuery &amp; jQuery UI on the author page. Since I separate out the header stuff into it’s own file (header.php); I added this bit of code before the closing &lt;/head&gt; tag in that file:</p>
<pre class="brush: php; title: ; notranslate">&lt;?php //if (is_author()) wp_enqueue_script('jquery-ui-core');
if (is_author()) {
 wp_deregister_script('jquery');
 wp_register_script('jquery', (&quot;http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js&quot;), false, '');
 wp_deregister_script('jquery-ui-core');
 wp_register_script('jquery-ui-core', (&quot;http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js&quot;), array('jquery'), '');
 wp_enqueue_script('jquery');
 wp_enqueue_script('jquery-ui-core');
} ?&gt;</pre>
<p>And that’s that. Now my author page will by default display my gravatar next to the Biographical Info entered in my profile. There will also be three other section available…</p>
<p>* Contact: Gives selected contact information for me.<br />
* Networks: Displays icons for some social networks I use with links to my profiles on those networks.<br />
* Last 5 Posts: Shows my latest posts.</p>
<p>Later when I have more time, I’ll update the zipped copy of the VectorLover2 theme on this site for people who want to download a complete copy of the code I used for the author pages.</p>
<p>Update: I forgot to thank Joost de Valk for his excellent article, <a title="User Contact Fields in WordPress 2.9 - Yoast" href="http://yoast.com/user-contact-fields-wp29/">User Contact Fields in WordPress 2.9</a>.<br />
Update 2: I changed the code to register jquery-ui-core, so that it recognizes jquery as a dependency. This tutorial had been working fine; but for whatever reason, it suddenly was trying to load jQuery after jQuery-UI (which doesn’t work so good).<br />
Update 3: Hmm, now that I look back at this old post I realize a couple of things: 1) several of the links I’d intended to be here are missing (since corrected) and 2) this post was written worse than I thought it was.</p>
<p><small><a href="http://coffeebear.net/2010/01/18/author-pages-with-hcard-jquery/">Author Pages with hCard &amp; jQuery</a> © <a href="http://coffeebear.net" rel="cc:attributionURL">Mark McKibben</a>, <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/us/">Creative Commons Attribution-NonCommercial-ShareAlike 3.0 United States</a>.</small></p>]]></content:encoded>
			<wfw:commentRss>http://coffeebear.net/2010/01/18/author-pages-with-hcard-jquery/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Database Caching 3/7 queries in 0.009 seconds using disk: basic
Object Caching 649/651 objects using disk: basic

Served from: coffeebear.net @ 2012-05-26 02:23:45 -->
