<?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>Web Development Blog &#187; Snippets</title>
	<atom:link href="http://eisabainyo.net/weblog/category/snippets/feed/" rel="self" type="application/rss+xml" />
	<link>http://eisabainyo.net/weblog</link>
	<description>Web Development, Web Design, Web Applications, Web 2.0, AJAX, WordPress Themes, Search Engine Optimisation, Latest Technologies and more..</description>
	<lastBuildDate>Tue, 24 Jan 2012 08:29:05 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Display a location-aware google map on page load with jQuery mobile</title>
		<link>http://eisabainyo.net/weblog/2012/01/14/display-location-aware-google-map-on-page-load-with-jquery-mobile/</link>
		<comments>http://eisabainyo.net/weblog/2012/01/14/display-location-aware-google-map-on-page-load-with-jquery-mobile/#comments</comments>
		<pubDate>Sat, 14 Jan 2012 09:07:29 +0000</pubDate>
		<dc:creator>eisabai</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Snippets]]></category>

		<guid isPermaLink="false">http://eisabainyo.net/weblog/?p=1851</guid>
		<description><![CDATA[The following snippet of code will display a google map with user&#8217;s default location on jQuery mobile page if location services is enabled.  Otherwise, it will use predefined lat and long values to create the map.   The code uses jQuery mobile pagecreate event.  
A little info on jQuery mobile pagecreate event: [...]<p>Read <a href="http://eisabainyo.net/weblog/2012/01/14/display-location-aware-google-map-on-page-load-with-jquery-mobile/">Display a location-aware google map on page load with jQuery mobile</a> on Web Development Blog!</p><div><h3>Other similiar posts that you might be interested in:</h3><ul><li><a href="http://eisabainyo.net/weblog/2011/01/31/top-10-jquery-mobile-code-snippets-that-you-need-to-know/" rel="bookmark" title="January 31, 2011">Top 10 jQuery Mobile Code Snippets that you need to know</a></li>

<li><a href="http://eisabainyo.net/weblog/2011/06/29/creating-a-contact-form-in-jquery-mobile-and-php/" rel="bookmark" title="June 29, 2011">Creating a Contact Form in jQuery Mobile and PHP</a></li>

<li><a href="http://eisabainyo.net/weblog/2011/06/23/10-useful-javascript-snippets-for-your-mobile-site/" rel="bookmark" title="June 23, 2011">10 Useful Javascript Snippets for your mobile websites</a></li>

<li><a href="http://eisabainyo.net/weblog/2009/04/27/code-to-embed-google-map-and-street-view/" rel="bookmark" title="April 27, 2009">Code to embed Google Map and Street View</a></li>

<li><a href="http://eisabainyo.net/weblog/2008/06/17/the-impact-of-web-servers-location-in-google-search/" rel="bookmark" title="June 17, 2008">The impact of web server&#8217;s location in google search ranking</a></li>

<li><a href="http://eisabainyo.net/weblog/2010/01/16/tips-on-building-websites-for-mobile-browsers/" rel="bookmark" title="January 16, 2010">Tips on building websites for mobile browsers</a></li>

<li><a href="http://eisabainyo.net/weblog/2009/02/02/jquery-calendar-widget-plugin/" rel="bookmark" title="February 2, 2009">jQuery Calendar Widget Plugin</a></li>
</ul><!-- Similar Posts took 382.207 ms --></div>]]></description>
			<content:encoded><![CDATA[<p>The following snippet of code will display a google map with user&#8217;s default location on jQuery mobile page if location services is enabled.  Otherwise, it will use predefined lat and long values to create the map.   The code uses jQuery mobile <a href="http://jquerymobile.com/demos/1.0/docs/api/events.html">pagecreate event</a>.  </p>
<p>A little info on jQuery mobile pagecreate event: </p>
<blockquote><p><strong>pagecreate</strong><br />
Triggered when the page has been created in the DOM (via ajax or other) but before all widgets have had an opportunity to enhance the contained markup. This event is most useful for user&#8217;s wishing to create their own custom widgets for child markup enhancement as the jquery mobile widgets do.</p>
<p><code>$( '#aboutPage' ).live( 'pagecreate',function(event){<br />
  ( ":jqmData(role='sweet-plugin')" ).sweetPlugin();<br />
});</code>
</p></blockquote>
<p>And the snippets:</p>
<p><strong>Javascript</strong></p>
<pre>
function initialize(lat,lng) {
	var latlng = new google.maps.LatLng(lat, lng);

	var myoptions = {
		zoom: 12,
		center: latlng,
		disableDefaultUI: true,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	};

	var map = new google.maps.Map(document.getElementById("googlemap"),myoptions);

	var icon = new google.maps.MarkerImage('images/marker.png',
			new google.maps.Size(20, 20), // size
			new google.maps.Point(0, 0), // origin
			new google.maps.Point(20, 20) // anchor
		);

	var mymarker = new google.maps.Marker({
		position: latlng,
		map: map,
		icon: icon
	});
}
</pre>
<pre>
$('.page-map').live("pagecreate", function() {
        var lat = -33.887418, lng = 151.17403;
	if(navigator.geolocation) {
		navigator.geolocation.getCurrentPosition(function(position){
			initialize(position.coords.latitude,position.coords.longitude);
		}, function() { console.log('Error with getCurrentPosition'); });
	} else {
                // predefined location
		initialize(lat, lng);
	}
});
</pre>
<p><strong>HTML</strong></p>
<pre>
&lt;div data-role=&quot;page&quot; class=&quot;page-map&quot;&gt;

	&lt;div data-role=&quot;header&quot;&gt;
		&lt;h1&gt;Google Map&lt;/h1&gt;
	&lt;/div&gt;&lt;!-- /header --&gt;

	&lt;div data-role=&quot;content&quot;&gt;
		 &lt;div id=&quot;googlemap&quot;&gt;&lt;/div&gt;
	&lt;/div&gt;&lt;!-- /content --&gt;

	&lt;div data-role=&quot;footer&quot;&gt;
		&lt;h4&gt;Footer content&lt;/h4&gt;
	&lt;/div&gt;&lt;!-- /footer --&gt;

&lt;/div&gt;&lt;!-- /page --&gt;
</pre>
<p>Read <a href="http://eisabainyo.net/weblog/2012/01/14/display-location-aware-google-map-on-page-load-with-jquery-mobile/">Display a location-aware google map on page load with jQuery mobile</a> on Web Development Blog!</p><div><h3>Other similiar posts that you might be interested in:</h3><ul><li><a href="http://eisabainyo.net/weblog/2011/01/31/top-10-jquery-mobile-code-snippets-that-you-need-to-know/" rel="bookmark" title="January 31, 2011">Top 10 jQuery Mobile Code Snippets that you need to know</a></li>

<li><a href="http://eisabainyo.net/weblog/2011/06/29/creating-a-contact-form-in-jquery-mobile-and-php/" rel="bookmark" title="June 29, 2011">Creating a Contact Form in jQuery Mobile and PHP</a></li>

<li><a href="http://eisabainyo.net/weblog/2011/06/23/10-useful-javascript-snippets-for-your-mobile-site/" rel="bookmark" title="June 23, 2011">10 Useful Javascript Snippets for your mobile websites</a></li>

<li><a href="http://eisabainyo.net/weblog/2009/04/27/code-to-embed-google-map-and-street-view/" rel="bookmark" title="April 27, 2009">Code to embed Google Map and Street View</a></li>

<li><a href="http://eisabainyo.net/weblog/2008/06/17/the-impact-of-web-servers-location-in-google-search/" rel="bookmark" title="June 17, 2008">The impact of web server&#8217;s location in google search ranking</a></li>

<li><a href="http://eisabainyo.net/weblog/2010/01/16/tips-on-building-websites-for-mobile-browsers/" rel="bookmark" title="January 16, 2010">Tips on building websites for mobile browsers</a></li>

<li><a href="http://eisabainyo.net/weblog/2009/02/02/jquery-calendar-widget-plugin/" rel="bookmark" title="February 2, 2009">jQuery Calendar Widget Plugin</a></li>
</ul><!-- Similar Posts took 142.851 ms --></div>]]></content:encoded>
			<wfw:commentRss>http://eisabainyo.net/weblog/2012/01/14/display-location-aware-google-map-on-page-load-with-jquery-mobile/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to &#8216;Post on Facebook Wall&#8217; on iPhone and Android using PhoneGap plugins</title>
		<link>http://eisabainyo.net/weblog/2011/06/25/how-to-post-on-facebook-wall-on-iphone-and-android-using-phonegap-plugins/</link>
		<comments>http://eisabainyo.net/weblog/2011/06/25/how-to-post-on-facebook-wall-on-iphone-and-android-using-phonegap-plugins/#comments</comments>
		<pubDate>Sat, 25 Jun 2011 01:45:51 +0000</pubDate>
		<dc:creator>eisabai</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Snippets]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://eisabainyo.net/weblog/?p=1751</guid>
		<description><![CDATA[For iPhone / iPad (iOS)
Prerequsites
- Install ChildBrowser Phonegap plugin
- Copy FBConnectExample/FBConnect.js into your www folder and include it in your HTML file
- Read and follow the instructions from How to post to the Facebook wall in an iPhone app with phonegap, FaceBook Connect and ChildBrother plugin by MosaCrea
The Javascript(jQuery) code:


$('#share-facebook').live(&#34;touchstart touchend&#34;, function() {
	var url = [...]<p>Read <a href="http://eisabainyo.net/weblog/2011/06/25/how-to-post-on-facebook-wall-on-iphone-and-android-using-phonegap-plugins/">How to &#8216;Post on Facebook Wall&#8217; on iPhone and Android using PhoneGap plugins</a> on Web Development Blog!</p><div><h3>Other similiar posts that you might be interested in:</h3><ul><li><a href="http://eisabainyo.net/weblog/2010/05/29/click-to-copy-and-open-site-script/" rel="bookmark" title="May 29, 2010">Click to copy and open site script</a></li>

<li><a href="http://eisabainyo.net/weblog/2010/02/07/7-days-traffic-building-exercise-%e2%80%93-day-4/" rel="bookmark" title="February 7, 2010">7 Days Traffic Building Exercise – Day 4</a></li>

<li><a href="http://eisabainyo.net/weblog/2010/02/19/tips-to-creating-an-email-signature-for-your-online-brand/" rel="bookmark" title="February 19, 2010">Tips to creating an email signature for your online brand</a></li>

<li><a href="http://eisabainyo.net/weblog/2010/11/29/how-to-customise-your-facebook-fan-page/" rel="bookmark" title="November 29, 2010">How to customise your Facebook Fan Page with FBML</a></li>

<li><a href="http://eisabainyo.net/weblog/2009/08/28/framebar-like-diggbar-example-in-html-and-css-with-no-javascript/" rel="bookmark" title="August 28, 2009">Framebar (like diggbar) example in html and css with no javascript</a></li>

<li><a href="http://eisabainyo.net/weblog/2007/08/23/facebook-application-development/" rel="bookmark" title="August 23, 2007">Facebook application development</a></li>

<li><a href="http://eisabainyo.net/weblog/2007/08/12/facebook-source-code/" rel="bookmark" title="August 12, 2007">Facebook source code</a></li>
</ul><!-- Similar Posts took 345.945 ms --></div>]]></description>
			<content:encoded><![CDATA[<p><strong>For iPhone / iPad (iOS)</strong></p>
<p>Prerequsites<br />
- Install <a href="https://github.com/jos3000/phonegap-plugins/tree/master/iPhone/ChildBrowser">ChildBrowser Phonegap plugin</a><br />
- Copy FBConnectExample/FBConnect.js into your www folder and include it in your HTML file<br />
- Read and follow the instructions from <a href="http://www.mosacrea.com/how-to-post-to-the-facebook-wall-in-an-iphone-app-with-phonegap-facebook-connect-and-childbrother-plugin/">How to post to the Facebook wall in an iPhone app with phonegap, FaceBook Connect and ChildBrother plugin by MosaCrea</a></p>
<p><strong>The Javascript(jQuery) code:<br />
</strong></p>
<pre>
$('#share-facebook').live(&quot;touchstart touchend&quot;, function() {
	var url = $(this).attr(&quot;rel&quot;);
	try {
		shareonfacebook(&quot; likes Web Development Blog by Ei Sabai.&quot;, &quot;http://eisabainyo.net/weblog/wp-content/uploads/2010/11/profile-small.gif&quot;, url);
	}
	catch(err) {
		console.log(err);
	}
	return false;
});
</pre>
<pre>
function shareonfacebook(text, image, url) {
	var client_id = &quot;xxxxxxxxxxxxx&quot;; // Your Facebook Client ID
	var redir_url = &quot;http://www.facebook.com/connect/login_success.html&quot;;

	if (typeof fbPlugin === 'undefined') {
		fbPlugin = FBConnect.install();
	}
	fbPlugin.connect(client_id, redir_url, &quot;touch&quot;);
    fbPlugin.onConnect = function() {
	    window.plugins.fbConnect.postFBWall(text, url, image, function() {
			navigator.notification.alert(
				'Thank you for sharing on Facebook.',
				function() {},
				'Thank you',
				'OK'
			);
		});
	};
}
</pre>
<p><strong>For Android</strong></p>
<p>Prerequsites<br />
- Install <a href="https://github.com/jos3000/phonegap-plugins/tree/master/Android/Facebook">Facebook for Android Phonegap plugin</a><br />
- Copy facebook.js into your www folder and include it in your HTML file</p>
<p><strong>The Javascript(jQuery) code:</strong></p>
<pre>
$('#share-facebook').live(&quot;touchstart touchend&quot;, function() {
	var url = $(this).attr(&quot;rel&quot;);
	try {
		shareonfacebook(&quot; likes Web Development Blog by Ei Sabai.&quot;, &quot;http://eisabainyo.net/weblog/wp-content/uploads/2010/11/profile-small.gif&quot;, url);
	}
	catch(err) {
		console.log(err);
	}
	return false;
});
</pre>
<pre>
function postonfacebook(text, image, url, token) {
	$.ajax({
		   type: 'POST',
		   url: &quot;https://graph.facebook.com/me/feed&quot;,
		   data: {
				message: text,
				picture: image,
				link: url,
				access_token: token,
				format: &quot;json&quot;
		   },
		   success: function (data) {
			   navigator.notification.alert(
					'Thank you for sharing on Facebook.',
					function() {},
					'Thank you',
					'OK'
				);
		   },
		   dataType: &quot;json&quot;,
		   timeout: 10000
	});
}
</pre>
<pre>
function shareonfacebook(text, image, url) {
	var client_id = &quot;xxxxxxxxxxxxx&quot;; // Your Facebook Client ID

	window.plugins.facebook.authorize(client_id, function(res){
		if (res.token !== undefined) {
			postonfacebook(text, image, url, res.token)
		} else {
			// call authorization method
			window.plugins.facebook.getAccess(function(res) {
				if (res.token !== undefined) {
					postonfacebook(text, image, url, res.token)
				}
			});
		}
	});
}
</pre>
<p><strong>Usage (for both iPhone and Android):</strong></p>
<pre>&lt;a href=&quot;#&quot; rel=&quot;http://eisabainyo.net/weblog/&quot; id=&quot;share-facebook&quot;&gt;Share on Facebook&lt;/a&gt;
</pre>
<p>Read <a href="http://eisabainyo.net/weblog/2011/06/25/how-to-post-on-facebook-wall-on-iphone-and-android-using-phonegap-plugins/">How to &#8216;Post on Facebook Wall&#8217; on iPhone and Android using PhoneGap plugins</a> on Web Development Blog!</p><div><h3>Other similiar posts that you might be interested in:</h3><ul><li><a href="http://eisabainyo.net/weblog/2010/05/29/click-to-copy-and-open-site-script/" rel="bookmark" title="May 29, 2010">Click to copy and open site script</a></li>

<li><a href="http://eisabainyo.net/weblog/2010/02/07/7-days-traffic-building-exercise-%e2%80%93-day-4/" rel="bookmark" title="February 7, 2010">7 Days Traffic Building Exercise – Day 4</a></li>

<li><a href="http://eisabainyo.net/weblog/2010/02/19/tips-to-creating-an-email-signature-for-your-online-brand/" rel="bookmark" title="February 19, 2010">Tips to creating an email signature for your online brand</a></li>

<li><a href="http://eisabainyo.net/weblog/2010/11/29/how-to-customise-your-facebook-fan-page/" rel="bookmark" title="November 29, 2010">How to customise your Facebook Fan Page with FBML</a></li>

<li><a href="http://eisabainyo.net/weblog/2009/08/28/framebar-like-diggbar-example-in-html-and-css-with-no-javascript/" rel="bookmark" title="August 28, 2009">Framebar (like diggbar) example in html and css with no javascript</a></li>

<li><a href="http://eisabainyo.net/weblog/2007/08/23/facebook-application-development/" rel="bookmark" title="August 23, 2007">Facebook application development</a></li>

<li><a href="http://eisabainyo.net/weblog/2007/08/12/facebook-source-code/" rel="bookmark" title="August 12, 2007">Facebook source code</a></li>
</ul><!-- Similar Posts took 33.579 ms --></div>]]></content:encoded>
			<wfw:commentRss>http://eisabainyo.net/weblog/2011/06/25/how-to-post-on-facebook-wall-on-iphone-and-android-using-phonegap-plugins/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>10 Useful Javascript Snippets for your mobile websites</title>
		<link>http://eisabainyo.net/weblog/2011/06/23/10-useful-javascript-snippets-for-your-mobile-site/</link>
		<comments>http://eisabainyo.net/weblog/2011/06/23/10-useful-javascript-snippets-for-your-mobile-site/#comments</comments>
		<pubDate>Thu, 23 Jun 2011 12:41:39 +0000</pubDate>
		<dc:creator>eisabai</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Snippets]]></category>

		<guid isPermaLink="false">http://eisabainyo.net/weblog/?p=1713</guid>
		<description><![CDATA[After developing a few mobile websites in the past few months, I notice that I am reusing certain Javascript code in every project.  Followings are the 10 Useful Javascript Snippets that I use for mobile sites.  Note that some snippets require jQuery mobile framework.
1. Add class name &#8220;iPhone&#8221; or &#8220;Android&#8221; to body element [...]<p>Read <a href="http://eisabainyo.net/weblog/2011/06/23/10-useful-javascript-snippets-for-your-mobile-site/">10 Useful Javascript Snippets for your mobile websites</a> on Web Development Blog!</p><div><h3>Other similiar posts that you might be interested in:</h3><ul><li><a href="http://eisabainyo.net/weblog/2010/05/30/designing-and-optimising-websites-for-ipad/" rel="bookmark" title="May 30, 2010">Designing and Optimising Websites for iPad</a></li>

<li><a href="http://eisabainyo.net/weblog/2012/01/14/display-location-aware-google-map-on-page-load-with-jquery-mobile/" rel="bookmark" title="January 14, 2012">Display a location-aware google map on page load with jQuery mobile</a></li>

<li><a href="http://eisabainyo.net/weblog/2011/06/20/how-to-use-google-fonts-in-your-wordpress-theme/" rel="bookmark" title="June 20, 2011">How to use Google Fonts in your WordPress Theme</a></li>

<li><a href="http://eisabainyo.net/weblog/2010/01/16/tips-on-building-websites-for-mobile-browsers/" rel="bookmark" title="January 16, 2010">Tips on building websites for mobile browsers</a></li>

<li><a href="http://eisabainyo.net/weblog/2009/05/11/opacity-in-css/" rel="bookmark" title="May 11, 2009">Opacity in CSS</a></li>

<li><a href="http://eisabainyo.net/weblog/2011/01/31/top-10-jquery-mobile-code-snippets-that-you-need-to-know/" rel="bookmark" title="January 31, 2011">Top 10 jQuery Mobile Code Snippets that you need to know</a></li>

<li><a href="http://eisabainyo.net/weblog/2009/05/28/check-username-availability-using-ajax-and-jquery/" rel="bookmark" title="May 28, 2009">Check username availability using AJAX and jQuery</a></li>
</ul><!-- Similar Posts took 41.768 ms --></div>]]></description>
			<content:encoded><![CDATA[<p>After developing a few mobile websites in the past few months, I notice that I am reusing certain Javascript code in every project.  Followings are the 10 Useful Javascript Snippets that I use for mobile sites.  Note that some snippets require jQuery mobile framework.</p>
<p><strong>1. Add class name &#8220;iPhone&#8221; or &#8220;Android&#8221; to body element if the page is viewed on iPhone or Android browser</strong></p>
<pre>if (navigator.userAgent.match(/iPhone/i)) {
	$('body').addClass('iPhone');
} else if (navigator.userAgent.match(/Android/i)) {
         $('body').addClass('Android');
}</pre>
<p><em>Examples of iPhone user agent string: </em><br />
Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A537a Safari/419.3<br />
Mozilla/5.0 (iPhone; U; XXXXX like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A477d Safari/419.3</p>
<p><em>Examples of Android user agent string: </em><br />
Mozilla/5.0 (Linux; U; Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1<br />
Mozilla/5.0 (Linux; U; Android 1.6; en-gb; Dell Streak Build/Donut AppleWebKit/528.5+ (KHTML, like Gecko) Version/3.1.2 Mobile Safari/ 525.20.1<br />
Mozilla/5.0 (Linux; U; Android 2.1-update1; de-de; HTC Desire 1.19.161.5 Build/ERE27) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17<br />
Mozilla/5.0 (Linux; U; Android 2.2; en-us; DROID2 GLOBAL Build/S273) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1<br />
Mozilla/5.0 (Linux; U; Android 2.2; en-gb; GT-P1000 Build/FROYO) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1<br />
Mozilla/5.0 (Linux; U; Android 2.1-update1; de-de; E10i Build/2.0.2.A.0.24) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17</p>
<p><strong>2. Remove the browser address bar</strong></p>
<pre>window.scrollTo(0, 1);</pre>
<p><strong>3. Prevent touch scrolling on a page</strong></p>
<pre>
notouchmove = function(event) {
	event.preventDefault();
}</pre>
<pre>
&lt;div data-role=&quot;page&quot; id=&quot;home&quot; ontouchmove=&quot;notouchmove(event);&quot;&gt;
...
&lt;/div&gt;
</pre>
<p>OR</p>
<pre>document.body.addEventListener('touchmove', function(event) {
	event.preventDefault();
}, false);</pre>
<p><strong>4. Display a message when the page is viewed in landscape</strong></p>
<pre>
var updateorientation = function (){
	var classname = '',
	top = 100;
	switch(window.orientation){
		case 0:
		classname += &quot;normal&quot;;
		break;

		case -90:
		classname += &quot;landscape&quot;;
		break;

		case 90:
		classname += &quot;landscape&quot;;
		break;

	}

	if (classname == 'landscape') {
		if ($('#overlay').length === 0) {
			window.scrollTo(0, 1);
			$('body').append('&lt;div id=&quot;overlay&quot; style=&quot;width: 100%; height:' + $(document).height() + 'px&quot;&gt;&lt;span style=&quot;top: ' + top + 'px&quot;&gt;Landscape view is not supported for this page.&lt;/span&gt;&lt;/div&gt;');
		}
	} else {
		$('#overlay').remove();
	}
};
</pre>
<p>Usage:</p>
<pre>
var supportsOrientationChange = &quot;onorientationchange&quot; in window,
orientationEvent = supportsOrientationChange ? &quot;orientationchange&quot; : &quot;resize&quot;;

window.addEventListener(orientationEvent, function() {
	updateorientation();
}, false);
</pre>
<p><strong>5. Truncate a description and show full description when touched</strong></p>
<pre>
var truncatedesc = function(trunc, len) {
	if (trunc) {
	  var org = trunc;

	  if (trunc.length &gt; len) {
		trunc = trunc.substring(0, len);
		trunc = trunc.replace(/w+$/, '');

		trunc = '&lt;span class=&quot;truncated&quot;&gt;' + trunc;
		trunc += '&lt;strong class=&quot;more-description&quot;&gt;...&lt;/strong&gt;&lt;/span&gt;';
		trunc += '&lt;span class=&quot;original&quot; style=&quot;display: none;&quot;&gt;' + org + '&lt;/span&gt;';
	  }

	  $('.truncated').live(&quot;touchstart touchend&quot;, function() {
		$(this).closest('div').find('.original').show();
		$(this).closest('div').find('.truncated').hide();
		return false;
	  });

	  return trunc;
	}
};</pre>
<p>Usage:</p>
<pre>truncatedesc(item.description, 100);</pre>
<p><strong>6. Redirect to another page upon successful ajax request (jQuery mobile)</strong></p>
<p>var ajaxurl = &#8216;http://&#8230;&#8217;;  // Your web service URL</p>
<pre>$.ajax({
	url: ajaxurl,
	type: 'GET',
	processData: false,
	contentType: "application/json",
	dataType: "jsonp",
	success: function(data) {
		$.mobile.changePage("results.html");
	},
	error: function() {
		alert('Error!');
	}
});</pre>
<p><strong>7. Remove active state from links in listview (jQuery mobile)</strong></p>
<pre>
$('div').live('pageshow', function (event, ui) {
	$('[data-role=listview] li').removeClass(&quot;ui-btn-active&quot;);
});</pre>
<p><strong>8. Disable default jQuery mobile style from select dropdown (jQuery mobile)</strong></p>
<pre>
$(document).bind(&quot;mobileinit&quot;, function(){
  	$.mobile.page.prototype.options.keepNative = &quot;select&quot;;
});</pre>
<p><strong>9. Dynamically update listview (jQuery mobile)</strong></p>
<pre>
var output  = '&lt;li&gt;&lt;img src=&quot;' + item.image + '&quot; alt=&quot;' + item.title + '&quot; /&gt;';
output += '&lt;h3&gt;&lt;a href=&quot;' + item.url + '&quot;&gt;' + item.title + '&lt;/a&gt;&lt;/h3&gt;';
output += '&lt;/li&gt;';	

$('#mylistul').append(output).listview('refresh');</pre>
<p><strong>10. Dynamically add form input and apply default style (jQuery mobile)</strong></p>
<pre>
var html = '&lt;input type=&quot;search&quot; name=&quot;suburb&quot; id=&quot;suburb&quot; placeholder=&quot;Enter suburb&quot; /&gt;';
$('#searchform').append(html);
$('#suburb').textinput();</pre>
<h3>Recommended Books</h3>
<p>While no book has already been released at Amazon on <a href="http://www.amazon.com/gp/redirect.html?ie=UTF8&#038;location=http%3A%2F%2Fwww.amazon.com%2Fs%3Fie%3DUTF8%26x%3D0%26ref_%3Dnb_sb_noss%26y%3D0%26field-keywords%3Djquery%2520mobile%26url%3Dsearch-alias%253Dstripbooks%23&#038;tag=eisabainyonet-20&#038;linkCode=ur2&#038;camp=1789&#038;creative=390957">jQuery mobile</a>, the following two books on HTML5  and jQuery will help you understand and work with jQuery mobile framework better as jQuery mobile is based on jQuery and uses HTML5. </p>
<div class="book"><a href="http://www.amazon.com/gp/product/0596806027/ref=as_li_ss_tl?ie=UTF8&#038;tag=eisabainyonet-20&#038;linkCode=as2&#038;camp=217145&#038;creative=399369&#038;creativeASIN=0596806027"><img src="http://eisabainyo.net/weblog/wp-content/uploads/2011/06/html5.png" alt="" title="HTML5: Up and Running" width="90"  class="alignnone size-full wp-image-1128" /><span>HTML5: Up and Running</span></a>
</div>
<div class="book"><a href="http://www.amazon.com/gp/product/0980576857/ref=as_li_ss_tl?ie=UTF8&#038;tag=eisabainyonet-20&#038;linkCode=as2&#038;camp=217145&#038;creative=399369&#038;creativeASIN=0980576857"><img src="http://eisabainyo.net/weblog/wp-content/uploads/2011/06/jqueryninja.jpg" alt="" title="jQuery: Novice to Ninja" width="90" height="111" class="alignnone size-full wp-image-1127" /><span>jQuery: Novice to Ninja</span></a>
</div>
<p>Read <a href="http://eisabainyo.net/weblog/2011/06/23/10-useful-javascript-snippets-for-your-mobile-site/">10 Useful Javascript Snippets for your mobile websites</a> on Web Development Blog!</p><div><h3>Other similiar posts that you might be interested in:</h3><ul><li><a href="http://eisabainyo.net/weblog/2010/05/30/designing-and-optimising-websites-for-ipad/" rel="bookmark" title="May 30, 2010">Designing and Optimising Websites for iPad</a></li>

<li><a href="http://eisabainyo.net/weblog/2012/01/14/display-location-aware-google-map-on-page-load-with-jquery-mobile/" rel="bookmark" title="January 14, 2012">Display a location-aware google map on page load with jQuery mobile</a></li>

<li><a href="http://eisabainyo.net/weblog/2011/06/20/how-to-use-google-fonts-in-your-wordpress-theme/" rel="bookmark" title="June 20, 2011">How to use Google Fonts in your WordPress Theme</a></li>

<li><a href="http://eisabainyo.net/weblog/2010/01/16/tips-on-building-websites-for-mobile-browsers/" rel="bookmark" title="January 16, 2010">Tips on building websites for mobile browsers</a></li>

<li><a href="http://eisabainyo.net/weblog/2009/05/11/opacity-in-css/" rel="bookmark" title="May 11, 2009">Opacity in CSS</a></li>

<li><a href="http://eisabainyo.net/weblog/2011/01/31/top-10-jquery-mobile-code-snippets-that-you-need-to-know/" rel="bookmark" title="January 31, 2011">Top 10 jQuery Mobile Code Snippets that you need to know</a></li>

<li><a href="http://eisabainyo.net/weblog/2009/05/28/check-username-availability-using-ajax-and-jquery/" rel="bookmark" title="May 28, 2009">Check username availability using AJAX and jQuery</a></li>
</ul><!-- Similar Posts took 11.614 ms --></div>]]></content:encoded>
			<wfw:commentRss>http://eisabainyo.net/weblog/2011/06/23/10-useful-javascript-snippets-for-your-mobile-site/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Top 10 jQuery Mobile Code Snippets that you need to know</title>
		<link>http://eisabainyo.net/weblog/2011/01/31/top-10-jquery-mobile-code-snippets-that-you-need-to-know/</link>
		<comments>http://eisabainyo.net/weblog/2011/01/31/top-10-jquery-mobile-code-snippets-that-you-need-to-know/#comments</comments>
		<pubDate>Mon, 31 Jan 2011 03:48:57 +0000</pubDate>
		<dc:creator>eisabai</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Snippets]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://eisabainyo.net/weblog/?p=1669</guid>
		<description><![CDATA[jQuery Mobile is a framework for mobile web apps and mobile websites with an aim to provide a unified user interface system across many mobile device platforms such iPhone, BlackBerry, Android and Windows Mobile.  The framework is built on top of one of the most popular Javascript frameworks, jQuery.  
Followings are some of [...]<p>Read <a href="http://eisabainyo.net/weblog/2011/01/31/top-10-jquery-mobile-code-snippets-that-you-need-to-know/">Top 10 jQuery Mobile Code Snippets that you need to know</a> on Web Development Blog!</p><div><h3>Other similiar posts that you might be interested in:</h3><ul><li><a href="http://eisabainyo.net/weblog/2011/06/07/how-to-use-hi-res-images-for-web-apps-in-iphone4/" rel="bookmark" title="June 7, 2011">How to use hi-res images in web apps for iPhone4</a></li>

<li><a href="http://eisabainyo.net/weblog/2010/01/16/tips-on-building-websites-for-mobile-browsers/" rel="bookmark" title="January 16, 2010">Tips on building websites for mobile browsers</a></li>

<li><a href="http://eisabainyo.net/weblog/2010/05/10/how-to-customise-wordpress-admin-login-page/" rel="bookmark" title="May 10, 2010">How to customise WordPress Admin Login page</a></li>

<li><a href="http://eisabainyo.net/weblog/2012/01/14/display-location-aware-google-map-on-page-load-with-jquery-mobile/" rel="bookmark" title="January 14, 2012">Display a location-aware google map on page load with jQuery mobile</a></li>

<li><a href="http://eisabainyo.net/weblog/2009/04/24/how-to-style-a-submit-button-in-css/" rel="bookmark" title="April 24, 2009">How to style a Submit button in CSS</a></li>

<li><a href="http://eisabainyo.net/weblog/2010/03/09/how-to-style-a-submit-button-in-css-example-2/" rel="bookmark" title="March 9, 2010">How to style a Submit button in CSS &#8211; Example 2</a></li>

<li><a href="http://eisabainyo.net/weblog/2011/06/23/10-useful-javascript-snippets-for-your-mobile-site/" rel="bookmark" title="June 23, 2011">10 Useful Javascript Snippets for your mobile websites</a></li>
</ul><!-- Similar Posts took 37.658 ms --></div>]]></description>
			<content:encoded><![CDATA[<p><a href="http://jquerymobile.com/">jQuery Mobile</a> is a framework for mobile web apps and mobile websites with an aim to provide a unified user interface system across many mobile device platforms such iPhone, BlackBerry, Android and Windows Mobile.  The framework is built on top of one of the most popular Javascript frameworks, <a href="http://jquery.com">jQuery</a>.  </p>
<p>Followings are some of the most useful code snippets that I&#8217;ve used in my recent web app developed using jQuery Mobile framework.  </p>
<p><strong>1. Disable truncation for list items and buttons</strong></p>
<p>If your list item or button has a long text, it will be truncated automatically by jQuery Mobile.  To disable this truncation, add &#8220;<code>white-space: normal;</code>&#8221; to the CSS selector in question.  </p>
<p>For example, to disable truncation for buttons:</p>
<pre>.ui-btn-text {
white-space: normal;
}</pre>
<p>To disable truncation for list descriptions:</p>
<pre>.ui-li-desc {
white-space: normal;
}</pre>
<p>To enable truncation, set it to &#8220;<code>white-space: nowrap;</code>&#8220;.  </p>
<p><strong>2. Display a random background image on page load</strong></p>
<p>jQuery Mobile has a number of page initialization events that you can use to trigger certain methods on page load.  The following CSS + Javascript can be used to display a random background image every time a page is loaded.  </p>
<p><strong>CSS</strong></p>
<pre>
.my-page  { background: transparent url(../images/bg.jpg) 0 0 no-repeat; }

.my-page.bg1 { background: transparent url(../images/bg-1.jpg) 0 0 no-repeat; }

.my-page.bg2 { background: transparent url(../images/bg-2.jpg) 0 0 no-repeat; }

.my-page.bg3 { background: transparent url(../images/bg-3.jpg) 0 0 no-repeat; }
</pre>
<p><strong>Javascript</strong></p>
<pre>
$('.my-page').live(&quot;pagecreate&quot;, function() {
	var randombg = Math.floor(Math.random()*4); // 0 to 3
	$('.my-page').removeClass().addClass('bg' + randombg);
});</pre>
<p><strong>3. Disable a button action</strong></p>
<p>To disable a button action (for eg: from opening a page), add the following Javascript.</p>
<pre>$('#home-button').button("disable");</pre>
<p>And to re-enable it:</p>
<pre>$('#home-button').button("enable");</pre>
<p><strong>4. Disable loading pop-up message </strong></p>
<p>I find the loading pop-up message a bit annoying because it gets triggered everytime you load a different page.  To disable this: add the following line of code into your JS file.</p>
<pre>$.mobile.pageLoading(true);</pre>
<p>By default, it is enabled like so:</p>
<pre>$.mobile.pageLoading();</pre>
<p><strong>5. Create a custom theme </strong></p>
<p>jQuery Mobile framework comes with <a href="http://jquerymobile.com/test/docs/#buttons/buttons-themes.html">5 themes</a> &#8211; Theme A, Theme B, Theme C, Theme D and Theme E.   But you can easily create  a new theme for your web app.  </p>
<p>The steps to create a new theme:<br />
1. Copy CSS for any theme from jQuery Mobile CSS file and paste it into your own CSS file.<br />
2. Give your theme a name and rename the CSS selectors appropriately.  Your theme name can be any alphabet character (a to z).  So for example, if you copied Theme C, and you want to call your theme Theme Z, rename <code>.ui-btn-up-c</code> to <code>.ui-btn-up-z</code>, <code>.ui-body-c</code> to <code>.ui-body-z</code> and so on.<br />
3. Change colors and styles of your custom theme<br />
4. To apply your custom theme z to any element, just set the data-theme attribute to z.  For example:
<pre>&lt;div data-role=&quot;page&quot; data-theme=&quot;z&quot;&gt;</pre>
<p><strong>6.  Use a custom font</strong></p>
<p>There are a few font-replacement methods available such as cufon, sIFR, FLIR, @font-face and Google Fonts API.  When building a web app using jQuery Mobile, I found that @font-face method is the easiest method to work with and the performance is quite satisfactory.  If you are interested in @font-face, here is a <a href="http://net.tutsplus.com/tutorials/design-tutorials/quick-tip-how-to-work-with-font-face/">helpful tutorial with a demo</a> on how to work with @font-face method. </p>
<p><strong>7. Create an image-only button with no text</strong></p>
<p>Sometimes, you may not want to have any text for your button but still use the rest of the features that comes with a button element.  This is usually the case with a home button or an info button.  To hide any text associated with the button, set data-iconpos attribute to &#8220;notext&#8221;.  For example:</p>
<pre>&lt;a href=&quot;../index.html&quot; data-icon=&quot;grid&quot;
class=&quot;ui-btn-right&quot; data-iconpos=&quot;notext&quot;&gt;Home&lt;/a&gt;</pre>
<p><strong>8. Open a link without using AJAX with page transitions</strong></p>
<p>To open a link without using AJAX with page transitions (ie: reloading the full page the old-school way), set rel attribute to &#8220;external&#8221;.  </p>
<pre>&lt;a href=&quot;../index.html&quot; data-icon=&quot;grid&quot;
class=&quot;ui-btn-right&quot; rel=&quot;external&quot;&gt;Home&lt;/a&gt;</pre>
<p><strong>9. Remove an arrow from a list item</strong></p>
<p>By default, jQuery Mobile framework adds an arrow next to every list item.  To disable this, set data-icon attribute to &#8220;false&#8221; on the list item that you&#8217;d like the arrow to be removed.</p>
<pre>&lt;li data-icon=&quot;false&quot;&gt;&lt;a href=&quot;contact.html&quot;&gt;Contact Us&lt;/a&gt;&lt;/li&gt;</pre>
<p><strong>10. Set background color of a page</strong></p>
<p>This may sound simple but it took me a few minutes to figure out how to apply a background color to a page without having it overwritten by jQuery Mobile CSS.   Normally, you&#8217;d set a background color to body element but if you are using jQuery Mobile framework, you need to set it to ui-page class.  </p>
<pre>.ui-page {
background: #eee;
}</pre>
<h3>Recommended Books</h3>
<p><a href="http://www.amazon.com/gp/product/1449306683/ref=as_li_ss_tl?ie=UTF8&#038;tag=eisabainyonet-20&#038;linkCode=as2&#038;camp=217145&#038;creative=399373&#038;creativeASIN=1449306683">jQuery Mobile</a><img src="http://www.assoc-amazon.com/e/ir?t=&#038;l=as2&#038;o=1&#038;a=1449306683&#038;camp=217145&#038;creative=399373" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /></p>
<p><a href="http://www.amazon.com/gp/product/1849515905/ref=as_li_ss_tl?ie=UTF8&#038;tag=eisabainyonet-20&#038;linkCode=as2&#038;camp=217145&#038;creative=399373&#038;creativeASIN=1849515905">jQuery Mobile First Look</a><img src="http://www.assoc-amazon.com/e/ir?t=&#038;l=as2&#038;o=1&#038;a=1849515905&#038;camp=217145&#038;creative=399373" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /></p>
<p>The following two books on HTML5  and jQuery will also help you understand and work with jQuery mobile framework better as jQuery mobile is based on jQuery and uses HTML5. </p>
<div class="book"><a href="http://www.amazon.com/gp/product/0596806027/ref=as_li_ss_tl?ie=UTF8&#038;tag=eisabainyonet-20&#038;linkCode=as2&#038;camp=217145&#038;creative=399369&#038;creativeASIN=0596806027"><img src="http://eisabainyo.net/weblog/wp-content/uploads/2011/06/html5.png" alt="" title="HTML5: Up and Running" width="90"  class="alignnone size-full wp-image-1128" /><span>HTML5: Up and Running</span></a>
</div>
<div class="book"><a href="http://www.amazon.com/gp/product/0980576857/ref=as_li_ss_tl?ie=UTF8&#038;tag=eisabainyonet-20&#038;linkCode=as2&#038;camp=217145&#038;creative=399369&#038;creativeASIN=0980576857"><img src="http://eisabainyo.net/weblog/wp-content/uploads/2011/06/jqueryninja.jpg" alt="" title="jQuery: Novice to Ninja" width="90" height="111" class="alignnone size-full wp-image-1127" /><span>jQuery: Novice to Ninja</span></a>
</div>
<p>Read <a href="http://eisabainyo.net/weblog/2011/01/31/top-10-jquery-mobile-code-snippets-that-you-need-to-know/">Top 10 jQuery Mobile Code Snippets that you need to know</a> on Web Development Blog!</p><div><h3>Other similiar posts that you might be interested in:</h3><ul><li><a href="http://eisabainyo.net/weblog/2011/06/07/how-to-use-hi-res-images-for-web-apps-in-iphone4/" rel="bookmark" title="June 7, 2011">How to use hi-res images in web apps for iPhone4</a></li>

<li><a href="http://eisabainyo.net/weblog/2010/01/16/tips-on-building-websites-for-mobile-browsers/" rel="bookmark" title="January 16, 2010">Tips on building websites for mobile browsers</a></li>

<li><a href="http://eisabainyo.net/weblog/2010/05/10/how-to-customise-wordpress-admin-login-page/" rel="bookmark" title="May 10, 2010">How to customise WordPress Admin Login page</a></li>

<li><a href="http://eisabainyo.net/weblog/2012/01/14/display-location-aware-google-map-on-page-load-with-jquery-mobile/" rel="bookmark" title="January 14, 2012">Display a location-aware google map on page load with jQuery mobile</a></li>

<li><a href="http://eisabainyo.net/weblog/2009/04/24/how-to-style-a-submit-button-in-css/" rel="bookmark" title="April 24, 2009">How to style a Submit button in CSS</a></li>

<li><a href="http://eisabainyo.net/weblog/2010/03/09/how-to-style-a-submit-button-in-css-example-2/" rel="bookmark" title="March 9, 2010">How to style a Submit button in CSS &#8211; Example 2</a></li>

<li><a href="http://eisabainyo.net/weblog/2011/06/23/10-useful-javascript-snippets-for-your-mobile-site/" rel="bookmark" title="June 23, 2011">10 Useful Javascript Snippets for your mobile websites</a></li>
</ul><!-- Similar Posts took 12.624 ms --></div>]]></content:encoded>
			<wfw:commentRss>http://eisabainyo.net/weblog/2011/01/31/top-10-jquery-mobile-code-snippets-that-you-need-to-know/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>10 most useful Javascript snippets from snipplr</title>
		<link>http://eisabainyo.net/weblog/2010/11/15/10-most-useful-javascript-snippets-from-snipplr/</link>
		<comments>http://eisabainyo.net/weblog/2010/11/15/10-most-useful-javascript-snippets-from-snipplr/#comments</comments>
		<pubDate>Sun, 14 Nov 2010 15:30:32 +0000</pubDate>
		<dc:creator>eisabai</dc:creator>
				<category><![CDATA[Snippets]]></category>

		<guid isPermaLink="false">http://eisabainyo.net/weblog/?p=1623</guid>
		<description><![CDATA[The following Javascript snippets are sourced from snipplr, a Social Snippet Repository.   They are written in pure Javascript lanaguage, without using any Javascript framework like jQuery, MooTools, Dojo, etc.
1. Email Validation
Source

function checkMail(email){
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(email)) {
		return true;
	}
	return false;
}

2. Toogle Checkboxes
Source

&#60;script type=&#34;text/javascript&#34;&#62;

function toggle_checkboxes(id) {
    if (!document.getElementById){ return; }
  [...]<p>Read <a href="http://eisabainyo.net/weblog/2010/11/15/10-most-useful-javascript-snippets-from-snipplr/">10 most useful Javascript snippets from snipplr</a> on Web Development Blog!</p><div><h3>Other similiar posts that you might be interested in:</h3><ul><li><a href="http://eisabainyo.net/weblog/2006/11/14/new-window-links-in-a-standards-compliant-world/" rel="bookmark" title="November 14, 2006">New-Window Links in a Standards-Compliant World</a></li>

<li><a href="http://eisabainyo.net/weblog/2010/09/01/10-useful-jquery-snippets/" rel="bookmark" title="September 1, 2010">10 Useful jQuery Snippets</a></li>

<li><a href="http://eisabainyo.net/weblog/2009/04/28/open-link-in-a-new-window-using-jquery/" rel="bookmark" title="April 28, 2009">Open link in a new window using jQuery</a></li>

<li><a href="http://eisabainyo.net/weblog/2009/02/20/store-login-information-in-cookie-using-jquery/" rel="bookmark" title="February 20, 2009">Store login information in cookie using jQuery</a></li>

<li><a href="http://eisabainyo.net/weblog/2011/06/23/10-useful-javascript-snippets-for-your-mobile-site/" rel="bookmark" title="June 23, 2011">10 Useful Javascript Snippets for your mobile websites</a></li>

<li><a href="http://eisabainyo.net/weblog/2010/06/17/clear-default-text-in-input-boxes-on-click-with-jquery/" rel="bookmark" title="June 17, 2010">Clear default text in input boxes on click with jQuery</a></li>

<li><a href="http://eisabainyo.net/weblog/2010/05/29/click-to-copy-and-open-site-script/" rel="bookmark" title="May 29, 2010">Click to copy and open site script</a></li>
</ul><!-- Similar Posts took 277.260 ms --></div>]]></description>
			<content:encoded><![CDATA[<p>The following Javascript snippets are sourced from snipplr, a Social Snippet Repository.   They are written in pure Javascript lanaguage, without using any Javascript framework like jQuery, MooTools, Dojo, etc.</p>
<p><strong>1. Email Validation</strong></p>
<p><a href="http://snipplr.com/view/814/email-javascript-validation/">Source</a></p>
<pre>
function checkMail(email){
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(email)) {
		return true;
	}
	return false;
}
</pre>
<p><strong>2. Toogle Checkboxes</strong></p>
<p><a href="http://snipplr.com/view/743/togglecheckboxes/">Source</a></p>
<pre>
&lt;script type=&quot;text/javascript&quot;&gt;

function toggle_checkboxes(id) {
    if (!document.getElementById){ return; }
    if (!document.getElementsByTagName){ return; }
    var inputs = document.getElementById(id).getElementsByTagName(&quot;input&quot;);
    for(var x=0; x &lt; inputs.length; x++) {
        if (inputs[x].type == 'checkbox'){
            inputs[x].checked = !inputs[x].checked;
        }
    }
}

&lt;/script&gt;

&lt;div id=&quot;parent_box&quot;&gt;

    &lt;input type=&quot;checkbox&quot; name=&quot;foo&quot; value=&quot;1&quot; /&gt; 1&lt;br/&gt;
    &lt;input type=&quot;checkbox&quot; name=&quot;foo&quot; value=&quot;2&quot; checked=&quot;checked&quot; /&gt; 2&lt;br/&gt;
    &lt;input type=&quot;checkbox&quot; name=&quot;foo&quot; value=&quot;3&quot; checked=&quot;checked&quot; /&gt; 3&lt;br/&gt;

    &lt;br/&gt;
    &lt;input type=&quot;button&quot; value=&quot;Toggle checkboxes&quot;
        onclick=&quot;toggle_checkboxes('parent_box')&quot; /&gt;

&lt;/div&gt;
</pre>
<p><strong>3. Image Preloader</strong></p>
<p><a href="http://snipplr.com/view/3657/images-preloader/">Source</a></p>
<pre>
var images = new Array();

function preloadImages(){
    for (i=0; i &lt; preloadImages.arguments.length; i++){
         images[i] = new Image();
        images[i].src = preloadImages.arguments[i];
    }
}

preloadImages(&quot;logo.jpg&quot;, &quot;main_bg.jpg&quot;, &quot;body_bg.jpg&quot;, &quot;header_bg.jpg&quot;);
</pre>
<p><strong>4. Javascript cookies</strong></p>
<p><a href="http://snipplr.com/view/470/javascript-cookies/">Source</a></p>
<pre>
/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */
function setCookie(name, value, expires, path, domain, secure) {
    document.cookie= name + &quot;=&quot; + escape(value) +
        ((expires) ? &quot;; expires=&quot; + expires.toGMTString() : &quot;&quot;) +
        ((path) ? &quot;; path=&quot; + path : &quot;&quot;) +
        ((domain) ? &quot;; domain=&quot; + domain : &quot;&quot;) +
        ((secure) ? &quot;; secure&quot; : &quot;&quot;);
}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + &quot;=&quot;;
    var begin = dc.indexOf(&quot;; &quot; + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(&quot;;&quot;, begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
function deleteCookie(name, path, domain) {
    if (getCookie(name)) {
        document.cookie = name + &quot;=&quot; +
            ((path) ? &quot;; path=&quot; + path : &quot;&quot;) +
            ((domain) ? &quot;; domain=&quot; + domain : &quot;&quot;) +
            &quot;; expires=Thu, 01-Jan-70 00:00:01 GMT&quot;;
    }
}
</pre>
<p><strong>5. Sort Dropdown Menu</strong></p>
<p><a href="http://snipplr.com/view/21/sort-dropdown-menu/">Source</a></p>
<pre>
function sortList(id) {
	var obj = document.getElementById(&quot;id&quot;);
	var values = new Array();
	for(var i = 0; i &lt; obj.options.length; i++) {
		values.push(obj.options[i].innerHTML + &quot;--xx--&quot; + obj.options[i].value);
	}

	values = values.sort();

	for(var i = 0; i &lt; values.length; i++) {
		valueArray = values[i].split('--xx--');
		obj.options[i].innerHTML = valueArray[0];
		obj.options[i].value = valueArray[1];
	}
}
</pre>
<p><strong>6. Determine if Browser Understands HTML5 Video</strong></p>
<p><a href="http://snipplr.com/view/38850/determine-if-browser-understands-html5-video/">Source</a></p>
<pre>
// Check if the browser understands the video element.
function understands_video() {
  return !!document.createElement('video').canPlayType; // boolean
}

if ( !understands_video() ) {
	// Must be older browser or IE.
	// Maybe do something like hide custom
	// HTML5 controls. Or whatever...
	videoControls.style.display = 'none';
}
</pre>
<p><strong>7. Get browser viewport width and height</strong></p>
<p><a href="http://snipplr.com/view/5896/get-browser-viewport-width-and-height/">Source</a></p>
<pre>
&lt;script type=&quot;text/javascript&quot;&gt;
&lt;!--

 var viewportwidth;
 var viewportheight;

 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight

 if (typeof window.innerWidth != 'undefined')
 {
      viewportwidth = window.innerWidth,
      viewportheight = window.innerHeight
 }

// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

 else if (typeof document.documentElement != 'undefined'
     &amp;&amp; typeof document.documentElement.clientWidth !=
     'undefined' &amp;&amp; document.documentElement.clientWidth != 0)
 {
       viewportwidth = document.documentElement.clientWidth,
       viewportheight = document.documentElement.clientHeight
 }

 // older versions of IE

 else
 {
       viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
       viewportheight = document.getElementsByTagName('body')[0].clientHeight
 }
document.write('&lt;p&gt;Your viewport width is '+viewportwidth+'x'+viewportheight+'&lt;/p&gt;');
//--&gt;
&lt;/script&gt;
</pre>
<p><strong>8. getElementsByClassName</strong></p>
<p><a href="http://snipplr.com/view/504/getelementsbyclassname/">Source</a></p>
<pre>
/*
    Written by Jonathan Snook, http://www.snook.ca/jonathan
    Add-ons by Robert Nyman, http://www.robertnyman.com
*/

function getElementsByClassName(oElm, strTagName, strClassName){
    var arrElements = (strTagName == &quot;*&quot; &amp;&amp; document.all)? document.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, &quot;\\-&quot;);
    var oRegExp = new RegExp(&quot;(^|\\s)&quot; + strClassName + &quot;(\\s|$)&quot;);
    var oElement;
    for(var i=0; i&lt;arrElements.length; i++){
        oElement = arrElements[i];
        if(oRegExp.test(oElement.className)){
            arrReturnElements.push(oElement);
        }
    }
    return (arrReturnElements)
}
</pre>
<p><strong>9. Delayed Redirect</strong></p>
<p><a href="http://snipplr.com/view/2032/delayed-redirect/">Source</a></p>
<pre>setTimeout( &quot;window.location.href =
'http://walkerwines.com.au/'&quot;, 5*1000 );</pre>
<p><strong>10. iPhone Style Change on Orientation Change</strong></p>
<p><a href="http://snipplr.com/view/14653/iphone-style-change-on-orientation-change/">Source</a></p>
<pre>
window.addEventListener('load', setOrientation, false);
window.addEventListener('orientationchange', setOrientation, false);

function setOrientation() {
 var orient = Math.abs(window.orientation) === 90 ? 'landscape' : 'portrait';
 var cl = document.body.className;
 cl = cl.replace(/portrait|landscape/, orient);
 document.body.className = cl;
}
</pre>
<p>Read <a href="http://eisabainyo.net/weblog/2010/11/15/10-most-useful-javascript-snippets-from-snipplr/">10 most useful Javascript snippets from snipplr</a> on Web Development Blog!</p><div><h3>Other similiar posts that you might be interested in:</h3><ul><li><a href="http://eisabainyo.net/weblog/2006/11/14/new-window-links-in-a-standards-compliant-world/" rel="bookmark" title="November 14, 2006">New-Window Links in a Standards-Compliant World</a></li>

<li><a href="http://eisabainyo.net/weblog/2010/09/01/10-useful-jquery-snippets/" rel="bookmark" title="September 1, 2010">10 Useful jQuery Snippets</a></li>

<li><a href="http://eisabainyo.net/weblog/2009/04/28/open-link-in-a-new-window-using-jquery/" rel="bookmark" title="April 28, 2009">Open link in a new window using jQuery</a></li>

<li><a href="http://eisabainyo.net/weblog/2009/02/20/store-login-information-in-cookie-using-jquery/" rel="bookmark" title="February 20, 2009">Store login information in cookie using jQuery</a></li>

<li><a href="http://eisabainyo.net/weblog/2011/06/23/10-useful-javascript-snippets-for-your-mobile-site/" rel="bookmark" title="June 23, 2011">10 Useful Javascript Snippets for your mobile websites</a></li>

<li><a href="http://eisabainyo.net/weblog/2010/06/17/clear-default-text-in-input-boxes-on-click-with-jquery/" rel="bookmark" title="June 17, 2010">Clear default text in input boxes on click with jQuery</a></li>

<li><a href="http://eisabainyo.net/weblog/2010/05/29/click-to-copy-and-open-site-script/" rel="bookmark" title="May 29, 2010">Click to copy and open site script</a></li>
</ul><!-- Similar Posts took 25.243 ms --></div>]]></content:encoded>
			<wfw:commentRss>http://eisabainyo.net/weblog/2010/11/15/10-most-useful-javascript-snippets-from-snipplr/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>10 Useful jQuery Snippets</title>
		<link>http://eisabainyo.net/weblog/2010/09/01/10-useful-jquery-snippets/</link>
		<comments>http://eisabainyo.net/weblog/2010/09/01/10-useful-jquery-snippets/#comments</comments>
		<pubDate>Wed, 01 Sep 2010 02:20:01 +0000</pubDate>
		<dc:creator>eisabai</dc:creator>
				<category><![CDATA[Snippets]]></category>

		<guid isPermaLink="false">http://eisabainyo.net/weblog/?p=1599</guid>
		<description><![CDATA[Following are 10 Useful jQuery snippets for any website.   To use these snippets, you must include jQuery library in your page first and then add the snippets inside DOM ready function as follow:
$(document).ready(function() {
   // add your snippets here
});
1. Display Warning Message for IE 6 Users
if ( (jQuery.browser.msie) &#38;&#38; (parseInt(jQuery.browser.version) &#60; [...]<p>Read <a href="http://eisabainyo.net/weblog/2010/09/01/10-useful-jquery-snippets/">10 Useful jQuery Snippets</a> on Web Development Blog!</p><div><h3>Other similiar posts that you might be interested in:</h3><ul><li><a href="http://eisabainyo.net/weblog/2009/02/20/store-login-information-in-cookie-using-jquery/" rel="bookmark" title="February 20, 2009">Store login information in cookie using jQuery</a></li>

<li><a href="http://eisabainyo.net/weblog/2010/06/17/clear-default-text-in-input-boxes-on-click-with-jquery/" rel="bookmark" title="June 17, 2010">Clear default text in input boxes on click with jQuery</a></li>

<li><a href="http://eisabainyo.net/weblog/2009/05/28/check-username-availability-using-ajax-and-jquery/" rel="bookmark" title="May 28, 2009">Check username availability using AJAX and jQuery</a></li>

<li><a href="http://eisabainyo.net/weblog/2011/06/29/creating-a-contact-form-in-jquery-mobile-and-php/" rel="bookmark" title="June 29, 2011">Creating a Contact Form in jQuery Mobile and PHP</a></li>

<li><a href="http://eisabainyo.net/weblog/2011/06/23/10-useful-javascript-snippets-for-your-mobile-site/" rel="bookmark" title="June 23, 2011">10 Useful Javascript Snippets for your mobile websites</a></li>

<li><a href="http://eisabainyo.net/weblog/2009/04/07/back-to-top-link-with-jquery/" rel="bookmark" title="April 7, 2009">Back to top link with jQuery</a></li>

<li><a href="http://eisabainyo.net/weblog/2009/04/28/open-link-in-a-new-window-using-jquery/" rel="bookmark" title="April 28, 2009">Open link in a new window using jQuery</a></li>
</ul><!-- Similar Posts took 87.106 ms --></div>]]></description>
			<content:encoded><![CDATA[<p>Following are 10 Useful jQuery snippets for any website.   To use these snippets, you must include <a href="http://jquery.com/">jQuery library</a> in your page first and then add the snippets inside DOM ready function as follow:</p>
<p><em>$(document).ready(function() {<br />
   // add your snippets here<br />
});</em></p>
<p><strong>1. Display Warning Message for IE 6 Users</strong></p>
<pre>if ( (jQuery.browser.msie) &amp;&amp; (parseInt(jQuery.browser.version) &lt; 7) ) {
	$('body').prepend('&lt;div class=&quot;warning&quot;&gt;You are using an old version of Internet Explorer which is not supported.  Please upgrade your browser in order to view this website.&lt;/div&gt;');
}</pre>
<p><strong>2. Add hasJS class to body tag when Javascript is enabled</strong></p>
<pre>$('body').addClass('hasJS');</pre>
<p><strong>3. Clear default text in input fields on click</strong></p>
<p>Sample Usage: </p>
<pre>&lt;input type=&quot;text&quot; name=&quot;search&quot; class=&quot;search&quot; value=&quot;Keywords&quot; title=&quot;Keywords&quot; /&gt;</pre>
<pre>$('input[type=text]').focus(function() {
    var title = $(this).attr('title');
    if ($(this).val() == title) {
        $(this).val('');
    }
}).blur(function() {
    var title = $(this).attr('title');
    if ($(this).val() == '') {
        $(this).val(title);
    }
});</pre>
<p><strong>4. Show/hide more content on click</strong></p>
<p>Sample Usage:</p>
<pre>&lt;p&gt;&lt;a href=&quot;#how-to&quot; class=&quot;toggle&quot;&gt;How to write a good article?&lt;/a&gt;&lt;/p&gt;</pre>
<pre>&lt;div id=&quot;how-to&quot;&gt;
	How to tips go here.
&lt;/div&gt;
</pre>
<pre>
$('a.toggle').toggle(function() {
	var id = $(this).attr(&quot;href&quot;);
	$(this).addClass(&quot;active&quot;);
	$(id).slideDown();
}, function() {
	var id = $(this).attr(&quot;href&quot;);
	$(this).removeClass(&quot;active&quot;);
	$(id).slideUp();
});
</pre>
<p><strong>5. Open Print dialog</strong></p>
<p>Sample Usage:</p>
<pre>&lt;a href=&quot;#&quot; class=&quot;print&quot;&gt;Print this page&lt;/a&gt;</pre>
<pre>
$('a.print').click(function(){
	window.print();
	return false;
});
</pre>
<p><strong>6. Add &#8220;hover&#8221; class to table data (and change the background color of the class via CSS)</strong></p>
<pre>
$('table').delegate('td', 'hover', function(){
	$(this).toggleClass('hover');
});
</pre>
<p><strong>7. Open link in a new window if rel is set to external</strong></p>
<p>Sample Usage:</p>
<pre>&lt;a href=&quot;http://www.google.com&quot; rel=&quot;external&quot;&gt;Google&lt;/a&gt;</pre>
<pre>$('a[rel=external]').attr('target', '_blank');</pre>
<p><strong>8. Add &#8220;odd&#8221; class to alternate table row (and change the background color of the class via CSS to have stripes effect for table)</strong></p>
<pre>$('tr:odd').addClass('odd');  </pre>
<p><strong>9. Check if div exists on page</strong></p>
<pre>if ( $('#myDiv').length ) {
    // do something with myDiv
}</pre>
<p><strong>10. Check/Uncheck all checkboxes</strong></p>
<p>Sample Usage:</p>
<pre>
&lt;div class=&quot;options&quot;&gt;
	&lt;ul&gt;
		&lt;li&gt;&lt;a href=&quot;#&quot; class=&quot;select-all&quot;&gt;Select All&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href=&quot;#&quot; class=&quot;reset-all&quot;&gt;Reset All&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;

	&lt;input type=&quot;checkbox&quot; id=&quot;option1&quot; /&gt;&lt;label for=&quot;option1&quot;&gt;Option 1&lt;/label&gt;
	&lt;input type=&quot;checkbox&quot; id=&quot;option2&quot; /&gt;&lt;label for=&quot;option2&quot;&gt;Option 2&lt;/label&gt;
	&lt;input type=&quot;checkbox&quot; id=&quot;option3&quot; /&gt;&lt;label for=&quot;option3&quot;&gt;Option 3&lt;/label&gt;
	&lt;input type=&quot;checkbox&quot; id=&quot;option4&quot; /&gt;&lt;label for=&quot;option4&quot;&gt;Option 4&lt;/label&gt;
&lt;/div&gt;
</pre>
<pre>
$('.select-all').live('click', function(){
	$(this).closest('.options').find('input[type=checkbox]').attr('checked', true);
	return false;
});

$('.reset-all').live('click', function(){
	$(this).closest('.options').find('input[type=checkbox]').attr('checked', false);
	return false;
});</pre>
<p>Read <a href="http://eisabainyo.net/weblog/2010/09/01/10-useful-jquery-snippets/">10 Useful jQuery Snippets</a> on Web Development Blog!</p><div><h3>Other similiar posts that you might be interested in:</h3><ul><li><a href="http://eisabainyo.net/weblog/2009/02/20/store-login-information-in-cookie-using-jquery/" rel="bookmark" title="February 20, 2009">Store login information in cookie using jQuery</a></li>

<li><a href="http://eisabainyo.net/weblog/2010/06/17/clear-default-text-in-input-boxes-on-click-with-jquery/" rel="bookmark" title="June 17, 2010">Clear default text in input boxes on click with jQuery</a></li>

<li><a href="http://eisabainyo.net/weblog/2009/05/28/check-username-availability-using-ajax-and-jquery/" rel="bookmark" title="May 28, 2009">Check username availability using AJAX and jQuery</a></li>

<li><a href="http://eisabainyo.net/weblog/2011/06/29/creating-a-contact-form-in-jquery-mobile-and-php/" rel="bookmark" title="June 29, 2011">Creating a Contact Form in jQuery Mobile and PHP</a></li>

<li><a href="http://eisabainyo.net/weblog/2011/06/23/10-useful-javascript-snippets-for-your-mobile-site/" rel="bookmark" title="June 23, 2011">10 Useful Javascript Snippets for your mobile websites</a></li>

<li><a href="http://eisabainyo.net/weblog/2009/04/07/back-to-top-link-with-jquery/" rel="bookmark" title="April 7, 2009">Back to top link with jQuery</a></li>

<li><a href="http://eisabainyo.net/weblog/2009/04/28/open-link-in-a-new-window-using-jquery/" rel="bookmark" title="April 28, 2009">Open link in a new window using jQuery</a></li>
</ul><!-- Similar Posts took 18.274 ms --></div>]]></content:encoded>
			<wfw:commentRss>http://eisabainyo.net/weblog/2010/09/01/10-useful-jquery-snippets/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Clear default text in input boxes on click with jQuery</title>
		<link>http://eisabainyo.net/weblog/2010/06/17/clear-default-text-in-input-boxes-on-click-with-jquery/</link>
		<comments>http://eisabainyo.net/weblog/2010/06/17/clear-default-text-in-input-boxes-on-click-with-jquery/#comments</comments>
		<pubDate>Thu, 17 Jun 2010 02:56:46 +0000</pubDate>
		<dc:creator>eisabai</dc:creator>
				<category><![CDATA[Snippets]]></category>

		<guid isPermaLink="false">http://eisabainyo.net/weblog/?p=1548</guid>
		<description><![CDATA[The following Javascript will clear default text value in input boxes when you click on them.  To trigger the Javascript, you&#8217;ll need to specify both title and value attributes and set class of the input field to &#8220;text&#8221;.  jQuery library is required for this to work.  
Javascript

$('.text').focus(function () {
	if ($(this).val() == $(this).attr("title")) [...]<p>Read <a href="http://eisabainyo.net/weblog/2010/06/17/clear-default-text-in-input-boxes-on-click-with-jquery/">Clear default text in input boxes on click with jQuery</a> on Web Development Blog!</p><div><h3>Other similiar posts that you might be interested in:</h3><ul><li><a href="http://eisabainyo.net/weblog/2010/09/01/10-useful-jquery-snippets/" rel="bookmark" title="September 1, 2010">10 Useful jQuery Snippets</a></li>

<li><a href="http://eisabainyo.net/weblog/2009/02/20/store-login-information-in-cookie-using-jquery/" rel="bookmark" title="February 20, 2009">Store login information in cookie using jQuery</a></li>

<li><a href="http://eisabainyo.net/weblog/2009/07/23/customising-recaptcha-theme/" rel="bookmark" title="July 23, 2009">Customising reCAPTCHA Theme</a></li>

<li><a href="http://eisabainyo.net/weblog/2009/05/28/check-username-availability-using-ajax-and-jquery/" rel="bookmark" title="May 28, 2009">Check username availability using AJAX and jQuery</a></li>

<li><a href="http://eisabainyo.net/weblog/2010/05/29/click-to-copy-and-open-site-script/" rel="bookmark" title="May 29, 2010">Click to copy and open site script</a></li>

<li><a href="http://eisabainyo.net/weblog/2011/06/29/creating-a-contact-form-in-jquery-mobile-and-php/" rel="bookmark" title="June 29, 2011">Creating a Contact Form in jQuery Mobile and PHP</a></li>

<li><a href="http://eisabainyo.net/weblog/2009/07/17/dropdown-menu-population-using-json-and-jquery/" rel="bookmark" title="July 17, 2009">Dropdown menu population using JSON and jQuery</a></li>
</ul><!-- Similar Posts took 79.251 ms --></div>]]></description>
			<content:encoded><![CDATA[<p>The following Javascript will clear default text value in input boxes when you click on them.  To trigger the Javascript, you&#8217;ll need to specify both title and value attributes and set class of the input field to &#8220;text&#8221;.  jQuery library is required for this to work.  </p>
<p><strong>Javascript</strong></p>
<pre>
$('.text').focus(function () {
	if ($(this).val() == $(this).attr("title")) {
		$(this).val("");
	}
}).blur(function () {
	if ($(this).val() == "") {
		$(this).val($(this).attr("title"));
	}
});
</pre>
<p>Examples: </p>
<pre>
&lt;input type=&quot;text&quot; name=&quot;q&quot; class=&quot;q text&quot; value=&quot;Search for terms&quot; title=&quot;Search for terms&quot; /&gt;

&lt;input type=&quot;password&quot; name=&quot;password&quot; class=&quot;text&quot; value=&quot;Password&quot; title=&quot;Password&quot;  /&gt;
</pre>
<p>Read <a href="http://eisabainyo.net/weblog/2010/06/17/clear-default-text-in-input-boxes-on-click-with-jquery/">Clear default text in input boxes on click with jQuery</a> on Web Development Blog!</p><div><h3>Other similiar posts that you might be interested in:</h3><ul><li><a href="http://eisabainyo.net/weblog/2010/09/01/10-useful-jquery-snippets/" rel="bookmark" title="September 1, 2010">10 Useful jQuery Snippets</a></li>

<li><a href="http://eisabainyo.net/weblog/2009/02/20/store-login-information-in-cookie-using-jquery/" rel="bookmark" title="February 20, 2009">Store login information in cookie using jQuery</a></li>

<li><a href="http://eisabainyo.net/weblog/2009/07/23/customising-recaptcha-theme/" rel="bookmark" title="July 23, 2009">Customising reCAPTCHA Theme</a></li>

<li><a href="http://eisabainyo.net/weblog/2009/05/28/check-username-availability-using-ajax-and-jquery/" rel="bookmark" title="May 28, 2009">Check username availability using AJAX and jQuery</a></li>

<li><a href="http://eisabainyo.net/weblog/2010/05/29/click-to-copy-and-open-site-script/" rel="bookmark" title="May 29, 2010">Click to copy and open site script</a></li>

<li><a href="http://eisabainyo.net/weblog/2011/06/29/creating-a-contact-form-in-jquery-mobile-and-php/" rel="bookmark" title="June 29, 2011">Creating a Contact Form in jQuery Mobile and PHP</a></li>

<li><a href="http://eisabainyo.net/weblog/2009/07/17/dropdown-menu-population-using-json-and-jquery/" rel="bookmark" title="July 17, 2009">Dropdown menu population using JSON and jQuery</a></li>
</ul><!-- Similar Posts took 22.251 ms --></div>]]></content:encoded>
			<wfw:commentRss>http://eisabainyo.net/weblog/2010/06/17/clear-default-text-in-input-boxes-on-click-with-jquery/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Click to copy and open site script</title>
		<link>http://eisabainyo.net/weblog/2010/05/29/click-to-copy-and-open-site-script/</link>
		<comments>http://eisabainyo.net/weblog/2010/05/29/click-to-copy-and-open-site-script/#comments</comments>
		<pubDate>Sat, 29 May 2010 11:08:08 +0000</pubDate>
		<dc:creator>eisabai</dc:creator>
				<category><![CDATA[Snippets]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://eisabainyo.net/weblog/?p=1463</guid>
		<description><![CDATA[I needed a script that copies a text (in my case, coupon code) onto clipboard and then open the web address associated with the coupon in a new window for my Coupons for Webmasters page.   For the clipboard copying, I&#8217;m using ZeroClipboard script written by Joseph Huckaby.  ZeroClipboard is a free and [...]<p>Read <a href="http://eisabainyo.net/weblog/2010/05/29/click-to-copy-and-open-site-script/">Click to copy and open site script</a> on Web Development Blog!</p><div><h3>Other similiar posts that you might be interested in:</h3><ul><li><a href="http://eisabainyo.net/weblog/2009/02/20/display-thickbox-on-page-load/" rel="bookmark" title="February 20, 2009">Display thickbox on page load</a></li>

<li><a href="http://eisabainyo.net/weblog/2011/06/29/creating-a-contact-form-in-jquery-mobile-and-php/" rel="bookmark" title="June 29, 2011">Creating a Contact Form in jQuery Mobile and PHP</a></li>

<li><a href="http://eisabainyo.net/weblog/2011/06/25/how-to-post-on-facebook-wall-on-iphone-and-android-using-phonegap-plugins/" rel="bookmark" title="June 25, 2011">How to &#8216;Post on Facebook Wall&#8217; on iPhone and Android using PhoneGap plugins</a></li>

<li><a href="http://eisabainyo.net/weblog/2009/07/23/customising-recaptcha-theme/" rel="bookmark" title="July 23, 2009">Customising reCAPTCHA Theme</a></li>

<li><a href="http://eisabainyo.net/weblog/2010/05/10/how-to-customise-wordpress-admin-login-page/" rel="bookmark" title="May 10, 2010">How to customise WordPress Admin Login page</a></li>

<li><a href="http://eisabainyo.net/weblog/2010/06/17/clear-default-text-in-input-boxes-on-click-with-jquery/" rel="bookmark" title="June 17, 2010">Clear default text in input boxes on click with jQuery</a></li>

<li><a href="http://eisabainyo.net/weblog/2009/02/20/store-login-information-in-cookie-using-jquery/" rel="bookmark" title="February 20, 2009">Store login information in cookie using jQuery</a></li>
</ul><!-- Similar Posts took 149.721 ms --></div>]]></description>
			<content:encoded><![CDATA[<p>I needed a script that copies a text (in my case, coupon code) onto clipboard and then open the web address associated with the coupon in a new window for my <a href="http://eisabainyo.net/website-templates/coupons-for-webmasters/">Coupons for Webmasters</a> page.   For the clipboard copying, I&#8217;m using <a href="http://code.google.com/p/zeroclipboard/">ZeroClipboard script written by Joseph Huckaby</a>.  ZeroClipboard is a free and open source library that provides an easy way to copy text to the clipboard using an invisible Adobe Flash movie, and a JavaScript interface.  And opening a new window was easier than I thought, with jQuery and a bit of googling.  </p>
<p><strong>HTML Code</strong></p>
<pre>
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Zero Clipboard Test&lt;/title&gt;

&lt;script type=&quot;text/javascript&quot; src=&quot;ZeroClipboard.js&quot;&gt;&lt;/script&gt;
&lt;script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js'&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;clipboard.js&quot;&gt;&lt;/script&gt;

&lt;/head&gt;
&lt;body &gt;
&lt;h1&gt;Zero Clipboard Test&lt;/h1&gt;

&lt;div class=&quot;coupon&quot;&gt;
&lt;h3&gt;Hostgator Hosting Coupon&lt;/h3&gt;
&lt;div class=&quot;desc&quot;&gt;20% off all plans for new customers&lt;/div&gt;
&lt;div class=&quot;expiry&quot;&gt;Expiry date: - &lt;/div&gt;
&lt;div class=&quot;coupon-code&quot; rel=&quot;http://eisabainyo.net/view/hostgator&quot;&gt;GREEN&lt;/div&gt;
&lt;div class=&quot;coupon-link&quot;&gt;Click to copy&lt;/div&gt;
&lt;/div&gt;

&lt;div class=&quot;coupon&quot;&gt;
&lt;h3&gt;Godaddy Domain Name Coupon&lt;/h3&gt;
&lt;div class=&quot;desc&quot;&gt;$7.49 for any .COM domain&lt;/div&gt;
&lt;div class=&quot;expiry&quot;&gt;Expiry date: - &lt;/div&gt;
&lt;div class=&quot;coupon-code&quot; rel=&quot;http://eisabainyo.net/view/godaddy&quot;&gt;OYH7&lt;/div&gt;
&lt;div class=&quot;coupon-link&quot;&gt;Click to copy&lt;/div&gt;
&lt;/div&gt;

&lt;div class=&quot;coupon&quot;&gt;
&lt;h3&gt;Website Templates&lt;/h3&gt;
&lt;div class=&quot;desc&quot;&gt;5% off any template (no coupon required)&lt;/div&gt;
&lt;div class=&quot;expiry&quot;&gt;Expiry date: 10 June 2010 &lt;/div&gt;
&lt;div class=&quot;coupon-link&quot;&gt;&lt;a href=&quot;http://eisabainyo.net/website-templates&quot; target=&quot;_blank&quot;&gt;Go to site&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;/body&gt;
&lt;/html&gt;
</pre>
<p><strong>ZeroClipboard Script </strong>(<a href="http://code.google.com/p/zeroclipboard/">download at Google Code</a>)<br />
You&#8217;ll need ZeroClipboard.js and ZeroClipboard.swf.  </p>
<p><strong>clipboard.js</strong></p>
<pre>
ZeroClipboard.setMoviePath("http://fullpath.to.your.site/ZeroClipboard.swf");

var clip = null;
var url = '';

function init() {
	clip = new ZeroClipboard.Client();
	clip.setHandCursor( true );

	$('.coupon-code').mouseover( function() {
		clip.setText(this.innerHTML);
		if (clip.div) {
			clip.receiveEvent('mouseout', null);
			clip.reposition(this);
		} else {
                        clip.glue(this);
                }
		clip.receiveEvent('mouseover', null);
		url = $(this).attr('rel');
	});

	clip.addEventListener('mouseUp', function(client) {
		window.open(url);
	});
}

$(document).ready(function() {
	init();
});
</pre>
<p>See the code in action at <a href="http://eisabainyo.net/website-templates/coupons-for-webmasters/">Coupons for Webmasters</a>. <a href="http://www.retailmenot.com/">RetailMeNot</a> is also using a similar script to achieve the same result.  </p>
<p>Read <a href="http://eisabainyo.net/weblog/2010/05/29/click-to-copy-and-open-site-script/">Click to copy and open site script</a> on Web Development Blog!</p><div><h3>Other similiar posts that you might be interested in:</h3><ul><li><a href="http://eisabainyo.net/weblog/2009/02/20/display-thickbox-on-page-load/" rel="bookmark" title="February 20, 2009">Display thickbox on page load</a></li>

<li><a href="http://eisabainyo.net/weblog/2011/06/29/creating-a-contact-form-in-jquery-mobile-and-php/" rel="bookmark" title="June 29, 2011">Creating a Contact Form in jQuery Mobile and PHP</a></li>

<li><a href="http://eisabainyo.net/weblog/2011/06/25/how-to-post-on-facebook-wall-on-iphone-and-android-using-phonegap-plugins/" rel="bookmark" title="June 25, 2011">How to &#8216;Post on Facebook Wall&#8217; on iPhone and Android using PhoneGap plugins</a></li>

<li><a href="http://eisabainyo.net/weblog/2009/07/23/customising-recaptcha-theme/" rel="bookmark" title="July 23, 2009">Customising reCAPTCHA Theme</a></li>

<li><a href="http://eisabainyo.net/weblog/2010/05/10/how-to-customise-wordpress-admin-login-page/" rel="bookmark" title="May 10, 2010">How to customise WordPress Admin Login page</a></li>

<li><a href="http://eisabainyo.net/weblog/2010/06/17/clear-default-text-in-input-boxes-on-click-with-jquery/" rel="bookmark" title="June 17, 2010">Clear default text in input boxes on click with jQuery</a></li>

<li><a href="http://eisabainyo.net/weblog/2009/02/20/store-login-information-in-cookie-using-jquery/" rel="bookmark" title="February 20, 2009">Store login information in cookie using jQuery</a></li>
</ul><!-- Similar Posts took 16.782 ms --></div>]]></content:encoded>
			<wfw:commentRss>http://eisabainyo.net/weblog/2010/05/29/click-to-copy-and-open-site-script/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>How to check if div exists in jQuery</title>
		<link>http://eisabainyo.net/weblog/2010/05/07/how-to-check-if-div-exists-in-jquery/</link>
		<comments>http://eisabainyo.net/weblog/2010/05/07/how-to-check-if-div-exists-in-jquery/#comments</comments>
		<pubDate>Fri, 07 May 2010 03:42:02 +0000</pubDate>
		<dc:creator>eisabai</dc:creator>
				<category><![CDATA[Snippets]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://eisabainyo.net/weblog/?p=1435</guid>
		<description><![CDATA[This is one of the most commonly used piece of code for jQuery.  Often times, we need to check if a div/element exists in the page before processing a block of script (eg: replacing the content of the div). 

if ( $("#message").length ) {
  $('#message').text("Hello!");
}

<p>Read <a href="http://eisabainyo.net/weblog/2010/05/07/how-to-check-if-div-exists-in-jquery/">How to check if div exists in jQuery</a> on Web Development Blog!</p><div><h3>Other similiar posts that you might be interested in:</h3><ul><li><a href="http://eisabainyo.net/weblog/2009/02/20/display-thickbox-on-page-load/" rel="bookmark" title="February 20, 2009">Display thickbox on page load</a></li>

<li><a href="http://eisabainyo.net/weblog/2011/06/29/creating-a-contact-form-in-jquery-mobile-and-php/" rel="bookmark" title="June 29, 2011">Creating a Contact Form in jQuery Mobile and PHP</a></li>

<li><a href="http://eisabainyo.net/weblog/2010/05/10/how-to-customise-wordpress-admin-login-page/" rel="bookmark" title="May 10, 2010">How to customise WordPress Admin Login page</a></li>

<li><a href="http://eisabainyo.net/weblog/2009/03/18/10-website-optimisation-tips-for-web-20-websites/" rel="bookmark" title="March 18, 2009">10 Website Optimisation Tips for Web 2.0 Websites</a></li>

<li><a href="http://eisabainyo.net/weblog/2009/05/28/check-username-availability-using-ajax-and-jquery/" rel="bookmark" title="May 28, 2009">Check username availability using AJAX and jQuery</a></li>

<li><a href="http://eisabainyo.net/weblog/2010/11/29/how-to-customise-your-facebook-fan-page/" rel="bookmark" title="November 29, 2010">How to customise your Facebook Fan Page with FBML</a></li>

<li><a href="http://eisabainyo.net/weblog/2011/01/31/top-10-jquery-mobile-code-snippets-that-you-need-to-know/" rel="bookmark" title="January 31, 2011">Top 10 jQuery Mobile Code Snippets that you need to know</a></li>
</ul><!-- Similar Posts took 177.227 ms --></div>]]></description>
			<content:encoded><![CDATA[<p>This is one of the most commonly used piece of code for jQuery.  Often times, we need to check if a div/element exists in the page before processing a block of script (eg: replacing the content of the div). </p>
<pre>
if ( $("#message").length ) {
  $('#message').text("Hello!");
}
</pre>
<p>Read <a href="http://eisabainyo.net/weblog/2010/05/07/how-to-check-if-div-exists-in-jquery/">How to check if div exists in jQuery</a> on Web Development Blog!</p><div><h3>Other similiar posts that you might be interested in:</h3><ul><li><a href="http://eisabainyo.net/weblog/2009/02/20/display-thickbox-on-page-load/" rel="bookmark" title="February 20, 2009">Display thickbox on page load</a></li>

<li><a href="http://eisabainyo.net/weblog/2011/06/29/creating-a-contact-form-in-jquery-mobile-and-php/" rel="bookmark" title="June 29, 2011">Creating a Contact Form in jQuery Mobile and PHP</a></li>

<li><a href="http://eisabainyo.net/weblog/2010/05/10/how-to-customise-wordpress-admin-login-page/" rel="bookmark" title="May 10, 2010">How to customise WordPress Admin Login page</a></li>

<li><a href="http://eisabainyo.net/weblog/2009/03/18/10-website-optimisation-tips-for-web-20-websites/" rel="bookmark" title="March 18, 2009">10 Website Optimisation Tips for Web 2.0 Websites</a></li>

<li><a href="http://eisabainyo.net/weblog/2009/05/28/check-username-availability-using-ajax-and-jquery/" rel="bookmark" title="May 28, 2009">Check username availability using AJAX and jQuery</a></li>

<li><a href="http://eisabainyo.net/weblog/2010/11/29/how-to-customise-your-facebook-fan-page/" rel="bookmark" title="November 29, 2010">How to customise your Facebook Fan Page with FBML</a></li>

<li><a href="http://eisabainyo.net/weblog/2011/01/31/top-10-jquery-mobile-code-snippets-that-you-need-to-know/" rel="bookmark" title="January 31, 2011">Top 10 jQuery Mobile Code Snippets that you need to know</a></li>
</ul><!-- Similar Posts took 140.421 ms --></div>]]></content:encoded>
			<wfw:commentRss>http://eisabainyo.net/weblog/2010/05/07/how-to-check-if-div-exists-in-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Align an image in center and middle using CSS</title>
		<link>http://eisabainyo.net/weblog/2010/04/22/align-an-image-in-center-and-middle-using-css/</link>
		<comments>http://eisabainyo.net/weblog/2010/04/22/align-an-image-in-center-and-middle-using-css/#comments</comments>
		<pubDate>Thu, 22 Apr 2010 02:02:22 +0000</pubDate>
		<dc:creator>eisabai</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Snippets]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://eisabainyo.net/weblog/?p=1410</guid>
		<description><![CDATA[Here&#8217;s a snippet of CSS and HTML code that aligns an image in center (horizontally) and middle (vertically).  Tested in Firefox, IE, Chrome and Safari.  

CSS
#enter {
	position: absolute;
	text-align: center;
	left: 50%;
	top: 50%;
	margin: -120px auto 0 -130px; /* value of top margin: height of the image divide by 2 (ie: 240 / 2), value of [...]<p>Read <a href="http://eisabainyo.net/weblog/2010/04/22/align-an-image-in-center-and-middle-using-css/">Align an image in center and middle using CSS</a> on Web Development Blog!</p><div><h3>Other similiar posts that you might be interested in:</h3><ul><li><a href="http://eisabainyo.net/weblog/2009/08/28/framebar-like-diggbar-example-in-html-and-css-with-no-javascript/" rel="bookmark" title="August 28, 2009">Framebar (like diggbar) example in html and css with no javascript</a></li>

<li><a href="http://eisabainyo.net/weblog/2011/06/07/how-to-use-hi-res-images-for-web-apps-in-iphone4/" rel="bookmark" title="June 7, 2011">How to use hi-res images in web apps for iPhone4</a></li>

<li><a href="http://eisabainyo.net/weblog/2010/03/09/how-to-style-a-submit-button-in-css-example-2/" rel="bookmark" title="March 9, 2010">How to style a Submit button in CSS &#8211; Example 2</a></li>

<li><a href="http://eisabainyo.net/weblog/2009/04/24/how-to-style-a-submit-button-in-css/" rel="bookmark" title="April 24, 2009">How to style a Submit button in CSS</a></li>

<li><a href="http://eisabainyo.net/weblog/2005/12/26/transitional-vs-strict/" rel="bookmark" title="December 26, 2005">Transitional vs. Strict</a></li>

<li><a href="http://eisabainyo.net/weblog/2009/07/02/some-simple-but-effective-css-rules-for-ie-6/" rel="bookmark" title="July 2, 2009">Some simple but effective CSS rules for IE 6</a></li>

<li><a href="http://eisabainyo.net/weblog/2011/01/31/top-10-jquery-mobile-code-snippets-that-you-need-to-know/" rel="bookmark" title="January 31, 2011">Top 10 jQuery Mobile Code Snippets that you need to know</a></li>
</ul><!-- Similar Posts took 344.775 ms --></div>]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a snippet of CSS and HTML code that aligns an image in center (horizontally) and middle (vertically).  Tested in Firefox, IE, Chrome and Safari.  </p>
<p><img src="http://eisabainyo.net/weblog/wp-content/uploads/2010/04/image-in-center-middle.gif" alt="" title="Image in center and middle" width="350" class="alignnone size-full wp-image-1412" /></p>
<p><strong>CSS</strong></p>
<pre>#enter {
	position: absolute;
	text-align: center;
	left: 50%;
	top: 50%;
	margin: -120px auto 0 -130px; /* value of top margin: height of the image divide by 2 (ie: 240 / 2), value of left margin: width of the image divide by 2 (ie: 260 / 2) */
	width: 260px; /* same as the image width */
}

#enter span a {
	display: block;
	width: 260px;
	height: 240px;
	margin: 0 auto;
	position: relative;
	background: transparent url(images/enter.jpg) 0 0 no-repeat;
	text-indent: -5000em;
	outline: 0;
}</pre>
<p><strong>HTML</strong></p>
<pre>&lt;body id=&quot;homepage&quot;&gt;
    &lt;div id=&quot;enter&quot;&gt;
	&lt;span&gt;&lt;a href=&quot;/home&quot;&gt;Enter Site&lt;/a&gt;&lt;/span&gt;
    &lt;/div&gt;
&lt;/body&gt;</pre>
<p>Read <a href="http://eisabainyo.net/weblog/2010/04/22/align-an-image-in-center-and-middle-using-css/">Align an image in center and middle using CSS</a> on Web Development Blog!</p><div><h3>Other similiar posts that you might be interested in:</h3><ul><li><a href="http://eisabainyo.net/weblog/2009/08/28/framebar-like-diggbar-example-in-html-and-css-with-no-javascript/" rel="bookmark" title="August 28, 2009">Framebar (like diggbar) example in html and css with no javascript</a></li>

<li><a href="http://eisabainyo.net/weblog/2011/06/07/how-to-use-hi-res-images-for-web-apps-in-iphone4/" rel="bookmark" title="June 7, 2011">How to use hi-res images in web apps for iPhone4</a></li>

<li><a href="http://eisabainyo.net/weblog/2010/03/09/how-to-style-a-submit-button-in-css-example-2/" rel="bookmark" title="March 9, 2010">How to style a Submit button in CSS &#8211; Example 2</a></li>

<li><a href="http://eisabainyo.net/weblog/2009/04/24/how-to-style-a-submit-button-in-css/" rel="bookmark" title="April 24, 2009">How to style a Submit button in CSS</a></li>

<li><a href="http://eisabainyo.net/weblog/2005/12/26/transitional-vs-strict/" rel="bookmark" title="December 26, 2005">Transitional vs. Strict</a></li>

<li><a href="http://eisabainyo.net/weblog/2009/07/02/some-simple-but-effective-css-rules-for-ie-6/" rel="bookmark" title="July 2, 2009">Some simple but effective CSS rules for IE 6</a></li>

<li><a href="http://eisabainyo.net/weblog/2011/01/31/top-10-jquery-mobile-code-snippets-that-you-need-to-know/" rel="bookmark" title="January 31, 2011">Top 10 jQuery Mobile Code Snippets that you need to know</a></li>
</ul><!-- Similar Posts took 16.628 ms --></div>]]></content:encoded>
			<wfw:commentRss>http://eisabainyo.net/weblog/2010/04/22/align-an-image-in-center-and-middle-using-css/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

