<?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>Ilia Draznin Online &#187; JavaScript</title>
	<atom:link href="http://iliadraznin.com/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://iliadraznin.com</link>
	<description>javascript • css • html5 &#38; ajax • art &#38; design • technology</description>
	<lastBuildDate>Sun, 29 Aug 2010 15:46:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Write single-page Ajax web applications with Sammy.js</title>
		<link>http://iliadraznin.com/2010/08/singlepage-ajax-web-apps-sammy-js/</link>
		<comments>http://iliadraznin.com/2010/08/singlepage-ajax-web-apps-sammy-js/#comments</comments>
		<pubDate>Tue, 17 Aug 2010 03:10:24 +0000</pubDate>
		<dc:creator>Ilia</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[hash]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[url]]></category>
		<category><![CDATA[web app]]></category>

		<guid isPermaLink="false">http://iliadraznin.com/?p=295</guid>
		<description><![CDATA[Tutsplus.com has a great intro tutorial to Sammy.js, a small JavaScript framework that allows you to write single page web apps, similar to Gmail for example. Because Sammy.js is built on top of jQuery it’s very small, only about 20kb. With this framework you can keep track of your app’s state via hash (#) in [...]]]></description>
			<content:encoded><![CDATA[<p><a rel="nofollow" href="http://net.tutsplus.com/tutorials/javascript-ajax/quick-tip-an-introduction-to-sammy-js/" target="_blank">Tutsplus.com</a> has a great intro tutorial to <a href="http://code.quirkey.com/sammy/">Sammy.js</a>, a small JavaScript framework that allows you to write single page web apps, similar to Gmail for example. Because Sammy.js is built on top of <a rel="nofollow" href="http://jquery.com/" target="_blank">jQuery</a> it’s very small, only about 20kb. With this framework you can keep track of your app’s state via hash (#) in the URL, without the need to refresh the site as you go from page to page, and of course it allows you to use the browser’s back button as well.</p>
<p>Check out the full tutorial at <a href="http://net.tutsplus.com/tutorials/javascript-ajax/quick-tip-an-introduction-to-sammy-js/">net.tutsplus.com</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://iliadraznin.com/2010/08/singlepage-ajax-web-apps-sammy-js/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Custom AddThis share button</title>
		<link>http://iliadraznin.com/2010/07/custom-addthis-share-button/</link>
		<comments>http://iliadraznin.com/2010/07/custom-addthis-share-button/#comments</comments>
		<pubDate>Fri, 30 Jul 2010 01:46:21 +0000</pubDate>
		<dc:creator>Ilia</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://iliadraznin.com/?p=272</guid>
		<description><![CDATA[I wanted to have an AddThis share button that would fit better with the site’s design, and if you’re reading this post on its own page you can scroll down and see what I mean. While AddThis provides plenty of ways to customize their buttons, there is no way to assign your own image to [...]]]></description>
			<content:encoded><![CDATA[<p>I wanted to have an AddThis share button that would fit better with the site’s design, and if you’re reading this post on its own page you can scroll down and see what I mean. While AddThis provides plenty of ways to customize their buttons, there is no way to assign your own image to the icon, which means doing it the hard way… well, relatively speaking of course.</p>
<p>There are three main steps to creating a customized share button. There’s some javascript to include in the footer.php, few lines of html to add at the end of your posts, and of course some styles and the icon itself.<br />
<span id="more-272"></span></p>
<h3>JavaScript</h3>
<p>You’ll want to add this js code in the footer file as probably the last piece of code. This means it won’t be loading until everything else is done. You can read detailed explanation of what you can do on <a href="http://www.addthis.com/help/client-api" target="_blank" rel="external nofollow">AddThis’ API page</a> but the short of it is — include this script file <b>“http://s7.addthis.com/js/250/addthis_widget.js”</b>. If you want to keep track of various stats AddThis provides, you’ll need to provide your username. This is done with the “addthis_config” variable. So for example, what I have is</p>
<pre class="brush:js">
&lt;script type=&quot;text/javascript&quot;&gt;
var addthis_config = { username:&quot;2late2die&quot;, data_track_clickback:true };
&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://s7.addthis.com/js/250/addthis_widget.js&quot;&gt;&lt;/script&gt;
</pre>
<h3>HTML</h3>
<p>The HTML is pretty much just a regular link, but with certain href target, class and a couple of special addthis attributes. You can style it anyway you want, as you would any other link. Here’s how said link might look</p>
<pre class="brush:php; html-script:true; gutter:false">
&lt;a href=&quot;http://www.addthis.com/bookmark.php?v=250&amp;amp;username=[username]&quot;
  class=&quot;addthis_button&quot; addthis:url=&quot;&lt;?php the_permalink() ?&gt;&quot;
  addthis:title=&quot;&lt;?php the_title_attribute() ?&gt;&quot;&gt;Share&lt;/a&gt;
</pre>
<p><b>“http://www.addthis.com/bookmark.php?v=250&amp;username=[your username here]”</b> is the url the link should be pointing to. It must have the “addthis_button” class, otherwise AddThis js won’t recognize it, and then the <b>addthis:url</b> and <b>addthis:title</b> attributes. These attributes are self explanatory, just remember to use PHP so that they are assigned dynamic values. If you have any code, or plugins, that insert tags with attributes or class names into the title (like in my case, wp-typography, which puts <code>&lt;span class=&quot;caps&quot;&gt;</code> around any caps-only words, like acronyms and such) then use the “the_title_attribute()” function, instead of the typical “the_title()”. It strips the tags and escapes any problematic characters.</p>
<h3>CSS</h3>
<p>This is really all up to you, depending on how you want to style the button and the tooltips with the various sites. By default the AddThis scripts provides its own style, so if you don’t mind the white tooltip box, all you’ll need to style is the link itself. If you want to style the tooltips as well, then you’ll need to dig into the generated code for them and the styles used by default, and figure out which ones you want to change. (You can check out my styles to see how I gave it a dark theme by switching a few colors.)</p>
<p>If you like optimizing your code you might decide to not include the AddThis styles file at all. You can do this by adding “ui_use_css:false” to “addthis_config”, i.e.</p>
<pre class="brush:js; gutter:false">
var addthis_config = { ui_use_css:false };
</pre>
<p>That CSS file weighs in at about 52k, which is actually quite hefty. There are, however, two reasons to keep, instead of removing it.<br />
First of all, by removing it, you will have to provide all the styles to AddThis widget from scratch, as it were, including all those icons for the various services, which are backgrounds of the links, not image tags in the HTML. It’s certainly doable but it’s a hastle that might be not worth it at the end (depending on how anal you are about optimizing your code). The other reason is that, because AddThis is a fairly popular widget, many of your users are likely to have already downloaded that css file when they encountered the AddThis button on other sites. This means it’s cached in the browser and takes little to no time to download.</p>
<p>Now, as for that FB “like” button, looks like it might be tricky…</p>
]]></content:encoded>
			<wfw:commentRss>http://iliadraznin.com/2010/07/custom-addthis-share-button/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Simple jQuery placeholder script for input fields</title>
		<link>http://iliadraznin.com/2010/03/simple-jquery-placeholder-script-input-fields/</link>
		<comments>http://iliadraznin.com/2010/03/simple-jquery-placeholder-script-input-fields/#comments</comments>
		<pubDate>Mon, 08 Mar 2010 05:19:35 +0000</pubDate>
		<dc:creator>Ilia</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[input]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://iliadraznin.com/?p=166</guid>
		<description><![CDATA[Placeholder is a very useful attribute of the &#60;input&#62; tag that is specified in the HTML5 spec. It provides a text that goes into the field, by default, and is used as a kind of a quick tip for the user about what they should type into the field, such as “type to search”, or [...]]]></description>
			<content:encoded><![CDATA[<p>Placeholder is a very useful attribute of the &lt;input&gt; tag that is specified in the HTML5 spec. It provides a text that goes into the field, by default, and is used as a kind of a quick tip for the user about what they should type into the field, such as “type to search”, or “type in username”. The nice thing about “placeholder”, as oppose to, for example, simply setting some value for the field, is that it automatically disappears when the user starts typing something in, but it reappears if the user ends up leaving the field empty. Unfortunately this attribute, and its functionality, is actually not supported by most browsers, including Firefox 3.6 and IE8, it is however supported by Chrome 4, and possibly Safari 4 though I can’t vouch for the latter.</p>
<p>I recently had a few projects that needed this functionality, and while some of them had email, password and other fields that required validation, one needed just very simple text fields with placeholder text. So I wrote this very simple javascript function, using jQuery, to do just that (I’m using jQuery 1.4.2 here).<span id="more-166"></span></p>
<pre class="brush: js;">
function setupPlaceholder(inputid) {
	if ($.browser.webkit) return false;

	var target = $('#'+inputid);
	if (target.length==0) {
		target = $('input[type="text"], input[type="email"], input[type="search"]');
	}

	target.each( function(i, el) {
		el = $(el);
		var ph = el.attr('placeholder');
		if (!ph) return true;

		el.addClass('placeholder');
		el.attr('value', ph);

		el.focus( function(e) {
			if( el.val()==ph ) {
				el.removeClass('placeholder');
				el.attr('value', '');
			}
		});

		el.blur( function(e) {
			if( $.trim(el.val())=='' ) {
				el.addClass('placeholder');
				el.attr('value', ph);
			}
		});
	});
}
</pre>
<p>The code is very straightforward. For one it checks that this is not a webkit browser, if it is I assume it supports placeholder attribute and so doesn’t need the code. Then it checks if an ID for the input was provided, just in case I wanted to do this on one field only. If there is no ID, or if it wasn’t found, it’ll simply apply to all inputs of type text, email or search (HTML5 input types).</p>
<p>When combined with some styles you end up with a nice input field with some “help” text, like this.</p>
<style type='text/css'><!--
	input#inputeg {
		margin:4px 0;
		border:1px solid #666;
		color:#000;
		font:normal 1.2em arial, verdana, sans-serif;
	}
	input#inputeg.placeholder { color:#999; border-color:#999; }
	input#inputeg:focus { border-color:#28d; }
--></style>
<input id="inputeg" type="text" placeholder="type something" />
<p><script src='http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js' type='text/javascript'></script><br />
<script type='text/javascript'><!--
function setupPlaceholder(inputid) {
	if ($.browser.webkit) return false;
	var target = $('#'+inputid);
	if (target.length==0) {
		target = $('input[type="text"], input[type="email"], input[type="search"]');
	}
	target.each( function(i, el) {
		el = $(el);
		var ph = el.attr('placeholder');
		if (!ph) return true;
		el.addClass('placeholder');
		el.attr('value', ph);
		el.focus( function(e) {
			if( el.val()==ph ) {
				el.removeClass('placeholder');
				el.attr('value', '');
			}
		});
		el.blur( function(e) {
			if( $.trim(el.val())=='' ) {
				el.addClass('placeholder');
				el.attr('value', ph);
			}
		});
	});
}
setupPlaceholder('inputeg');
//--></script></p>
<p>The one “catch” with this script is that I don’t check the case where a user would put the same text in as the placeholder text. If the user does this, then when they focus on the field again, the text will be erased (’cause the script thought it’s the placeholder text). To fix that you can add a flag that keeps track of whether the user has edited the field or not.</p>
]]></content:encoded>
			<wfw:commentRss>http://iliadraznin.com/2010/03/simple-jquery-placeholder-script-input-fields/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
