<?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>operationmobile.com</title> <atom:link href="http://operationmobile.com/feed/" rel="self" type="application/rss+xml" /><link>http://operationmobile.com</link> <description>Hire us for your mobile mission</description> <lastBuildDate>Mon, 30 Apr 2012 00:14:25 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.2</generator> <xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" /> <item><title>Quick tip for using Knockout.js and jQuery Mobile List Dividers</title><link>http://operationmobile.com/quick-tip-for-using-knockout-js-and-jquery-mobile-list-dividers/</link> <comments>http://operationmobile.com/quick-tip-for-using-knockout-js-and-jquery-mobile-list-dividers/#comments</comments> <pubDate>Mon, 30 Apr 2012 00:14:25 +0000</pubDate> <dc:creator>Jag</dc:creator> <category><![CDATA[jQuery Mobile]]></category> <category><![CDATA[Knockout.js]]></category><guid isPermaLink="false">http://operationmobile.com/?p=393</guid> <description><![CDATA[For my latest project I needed to bind a Knockout.js observableArray to a jQuery Mobile listview with a list divider at the top. I initially tried adding the data-bind attribute to the ul element as shown in the code below (see jsFiddle for the complete code listing and working demo). &#60;ul data-role=&#34;listview&#34; data-bind=&#34;foreach: fruit&#34;&#62; &#160; [...]]]></description> <content:encoded><![CDATA[<p>For my latest project I needed to bind a Knockout.js observableArray to a jQuery Mobile listview with a list divider at the top.</p><p>I initially tried adding the data-bind attribute to the ul element as shown in the code below (see <a href="http://jsfiddle.net/QvHKg/3/" title="jsFiddle Knockout.js without comment based control" target="_blank">jsFiddle</a> for the complete code listing and working demo).</p><div class="codecolorer-container html4strict railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/ul.html"><span style="color: #000000; font-weight: bold;">ul</span></a> data-role<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;listview&quot;</span> data-bind<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;foreach: fruit&quot;</span>&gt;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a> data-role<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;list-divider&quot;</span>&gt;</span>Fruit<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/h3.html"><span style="color: #000000; font-weight: bold;">h3</span></a> data-bind<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot; text: Name&quot;</span><span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br /> <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/ul.html"><span style="color: #000000; font-weight: bold;">ul</span></a>&gt;</span></div></div><p>But this meant the list divider was repeated for every list item!</p><p><img src="https://lh6.googleusercontent.com/-1xEH2xslCNY/T53VsPt4ZoI/AAAAAAAAAKQ/9nQu51C9njs/s512/knockoutlistdivider-repeating.png" alt="Knockout.js without comment based control" /></p><h3>Comment based control flows to the rescue</h3><p>By using a comment based control flow (introduced in <a href="http://blog.stevensanderson.com/2011/12/21/knockout-2-0-0-released/" title="Knockout.js 2.0" target="_blank">knockout.js 2.0</a>) the <strong>foreach</strong> binding can be moved below the list divider but still within the ul element.</p><p>See <a href="http://jsfiddle.net/ycQwH/3/" title="jsFiddle Knockout.js without comment based control" target="_blank">jsFiddle</a> for the complete code listing and working demo.</p><div class="codecolorer-container html4strict railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/ul.html"><span style="color: #000000; font-weight: bold;">ul</span></a> data-role<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;listview&quot;</span>&gt;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a> data-role<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;list-divider&quot;</span>&gt;</span>Fruit<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br /> &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">&lt;!-- ko foreach: fruit --&gt;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/h3.html"><span style="color: #000000; font-weight: bold;">h3</span></a> data-bind<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot; text: Name&quot;</span><span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br /> &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">&lt;!-- /ko --&gt;</span><br /> <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/ul.html"><span style="color: #000000; font-weight: bold;">ul</span></a>&gt;</span></div></div><p><img src="https://lh4.googleusercontent.com/-6MfwrXp8OrM/T53VsDoS96I/AAAAAAAAAKU/BSg7AnK1sdA/s512/knockoutlistdivider-fixed.png" alt="Knockout.js jQuery Mobile Comment Based Control Flow" /></p> ]]></content:encoded> <wfw:commentRss>http://operationmobile.com/quick-tip-for-using-knockout-js-and-jquery-mobile-list-dividers/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Mission Accomplished: Presented about building web apps using jQuery Mobile</title><link>http://operationmobile.com/mission-accomplished-presented-about-building-web-apps-using-jquery-mobile/</link> <comments>http://operationmobile.com/mission-accomplished-presented-about-building-web-apps-using-jquery-mobile/#comments</comments> <pubDate>Wed, 21 Mar 2012 21:36:01 +0000</pubDate> <dc:creator>Jag</dc:creator> <category><![CDATA[Android]]></category> <category><![CDATA[Design]]></category> <category><![CDATA[HTML5]]></category> <category><![CDATA[iOS]]></category> <category><![CDATA[JavaScript]]></category> <category><![CDATA[jQuery Mobile]]></category><guid isPermaLink="false">http://operationmobile.com/?p=368</guid> <description><![CDATA[Yesterday I presented about using jQuery Mobile to the Cambridge Mobile App Group in Cambridge. I’ve uploaded the slides to Slideshare and the code to github. You can view the jQuery Mobile web app built during talk by clicking here or by scanning the QR code below.]]></description> <content:encoded><![CDATA[<p>Yesterday I presented about using jQuery Mobile to the <a href="http://www.meetup.com/Cambridge-Mobile-App-Group/events/51211512/" title="CMAG Cambridge" target="_blank">Cambridge Mobile App Group in Cambridge</a>.</p><p><img src="http://photos1.meetupstatic.com/photos/event/8/9/0/600_103142192.jpeg" alt="Jag Reehal Presenting about jQuery Mobile" /></p><p>I’ve uploaded the slides to Slideshare and the code to <a href="https://github.com/operationmobile/jQueryMobileDemo" title="jQueryMobileDemo code" target="_blank">github</a>.</p><div style="width:425px" id="__ss_12106662"> <object id="__sse12106662" width="425" height="355"><param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=jquerymobileslideshare-120321155047-phpapp02&#038;stripped_title=building-jquery-mobile-web-apps&#038;userName=operationmobile" /><param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/><param name="wmode" value="transparent"/><embed name="__sse12106662" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=jquerymobileslideshare-120321155047-phpapp02&#038;stripped_title=building-jquery-mobile-web-apps&#038;userName=operationmobile" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" wmode="transparent" width="425" height="355"></embed></object></div><p>You can view the jQuery Mobile web app built during talk by <a href="http://dl.dropbox.com/u/24023585/jQueryMobile/Presentation/final.html" title="jQuery Mobile Demo" target="_blank">clicking here</a> or by scanning the QR code below.</p><p><img height="240" id="QRImage" width="240" src="http://chart.apis.google.com/chart?cht=qr&#038;chl=http%3A//dl.dropbox.com/u/24023585/jQueryMobile/Presentation/final.html&#038;chs=240x240" /></p> ]]></content:encoded> <wfw:commentRss>http://operationmobile.com/mission-accomplished-presented-about-building-web-apps-using-jquery-mobile/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>How to create a jQuery Mobile App using ASP.NET MVC</title><link>http://operationmobile.com/how-to-create-a-jquery-mobile-app-using-asp-net-mvc/</link> <comments>http://operationmobile.com/how-to-create-a-jquery-mobile-app-using-asp-net-mvc/#comments</comments> <pubDate>Wed, 29 Feb 2012 00:03:21 +0000</pubDate> <dc:creator>Jag</dc:creator> <category><![CDATA[ASP.NET MVC]]></category> <category><![CDATA[jQuery Mobile]]></category><guid isPermaLink="false">http://operationmobile.com/?p=356</guid> <description><![CDATA[In this post I’ll show you how to create a mobile web app using jQuery Mobile and ASP.NET MVC 4. I’ve used AppHarbor to host the app so you can see it action by clicking here. The source code for the demo in this post can be found on github. The first step in creating [...]]]></description> <content:encoded><![CDATA[<p>In this post I’ll show you how to create a mobile web app using jQuery Mobile and ASP.NET MVC 4.</p><p>I’ve used AppHarbor to host the app so you can see it action by <a href="http://yummybakesaspnetmvcjquerymobile.apphb.com/" title="Demo of Yummy Bakes on AppHarbor" target="_blank">clicking here</a>.</p><p><img src="https://lh3.googleusercontent.com/-f1OT_hMWzWY/T01BSuK7LqI/AAAAAAAAAJM/rkh_u4YCYZo/s512/yummybakes.png" alt="Yummy Bakes" /></p><p>The source code for the demo in this post can be found on <a href="https://github.com/operationmobile/YummyBakesASPNETMVCjQueryMobile" title="source code on github" target="_blank">github</a>.</p><p>The first step in creating a mobile ASP.NET MVC mobile web app is to either choose select the &#8216;Mobile Application&#8217; project template or an empty project.</p><p><img src="https://lh5.googleusercontent.com/-D7zr5-OHpPk/T01BSqtl06I/AAAAAAAAAJE/pBfcOHDSbxE/s376/aspnetmvcprojecttemplate.png" alt="ASP.NET MVC project template" /></p><p>As personal preference I prefer the empty solution as it won’t be cluttered by controllers, views and scripts you don’t need.</p><p>In the layout file for the app (used as the template for other views) we add the CSS and JavaScript resources required.</p><div class="codecolorer-container html4strict railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #00bbdd;">&lt;!DOCTYPE html&gt;</span><br /> <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>&gt;</span><br /> <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>&gt;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/meta.html"><span style="color: #000000; font-weight: bold;">meta</span></a> <span style="color: #000066;">charset</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;utf-8&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/meta.html"><span style="color: #000000; font-weight: bold;">meta</span></a> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;viewport&quot;</span> <span style="color: #000066;">content</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;width=device-width, initial-scale=1&quot;</span>&gt;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">title</span></a>&gt;</span>@ViewBag.Title<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">title</span></a>&gt;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/link.html"><span style="color: #000000; font-weight: bold;">link</span></a> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.css&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/link.html"><span style="color: #000000; font-weight: bold;">link</span></a> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl(&quot;</span>~<span style="color: #66cc66;">/</span>css<span style="color: #ff0000;">&quot;)&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span> &nbsp; &nbsp;<br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://code.jquery.com/jquery-1.6.4.min.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://ajax.aspnetcdn.com/ajax/jquery.validate/1.7/jquery.validate.min.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl(&quot;</span>~<span style="color: #66cc66;">/</span>js<span style="color: #ff0000;">&quot;)&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span> &nbsp; &nbsp;<br /> <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>&gt;</span><br /> <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;section data-role<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;page&quot;</span> data-theme<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;d&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;@ViewBag.PageId&quot;</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;section data-role<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;header&quot;</span>data-theme<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;e&quot;</span>&gt;</span> <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;section <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;header&quot;</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;@Url.Action(&quot;</span>Index<span style="color: #ff0000;">&quot;, &quot;</span>Recipe<span style="color: #ff0000;">&quot;)&quot;</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/h2.html"><span style="color: #000000; font-weight: bold;">h2</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;header-text&quot;</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/img.html"><span style="color: #000000; font-weight: bold;">img</span></a> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;~/Content/Images/logo.png&quot;</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;YummyCake&quot;</span>&gt;</span>Yummy Bakes<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/h2.html"><span style="color: #000000; font-weight: bold;">h2</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>section&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>section&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;section data-role<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;content&quot;</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @RenderBody()<br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>section&gt;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>section&gt;</span><br /> <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span><br /> <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>&gt;</span></div></div><p>Here we’re using the new ASP.NET MVC 4 bundling and minification functionality in combination with content delivery networks (CDN’s) to increase the performance of the application.</p><p>You can read more about bundling and minification in the post &#8216;<a href="http://operationmobile.com/asp-net-mvc-mobile-performance-tip-bundle-and-minify/" title="ASP.NET MVC Mobile Performance Tip – Bundle and Minify" target="_blank">ASP.NET MVC Mobile Performance Tip – Bundle and Minify</a>&#8216;.</p><h3>jQuery Mobile data-* attributes</h3><p>If you’ve not used jQuery Mobile before you may be wondering what the data-* attributes are for.</p><p>jQuery Mobile uses the attributes to apply styles and functionality to elements on the page.</p><p>As the same header will be used in all of the pages in this mobile web app we can define it in the layout file.</p><p>The call to RenderBody() is wrapped in a data-role= &#8220;content&#8221; attribute which jQuery Mobile uses to define the content of a page.</p><p>See the <a href="http://jquerymobile.com/demos" title="jQM docs" target="_blank">jQuery docs </a>for more information about page structure.</p><p>Now we’ve created the layout template the next thing to do is create the ASP.NET MVC controller for the mobile web app.</p><div class="codecolorer-container csharp railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span><br /> <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Linq</span><span style="color: #008000;">;</span><br /> <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Web.Mvc</span><span style="color: #008000;">;</span><br /> <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">YummyBakesASPNETMVC.Data</span><span style="color: #008000;">;</span><br /> <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">YummyBakesASPNETMVC.Models</span><span style="color: #008000;">;</span><br /> <br /> <span style="color: #0600FF; font-weight: bold;">namespace</span> YummyBakesASPNETMVC<span style="color: #008000;">.</span><span style="color: #0000FF;">Controllers</span><br /> <span style="color: #008000;">&#123;</span><br /> &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> RecipeController <span style="color: #008000;">:</span> YummyBakesBaseController<br /> &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> ActionResult Index<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> View<span style="color: #008000;">&#40;</span>SampleRecipes<span style="color: #008000;">.</span><span style="color: #0000FF;">Recipes</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Take</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">3</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToList</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br /> <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> ActionResult Details<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> id<span style="color: #008000;">&#41;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ViewBag<span style="color: #008000;">.</span><span style="color: #0000FF;">PageId</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;recipe-details&quot;</span><span style="color: #008000;">;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> View<span style="color: #008000;">&#40;</span>SampleRecipes<span style="color: #008000;">.</span><span style="color: #0000FF;">Recipes</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Single</span><span style="color: #008000;">&#40;</span>r <span style="color: #008000;">=&gt;</span> r<span style="color: #008000;">.</span><span style="color: #0000FF;">Id</span> <span style="color: #008000;">==</span> id<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br /> <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> ActionResult Find<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> View<span style="color: #008000;">&#40;</span>SampleRecipes<span style="color: #008000;">.</span><span style="color: #0000FF;">Recipes</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br /> <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> ActionResult AddReview<span style="color: #008000;">&#40;</span>Review review<span style="color: #008000;">&#41;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; review<span style="color: #008000;">.</span><span style="color: #0000FF;">DatePublished</span> <span style="color: #008000;">=</span> DateTime<span style="color: #008000;">.</span><span style="color: #0000FF;">Now</span><span style="color: #008000;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">//SampleRecipes.Recipes.Single(r =&gt; r.Id == review.RecipeId).Reviews.Add(review);</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> Content<span style="color: #008000;">&#40;</span>RenderPartialViewToString<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Review&quot;</span>, review<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br /> &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br /> <span style="color: #008000;">&#125;</span></div></div><p>The Index action for the RecipeController will return a view model containing the top 3 baking recipes.</p><p>To keep things simple the recipes are coming back from a static list and not from a database.</p><p>In the view for the Index action the user will see text about the app, a link to a page to find recipes and a list of the top three recipes.</p><p><img src="https://lh4.googleusercontent.com/-ZnvAilZU_J8/T01BSoDEZLI/AAAAAAAAAJI/IAhKhAk7eY0/s512/yummybakeshome.png" alt="Yummy Bakes Home" /></p><p>The markup for the view is shown below.</p><div class="codecolorer-container html4strict railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">@model IEnumerable<span style="color: #009900;">&lt;YummyBakesASPNETMVC.Models.Recipe&gt;</span><br /> @{<br /> &nbsp; &nbsp; ViewBag.Title = &quot;Yummy Bakes&quot;; &nbsp; &nbsp;<br /> }<br /> <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;intro&quot;</span>&gt;</span><br /> &nbsp; &nbsp; From old favourites to new twists on modern classics, from sweet to savoury we've<br /> &nbsp; &nbsp; got a recipe just for you!<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;@Url.Action(&quot;</span>Find<span style="color: #ff0000;">&quot;,&quot;</span>Recipe<span style="color: #ff0000;">&quot;)&quot;</span> data-role<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;button&quot;</span> data-icon<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;search&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;find-recipe-link&quot;</span>&gt;</span>Find a recipe<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a>&gt;</span><br /> <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/ul.html"><span style="color: #000000; font-weight: bold;">ul</span></a> data-role<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;listview&quot;</span> data-divider-theme<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;e&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;recipe-list&quot;</span>&gt;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a> data-role<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;list-divider&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;list-divider&quot;</span>&gt;</span>Top Recipes<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br /> &nbsp; &nbsp; @foreach (var recipe in @Model)<br /> &nbsp; &nbsp; {<br /> &nbsp; &nbsp; &nbsp; &nbsp; Html.RenderPartial(&quot;RecipeListItem&quot;, recipe);<br /> &nbsp; &nbsp; }<br /> <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/ul.html"><span style="color: #000000; font-weight: bold;">ul</span></a>&gt;</span></div></div><p>Note how the RenderPartial method to output the list items.</p><p>Partial views are a great way of separating the responsibly of a view and help keep ASP.NET MVC mobile web apps in a maintainable structure.</p><p>Again if you’re new to jQuery Mobile the data-role=&#8221;listview&#8221; attribute in the ul tag is used to style lists, the data-role=&#8221;button&#8221; attribute makes a standard hyperlink look like a button for which we add an icon to by using the data-icon attribute.</p><p>The recipe detail view uses partial views to display information for the recipe for which CSS is used to add the background images and style the lists.</p><p>It also contains a form so users can submit reviews.</p><p><img src="https://lh6.googleusercontent.com/-gHfVw1S-CrE/T01BTWZn58I/AAAAAAAAAJQ/w0u2NtIGGOY/s512/yummybakesreview.png" alt="YummBakes Review" /></p><p>I’ve commented out the line in the code that would actually persist the review (because I don’t want to manage spam) so any reviews you add will only be shown locally on the page.</p><p>The JavaScript below shows the AJAX call used to submit a new review.</p><p>Pay attention to the line which refreshes the list view called in the complete event.  Without this the list of reviews would not get updated.  See the post &#8216;<a href="http://operationmobile.com/dont-forget-to-call-refresh-when-adding-items-to-your-jquery-mobile-list/" title="Don’t forget to call refresh when adding items to your jQuery Mobile list" target="_blank">Don’t forget to call refresh when adding items to your jQuery Mobile list</a>&#8216;.</p><div class="codecolorer-container javascript railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.review-form&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">validate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; submitHandler<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>form<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> data <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RecipeId<span style="color: #339933;">:</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#recipeId'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Author<span style="color: #339933;">:</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#name'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Title<span style="color: #339933;">:</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#title'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Rating<span style="color: #339933;">:</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.starRating span.chosen&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">length</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Body<span style="color: #339933;">:</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#review-body'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br /> <br /> &nbsp; &nbsp; &nbsp; &nbsp; $.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type<span style="color: #339933;">:</span> <span style="color: #3366CC;">'POST'</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; url<span style="color: #339933;">:</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.review-form&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'action'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; data<span style="color: #339933;">:</span> data<span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; success<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>result<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.review-collapsible'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">trigger</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'collapse'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.review-form&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">reset</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.reviews'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span>result<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; error<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>request<span style="color: #339933;">,</span> <span style="color: #000066;">status</span><span style="color: #339933;">,</span> error<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>request.<span style="color: #660066;">responseText</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span><span style="color: #000066;">status</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>error<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; complete<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.reviews'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">listview</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'refresh'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br /> <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br /> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div><p>As we’ll see in this series about creating mobile web apps there are a number of ways of how we could have structured an application like this.</p><p>This example uses multiple pages, so whenever a user clicks on a link to see the detail for a recipe, a request is made to the server which is handled by a controller action with its’ own view.</p><p>In later posts in the series we’ll see how this differs to ASP.NET MVC single page applications.</p> ]]></content:encoded> <wfw:commentRss>http://operationmobile.com/how-to-create-a-jquery-mobile-app-using-asp-net-mvc/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>ASP.NET MVC Mobile Performance Tip – Bundle and Minify</title><link>http://operationmobile.com/asp-net-mvc-mobile-performance-tip-bundle-and-minify/</link> <comments>http://operationmobile.com/asp-net-mvc-mobile-performance-tip-bundle-and-minify/#comments</comments> <pubDate>Wed, 22 Feb 2012 01:24:04 +0000</pubDate> <dc:creator>Jag</dc:creator> <category><![CDATA[ASP.NET MVC]]></category> <category><![CDATA[JavaScript]]></category> <category><![CDATA[Performance]]></category><guid isPermaLink="false">http://operationmobile.com/?p=342</guid> <description><![CDATA[A few months ago I wrote a blog post about how you could improve the performance of your ASP.NET MVC apps using a third party library to compress and combine your CSS and JavaScript resources. The latest release of ASP.NET (v4.5) comes with its&#8217; own bundling and minification tools. And the great news is they&#8217;re [...]]]></description> <content:encoded><![CDATA[<p>A few months ago I wrote a blog post about how you could <a href="http://operationmobile.com/asp-net-mvc-mobile-performance-tip-compress-and-combine/" title="ASP.NET MVC Mobile Performance Tip – Compress and Combine" target="_blank">improve the performance of your ASP.NET MVC apps using a third party library to compress and combine your CSS and JavaScript resources</a>.</p><p>The latest release of ASP.NET (v4.5) comes with its&#8217; own bundling and minification tools.</p><p>And the great news is they&#8217;re very easy to use.</p><p>For example if your layout file contained three CSS and four JavaScript resources</p><div class="codecolorer-container html4strict railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #00bbdd;">&lt;!DOCTYPE html&gt;</span><br /> <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>&gt;</span><br /> <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>&gt;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/meta.html"><span style="color: #000000; font-weight: bold;">meta</span></a> <span style="color: #000066;">charset</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;utf-8&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">title</span></a>&gt;</span>@ViewBag.Title<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">title</span></a>&gt;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/link.html"><span style="color: #000000; font-weight: bold;">link</span></a> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;@Url.Content(&quot;</span>~<span style="color: #66cc66;">/</span><span style="color: #000066;">Content</span><span style="color: #66cc66;">/</span>Site.css<span style="color: #ff0000;">&quot;)&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/link.html"><span style="color: #000000; font-weight: bold;">link</span></a> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;@Url.Content(&quot;</span>~<span style="color: #66cc66;">/</span><span style="color: #000066;">Content</span><span style="color: #66cc66;">/</span>html5reset-1.6.1.css<span style="color: #ff0000;">&quot;)&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/link.html"><span style="color: #000000; font-weight: bold;">link</span></a> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;@Url.Content(&quot;</span>~<span style="color: #66cc66;">/</span><span style="color: #000066;">Content</span><span style="color: #66cc66;">/</span>photoswipe.css<span style="color: #ff0000;">&quot;)&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;@Url.Content(&quot;</span>~<span style="color: #66cc66;">/</span>Scripts<span style="color: #66cc66;">/</span>respond.min.js<span style="color: #ff0000;">&quot;)&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;@Url.Content(&quot;</span>~<span style="color: #66cc66;">/</span>Scripts<span style="color: #66cc66;">/</span>modernizr-<span style="color: #cc66cc;">1.7</span>.min.js<span style="color: #ff0000;">&quot;)&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;@Url.Content(&quot;</span>~<span style="color: #66cc66;">/</span>Scripts<span style="color: #66cc66;">/</span>klass.min.js<span style="color: #ff0000;">&quot;)&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;@Url.Content(&quot;</span>~<span style="color: #66cc66;">/</span>Scripts<span style="color: #66cc66;">/</span><span style="color: #000066;">code</span>.photoswipe-2.1.6.min.js<span style="color: #ff0000;">&quot;)&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br /> <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>&gt;</span><br /> <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span><br /> &nbsp; &nbsp; @RenderBody()<br /> <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span><br /> <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>&gt;</span></div></div><p>You can bundle and minify CSS and Javascript resources for your ASP.NET mobile apps by using standard HTML like this</p><div class="codecolorer-container html4strict railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #00bbdd;">&lt;!DOCTYPE html&gt;</span><br /> <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>&gt;</span><br /> <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>&gt;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/meta.html"><span style="color: #000000; font-weight: bold;">meta</span></a> <span style="color: #000066;">charset</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;utf-8&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">title</span></a>&gt;</span>@ViewBag.Title<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">title</span></a>&gt;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/link.html"><span style="color: #000000; font-weight: bold;">link</span></a> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;/Content/css&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;/Scripts/js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br /> <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>&gt;</span><br /> <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span><br /> &nbsp; &nbsp; @RenderBody()<br /> <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span><br /> <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>&gt;</span></div></div><p>or like this using HTML helpers</p><div class="codecolorer-container html4strict railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #00bbdd;">&lt;!DOCTYPE html&gt;</span><br /> <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>&gt;</span><br /> <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>&gt;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/meta.html"><span style="color: #000000; font-weight: bold;">meta</span></a> <span style="color: #000066;">charset</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;utf-8&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">title</span></a>&gt;</span>@ViewBag.Title<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">title</span></a>&gt;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/link.html"><span style="color: #000000; font-weight: bold;">link</span></a> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl(&quot;</span>~<span style="color: #66cc66;">/</span><span style="color: #000066;">Content</span><span style="color: #66cc66;">/</span>css<span style="color: #ff0000;">&quot;)&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl(&quot;</span>~<span style="color: #66cc66;">/</span>Scripts<span style="color: #66cc66;">/</span>js<span style="color: #ff0000;">&quot;)&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br /> <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>&gt;</span><br /> <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span><br /> &nbsp; &nbsp; @RenderBody()<br /> <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span><br /> <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>&gt;</span></div></div><p><em>Note: Scott Gu reckons the helper will probably be called Html.Bundle in the future.</em></p><p>Using HTML helpers gives you the advantage of adding a unqiue hash based upon the contents of the directory structure on the server for the script resource e.g.</p><p><img src="https://lh5.googleusercontent.com/-IvaRiCL4NVg/T0QdShs2rkI/AAAAAAAAAI0/6DuTWa0LEAk/s458/Bundling-and-Minification-Hash-Files.png" alt="Bundling and Minification Hash Files" /></p><p>ASP.NET will then cache the output for a year which means it will be served from the cache.</p><p>Should any files in a resource directory change the generated hash will also change and user will get an updated version of the file.</p><h3>So how does ASP.NET MVC 4.5 bundling and minification perform?</h3><p>This is Chrome resource graph for loading the page without any bundling or minification</p><p><img src="https://lh6.googleusercontent.com/-Fr4QzpxtPMk/Tps5b_Y_0vI/AAAAAAAAADU/B3lj360WAjQ/s800/chrome-resource-without-squishit.png" alt="Without bundling or minification" /></p><p>and here’s the resource graph for a ASP.NET MVC app using the new bundling or minification tools.</p><p><img src="https://lh4.googleusercontent.com/-JKBf_FBnFaw/T0QdS3_E2DI/AAAAAAAAAIw/uTUuwVecquw/s644/ASP.NET-4.5-Bundling-and-Minification-Support.png" alt="With bundling or minification" /></p><p>The images say it all!</p> ]]></content:encoded> <wfw:commentRss>http://operationmobile.com/asp-net-mvc-mobile-performance-tip-bundle-and-minify/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>How to create a jQuery Mobile Plugin</title><link>http://operationmobile.com/how-to-create-a-jquery-mobile-plugin/</link> <comments>http://operationmobile.com/how-to-create-a-jquery-mobile-plugin/#comments</comments> <pubDate>Wed, 08 Feb 2012 08:13:20 +0000</pubDate> <dc:creator>Jag</dc:creator> <category><![CDATA[jQuery Mobile]]></category><guid isPermaLink="false">http://operationmobile.com/?p=324</guid> <description><![CDATA[In this post we’ll see how to create a jQuery Mobile plugin. This plugin will enhance a users&#8217; experience of your jQuery Mobile app by adding a &#8216;Back to top&#8217; button to a page. This will save them from having to continuously scroll to get back to the top of a page. See the post [...]]]></description> <content:encoded><![CDATA[<p>In this post we’ll see how to create a jQuery Mobile plugin.</p><p>This plugin will enhance a users&#8217; experience of your jQuery Mobile app by adding a &#8216;Back to top&#8217; button to a page.</p><p>This will save them from having to continuously scroll to get back to the top of a page.</p><p><img src="https://lh3.googleusercontent.com/-DwGd1ULbDXg/Tx3mfLmtqEI/AAAAAAAAAIA/bZwPN9GBoHM/s743/backToTop_iPhone_4_screenshot.png" alt="back top to demo on the iPhone" /></p><p>See the post &#8216;<a href="http://operationmobile.com/jquery-mobile-ux-add-a-back-to-top-button/" title="jQuery Mobile UX: Add a back to top button">jQuery Mobile UX: Add a back to top button</a>&#8216; for more details abouts how it works.</p><h3>The first step in creating a jQuery Mobile plugin&#8230; use a boilerplate!</h3><p>Thanks to <a href="http://twitter.com/addyosmani" title="Addy Osmani Twitter" target="_blank">Addy Osmani</a> creating a jQuery Mobile plugin is easy becuase he&#8217;s put together boilerplates for jQuery plugins.</p><p>You can find out more by reading his Smashing Magazine article &#8216;<a href="http://coding.smashingmagazine.com/2011/10/11/essential-jquery-plugin-patterns/ " title="Essential jQuery Plugin Patterns" target="_blank">Essential jQuery Plugin Patterns</a>&#8216;.</p><p>The boilerplate code for the plugin can be found on <a href="https://github.com/addyosmani/jquery-plugin-patterns" title="boilerplate code for the plugin" target="_blank">github</a>.</p><h3>Getting started with the jQuery Mobile Plugin Boilerplate</h3><p>For a jQuery Mobile plugin we will use the &#8216;jquery.widget-factory.mobile-plugin.boilerplate.js&#8217; boilerplate.</p><p>All that&#8217;s left is to define the namespace, add the options and write the functions for the plug in.</p><h3>jQuery Mobile plugin namespaces</h3><p>As this is a mobile plugin we&#8217;ll use mobile as the first parameter and the name of the plug in as the second parameter.</p><div class="codecolorer-container javascript railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$.<span style="color: #660066;">widget</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;mobile.backToTop&quot;</span><span style="color: #339933;">,</span> $.<span style="color: #660066;">mobile</span>.<span style="color: #660066;">widget</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span></div></div><h3>jQuery Mobile plugin options</h3><p>Options allow users to configure the plugin.</p><p>For this plugin the user is able to specify:</p><p>The <strong>id</strong>. The default is &#8216;backToTop&#8217;.</p><p>The <strong>text</strong>.  The default is &#8216;Back to top&#8217;.</p><p>The <strong>theme</strong>. The default is &#8216;a&#8217;.  However the user can provide the letter if they want to use a particular theme.</p><p>The <strong>position</strong>.  The default is the top left corner.  The user can specify another location using the values &#8216;topright&#8217;,'bottomleft&#8217; and &#8216;bottomright.</p><h3>The _create function</h3><p>This function will run the first time the widget is called.</p><p>For the back to top plugin the _create function is used to add the button to the page, position it and bind events.</p><h3>Deciding if a plugin functions should be private or public?</h3><p>Any functions you want to be able to be called externally should be public and called like this</p><div class="codecolorer-container javascript railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">backToTop</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;click&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div><p>or like this passing an argument</p><div class="codecolorer-container javascript railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">backToTop</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;position&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;bottomleft&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div><p>Private functions start with _underscores.</p><h3>Using the plugin</h3><p>This plugin adds a button to the document body so it doesn&#8217;t need to listen to the create event for an indivual page.</p></ul><div class="codecolorer-container javascript railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;pageinit&quot;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; $<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">backToTop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; id<span style="color: #339933;">:</span> <span style="color: #3366CC;">'backToTopPlugin'</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; text<span style="color: #339933;">:</span> <span style="color: #3366CC;">'Back to top'</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; theme<span style="color: #339933;">:</span> <span style="color: #3366CC;">'b'</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; position<span style="color: #339933;">:</span> <span style="color: #3366CC;">'bottomright'</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&#125;</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></div><p>This means it doesn&#8217;t matter if there are multiple jQuery Mobile pages within the same document the _create function will only be called once, and work on all of the pages.</p><h3>The code for the jQuery Mobile plugin</h3><p>Rather than having to keep updating this post with the latest version of the plugin, the code is stored on <a href="https://github.com/operationmobile/jquery-mobile-backtotop-plugin" title="github">github</a>.</p> ]]></content:encoded> <wfw:commentRss>http://operationmobile.com/how-to-create-a-jquery-mobile-plugin/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Mobile Intel: Tablets and smartphones &#8211; so what&#8217;s the big deal?</title><link>http://operationmobile.com/mobile-intel-tablets-and-smartphones-so-whats-the-big-deal/</link> <comments>http://operationmobile.com/mobile-intel-tablets-and-smartphones-so-whats-the-big-deal/#comments</comments> <pubDate>Mon, 30 Jan 2012 23:14:58 +0000</pubDate> <dc:creator>Jag</dc:creator> <category><![CDATA[UX]]></category><guid isPermaLink="false">http://operationmobile.com/?p=310</guid> <description><![CDATA[Mel Findlater gave an excellent talk today for the Cambridge Usability Group about how tablets in particular can change lives. She started by giving an insight into how tablets have transformed the lives of people with disabilities by helping them communicate, interact and learn. By using a mainstream rather than a specialist device they felt [...]]]></description> <content:encoded><![CDATA[<p><a href="http://twitter.com/melfindlater" title="Mel Findlater" target="_blank">Mel Findlater</a> gave an excellent talk today for the <a href="http://www.ukupa.org.uk/cambridge/ " title="Cambridge Usability Group" target="_blank">Cambridge Usability Group</a> about how tablets in particular can change lives.</p><p><img src="https://lh6.googleusercontent.com/-bRTRHwMuRjg/TychyFNOxVI/AAAAAAAAAIc/Quwo9vghJzk/s600/Tablets-and-smartphones-can-change-lives-with-Mel-Findlater.png" alt="Mel Findlater" /></p><p>She started by giving an insight into how tablets have transformed the lives of people with disabilities by helping them communicate, interact and learn.</p><p>By using a mainstream rather than a specialist device they felt more confident allowing them to break down barriers and build relationships which otherwise would have been difficult to do.</p><p>Mel also talked about the role tablets played in ‘keeping dementia at bay’ and played a video of an elderly gentleman talking about how an iPad gave him opportunities to do challenging tasks and activities.</p><p>It’s very rare to attend a presentation were so many of the audience wanted to share their experiences and ideas, which goes some way to tell you how good a job Mel did.</p><p>Mel mentioned she’s trying to put together an event for developing apps for older and disabled users so if you’re interested <a href="http://melfindlater.wordpress.com/contact/" title="Contact Mel Findlater" target="_blank">let her know</a>.</p><p>There’s also a <a href="http://www.meetup.com/android/events/44307862/" title="Official RNIB Accessibility Hackathon" target="_blank">Official RNIB Accessibility Hackathon</a> taking place on Saturday 11th Febuary 2012 in London, so if you’re interested developing apps with accessibility in mind make sure you sign up!</p> ]]></content:encoded> <wfw:commentRss>http://operationmobile.com/mobile-intel-tablets-and-smartphones-so-whats-the-big-deal/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>jQuery Mobile UX: Add a back to top button</title><link>http://operationmobile.com/jquery-mobile-ux-add-a-back-to-top-button/</link> <comments>http://operationmobile.com/jquery-mobile-ux-add-a-back-to-top-button/#comments</comments> <pubDate>Tue, 24 Jan 2012 00:03:52 +0000</pubDate> <dc:creator>Jag</dc:creator> <category><![CDATA[Design]]></category> <category><![CDATA[HTML5]]></category> <category><![CDATA[jQuery Mobile]]></category> <category><![CDATA[UX]]></category><guid isPermaLink="false">http://operationmobile.com/?p=284</guid> <description><![CDATA[In this post we&#8217;ll see how you can improve the user experience (UX) of your jQuery Mobile apps by adding a back to top button. You can check out a demo of the back to top button here. Just remember to resize your browser window so you have to scroll! How does it improve the [...]]]></description> <content:encoded><![CDATA[<p>In this post we&#8217;ll see how you can improve the user experience (UX) of your jQuery Mobile apps by adding a back to top button.</p><p><img src="https://lh3.googleusercontent.com/-DwGd1ULbDXg/Tx3mfLmtqEI/AAAAAAAAAIA/bZwPN9GBoHM/s743/backToTop_iPhone_4_screenshot.png" alt="back top to demo on the iPhone" /></p><p>You can check out a demo of the back to top button <a href="http://db.tt/Qriblwdg" title="back to top demo" target="_blank">here</a>.</p><p>Just remember to resize your browser window so you have to scroll!</p><h3>How does it improve the UX of your jQuery Mobile app?</h3><p>No doubt you&#8217;ve been to a page on your mobile device where the only way to get back to the top of the page is to continuously keep swiping?</p><p>Using the <a href="http://operationmobile.com/example-of-using-the-jquery-mobile-scrollstart-and-scrollstop-events/" title="Example of using the jQuery Mobile scrollstart and scrollstop events" target="_blank">jQuery Mobile scrollstart and scrollstop events</a> we can show a back to top button whenever the user has scrolled to a position which is greater of their browsers viewport as shown in the mock up below.</p><p><img src="https://lh3.googleusercontent.com/-zYPYyyTpuPc/Tx3m_AV1BMI/AAAAAAAAAIM/N0MW22sghYc/s510/backToTopMockup.png" alt="back to top mock up" /></p><h3>How to create the back to top button</h3><p>The first step is to add a button element to the body and bind a click event to it.</p><div class="codecolorer-container javascript railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'body'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;a href=&quot;&quot; id=&quot;backToTop&quot; data-role=&quot;button&quot; data-icon=&quot;arrow-u&quot; data-theme=&quot;b&quot;&gt;Back to top&lt;/a&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#backToTop'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span>backToTop.<span style="color: #660066;">click</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div><p>The click event is handled by a function which scrolls to the top of the document body element.</p><p>While we could use the <a href="http://jquerymobile.com/demos/1.0/docs/api/methods.html" title="jQuery mobile methods" target="_blank">jQuery Mobile silentScroll</a> function to scroll to the top of the page, the animate function gives a nice smooth scroll.</p><div class="codecolorer-container javascript railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">click<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; backToTop.<span style="color: #660066;">hideBackToTopButton</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> &nbsp; &nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'html, body'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>scrollTop<span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">800</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> <span style="color: #009900;">&#125;</span></div></div><p>As we are dynamically adding an element to a jQuery Mobile page we need to call the trigger function.</p><div class="codecolorer-container javascript railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'body'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">trigger</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'create'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div><p>Next we bind the scrollstart event to a function to hide the button.</p><div class="codecolorer-container javascript railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$<span style="color: #009900;">&#40;</span>window<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">on</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'scrollstart'</span><span style="color: #339933;">,</span> backToTop.<span style="color: #660066;">scrollStart</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> <br /> scrollStart<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#backToTop'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> <span style="color: #009900;">&#125;</span></div></div><p>The scrollstop event is bound to a function that checks if the Y offset is greater than the height of browsers&#8217; viewport.</p><p>Fading the button is much smoother than just showing it.</p><div class="codecolorer-container javascript railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$<span style="color: #009900;">&#40;</span>window<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">on</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'scrollstop'</span><span style="color: #339933;">,</span> backToTop.<span style="color: #660066;">scrollStop</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> <br /> scrollStop<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> windowHeight <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>window<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">height</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>window.<span style="color: #660066;">pageYOffset</span> <span style="color: #339933;">&gt;</span> windowHeight<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#backToTop'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeIn</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'slow'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br /> <span style="color: #009900;">&#125;</span></div></div><p>The final step is to hook up the code for the back to top button to the page.</p><div class="codecolorer-container css railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="css codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$<span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'#backToTopDemoPage'</span><span style="color: #00AA00;">&#41;</span>.live<span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'pageinit'</span><span style="color: #00AA00;">,</span> function <span style="color: #00AA00;">&#40;</span>event<span style="color: #00AA00;">,</span> ui<span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">&#123;</span><br /> &nbsp; &nbsp; backToTop.init<span style="color: #00AA00;">&#40;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span><br /> <span style="color: #00AA00;">&#125;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span></div></div><p>For more about jQuery Mobile events check out the <a href="http://code.jquery.com/mobile/latest/demos/docs/api/events.html" title="jQuery Mobile event docs" target="_blank">docs</a>.</p><h3>Styling the jQuery Mobile button</h3><p>As jQuery Mobile has excellent theming support you can use a data theme HTML5 attribute to style the button.</p><p>The location of the button can be changed using CSS styles.</p><p>For example to show the button in the top left corner use the CSS</p><div class="codecolorer-container css railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="css codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0px</span><span style="color: #00AA00;">;</span><br /> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0px</span><span style="color: #00AA00;">;</span></div></div><p>to show the button in the botton right corner set the CSS as below:</p><div class="codecolorer-container css railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="css codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">bottom</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0px</span><span style="color: #00AA00;">;</span><br /> <span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0px</span><span style="color: #00AA00;">;</span></div></div><p>or a combination of both.</p><p>The complete code listing is shown below.</p><div class="codecolorer-container html4strict railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #00bbdd;">&lt;!DOCTYPE html&gt;</span><br /> <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>&gt;</span><br /> <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>&gt;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">title</span></a>&gt;</span>Back to top demo<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">title</span></a>&gt;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/meta.html"><span style="color: #000000; font-weight: bold;">meta</span></a> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;viewport&quot;</span> <span style="color: #000066;">content</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/link.html"><span style="color: #000000; font-weight: bold;">link</span></a> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://code.jquery.com/jquery-1.6.4.min.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span> &nbsp; &nbsp;<br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; var backToTop = {<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; init: function () {<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $('html, body').append('<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;backToTop&quot;</span> data-role<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;button&quot;</span> data-icon<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;arrow-u&quot;</span> data-theme<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;b&quot;</span>&gt;</span>Back to top<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a>&gt;</span>');<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $('#backToTop').click(backToTop.click);<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $(window).bind('scrollstart', backToTop.scrollStart);<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $(window).bind('scrollstop', backToTop.scrollStop);<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $('body').trigger('create');<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; click: function () {<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $('html, body').animate({scrollTop: 0}, 800);<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; scrollStart: function () {<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $('#backToTop').hide();<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; scrollStop: function () {<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var windowHeight = $(window).height();<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (window.pageYOffset &gt; windowHeight) {<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $('#backToTop').fadeIn('slow');<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br /> &nbsp; &nbsp; &nbsp; &nbsp; };<br /> <br /> &nbsp; &nbsp; &nbsp; &nbsp; $('#backToTopDemoPage').live('pageinit', function (event, ui) {<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; backToTop.init();<br /> &nbsp; &nbsp; &nbsp; &nbsp; });<br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/style.html"><span style="color: #000000; font-weight: bold;">style</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; #backToTop {<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; position: fixed;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; top: 0px;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; left: 0px;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; display: none;<br /> &nbsp; &nbsp; &nbsp; &nbsp; }<br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/style.html"><span style="color: #000000; font-weight: bold;">style</span></a>&gt;</span><br /> <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>&gt;</span><br /> <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> data-role<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;page&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;backToTopDemoPage&quot;</span> data-theme<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;d&quot;</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> data-role<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;content&quot;</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; incididunt ut labore et dolore magna aliqua.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; incididunt ut labore et dolore magna aliqua.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; incididunt ut labore et dolore magna aliqua.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; incididunt ut labore et dolore magna aliqua.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; incididunt ut labore et dolore magna aliqua.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; incididunt ut labore et dolore magna aliqua.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; incididunt ut labore et dolore magna aliqua.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; incididunt ut labore et dolore magna aliqua.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; incididunt ut labore et dolore magna aliqua.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; incididunt ut labore et dolore magna aliqua.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; incididunt ut labore et dolore magna aliqua.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; incididunt ut labore et dolore magna aliqua.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; incididunt ut labore et dolore magna aliqua.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; incididunt ut labore et dolore magna aliqua.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; incididunt ut labore et dolore magna aliqua.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; incididunt ut labore et dolore magna aliqua.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; incididunt ut labore et dolore magna aliqua.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; incididunt ut labore et dolore magna aliqua.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; incididunt ut labore et dolore magna aliqua.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; incididunt ut labore et dolore magna aliqua.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; incididunt ut labore et dolore magna aliqua.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; incididunt ut labore et dolore magna aliqua.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; incididunt ut labore et dolore magna aliqua.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; incididunt ut labore et dolore magna aliqua.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; incididunt ut labore et dolore magna aliqua.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; incididunt ut labore et dolore magna aliqua.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; incididunt ut labore et dolore magna aliqua.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; incididunt ut labore et dolore magna aliqua.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; incididunt ut labore et dolore magna aliqua.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; incididunt ut labore et dolore magna aliqua.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; incididunt ut labore et dolore magna aliqua.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; incididunt ut labore et dolore magna aliqua.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; incididunt ut labore et dolore magna aliqua.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; incididunt ut labore et dolore magna aliqua.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; incididunt ut labore et dolore magna aliqua.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; incididunt ut labore et dolore magna aliqua.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; incididunt ut labore et dolore magna aliqua.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; incididunt ut labore et dolore magna aliqua.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; incididunt ut labore et dolore magna aliqua.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; incididunt ut labore et dolore magna aliqua.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; incididunt ut labore et dolore magna aliqua.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; incididunt ut labore et dolore magna aliqua.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; incididunt ut labore et dolore magna aliqua.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; incididunt ut labore et dolore magna aliqua.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; incididunt ut labore et dolore magna aliqua.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br /> <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span><br /> <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>&gt;</span></div></div><p>In the next post we’ll be looking at how to creating a back to top jQuery Mobile plugin.</p> ]]></content:encoded> <wfw:commentRss>http://operationmobile.com/jquery-mobile-ux-add-a-back-to-top-button/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Using jQuery Mobile &#8211; Remember to use pageinit() and not $(document).ready()</title><link>http://operationmobile.com/using-jquery-mobile-remember-to-use-pageinit-and-not-document-ready/</link> <comments>http://operationmobile.com/using-jquery-mobile-remember-to-use-pageinit-and-not-document-ready/#comments</comments> <pubDate>Tue, 17 Jan 2012 00:12:54 +0000</pubDate> <dc:creator>Jag</dc:creator> <category><![CDATA[jQuery Mobile]]></category><guid isPermaLink="false">http://operationmobile.com/?p=277</guid> <description><![CDATA[A quick reminder when developing with jQuery Mobile 1.0 you should use pageinit() and not $(document).ready() to execute events when the DOM is loaded. This is specified in the jQuery Mobile docs. So instead of $&#40;document&#41;.ready&#40;function&#40;&#41; &#123; &#160; // code &#125;&#41;; you should use something like this $&#40;'div[data-role=&#34;page&#34;]'&#41;.live&#40;'pageinit', function&#40;&#41; &#123; &#160; // code &#125;&#41;;]]></description> <content:encoded><![CDATA[<p>A quick reminder when developing with jQuery Mobile 1.0 you should use pageinit() and not $(document).ready() to execute events when the DOM is loaded.</p><p>This is specified in the <a href="http://jquerymobile.com/test/docs/api/events.html" title="jQuery Mobile docs" target="_blank">jQuery Mobile docs</a>.</p><p>So instead of</p><div class="codecolorer-container javascript railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br /> &nbsp; <span style="color: #006600; font-style: italic;">// code</span><br /> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div><p>you should use something like this</p><div class="codecolorer-container javascript railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div[data-role=&quot;page&quot;]'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">live</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'pageinit'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br /> &nbsp; <span style="color: #006600; font-style: italic;">// code</span><br /> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div> ]]></content:encoded> <wfw:commentRss>http://operationmobile.com/using-jquery-mobile-remember-to-use-pageinit-and-not-document-ready/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Example of using the jQuery Mobile scrollstart and scrollstop events</title><link>http://operationmobile.com/example-of-using-the-jquery-mobile-scrollstart-and-scrollstop-events/</link> <comments>http://operationmobile.com/example-of-using-the-jquery-mobile-scrollstart-and-scrollstop-events/#comments</comments> <pubDate>Tue, 17 Jan 2012 00:02:53 +0000</pubDate> <dc:creator>Jag</dc:creator> <category><![CDATA[JavaScript]]></category> <category><![CDATA[jQuery Mobile]]></category><guid isPermaLink="false">http://operationmobile.com/?p=272</guid> <description><![CDATA[In this post we’ll see how easy it is to bind to the jQuery Mobile scrollstart and scrollstop events. The JavsScript below shows how to bind to the scrollstart and scrollstop events. $&#40;'div[data-role=&#34;page&#34;]'&#41;.live&#40;'pageinit', function &#40;event, ui&#41; &#123; &#160; &#160; var eventsElement = $&#40;'#events'&#41;; &#160; &#160; $&#40;window&#41;.bind&#40;'scrollstart', function &#40;&#41; &#123; &#160; &#160; &#160; &#160; console.log&#40;'start'&#41;; &#160; [...]]]></description> <content:encoded><![CDATA[<p>In this post we’ll see how easy it is to bind to the <a href="http://jquerymobile.com/test/docs/api/events.html" title="jQuery Mobile docs" target="_blank">jQuery Mobile scrollstart and scrollstop events</a>.</p><p>The JavsScript below shows how to bind to the scrollstart and scrollstop events.</p><div class="codecolorer-container javascript railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div[data-role=&quot;page&quot;]'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">live</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'pageinit'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>event<span style="color: #339933;">,</span> ui<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> eventsElement <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#events'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> &nbsp; &nbsp; $<span style="color: #009900;">&#40;</span>window<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'scrollstart'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'start'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.ui-body-c'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'background'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'green'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; eventsElement.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;li&gt;&lt;a href=&quot;&quot;&gt;Start&lt;/a&gt;&lt;/li&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; eventsElement.<span style="color: #660066;">listview</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'refresh'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> <br /> &nbsp; &nbsp; $<span style="color: #009900;">&#40;</span>window<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'scrollstop'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp;console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'stop'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp;$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.ui-body-c'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'background'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'red'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp;eventsElement.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;li&gt;&lt;a href=&quot;&quot;&gt;Stop&lt;/a&gt;&lt;/li&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp;eventsElement.<span style="color: #660066;">listview</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'refresh'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&#125;</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></div><p>When the user starts scrolling the background turns green and when the user stops scrolling the background turns red.</p><p>Whenever a scroll event is triggered an item is added to the list.</p><p>You see can see a demo of the scrollstart and scrollstop events in action <a href="http://dl.dropbox.com/u/24023585/jQueryMobile/scrollstartscrollstopdemo.html" title="scroll event demo" target="_blank">here</a>.</p> ]]></content:encoded> <wfw:commentRss>http://operationmobile.com/example-of-using-the-jquery-mobile-scrollstart-and-scrollstop-events/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>JavaScript best practice: Always specify a radix when using parseInt</title><link>http://operationmobile.com/javascript-best-practice-always-specify-a-radix-when-using-parseint/</link> <comments>http://operationmobile.com/javascript-best-practice-always-specify-a-radix-when-using-parseint/#comments</comments> <pubDate>Tue, 10 Jan 2012 00:56:37 +0000</pubDate> <dc:creator>Jag</dc:creator> <category><![CDATA[JavaScript]]></category> <category><![CDATA[jQuery Mobile]]></category><guid isPermaLink="false">http://operationmobile.com/?p=257</guid> <description><![CDATA[Whenever you use the parseInt function make sure you always specify the radial, even though it&#8217;s optional… otherwise you could end up with some unexpected results. For example the JavaScript code below parses two numbers without specifying a radial and adds them together $&#40;'#Calculate'&#41;.click&#40;function&#40;&#41; &#123; &#160; &#160; var firstNumber = parseInt&#40;$&#40;'#firstNumber'&#41;.val&#40;&#41;&#41;; &#160; &#160; var secondNumber [...]]]></description> <content:encoded><![CDATA[<p>Whenever you use the parseInt function make sure you always specify the radial, even though it&#8217;s optional… otherwise you could end up with some unexpected results.</p><p>For example the JavaScript code below parses two numbers without specifying a radial and adds them together</p><div class="codecolorer-container javascript railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#Calculate'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> firstNumber <span style="color: #339933;">=</span> parseInt<span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#firstNumber'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> secondNumber <span style="color: #339933;">=</span> parseInt<span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#secondNumber'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> &nbsp; &nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#total'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>firstNumber <span style="color: #339933;">+</span> secondNumber<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></div><p>When the user enters &#8217;043&#8242; as the first number and &#8217;1&#8242; and the second number</p><p><img src="https://lh5.googleusercontent.com/-QN1iNxIcjd0/TwuK6y12I-I/AAAAAAAAAHk/uXJmo27TAOA/s512/parseIntWithoutRadix.png" alt="What happens when you don't use parseInt" /></p><p>the calculated result is 36 and <strong>NOT</strong> 44.  You can test this yourself using this <a href="http://jsfiddle.net/Qgb2J/" title="parseInt without radix" target="_blank">jsFiddle</a>.</p><p>This happens because the input began with “0” and so the radix of eight (octal) was used.</p><p>The solution is to specify a radix, which in our case is ten (decimal).</p><div class="codecolorer-container javascript railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#Calculate'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> firstNumber <span style="color: #339933;">=</span> parseInt<span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#firstNumber'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #CC0000;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> secondNumber <span style="color: #339933;">=</span> parseInt<span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#secondNumber'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #CC0000;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> &nbsp; &nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#total'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>firstNumber <span style="color: #339933;">+</span> secondNumber<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></div><p>For this reason the best practice is to always specify a radix when using parseInt.</p> ]]></content:encoded> <wfw:commentRss>http://operationmobile.com/javascript-best-practice-always-specify-a-radix-when-using-parseint/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
<!-- Served from: operationmobile.com @ 2012-05-21 00:35:21 by W3 Total Cache -->
