<?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>nooshu &#187; mobile Archives </title>
	<atom:link href="http://nooshu.com/tag/mobile/feed" rel="self" type="application/rss+xml" />
	<link>http://nooshu.com</link>
	<description>Kneeling on the shoulders of giants</description>
	<lastBuildDate>Sun, 15 Apr 2012 13:42:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>HTML5 date input type on mobile</title>
		<link>http://nooshu.com/html5-date-input-type-on-mobile?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=html5-date-input-type-on-mobile</link>
		<comments>http://nooshu.com/html5-date-input-type-on-mobile#comments</comments>
		<pubDate>Tue, 06 Mar 2012 12:36:00 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Browsers]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[input]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[webkit]]></category>

		<guid isPermaLink="false">http://nooshu.com/?p=2118</guid>
		<description><![CDATA[While developing a new mobile website I ran into an annoying issue while validating the input. Here's a solution, not nice but it works!]]></description>
			<content:encoded><![CDATA[<p>Whilst developing a new mobile only website, the UX team specified in the wireframes that a datepicker was needed for an input field; but nowhere else on the site was a datepicker used, so I really wanted to avoid using a <a href="http://jqueryui.com/demos/datepicker/">JavaScript heavy solution</a>. I couldn&#8217;t justify including so much extra JavaScript, CSS and images for so little usage. So what other options do we have?</p>
<p>Well there is a jQuery plug-in called <a href="http://code.google.com/p/mobiscroll/">Mobiscroll</a> which is around 16KB is size and works on iOS and Android devices. Unfortunately there&#8217;s no mention of Windows-based mobiles which is a real shame, as it&#8217;s almost a perfect solution. The other option we have is to take advantage of some cutting edge HTML5 form input types; the date input type. Support is <a href="http://www.quirksmode.org/html5/inputs_mobile.html">nowhere near 100%</a> yet, but if you approach its usage from a progressive enhancement standpoint, it works well. On mobile browsers that support it, the user gets a fancy datepicker that&#8217;s very intuitive; browsers that don&#8217;t simply drop back to a standard text input. It&#8217;s worth noting that <a href="http://www.modernizr.com/docs#inputtypes">Modernizr can&#8217;t detect that date inputs create a datepicker</a>, since Modernizr can&#8217;t do it I assume it isn&#8217;t possible. Damn!</p>
<div id="attachment_2120" class="wp-caption alignnone" style="width: 528px"><a href="http://nooshu.com/wp-content/uploads/2012/03/date-type-input-mobile.gif"><img src="http://nooshu.com/wp-content/uploads/2012/03/date-type-input-mobile-518x420.gif" alt="An example of the date input type on iPhone, iPad and iPods." title="date-type-input-mobile" width="518" height="420" class="size-medium wp-image-2120" /></a><p class="wp-caption-text">The date input type as displayed on iOS mobile Webkit devices.</p></div>
<p>Once I&#8217;d decided on how the date picker was going to work (HTML5) it was time to implement it and test it across my available mobile browsers. Implementation was dead simple:</p>
<div class="codecolorer-container html4strict default customCodeColor" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">&lt;!-- Fancy datepicker on supported devices, standard text input on unsupported --&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;date&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;fancyDate&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;fancyDate&quot;</span>&gt;</span></div></td></tr></tbody></table></div>
<p>Where things got a little tricky (and annoying) was the client-side validation of the input. Since the wireframes contained lots of forms with a varying range of input types and requirements, I decided to go with quite a heavyweight <a href="http://bassistance.de/jquery-plugins/jquery-plugin-validation/">validation script</a> (around 21KB minified). This turned out to be a very good decision in the end, as there are a few quirks to the date input element.</p>
<p>First thing I had to consider was how were users going to input the date when they don&#8217;t have the fancy datepicker? The most intuitive way (at least for me) is they simply enter in the format dd/mm/yyyy. Great, that&#8217;s sorted! And guess what, when a user uses the fancy datepicker it also returns a value of dd/mm/yyyy&#8230;. no, no it doesn&#8217;t! It looks like that&#8217;s the value that will be returned as that&#8217;s how it is displayed, but no, it&#8217;s never that easy. Webkit actually returns the date in the format yyyy-mm-dd, not quite what I was expecting! Unfortunately this breaks our validation as it is looking for a format of dd/mm/yyyy!</p>
<p>So what&#8217;s the fix? Well you could take the easy route and make your non-fancy datepicker users enter the date in the yyyy-mm-dd format; but that just feels wrong. No user is going to expect to enter a date like that, it&#8217;s completely unintuitive! No I&#8217;m afraid it&#8217;s going to take a little hack to fix this issue. The hack involves using a second input field of type &#8220;text&#8221;; when a user interacts with the fancy datepicker or enters in the date manually, the date is &#8220;cleaned up&#8221; and passed along to the second input field. You then do your form validation against this second field. You can see an example of this working <a href="http://dl.dropbox.com/u/7851949/html5-mobile-datepicker/form.html">here</a>.</p>
<div class="codecolorer-container javascript default customCodeColor" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #006600; font-style: italic;">/**<br />
&nbsp;* iOS input type=&quot;date&quot; returns a value of yyyy-mm-dd even when<br />
&nbsp;* it displays dd/mm/yyyy. This breaks validation. Fix for this using a second input.<br />
&nbsp;* Keyup event for testing in a browser, not needed for mobile.<br />
&nbsp;*/</span><br />
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;input[type='date']&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">on</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;blur keyup&quot;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> $this <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; value <span style="color: #339933;">=</span> $this.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Does the input have &quot;-&quot;, if so it is from the webkit datepicker, fix it</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>value.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;-&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!==</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> cleanDateArray <span style="color: #339933;">=</span> value.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'-'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; value <span style="color: #339933;">=</span> cleanDateArray<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;/&quot;</span> <span style="color: #339933;">+</span> cleanDateArray<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;/&quot;</span> <span style="color: #339933;">+</span> cleanDateArray<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Set the hidden value to validate on, trigger the blur and keyup event for validation as you type</span><br />
&nbsp; &nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#hiddenDateField&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>value<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">trigger</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;blur&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">trigger</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;keyup&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>A couple of points to note about using this method. Even though we aren&#8217;t validating the datepicker input, we still have to set &#8220;date: false&#8221; in the validation rules. This is because the validation plug-in automatically tries to validate date inputs. Validation fails because it doesn&#8217;t like the dd/mm/yyyy format. I&#8217;ve also used the dateITA method to validate the date on the &#8220;hidden&#8221; input (you can find this in the additional-methods.min.js file). This additional method is more robust than the plug-ins standard date validation. A minor pitfall with this hack is that setting the second input to type &#8220;hidden&#8221; will stop its validation; this is due to the validation plug-in ignoring hidden inputs. So to hide the input you can set &#8220;display: none&#8221; in the CSS (urghh I know, I feel dirty too!).</p>
<p>So there you have it, that&#8217;s how I solved validating a date input on mobile with fancy datepicker and standard text fallback. It&#8217;s not ideal by any means, but it works. Another solution would be writing a validator Regex that accepts both dd/mm/yyyy and yyyy-mm-dd date formats, but this means returning both types of dates to the server on submit. Due to server-side constraints with the project, this isn&#8217;t an option (boo!). Is there a much simpler method that I&#8217;m completely missing? If so please leave a comment! :)</p>
]]></content:encoded>
			<wfw:commentRss>http://nooshu.com/html5-date-input-type-on-mobile/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using the DeviceAtlas API with WordPress</title>
		<link>http://nooshu.com/using-the-deviceatlas-api-with-wordpress?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=using-the-deviceatlas-api-with-wordpress</link>
		<comments>http://nooshu.com/using-the-deviceatlas-api-with-wordpress#comments</comments>
		<pubDate>Tue, 22 Jun 2010 20:14:00 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Mobile]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[mobile]]></category>

		<guid isPermaLink="false">http://nooshu.com/?p=1221</guid>
		<description><![CDATA[Building a mobile site can be quite painful, but it's made much easier using the DeviceAtlas API.]]></description>
			<content:encoded><![CDATA[<p>Over the past couple of weeks I&#8217;ve had the absolute pleasure (no not really!) of adapting a WordPress site and making it accessible on as many mobile phones as possible. Now I must admit I&#8217;ve not had much experience building mobile sites so this is all new ground for me; and by mobile website I don&#8217;t mean for the iPhone only (for more information on this plus lots of swear words see &#8216;<a href="http://www.quirksmode.org/blog/archives/2010/02/the_iphone_obse.html">The iPhone Obsession</a>&#8216; by PPK).</p>
<p>Luckily there are already many plug-ins available for WordPress that can get you started on your way, one that really grabbed my attention was  &#8216;<a href="http://mobiforge.com/running/story/the-dotmobi-wordpress-mobile-pack">WordPress Mobile Pack</a>&#8216; by MobiForge. The plug-in contains a mobile optimised theme that you can adapt for your needs and the &#8216;mobile switcher&#8217; functionality. Mobile switcher detects if a user is browsing from a desktop or a mobile phone and switched the theme accordingly. Great, we&#8217;re already half way there!</p>
<p>One of the specifications for the site was that it must work on a set of 4 different screen widths (480px, 320px, 240px and 176px) and this is where the DeviceAtlas API comes in very useful. Device Atlas keep a huge database of mobile phone user agent strings plus specifications associated with a particular mobile phone that you can tap into and use in your web application.</p>
<p>Now one thing I must mention is that according to the mobiForge page listed above, WordPress Mobile Pack includes DeviceAtlas integration. This turns out not to be the case. I couldn&#8217;t find any settings regarding DeviceAtlas in the plug-in admin area and very little mentioned on the forums. I assume the page hasn&#8217;t been updated for a while and the functionality has been removed. This isn&#8217;t a problem though as it&#8217;s fairly simple to integrate the DeviceAtlas API into your PHP application i.e. WordPress. Here&#8217;s how you do it.</p>
<p>First you must register with DeviceAtlas and order a developer licence (there&#8217;s a free option available <a href="http://deviceatlas.com/products">here</a>). Once registered grab a copy of the <a href="http://deviceatlas.com/downloads">PHP API</a> and the latest Device JSON file (under &#8216;My account&#8217;). Unpack the API into the root of your web application (or wherever you like, just make sure the includes are set correctly) and copy the JSON file into the json directory along side it. You are now ready to include the API into the base WordPress Mobile Pack theme. Copy and paste the following into your header.php above the doctype:</p>
<div class="codecolorer-container php default customCodeColor" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #666666; font-style: italic;">//Include the DA API</span><br />
<span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'Mobi/Mtld/DA/Api.php'</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">//Include the JSON file with the device data</span><br />
<span style="color: #000088;">$tree</span> <span style="color: #339933;">=</span> Mobi_Mtld_DA_Api<span style="color: #339933;">::</span><span style="color: #004000;">getTreeFromFile</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'json/DeviceAtlas.json'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">//Grab the User Agent string</span><br />
<span style="color: #000088;">$ua</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_USER_AGENT'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<p>Great now we know the user agent that the user is using to view the website (well it may not be 100% accurate but better than nothing). So now you want to query the JSON file and pick out the relevant phone specifications you need. I&#8217;m just looking for the width of the device, so I included this in the head tag:</p>
<div class="codecolorer-container php default customCodeColor" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
&nbsp; &nbsp; try <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//Query the JSON file ($tree) with the User Agent string and look for the display width</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$displayWidth</span> <span style="color: #339933;">=</span> Mobi_Mtld_DA_Api<span style="color: #339933;">::</span><span style="color: #004000;">getPropertyAsInteger</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tree</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ua</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;displayWidth&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> catch <span style="color: #009900;">&#40;</span>Mobi_Mtld_Da_Exception_InvalidPropertyException <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$displayWidth</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">240</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Default to 240 if unknown</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//Add stylesheet tweaks depending display width</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$displayWidth</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">480</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span><br />
&nbsp; &nbsp; &lt;link href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'stylesheet_directory'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>/480.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;<br />
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$displayWidth</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">320</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><br />
&nbsp; &nbsp; &lt;link href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'stylesheet_directory'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>/320.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;<br />
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$displayWidth</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">240</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><br />
&nbsp; &nbsp; &lt;link href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'stylesheet_directory'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>/240.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;<br />
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$displayWidth</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">176</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><br />
&nbsp; &nbsp; &lt;link href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'stylesheet_directory'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>/176.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;<br />
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<p>All this code does is find the display width of the phone viewing the website and add a CSS file with relevant site tweaks, allowing you to optimise for that screen size. If the device isn&#8217;t found I&#8217;ve defaulted to a screen size in the middle of the screen sizes.</p>
<p>Looking through the API docs there are plenty of ways to distinguish between your users, using the following code will allow you to target specific phone brands:</p>
<div class="codecolorer-container php default customCodeColor" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #666666; font-style: italic;">//Output example $make = 'Nokia'</span><br />
<span style="color: #000088;">$make</span> <span style="color: #339933;">=</span> Mobi_Mtld_DA_Api<span style="color: #339933;">::</span><span style="color: #004000;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tree</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ua</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'vendor'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<p>So now you can target only Nokia users. Or instead of loading a different CSS file you could include a different sized image for different screen widths; there are tonnes of options available.</p>
<p>I must admit I really dislike having to &#8216;sniff&#8217; for the user agent string and having a different CSS file / image per device width, it reminds me of the Netscape / IE browser war days, oh how much fun that was! I guess it&#8217;s a necessary evil. </p>
<p>A word or warning when it comes to DeviceAtlas, there seems to be distinct lack of support available. I wrote a couple of emails asking questions and got no reply, and lots of questions on the forum are left unanswered. So if you get stuck you may need to figure it out for yourself I&#8217;m afraid.</p>
<p>All in all I&#8217;m pleased with the results of my first adventure into the world of mobile web development. I still have lots to learn so if you have any tips and tricks please let me know! </p>
]]></content:encoded>
			<wfw:commentRss>http://nooshu.com/using-the-deviceatlas-api-with-wordpress/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

