<?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/"
xmlns:series="http://organizeseries.com/"
> <channel><title>SitePoint &#187; Mobile Web Development</title> <atom:link href="http://www.sitepoint.com/category/mobile/web-mobile/feed/" rel="self" type="application/rss+xml" /><link>http://www.sitepoint.com</link> <description>Learn CSS &#124; HTML5 &#124; JavaScript &#124; Wordpress &#124; Tutorials-Web Development &#124; Reference &#124; Books and More</description> <lastBuildDate>Mon, 13 May 2013 13:12:07 +0000</lastBuildDate> <language>en-US</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.5.1</generator> <item><title>Build a Responsive, Mobile-Friendly Website From Scratch: CSS stylesheet</title><link>http://www.sitepoint.com/build-a-responsive-mobile-friendly-website-from-scratch-css-stylesheet/</link> <comments>http://www.sitepoint.com/build-a-responsive-mobile-friendly-website-from-scratch-css-stylesheet/#comments</comments> <pubDate>Tue, 07 May 2013 07:10:27 +0000</pubDate> <dc:creator>Annarita Tranfici</dc:creator> <category><![CDATA[Mobile]]></category> <category><![CDATA[Mobile Web Development]]></category> <category><![CDATA[Mobile Web Discussion]]></category> <category><![CDATA[Mobile Web Tutorials]]></category> <guid
isPermaLink="false">http://buildmobile.com/?p=5731</guid> <description><![CDATA[In the fourth part of her series, Annarita Tranfici introduces the first CSS rules in order to have a general idea of the graphic style that the homepage will display.]]></description> <content:encoded><![CDATA[<p></p><p>In the last article of this series, I’ve shown how to start building a website from scratch with a particular focus on the HTML code and its main elements.</p><p>Now it&#8217;s time to introduce the first CSS rules in order to have a general idea of the graphic style that the homepage of our website will display, especially for the pc-desktop version.</p><p>First of all, before having a look on the rules we have to apply in order to create a particular design for our homepage, let&#8217;s see how it will appear in our browser window (my default browser is Chrome but, with the application of some specific rules, you&#8217;ll be able to obtain the same result for all modern web-browsers).</p><p>The homepage of our totally customizable website should look more or less as following:</p><p><a
href="http://buildmobile.com/files/2013/04/website-screenshot-desktop-version.png"><img
class="wp-image-5732 aligncenter" alt="website-screenshot-desktop-version" src="http://buildmobile.com/files/2013/04/website-screenshot-desktop-version-1024x910.png" width="614" height="546" /></a>As you can see, I have imagined a very big banner to allow the designer to express all his creativity and chosen colors that combine in a clear and positive way (I really love them!). Having said that, let&#8217;s dive deep into the code.<div
id='div-gpt-ad-1328644474660-10' style='width:728px; height:90px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1328644474660-10'); });</script> </div></p><p>As for the HTML section, in this case we&#8217;ll proceed step-by-step from the upper part of our layout to the bottom part. The code for the very first part (which includes the elements of banner, newsletter bar and menu) will be shown piece after piece with a very short comment, as for the other items of the page.</p><p>The first one is the banner element, with this code for styling:</p><pre class="brush: css; title: ; notranslate">
#banner
{
   width: 100%;
   margin-top: 0.2em;
}
</pre><p>These first rules simple enough to understand. To space the banner from the top of the browser window we&#8217;re applying a margin of 0.2em and to let our banner-image cover all the width of our browser&#8217;s window, we&#8217;ve set the corresponding rule with a percentage of 100.</p><p>Let&#8217;s go on with the rules for styling our newsletter-box. In this case we have to pay attention for the rules to put on the id and the ones to consider for the class since I have decided, for personal clarity, to not choose different names for elements that substantially indicate the same part. So, for the class we set a background color (which will be the color of the box and a margin-top of 0.2 em&#8211;you&#8217;ll find out why it&#8217;s better to use these kind of measurements for a responsive website in <a
title="Responsive Web Design: Using Fonts Responsively" href="http://buildmobile.com/understanding-responsive-web-design-how-to-manage-fonts/">this</a> article, which will give you a short overview on the most common units used in Web Design) to slightly space the newsletter-box from the banner above.</p><p>The id &#8220;newsletter-box&#8221;, that is the space where we&#8217;ll find the input field and the submit button, has three simple rules, to define the spacing with the box that contains the above-mentioned elements. As you can see, there&#8217;s an id (&#8220;mobile-newsletter-box&#8221;) that seems to be inappropriate to the version we&#8217;re analysing.  Actually, it&#8217;s not so: since there&#8217;ll be a change of view when passing from a pc-desktop version to a tablet version or a mobile-phone one, we have to &#8220;suggest&#8221; to our stylesheet how to perform and display the page elements.</p><p>In this case, as you&#8217;ll see in the next article when we&#8217;ll discuss about the rules to set thinking responsively, the disposition of all the elements characterizing the newsletter bar will totally change. What we have to do now is avoid having the mobile-display shown in the pc-desktop version. To achieve this result, we simply set to the rule &#8220;display&#8221; the none parameter.</p><p>A nice effect I&#8217;d like to talk about is the transition I have applied to the white box where the user inserts his e-mail to receive news. Setting to the element a transition, the resulting effect is an enlargement of the box; the other thing I&#8217;ve done is to indicate the time that this has to last. This is a CSS3 rule that creates a simple and light movement with a very pleasant output.</p><p>The last rule to discuss is the width applied when the newsletter box is clicked: setting this to 17em, the box will appear larger than usual.</p><pre class="brush: css; title: ; notranslate">
.newsletter-box
{
   background-color: #c32526;
   margin-top: 0.2em;
}
#newsletter-box
{
   margin-top: 0.5em;
   height: 1.8em;
   padding: 0.3em;
}
#mobile-newsletter-box
{
   display: none;
}
#newsletter-email
{
   width: 12em;
   -webkit-transition: all 1s;
   -moz-transition: width 1s;
   -o-transition: width 1s;
   -ms-transition: width 1s;
   transition: width 1s;
}
#newsletter-email:focus
{
   width: 17em;
}
</pre><p>Let&#8217;s go on now analyzing our navigation bar. To delete the default bullet points of our menu list, we set the parameter to none, while to center it we recourse to the well-known rule &#8220;text-align: center&#8221;. Then we change the padding and the margin rules to the size that seems to be appropriate for our purpose. To let the elements of the list appear one after another horizontally, we change the display from the default setting &#8220;block&#8221; to &#8220;inline&#8221; and also, in this case, specify the margin parameters.</p><p>Now, it&#8217;s time to have a look at the rules applied to the link elements: as font, I&#8217;ve chosen &#8220;Bebas Neue&#8221; (you can download it <a
title="Bebas Neue font" href="http://www.dafont.com/bebas-neue.font">here</a>). I&#8217;ve set a font-size of 1.3 em, removed the underlining with the rule &#8220;text-decoration: none&#8221; and set the color I preferred. This color changes when the cursor moves on the menu items and, moreover, when the user clicks on the link of the page he desires to visit, there&#8217;s a 3D effect, and you can obtain it setting the rule &#8220;position: relative&#8221; on the menu links and the parameters top and left on the active state of the same element. In this way, you&#8217;ll have a slight movement that will give you the impression of a clickable 3D button.</p><pre class="brush: css; title: ; notranslate">ul.menu-list
{
   list-style-type: none;
   padding: 0;
   margin: 1em 0em;
   text-align: center;
}
li.menu-item
{
   display: inline;
   margin: 0em 1.5em;
}
a.menu-item-link
{
   font-family: &quot;Bebas Neue&quot;,Calibri,Arial,Helvetica,sans-serif;
   font-size: 1.3em;
   text-decoration: none;
   color: #c31f05;
position: relative;
}
a.menu-item-link:hover
{
   color: #000000;
}
a.menu-item-link:active
{
   top: 0.1em;
   left: 0.1em;
}
#menu-select
{
   display: none;
}
</pre><p>Now, move on to the general part, that is on the rules applied to elements such as heading, paragraphs, images, boxes appearance and so on. Here is the code with the specifications of the rules for the layout I have thought out, planned and realized.</p><pre class="brush: css; title: ; notranslate">
body
{
   max-width: 1024px;
   margin: 0 auto;
   font-family: &quot;Cwmagic&quot;,Calibri,Arial,Helvetica,sans-serif;
   background-color: #E3E3E3;
   font-size: 1.2em;
   line-height: 1.5em;
}
img
{
   border: 0em;
}
h1,
h2,
h3
{
   text-align: center;
}
.float-left
{
   float: left;
}
.float-right
{
   float: right;
}
.clear-both
{
   clear: both;
}
.shadow
{
   -webkit-box-shadow: 0.4em 0.4em 0.2em #5C5B5B;
   -moz-box-shadow: 0.4em 0.4em 0.2em #5C5B5B;
   -o-box-shadow: 0.4em 0.4em 0.2em #5C5B5B;
   -ms-box-shadow: 0.4em 0.4em 0.2em #5C5B5B;
   box-shadow: 0.4em 0.4em 0.2em #5C5B5B;
   margin-right: 0.4em !important;
}
.long-box,
.small-box
{
   background-color: #cdcdcd;
   padding: 0em 0.3em;
   margin: 0em;
   margin-bottom: 1em;
}
.small-box
{
   width: 47%;
}
p
{
   margin-top: 0;
   margin-bottom: 0.5em;
}
</pre><p>I won&#8217;t explain the rules one by one as for the first part, especially because they are almost all the same. The only thing to which I&#8217;d like you&#8217;d pay attention is the classes float left, float right and clear both; in fact, I&#8217;ve preferred to create a class which &#8220;identifies&#8221; these rules and applies them to the elements in the HTML code rather than repeating the elements. Another element worthy of note is the CSS3 rule &#8220;<a
title="box-shadow" href="http://www.css3.info/preview/box-shadow/">shadow</a>&#8220;.</p><blockquote><p>This property allows designers to easily implement multiple drop shadows (outer or inner) on box elements, specifying values for color, size, blur and offset.</p><p>It can accept a comma-separated list of shadows, each defined by 2-4 length values (specifying in order the horizontal offset, vertical offset, optional blur distance and optional spread distance of the shadow), an optional color value and an optional ‘inset‘ keyword (to create an inner shadow, rather than the default outer shadow).</p><p>Browser support is growing of late with Mozilla (Firefox), Webkit (Safari/Chrome/Konqueror), Opera and the IE9 Platform Preview all offering a decent implementation of the specification.</p></blockquote><p>Let&#8217;s conclude this article with the rules applied to elements present in the footer, that is the footer itself and the bar containing the icons for the linking to the most important social networks&#8217; profile.</p><pre class="brush: css; title: ; notranslate">
#main-footer
{
   background-color: #c32526;
   text-align: center;
}
.social-bar a
{
   text-decoration: none;
   margin-right: 3em;
}
</pre><p>Finally, let&#8217;s see how to manage fonts in the CSS stylesheet, bearing in mind that Internet Explorer requires a different format for the fonts, that is &#8220;eot&#8221;. Here is the code.</p><pre class="brush: css; title: ; notranslate">
/*
 ***********************************
     FONT FOR INTERNET EXPLORER
 ***********************************
*/
@font-face
{
   font-family: &quot;Bebas Neue&quot;;
   src: url(../css/bebasneue.eot);
}
@font-face
{
   font-family: &quot;Palatino Linotype&quot;;
   src: url(../css/pala.eot);
}
/*
 ***********************************
       FONT FOR OTHER BROWSERS
 ***********************************
*/
@font-face
{
   font-family: &quot;Bebas Neue&quot;;
   src:
      local(&quot;Bebas Neue&quot;),
      local(&quot;Bebas Neue&quot;),
      url(&quot;../css/bebasneue.ttf&quot;);
}
@font-face
{
   font-family: &quot;Palatino Linotype&quot;;
   src:
      local(&quot;Palatino Linotype&quot;),
      local(&quot;Palatino Linotype&quot;),
      url(&quot;../css/pala.ttf&quot;);
}
</pre><h2>Conclusion</h2><p>In this article we&#8217;ve seen the basic rules to create a simple layout for a website. After concentrating on the pc-desktop version, in the next part we&#8217;ll see which are the rules to apply to make this layout responsive.</p><div
class='after-content-widget-1'><div
id="sitepointcontextualcontentmanagerwidget-5" class="widget widget_sitepointcontextualcontentmanagerwidget"><div
class="dfp-ad show-desktop"><div
id="div-gpt-ad-1340873946991-4" style="width: 728px; height: 90px;"> <script type="text/javascript">googletag.cmd.push(function() { googletag.display("div-gpt-ad-1340873946991-4"); });</script> </div></div></div></div>]]></content:encoded> <wfw:commentRss>http://www.sitepoint.com/build-a-responsive-mobile-friendly-website-from-scratch-css-stylesheet/feed/</wfw:commentRss> <slash:comments>0</slash:comments> <series:name><![CDATA[Build a Responsive, Mobile-Friendly Website From Scratch]]></series:name> </item> <item><title>Build a Responsive, Mobile-Friendly Website From Scratch: Semantic HTML</title><link>http://www.sitepoint.com/build-a-responsive-mobile-friendly-website-from-scratch-dive-into-the-code/</link> <comments>http://www.sitepoint.com/build-a-responsive-mobile-friendly-website-from-scratch-dive-into-the-code/#comments</comments> <pubDate>Tue, 16 Apr 2013 17:37:35 +0000</pubDate> <dc:creator>Annarita Tranfici</dc:creator> <category><![CDATA[Mobile]]></category> <category><![CDATA[Mobile Web Development]]></category> <category><![CDATA[Mobile Web Discussion]]></category> <category><![CDATA[Mobile Web Tutorials]]></category> <category><![CDATA[mobile]]></category> <category><![CDATA[Tutorials]]></category> <guid
isPermaLink="false">http://buildmobile.com/?p=5691</guid> <description><![CDATA[In the last article, as promised, we&#8217;ve begun doing some practical work with the planning and creation of a mockup. Now, we’ve focused on how to build a personal project wireframe thinking responsively and—consequently—how a responsive design can adapt to three target layouts: Default (PC desktop), Portrait Tablet, and Smartphone. We’ve seen how to arrange [...]]]></description> <content:encoded><![CDATA[<p></p><p>In <a
title="Build a Responsive, Mobile-Friendly Website From Scratch: Design a Mockup" href="http://buildmobile.com/build-a-responsive-mobile-friendly-website-from-scratch-design-a-mockup/" target="_blank">the last article</a>, as promised, we&#8217;ve begun doing some practical work with the planning and creation of a mockup. Now, we’ve focused on how to build a personal project wireframe thinking responsively and—consequently—how a responsive design can adapt to three target layouts: Default (PC desktop), Portrait Tablet, and Smartphone.</p><p>We’ve seen how to arrange the elements of a typical website in the three main devices’ categories by creating a template that represents the common content elements. In this third part of this series, I’ll concentrate on writing the HTML code and work on the structure of the homepage, while in the very next, I&#8217;ll be setting the first CSS styling rules to build the initial design of our project.</p><h3>First Step: HTML code</h3><p>Let&#8217;s begin building the structure of our website through the use of HTML code. To avoid confusion and miss some steps, we&#8217;ll proceed by dividing the layout into three parts, just like we did during the mockup design phase. We&#8217;ll pause from time to time on parts of the code that are inherent only to that single part. The first part we&#8217;ll face with will of course be the header, that is the part that in our mockup consists of the following elements: banner, newsletter-box, and main menu bar. Now, what we have to do as our first task is declare the type document that for HTML5 is indicated in the following way:<div
id='div-gpt-ad-1328644474660-10' style='width:728px; height:90px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1328644474660-10'); });</script> </div></p><pre class="brush: xml; title: ; notranslate">&lt;!DOCTYPE html&gt;</pre><p>Next, we must add the section that is necessary to help the web browser to interpret the content in the following body section. This section contains specific tags, CSS stylesheets, and other elements that remain hidden and are not displayed in the browser. These elements are generally called <strong>meta information</strong> (basically &#8220;information about information&#8221;) because their function is to describe what kind of information is on the page.</p><p>The first meta-tag which needs a specification is &#8220;meta charset&#8221;; it defines what character coding is used in the page. In our case, we set it to UTF-8, which is a variable width Unicode format compatible with ASCII or plain text for the basic alphanumeric characters. By using the &#8220;upper half&#8221; of the 8-bit ASCII set and extension codes, it can handle over a million unique characters.</p><p>It&#8217;s a requirement that any web page defines the formatting of the page within it&#8217;s header info so that all the browsers know exactly how to read and interpret the content. Otherwise, they&#8217;ll show the characters using their &#8220;best guess,&#8221; which isn&#8217;t always accurate. The guess could be wrong, and this will lead to showing the wrong characters to the users.</p><p>The next item we have to pay attention to is the <strong>viewport</strong> property. Setting a viewport tells the browser how content should fit on the device&#8217;s screen and informs the browser that the site is optimized for mobile. For example&#8230;</p><pre class="brush: xml; title: ; notranslate">&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;</pre><p>&#8230;tells the browser to set the viewport to the width of the device with an initial scale of 1. After this, we insert into the title tag the name we&#8217;ve chosen for our website. Finally, we have to link our HTML page to the <strong>CSS stylesheets</strong> that we&#8217;ll use to define the style of our homepage; the HTML &#8220;link&#8221; element specifies relationships between the current document and other documents. With this line of code&#8230;</p><pre class="brush: xml; title: ; notranslate">&lt;link rel=&quot;stylesheet&quot; href=&quot;css/common.css&quot; type=&quot;text/css&quot; /&gt;</pre><p>&#8230;we link the document to the common stylesheet (that is, the document which contains all the common CSS rules that will be shared by the three versions of the project), while this one&#8230;</p><pre class="brush: xml; title: ; notranslate">&lt;link rel=&quot;stylesheet&quot; href=&quot;css/responsive.css&quot; type=&quot;text/css&quot; /&gt;</pre><p>&#8230;recalls to the file where there are the specifications of the particular rules that will be applied only to that particular device indicated. Please note that since we&#8217;re using HTML5, you don&#8217;t actually need to specify <code>type="text/css"</code>.</p><p>Close the head tag and move on to the <strong>body</strong> section. At this point, we have to create two separate divs: one for the <strong>banner</strong>, and one for the <strong>newsletter box</strong>.</p><p>In the first, in addition to the id, it&#8217;s a good practice for accessibility to use a WAI-ARIA role; generally roles describe widgets and structure. Structural roles are added to markup as attributes of elements, which makes it perfect for our purposes.</p><p><strong>WAI-ARIA</strong> (<em>Web Accessibility Initiative &#8211; Accessible Rich Internet Applications</em>) is a technical specification published by the World Wide Web Consortium that specifies how to increase the accessibility of web pages. It allows web pages (or portions of pages) to declare themselves as applications rather than as static documents by adding role, property, and state information to dynamic web applications in order to make controls and content updates accessible to users with disabilities. That&#8217;s why all these kinds of specifications are so important.</p><p>Let&#8217;s continue our project by building a <strong>newsletter opt-In form</strong>. first of all, add a form with &lt;form&gt; tags. The opening tag should include the form name, a method which can be either &#8220;query&#8221; or &#8220;post,&#8221; and the destination or &#8220;action&#8221; where the form should send the input (I put a # to indicate that it is not fixed).</p><p>Now, add a text field with a label to collect the email address and assign an ID and a class for the following changes of style you might apply to your form. Finally, add a submit button to the form. The information put into the form fields will be sent to the receiving page for processing when the visitor clicks the submit button. Insert the word &#8220;Submit&#8221; for the input type, name and value fields to create a submit button, and close the form and div tags.</p><p>So, at this point, you should have the following code:</p><pre class="brush: xml; title: ; notranslate">&lt;!DOCTYPE html&gt;
&lt;html&gt;
   &lt;head&gt;
      &lt;meta charset=&quot;UTF-8&quot;/&gt;
      &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;
      &lt;title&gt;Website name&lt;/title&gt;
      &lt;link rel=&quot;stylesheet&quot; href=&quot;css/common.css&quot; type=&quot;text/css&quot; /&gt;
      &lt;link rel=&quot;stylesheet&quot; href=&quot;css/responsive.css&quot; type=&quot;text/css&quot; /&gt;
  &lt;/head&gt;
   &lt;body&gt;
      &lt;header&gt;
         &lt;div id=&quot;banner&quot; role=&quot;banner&quot;&gt;&lt;/div&gt;
         &lt;div id=&quot;newsletter-box&quot;&gt;
            &lt;form name=&quot;newsletter-form&quot; action=&quot;#&quot; method=&quot;post&quot;&gt;
               &lt;label for=&quot;newsletter-email&quot;&gt;Newsletter:&lt;/label&gt;
               &lt;input type=&quot;email&quot; id=&quot;newsletter-email&quot; class=&quot;newsletter-email&quot; name=&quot;email&quot; required=&quot;required&quot; placeholder=&quot;Your email&quot; /&gt;
               &lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Submit&quot; /&gt;
            &lt;/form&gt;
         &lt;/div&gt;
      &lt;/header&gt;</pre><p>Let&#8217;s proceed with the central part of our layout, namely the one used for different types of content.</p><p>First and foremost, let&#8217;s create a classic <strong>menu</strong>, composed of five options that will be the main categories of the whole website: Homepage, News, Graphics, Mobile, and Web Design. In this case, the element most suitable for our purpose is the <strong>nav</strong> element, which is a semantic element used for declaring a navigational section of a website (that is, a section of a page that links to other pages or to parts within the page).</p><p>Within the nav tag, let&#8217;s add an unordered list (to which we&#8217;ll assign a class called &#8220;menu-item&#8221;). For the content section, let&#8217;s create a main div whose ID is &#8220;content&#8221;, a wrapper div, and put an article within it. The <strong>article</strong> element is a specialized kind of section; it has a more specific semantic meaning as an independent, self-contained part of the page. In our sample, it&#8217;ll be used to contain the description of the purpose of our website.</p><p>As for the wrapper div, it will contain three more elements: a div which contains all the information about the author (and a photo,if you want), an aside in which the author can add his screencasts, and another aside intended for his latest tweets. Two points on the <strong>aside</strong> element: it is used for tangentially-related content. However, in the interpretation of this new element there lies some confusion as to how it should be used; remember that just because some content appears to the left or right of the main content isn’t enough reason to use the aside element. The better way to decide whether you should use an aside or not involves asking yourself if the content within the aside can be removed without reducing the meaning of the main content or if the main content is truly dependent on the aside. Pullquotes, glossaries, or even related links are some examples of tangentially related content that are appropriate for an aside.</p><p>The code for this second part is the following:</p><pre class="brush: xml; title: ; notranslate">
      &lt;nav class=&quot;menu&quot;&gt;
         &lt;ul class=&quot;menu-list&quot;&gt;
            &lt;li class=&quot;menu-item&quot;&gt;
               &lt;a class=&quot;menu-item-link&quot; href=&quot;./homepage&quot; title=&quot;Homepage&quot;&gt;Homepage&lt;/a&gt;
            &lt;/li&gt;
            &lt;li class=&quot;menu-item&quot;&gt;
               &lt;a class=&quot;menu-item-link&quot; href=&quot;./news&quot; title=&quot;News&quot;&gt;News&lt;/a&gt;
            &lt;/li&gt;
            &lt;li class=&quot;menu-item&quot;&gt;
               &lt;a class=&quot;menu-item-link&quot; href=&quot;./graphics&quot; title=&quot;Graphics&quot;&gt;Graphics&lt;/a&gt;
            &lt;/li&gt;
            &lt;li class=&quot;menu-item&quot;&gt;
               &lt;a class=&quot;menu-item-link&quot; href=&quot;./mobile&quot; title=&quot;Mobile&quot;&gt;Mobile&lt;/a&gt;
            &lt;/li&gt;
            &lt;li class=&quot;menu-item&quot;&gt;
               &lt;a class=&quot;menu-item-link&quot; href=&quot;./webdesign&quot; title=&quot;Web Design&quot;&gt;Web Design&lt;/a&gt;
            &lt;/li&gt;
         &lt;/ul&gt;
      &lt;/nav&gt;
      &lt;div id=&quot;content&quot;&gt;
         &lt;article id=&quot;description-box&quot;&gt;
            &lt;h3&gt;Title&lt;/h3&gt;
            &lt;p&gt;
               Your content here
            &lt;/p&gt;
         &lt;/article&gt;
         &lt;div id=&quot;wrapper&quot;&gt;
            &lt;div id=&quot;author-info-box&quot;&gt;
               &lt;p&gt;
                  Information about the author &lt;br /&gt;
               &lt;/p&gt;
            &lt;/div&gt;
	    &lt;aside id=&quot;video-box&quot;&gt;
               &lt;video&gt;
 &lt;source src=&quot;movie.mp4&quot; type='video/mp4;' /&gt;
 &lt;source src=&quot;movie.webm&quot; type='video/webm;' /&gt;
&lt;/video&gt;
            &lt;/aside&gt;
            &lt;aside id=&quot;twitter-box&quot;&gt;
               &lt;p&gt;
                  &lt;img class=&quot;twitter-bird&quot; src=&quot;./images/twitter-bird.png&quot; alt=&quot;Twitter Bird&quot; /&gt;
                  Follow me on Twitter! &lt;br /&gt;
                  We're in (number of follower)
               &lt;/p&gt;
            &lt;/aside&gt;
               &lt;br class=&quot;clear-both&quot; /&gt;
         &lt;/div&gt;
      &lt;/div&gt;
</pre><p>The last remaining part is the section called <strong>footer</strong>, which generally contains information about its sections, the author, links to related documents, copyright data, and so on. In some cases, you can also find links to profiles or personal pages of ubiquitous social networks such as Facebook, Twitter, Google+, and LinkedIn. So, we place the principal information in a paragraph inserted in the new HTML5 tag &lt;footer&gt; and the links directed to the social profiles mentioned above in a div whose main class is named &#8220;social-bar&#8221;.</p><p>Here is the code of this last part:</p><pre class="brush: xml; title: ; notranslate">
      &lt;footer id=&quot;main-footer&quot;&gt;
         &lt;p&gt;
            Author's name. All rights reserved. Copyright &amp;copy; 2012 - 2013.
         &lt;/p&gt;
         &lt;div class=&quot;social-bar&quot;&gt;
            &lt;a href=&quot;./facebook&quot; title=&quot;Facebook&quot;&gt;
               &lt;img src=&quot;./images/icons/facebook.png&quot; alt=&quot;Facebook icon&quot; /&gt;
            &lt;/a&gt;
            &lt;a href=&quot;./twitter&quot; title=&quot;Twitter&quot;&gt;
               &lt;img src=&quot;./images/icons/twitter.png&quot; alt=&quot;Twitter icon&quot; /&gt;
            &lt;/a&gt;
            &lt;a href=&quot;./googleplus&quot; title=&quot;Google+&quot;&gt;
               &lt;img src=&quot;./images/icons/google.png&quot; alt=&quot;Google+ icon&quot; /&gt;
            &lt;/a&gt;
            &lt;a href=&quot;./linkedin&quot; title=&quot;LinkedIn&quot;&gt;
               &lt;img src=&quot;./images/icons/linkedin.png&quot; alt=&quot;Linkedin icon&quot; /&gt;
            &lt;/a&gt;
         &lt;/div&gt;
      &lt;/footer&gt;
   &lt;/body&gt;
&lt;/html&gt;
</pre><h3>Conclusion</h3><p>In this article, we&#8217;ve seen how to start building a website from scratch with a particular focus on the HTML code and its main elements. In the next article, I&#8217;ll introduce the first CSS rules in order to have a general idea of the graphic style that the homepage of our website will display. Once we pass this step, we&#8217;ll concentrate on the aspects and the procedures to be followed to convert our static homepage into a responsive homepage that will be viewed correctly on numerous different devices.</p><div
class='after-content-widget-1'><div
id="sitepointcontextualcontentmanagerwidget-5" class="widget widget_sitepointcontextualcontentmanagerwidget"><div
class="dfp-ad show-desktop"><div
id="div-gpt-ad-1340873946991-4" style="width: 728px; height: 90px;"> <script type="text/javascript">googletag.cmd.push(function() { googletag.display("div-gpt-ad-1340873946991-4"); });</script> </div></div></div></div>]]></content:encoded> <wfw:commentRss>http://www.sitepoint.com/build-a-responsive-mobile-friendly-website-from-scratch-dive-into-the-code/feed/</wfw:commentRss> <slash:comments>4</slash:comments> <series:name><![CDATA[Build a Responsive, Mobile-Friendly Website From Scratch]]></series:name> </item> <item><title>Build a Responsive, Mobile-Friendly Website From Scratch: Design a Mockup</title><link>http://www.sitepoint.com/build-a-responsive-mobile-friendly-website-from-scratch-design-a-mockup/</link> <comments>http://www.sitepoint.com/build-a-responsive-mobile-friendly-website-from-scratch-design-a-mockup/#comments</comments> <pubDate>Tue, 09 Apr 2013 19:52:22 +0000</pubDate> <dc:creator>Annarita Tranfici</dc:creator> <category><![CDATA[Mobile]]></category> <category><![CDATA[Mobile Web Development]]></category> <category><![CDATA[Mobile Web Tutorials]]></category> <guid
isPermaLink="false">http://buildmobile.com/?p=5668</guid> <description><![CDATA[In the first article of this brand new series, I have introduced the main objectives of the series and given a short but complete introduction on the critical components of media queries and responsive breakpoints. Now, it&#8217;s time to begin doing some practical work. As I have mentioned before, I’ll start with the planning and [...]]]></description> <content:encoded><![CDATA[<p></p><p>In the <a
title="Build a Responsive, Mobile-Friendly Website From Scratch: Introduction" href="http://buildmobile.com/building-a-responsive-website-introduction/">first article</a> of this brand new series, I have introduced the main objectives of the series and given a short but complete introduction on the critical components of media queries and responsive breakpoints. Now, it&#8217;s time to begin doing some practical work. As I have mentioned before, I’ll start with the planning and creation of a mockup for each of the three main device types on which our responsive website will be designed, tested, and displayed: PC desktops, tablets, and mobile phones.</p><h3>3&#8230;2&#8230;1&#8230; Let&#8217;s Start!</h3><p>Before continuing, I want to give you a little advice: remember that the more mockups you do, the more arduous and confusing your job will become. Responsive mockups are not the same as static mockups; you don’t really know where your content will be placed, because it depends on the screen size.</p><p>Obviously, as we&#8217;ve seen in the previous series, designing mockups for every screen size is nearly impossible, because there are potentially hundreds of screens, layouts, and orientations that you have to accommodate. This is why I suggest that you select your target screens/layouts and build the project mockups only for your top three main devices&#8217; categories.<div
id='div-gpt-ad-1328644474660-10' style='width:728px; height:90px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1328644474660-10'); });</script> </div></p><p>For obvious reasons, I won&#8217;t show you how to design and build the entire website, but I&#8217;ll focus on the homepage, although I&#8217;m sure that once you have understood the logic and basis of responsive web design, you&#8217;ll be able to proceed with building the entire portal and everything will fall into place. I should reiterate that creating mockups doesn&#8217;t usually require that you lay out every single view to perfection, and that they are effective as soon as they&#8217;re enough of an abstraction of the final product (website or app) that they give you sufficient information to begin building.</p><p>I have chosen to build my project mockup using <a
title="Build a project mockup using Balsamiq" href="http://buildmobile.com/build-a-project-mockup-using-balsamiq/">Balsamiq Mockups</a>. As I have explained in detail in the linked article, Balsamiq Mockups is a tool that helps developers to create wireframes and communicate with clients and coworkers with visual representations of their design plans. Balsamiq is offline desktop software, and you can work with it using the operating system of your choice, since it runs on Mac, Windows, and Linux.</p><p>Let&#8217;s start planning the mockup of our website working on the PC desktop version.</p><p>First and foremost, let me introduce the kind of website we&#8217;re going to desogm and all of the elements that we&#8217;ll find within it. In fact, when building a web app or website, it&#8217;s a good practice to identify your content ahead of time and designate respective content areas within the website template. For our purposes, we&#8217;ll build a website with main content topics like graphics, web design and mobile development, a place where the design-addicted can read articles about their favourite fields, discuss, learn new techniques, and stay informed.</p><p>Let’s see how can we proceed using the elements of Balsamiq Mockups and focus on one target layout first. We have to work on the placement of blocks on the layouts, and as a first step, I place the browser window shape to represent the profile of any browser page and set its size using slight adjustments with the mouse.</p><p>As for the style of the main page, the first thing to determine is which elements we want to show on our brand new homepage. Generally, we might find a header, a newsletter bar, a menu-list, some sidebars (based on the extra-content you want to enter), a text box for the most important information, an image, or some links, for example.</p><p>Thanks to its simple, intuitive drag-and-drop system, we can easily add everything we want with a few clicks. For the first components of our page, we have to open the category called “Big.” Here, we’ll find the following elements elements: title/headline, the text area, and the image box. So, drag and drop each of these into your mockup.  Then, open the category &#8220;Common&#8221; to find rectangles, text areas, text input boxes, image and icons&#8217; indicators, and link pointers. Let&#8217;s place the two sidebars to the left of the author information box (where it could be nice adding a photo) under the main content box, which occupies the full window width.</p><p>At this point, our design concept should look something like this:</p><p><a
href="http://buildmobile.com/files/2013/04/pc-desktop-mockup1.png"><img
class="alignnone  wp-image-5672" alt="pc-desktop-mockup" src="http://buildmobile.com/files/2013/04/pc-desktop-mockup1.png" width="599" height="305" /></a></p><p>Once you’ve dragged and dropped the elements, you’ll see that each element has extensive editing options. When you click on the title/headline or within the text box, you’ll see a typical text editor, where you’ll be able to specify the characteristics or content. You can modify texts selecting size, text alignment, format, and color. You can also set the background color, set the border color, add a scrollbar, and play with opacity and focus.</p><p>For images, we can show or hide a border, crop the image, and hyperlink the chosen image to lead to a new URL or screen. Since this is a mockup project intended mainly to keep in mind all the page elements and their arrangement, is not necessary in my opinion to make ultra-precise stylistic changes. What is important is to have a sort of &#8220;skeleton,&#8221; or a point of departure to fix attention on what is necessary to build into the structure with the help of the HTML code and the CSS3 styling rules.</p><p>Once we&#8217;re done with this first passage, let&#8217;s continue planning our tablet version.</p><p><a
href="http://buildmobile.com/files/2013/04/tablet-mockup.png"><img
class="alignnone  wp-image-5673" alt="tablet-mockup" src="http://buildmobile.com/files/2013/04/tablet-mockup.png" width="599" height="305" /></a></p><p>As you can see in the image above, all the elements used in this second mockup are the same; the only thing that has changed is their arrangement. In the top part of the page, almost everything has the same style: the banner and the newsletter bar occupy all the window width on the PC desktop as well as the tablet version.</p><p>What <em>has</em> changed is the alignment of the menu-list items. In order to make the reading of menu items clear and easy even on a screen with a reduced size, I have planned to increase the space between all the present items. Additionally, the bottom part of the mockup introduces some slight changes: the sidebars that were placed on the left side of the author box have been moved under this and positioned next to each other in order to give them a larger width. Look below for clarity.</p><p><a
href="http://buildmobile.com/files/2013/04/smartphone-mockup.png"><img
class="alignnone  wp-image-5674" alt="smartphone-mockup" src="http://buildmobile.com/files/2013/04/smartphone-mockup-1024x521.png" width="600" height="305" /></a></p><p>As our last step in the mockup process, let&#8217;s tackle the smartphone version.  I have placed the iPhone shape (as said before, it’s the only one available to represent the profile of all modern smartphones) and duplicated it twice to allow you to view what the user would see by scrolling through the site from the top to the bottom.</p><p>As you can see, for the top part of the portal, the arrangement of the newsletter elements has changed, andthe menu-item list is also different compared to the PC desktop and tablet mockups. The input box and the submit button are presented vertically in order to make the process of writing and sending data faster and simpler. As for the menu, the best solution to adopt in this case (since the menu is composed of only five items) is to create a drop-down menu that the user can easily touch to load the page he desires to visit.</p><p>All the other components of the page are set to their max width to make the content intuitive and accessible. Even if at this stage you cannot see it, for the text view, you can think about a simple trick to make your users satisfied. Remember that, if your content is too long, they would have to scroll down the page many times to reach the end, and this could easily cause disorientation and boredom. So you could solve this &#8220;too much content&#8221; problem by placing a &#8220;Read more&#8221; link that takes the user directly to the information he demands and makes the homepage more streamlined, easier to load, and pleasant to visit, even on a narrow smartphone screen.</p><h3>Conclusion</h3><p>In this article, we&#8217;ve seen how to build a project mockup thinking responsively and—consequently—how a responsive design can adapt to three target layouts: Default (PC desktop), Portrait Tablet, and Smartphone. We&#8217;ve seen how to arrange the elements of a typical website in the three main devices&#8217; categories by creating a template that represents the common content elements. In the third part of this series, we&#8217;ll start to write the HTML code and work on the structure of the homepage and set the first CSS styling rules to build an initial design.</p><div
class='after-content-widget-1'><div
id="sitepointcontextualcontentmanagerwidget-5" class="widget widget_sitepointcontextualcontentmanagerwidget"><div
class="dfp-ad show-desktop"><div
id="div-gpt-ad-1340873946991-4" style="width: 728px; height: 90px;"> <script type="text/javascript">googletag.cmd.push(function() { googletag.display("div-gpt-ad-1340873946991-4"); });</script> </div></div></div></div>]]></content:encoded> <wfw:commentRss>http://www.sitepoint.com/build-a-responsive-mobile-friendly-website-from-scratch-design-a-mockup/feed/</wfw:commentRss> <slash:comments>4</slash:comments> <series:name><![CDATA[Build a Responsive, Mobile-Friendly Website From Scratch]]></series:name> </item> <item><title>Build a Responsive, Mobile-Friendly Website From Scratch: Introduction</title><link>http://www.sitepoint.com/building-a-responsive-website-introduction/</link> <comments>http://www.sitepoint.com/building-a-responsive-website-introduction/#comments</comments> <pubDate>Mon, 25 Mar 2013 14:51:30 +0000</pubDate> <dc:creator>Annarita Tranfici</dc:creator> <category><![CDATA[Mobile]]></category> <category><![CDATA[Mobile Web Development]]></category> <category><![CDATA[Mobile Web Tutorials]]></category> <category><![CDATA[Responsive Design]]></category> <category><![CDATA[Tutorials]]></category> <guid
isPermaLink="false">http://buildmobile.com/?p=5635</guid> <description><![CDATA[In the last series (&#8220;Understanding Responsive Web Design&#8220;), I defined the basic features of this new and important responsive approach to mobile-friendly, device-agnostic design. Now, let&#8217;s set the stage for a more concrete work. We&#8217;ve seen that there are many aspects to take into consideration throughout the responsive design process: screen size, operating platform, user [...]]]></description> <content:encoded><![CDATA[<p></p><p>In the last series (&#8220;<a
title="Understanding Responsive Web Design" href="http://buildmobile.com/series/understanding-responsive-web-design/">Understanding Responsive Web Design</a>&#8220;), I defined the basic features of this new and important responsive approach to mobile-friendly, device-agnostic design. Now, let&#8217;s set the stage for a more concrete work.</p><p>We&#8217;ve seen that there are many aspects to take into consideration throughout the responsive design process: screen size, operating platform, user behavior, and so on. We have explored the various measurement options for fonts in a website, and we&#8217;ve covered the best way to approach <a
title="Responsive Web Design: Using Fonts Responsively" href="http://buildmobile.com/understanding-responsive-web-design-how-to-manage-fonts/">typography</a> in terms of responsive web design. We&#8217;ve explored the characteristics of four different <a
title="Responsive Web Design: Fluid Layouts" href="http://buildmobile.com/responsive-web-design-fluid-layouts/">layout types</a> and their respective fields of implementation. We&#8217;ve covered some common problems that a web designer may encounter when managing responsive <a
title="Understanding Responsive Web Design: Responsive Imagery" href="http://buildmobile.com/understanding-responsive-web-design-how-to-manage-images/">images</a> (and pointed out potential solutions). Finally, we&#8217;ve explored the problem of <a
title="Understanding Responsive Web Design: Cross-browser Compatibility" href="http://buildmobile.com/understanding-responsive-web-design-cross-browser-compatibility/">cross-browser compatibility</a> and proposed different ways to achieve it.<div
id='div-gpt-ad-1328644474660-10' style='width:728px; height:90px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1328644474660-10'); });</script> </div></p><p>Now it&#8217;s time to demonstrate some <strong>real-world technical applications</strong> of the responsive web design and build a real responsive website.</p><h3>Objectives</h3><p>Let&#8217;s start with defining the objectives of this new series, and highlight what you&#8217;ll learn. Thanks to this tutorial&#8230;</p><ol><li>You&#8217;ll learn how to create a responsive design mockup, taking into account the main features of a website, the users&#8217; needs, and the way to effectively combine responsive graphics and web design. The mockup of the website won&#8217;t be unique to one platform, and it&#8217;ll provide an example of the possible structure of a portal from several standpoints—imagining the view on three different devices: smartphones, tablets, and desktop PCs.</li><li>You&#8217;ll learn how to take full advantage of modern web technologies, namely HTML5 and CSS3, applying them step-by-step to each component of your web content.</li><li>You&#8217;ll see how to implement some rules related to responsive web design, by applying what we have analyzed conceptually in prior articles.</li></ol><h3>Media Queries</h3><p>One of the foundations or responsive design is <strong>media queries</strong>, which ultimately make the site accessible and usable by the largest number of users, including those who do not use recent versions of popular browsers such as Internet Explorer, Mozilla Firefox, and Chrome.</p><p>Let&#8217;s start by getting our hands dirty with media queries; they represent one the most important tools that a web designer has to make their website responsive and mobile-friendly.</p><p>Media queries are composed of <strong>two main parts</strong>:</p><ul><li><strong>@ media screen</strong> — The first part of a media query is the type of support. You might recognize this syntax from writing your own CSS styles, especially if you used this method before when designing printing options for your website.</li><li>(<strong>min-width: 500px</strong>) — The second part is the query itself. It includes the function to be evaluated (in this case, the minimum width of the browser window) and the corresponding value to test that the rule has been applied (in this case, a value of 500px).</li></ul><p>Thinking about responsive web design, there is a tendency to focus exclusively on the width property, but there quite a few other attributes to consider when designing for a variety of screen sizes. There are many more valid properties associated with media queries. They are:</p><ol><li><strong>width / height</strong> — With these properties, you can set the width and height of the display area including any scroll bar. You can use the prefixes min and max.</li><li><strong>device-width/height</strong> — These properties set the width and the height of the rendering surface, that is, the width and height of the entire screen of the device and not simply of the display area of the document. Even in this case, you can still use the min and max prefixes.</li><li><strong>orientation</strong> — it sets a vertical or horizontal orientation. By specifying particular rules in the CSS stylesheet, you will be able to define how the various elements of a web page will be displayed on the device, in this case, depending on the orientation of the device we use. We can then specify the type of orientation; landscape and portrait that allow us to change the layout of your design according to the current orientation of the browser.</li><li><strong>aspect-ratio</strong> — This is a property that sets the ratio between the width and height of the display of a document. Even in this case, you can <em>still</em> use the min and max prefixes.</li><li><strong>device-aspect-ratio</strong> — This attribute monitors the ratio between the width and height of the device. Prefixes min and max are allowed.</li><li><strong>color</strong> — This applies certain CSS styles for all color devices. Prefixes min and max are allowed, but very few black and white devices (besides inexpensive Kindles) remain as popular browsing options</li><li><strong>color-index</strong> — This describes the number of colors in the palette supported by a device. It can have min and max prefixes.</li><li><strong>monochrome</strong> — This property indicates the number of bits per pixel of a monochrome device (grayscale).</li><li><strong>resolution —</strong> Resolution sets the resolution (i.e. the density of pixels) of the output device. The values ​​of the resolution can be expressed in DPI (dots per inch) or in DPCM (dots per centimeter).</li><li><strong>scan</strong> — a valid property for television screens that indicates the type of scan, interlaced or progressive. The values ​​can be precisely progressive or interlaced.</li><li><strong>grid</strong> — Grid indicates whether the device is a bitmap type or a &#8220;grid&#8221; equivalent.</li></ol><h3>Breakpoints</h3><p>After this short overview of the main (and often underutilized) properties of media queries, let&#8217;s proceed by pointing out what are the best responsive <strong>breakpoints</strong> and how to determine them for a given project.</p><p>Breakpoints in terms of responsive web design are browser widths that have a media query declaration to change the layout once the browser is within a declared width range. More specifically, a breakpoint is a point on a line that starts from 0, where there is a change (via CSS) within the layout of the page. Breakpoints are defined with numeric values ​​and units of measurement based on the media queries entered into your CSS stylesheets.</p><p>In general, every responsive website has a minimum of two breakpoints — one for tablets and one for mobile devices. Each breakpoint corresponds to a media query. In the media query below, I wrote CSS that only takes effect when the minimum width of the browser window (min-width) is equal to a specific value (that can be 320px, 480px, 768px, etc..).</p><p>Here is an example of one of these standard breakpoints:</p><pre class="brush: css; title: ; notranslate">@media only screen and (min-width : 320px) {
/* Styles */
}</pre><p>But, <strong>how many breakpoints does a web designer need to create?</strong> This depends on the characteristics of the website, on its layout, and on the techniques that you decided to implement in order to turn your design plans into something truly interactive and responsive In essence, we could answer the previous question in this way: <span
style="text-decoration: underline">You need a breakpoint for every device that you deliberately choose to support.</span></p><h4>Breakpoints According to the Devices</h4><p>Today, the prevailing practice tends to set breakpoints based on the size of the screen (or browser window) of the following popular device types:</p><ul><li>Smartphone (with portrait or landscape orientation)</li><li>Tablet (with portrait or landscape orientation as well)</li><li>Netbook</li><li>Desktop PC monitor with high or very high resolution</li></ul><p>Translating this scheme into pixels, you can see how for smartphone and tablet categories, the &#8220;standard&#8221; sizes adopted mainly correspond to the screen dimensions of the iPhone and iPad:</p><ul><li>320px — iPhone in portrait orientation</li><li>480px — iPhone in landscape orientation</li><li>768px — iPad in portrait orientation</li><li>1024px — iPad in landscape orientation (as well as netbooks, since these devices typically have a horizontal resolution of 1024px).</li></ul><p>Someone might argue that not all smartphones and tablets are iPhones or iPads, and they&#8217;d be unquestionably correct. But, in this case the screen size of the Apple device is used more as a reference point for a greater category of devices. Moreover, creating a breakpoint for each and every device would be totally absurd.</p><p>A good practice could be defining a set of main breakpoints possibly combined with some secondary breakpoints in order to fit the document to specific devices. You could also think about creating a custom breakpoint; this is very straightforward but requires a familiarity with media queries, so I suggest practicing initially with basic media queries and common breakpoints.</p><p>It&#8217;s extremely important to test your dynamic layouts, including the breakpoints themselves, and the CSS that executes under certain screen size conditions. If you do not have both of those aspects of your responsive design in good order, you&#8217;ll end up with glaring layout and functionality problems that make your website less responsive than if you hadn&#8217;t attempted any mobile-friendly accommodations. Test your designs thoroughly!</p><h3>Conclusion</h3><p>I have introduced the main objectives of the series, and above all, I have given a short but complete introduction on the critical components of media queries and responsive breakpoints. In the next article, I&#8217;ll start with the planning and the creation of a mockup for each of the three main device types on which our website will be designed, tested, and displayed.</p><p><em>Want to learn more about Responsive Web Design? Check out SitePoint&#8217;s new book, <a
href="http://www.sitepoint.com/books/responsive1/" target="_blank">Jump Start Responsive Web Design</a>!</em></p><div
class='after-content-widget-1'><div
id="sitepointcontextualcontentmanagerwidget-5" class="widget widget_sitepointcontextualcontentmanagerwidget"><div
class="dfp-ad show-desktop"><div
id="div-gpt-ad-1340873946991-4" style="width: 728px; height: 90px;"> <script type="text/javascript">googletag.cmd.push(function() { googletag.display("div-gpt-ad-1340873946991-4"); });</script> </div></div></div></div>]]></content:encoded> <wfw:commentRss>http://www.sitepoint.com/building-a-responsive-website-introduction/feed/</wfw:commentRss> <slash:comments>7</slash:comments> <series:name><![CDATA[Build a Responsive, Mobile-Friendly Website From Scratch]]></series:name> </item> <item><title>Understanding Responsive Web Design: Cross-browser Compatibility</title><link>http://www.sitepoint.com/understanding-responsive-web-design-cross-browser-compatibility/</link> <comments>http://www.sitepoint.com/understanding-responsive-web-design-cross-browser-compatibility/#comments</comments> <pubDate>Wed, 13 Mar 2013 13:06:22 +0000</pubDate> <dc:creator>Annarita Tranfici</dc:creator> <category><![CDATA[Mobile]]></category> <category><![CDATA[Mobile Web Development]]></category> <guid
isPermaLink="false">http://buildmobile.com/?p=5594</guid> <description><![CDATA[In the last article, I described three ways to work with with images from a responsive design standpoint, discussing the best solution to adopt while serving properly-sized imagery to a variety of screen sizes. In today&#8217;s article, I&#8217;ll focus on imagery management from another point of view, that is cross-browser compatibility. During the creation of [...]]]></description> <content:encoded><![CDATA[<p></p><p>In the <a
title="Understanding Responsive Web Design: Responsive Imagery" href="http://buildmobile.com/understanding-responsive-web-design-how-to-manage-images/">last article</a>, I described three ways to work with with images from a responsive design standpoint, discussing the best solution to adopt while serving properly-sized imagery to a variety of screen sizes. In today&#8217;s article, I&#8217;ll focus on imagery management from another point of view, that is <strong>cross-browser compatibility</strong>.</p><p>During the creation of a website — especially if your aim to make its structure responsive — one of the most important and frequent problems that a web designer has to face involves cross-browser compatibility, that is, compatibility across different browsers.</p><p>What does &#8220;compatibility&#8221; stands for? The designer of a website must ensure that their design works properly and that its appearance is error-free and functional on any platform used to view it. It &#8216;s definitely one of the most complicated and frustrating aspects you must consider when designing a new project, but it&#8217;s essential that the you do not leave anything to chance and keep cross-browser compatibility in mind throughout the design process.</p><p>Many of the new CSS capabilities introduced in the new CSS3 version are still not widely supported by all major browsers. In fact, some are not recognized and therefore ignored completely, which can pose major problems if your design relied on unsupported CSS. It&#8217;s not just a variety of browser types either; different <em>versions</em> of the same browser can support (or fail to support) various design techniques, which complicates cross-browser compatibility even further.<div
id='div-gpt-ad-1328644474660-10' style='width:728px; height:90px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1328644474660-10'); });</script> </div></p><p>Let&#8217;s get back to image management, which probably is the weak point of the RWD approach, especially for browser compatibility issues. Photos and media need to be flexible and adapt to different devices, and at the same time, it&#8217;s crucial that they don&#8217;t slow down page loading in the process. Therefore, there is still no definitive, ideal solution to problems such as different screen sizes, restricted bandwidth (in cases of mobile browsing), performance on high-resolution (&#8220;retina&#8221;) displays, and so on.</p><p>It is clear that using a single image (the largest possible version) for all devices is not an advisable solution. Think about the time a poor smartphone-2G user would take to load your design. After your ultra-slow image loads, those high-resolution images will probably display at about one quarter of their original size.</p><p>The largest problem is that media queries do not work with older browsers. Consequently, a responsive web page with many CSS3 rules applied can be seen correctly only by those who have recently-updated browsers with strong CSS3 support. Fortunately, there are three JavaScript solutions that can help us serve responsive websites to older browsers lacking CSS3 support: <strong>Respond.js</strong>, <strong>Modernizr</strong>, and <strong>adaptive.960.js</strong>. Let&#8217;s have a look together.</p><h3>Respond.js</h3><p>The first solution is also the simplest one — I&#8217;m talking about a script called respond.js, which enables the older browser versions to understand and execute CSS3 media queries. Here&#8217;s all it takes to get started.</p><pre class="brush: jscript; title: ; notranslate">&lt;script type=&quot;text/javascript&quot; src=&quot;js/respond.min.js&quot;&gt;&lt;/script&gt;</pre><p>This script is called on the page (as shown above) and adds support to media queries, min-width, max-width, and all media types (e.g. screen) for older browsers. This script can help your CSS3 instructions work properly, even for older browsers.</p><p>Respond.js may seem like it&#8217;s too easy to be an ideal solution, but for many projects this is an great solution because the code is read from the latest CSS3 PC browser and all browser designed for smartphones. The sole purpose of the script is to make older browsers read the CSS3 instructions within media queries. Nothing more, nothing less.</p><h3>Modernizr</h3><p>The second solution is the use of a tool called Modernizr. As explained in <a
href="http://modernizr.com/docs/" target="_blank">the documentation page of its website</a>, &#8220;Modernizr is a small JavaScript library that detects the availability of native implementations for next-generation web technologies, i.e. features that stem from the HTML5 and CSS3 specifications.&#8221;</p><p>Many of these features are already implemented in at least one major browser (most of them in two or more), and what Modernizr does is—very simply—tells you whether the current browser has this feature natively implemented or not. This is an indispensable tool that gives you fine control over the experience through JavaScript-driven feature detection.</p><p>After the first phase of detecting features, Modernizr creates a JavaScript object with the results and adds classes to the HTML element for you to target with your CSS. It&#8217;s a gorgeous solution, because it makes it easy for you to write conditional JavaScript and CSS to handle each situation, whether a browser supports a feature or not.</p><p>Modernizr supports these browsers: IE6+, Firefox 3.5+, Opera 9.6+, Safari 2+, Chrome, Mobile Safari, Android WebKit browser, Opera Mobile, and Firefox Mobile.</p><p>You can <a
href="http://modernizr.com/" target="_blank">download the full version</a> of the library and implement it according to your specifications. However, if you only needs to test the compatibility of CSS3 in your browser, you can set the various options offered by the library and create your own compressed code. Paste the code into an external .js file and include it at the tag of your HTML document. The Modernizr team recommend to include the library just after importing CSS.</p><p>You should have this code:</p><pre class="brush: xml; title: ; notranslate">&lt;!DOCTYPE html&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
 &lt;head&gt;
  &lt;title&gt;Your title&lt;/title&gt;
  &lt;script type=&quot;text/javascript&quot; src=&quot;modernizr-latest.js&quot;&quot;&gt;&lt;/script&gt;
 &lt;/head&gt;
 &lt;body&gt;Your content&lt;/body&gt;
&lt;/html&gt;
</pre><p>Now you have a JavaScript library that indicates you whether the CSS3 or HTML5 functions you used are supported or not. Let the page run on the browser and look at the code with Chrome developer tools or Firebug.</p><p>You should see something like this:</p><pre class="brush: xml; title: ; notranslate">&lt;html class=&quot;js flexbox canvas canvastext webgl no-touch geolocation postmessage websqldatabase no-indexeddb hashchange history draganddrop websockets rgba hsla multiplebgs backgroundsize borderimage no-borderradius boxshadow textshadow opacity cssanimations csscolumns cssgradients cssreflections csstransforms csstransforms3d csstransitions fontface generatedcontent video audio no-localstorage no-sessionstorage webworkers applicationcache svg inlinesvg smil svgclippaths&quot;&gt;
....
&lt;/html&gt;</pre><h3>adapt.960.js</h3><p>The third solution that we consider is very different from the previous two, especially because it does not make use of CSS3 and accordingly of media queries. However, the concept is very similar to the CSS3 media queries.</p><p>If we use CSS3 in a single file, this library requires us to separate the code into several CSS files, one for each device type. The library parses the resolution of the device and calls the CSS designed for that specific screen resolution.</p><p>We can <a
href="http://adapt.960.gs/" target="_blank">download the script</a> and see immediately how it works. Activate the library on your page with the following line:</p><pre class="brush: jscript; title: ; notranslate">&lt;script type=&quot;text/javascript&quot; src=&quot;js/adapt.min.js&quot;&gt;&lt;/script&gt;</pre><p>Then, copy the following code:</p><pre class="brush: jscript; title: ; notranslate">&lt;script type=&quot;text/javascript&quot;&gt;
var ADAPT_CONFIG = {
 // Where is your CSS?
 path: 'assets/css/',
 dynamic: true,
 callback: myCallback,
 range: [
   '0px    to 760px  = mobile.css',
   '760px  to 980px  = 720.css',
   '980px  to 1280px = 960.css',
   '1280px to 1600px = 1200.css',
   '1600px to 1920px = 1560.css',
   '1940px to 2540px = 1920.css',
   '2540px           = 2520.css'
 ]
};
&lt;/script&gt;
</pre><p>We see the list of CSS files within the &#8220;range,&#8221; one for each group of resolutions. Each of these files contains CSS properties related only to a specific device, just as the code enclosed within the CSS media queries.</p><p>The common CSS—that is the CSS that should apply to all screen sizes—should be included in a different CSS file, which for convenience we can call <em>master.css</em> and retrieve it before the integration of this library, just like normal CSS file:</p><pre class="brush: css; title: ; notranslate">&lt;link href=&quot;assets/master.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; media=&quot;screen&quot; /&gt;</pre><h3>Conclusion</h3><p><strong>Which of the three solutions should we adopt?</strong> They are all valid, sensible approaches. If you choose to apply the first solution (respond.js), you&#8217;ll have to write and manage a single CSS file, unlike adapt.960.js, which requires multiple CSS files. Finally, if you choose to try Modernizr, you&#8217;ll take advantage of new CSS3 capabilities in the browsers that can support them and still have easy and reliable means of controlling the situation for the browsers that cannot.</p><p>If you believe that, within few years, older browsers will be irrelevant and that mobile browsers will supersede their desktop counterparts, I believe that it is better to work with media queries and extend support for older browsers with JavaScripts plugins that are available.</p><p>Remember that there are also web-based services to test a responsive website and simulate resizing of the browser window. Two of these are <a
title="responsive.is" href="http://responsive.is/typecast.com">responsive.is</a>, which is very easy to use, and <a
title="www.studiopress.com" href="http://www.studiopress.com/responsive/">studiopress.com</a>, which, after entering the web address, makes different views of your website appear side-by-side.</p><p>In addition to web-based solutions, there are also applications that can be installed directly on your personal computer. Among them, we find <a
title="Opera Mobile Emulator" href="http://www.opera.com/it/developer/mobile-emulator">Opera Mobile Emulator</a>, which is available for Mac, Linux, and Windows. After installing and opening the application, you&#8217;ll have a list of devices that it can emulate (with the unfortunate exception of Apple devices).</p><p>To conclude this article, I&#8217;d like to share a very useful online tool to test the compatibility of your live website: <a
title="crossbrowsertesting.com" href="http://crossbrowsertesting.com/">crossbrowsertesting.com</a>. You must choose an operating system and a web browser, and that&#8217;s all. A series of well-organized screenshots on multiple browsers will allow you to have a complete view of your site, and in this way, it will be easier to understand on which elements you should modify to make your project perfectly compatible with any platform.</p><p><em>Want to learn more about Responsive Web Design? Check out SitePoint&#8217;s new book, <a
href="http://www.sitepoint.com/books/responsive1/" target="_blank">Jump Start Responsive Web Design</a>!</em></p><div
class='after-content-widget-1'><div
id="sitepointcontextualcontentmanagerwidget-5" class="widget widget_sitepointcontextualcontentmanagerwidget"><div
class="dfp-ad show-desktop"><div
id="div-gpt-ad-1340873946991-4" style="width: 728px; height: 90px;"> <script type="text/javascript">googletag.cmd.push(function() { googletag.display("div-gpt-ad-1340873946991-4"); });</script> </div></div></div></div>]]></content:encoded> <wfw:commentRss>http://www.sitepoint.com/understanding-responsive-web-design-cross-browser-compatibility/feed/</wfw:commentRss> <slash:comments>0</slash:comments> <series:name><![CDATA[Understanding Responsive Web Design]]></series:name> </item> <item><title>Build a Contacts Management App Using HTML5, JS, CSS3, and Wakanda Studio</title><link>http://www.sitepoint.com/build-contacts-app-with-html5-css-javascript-wakanda-studio/</link> <comments>http://www.sitepoint.com/build-contacts-app-with-html5-css-javascript-wakanda-studio/#comments</comments> <pubDate>Thu, 07 Mar 2013 18:32:09 +0000</pubDate> <dc:creator>Saad Mousliki</dc:creator> <category><![CDATA[Mobile]]></category> <category><![CDATA[Mobile Web Development]]></category> <category><![CDATA[Mobile Web Discussion]]></category> <category><![CDATA[Mobile Web Tutorials]]></category> <category><![CDATA[HTML5 Tutorials & Articles]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[Mobile Tools]]></category> <category><![CDATA[Tutorials]]></category> <guid
isPermaLink="false">http://buildmobile.com/?p=5571</guid> <description><![CDATA[Many years ago, JavaScript developers were considered second-class citizens in the programming world. JavaScript was only used to perform some easy client-side tasks such as alert messages, form validation, and style manipulation. Nobody was convinced to use it for intensive programming applications due to its limitations and several serious security problems. But, in the past [...]]]></description> <content:encoded><![CDATA[<p></p><p>Many years ago, JavaScript developers were considered second-class citizens in the programming world. JavaScript was only used to perform some easy client-side tasks such as alert messages, form validation, and style manipulation. Nobody was convinced to use it for intensive programming applications due to its limitations and several serious security problems.</p><p>But, in the past few years with the arrival of HTML5, JQuery, NodeJS, WebRTC, Google API, and others, JavaScript has become a mature language for developing a robust business applications via server-side coding, NoSQL Databases, JSON format, REST for communication and many other worthy methods.</p><p>In this article, we will prove how possible (and even <em>easy</em>) it is to develop a mobile web application that retrieves the phone contacts on disconnected mode and retrieves contacts from a remote server in connected mode using HTML5, JavaScript, and CSS3. We&#8217;ll package it using PhoneGap to build to a native mobile app that will work online and offline.</p><h3>Background</h3><p>Before starting using this guide, you should have some basics on HTML5, JavaScript, and the mobile development world. In this article, I&#8217;ll also use the <a
href="http://doc.wakanda.org/Datastore/Datastore.100-588923.en.html" target="_blank">Wakanda DataStore</a> as a NoSQL database that will be remotely added by our native app to get data using REST/HTTP and JSON format, so having some basics on Wakanda could be very helpful.<div
id='div-gpt-ad-1328644474660-10' style='width:728px; height:90px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1328644474660-10'); });</script> </div></p><h3>Using The Code</h3><p><strong>Application Architecture</strong></p><p
style="text-align: center"><img
class="aligncenter  wp-image-5572" alt="application-architecture" src="http://buildmobile.com/files/2013/03/application-architecture.png" width="542" height="230" /></p><p>The PhoneGap build input for this mobile application is freely available for download. It&#8217;s a zip file developed using the Wakanda Studio smartphone part. The bundle contains numerous noteworthy files.</p><p>First and most importantly, it contains the index.html file, which is the main page of our application. This page has three views: one for the homepage that contains two buttons to choose between connected or disconnected mode, a view containing a grid that will load data from the remote Wakanda Server, and a third view that contains a richText widget, which will load the list of mobile contacts using the PhoneGap contact API.</p><p
style="text-align: center"><img
class="aligncenter  wp-image-5573" alt="phonegap-build-input" src="http://buildmobile.com/files/2013/03/phonegap-build-input-533x1024.png" width="320" height="614" /></p><p
style="text-align: left">The second file worth mentioning is the config.xml file. This XML file provides some necessary settings to the PhoneGap build service. which to package the app and prepare it for mobile devices. Below is the config.xml data.</p><pre class="brush: xml; title: ; notranslate">
&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?--&gt;
    GET CONTACTS
        An application that gets contacts from DataStore and also from phone
        Saad Mousliki
</pre><p>(You could take a look to <a
href="https://build.phonegap.com/docs/config-xml" target="_blank">the official PhoneGap documentation</a> to learn more about how to write this file.)<br
/> Two additional noteworthy files are splash.png and icon.png. These two files serve as the splash screen and the icon that will be displayed when installing the packaged app on your mobile device.</p><p>Next is the walib folder, which contains the WAF (Wakanda Application Framework) API—a set of JavaScript libraries used to manipulate UI, HTTP/REST communication, mapping, etc.</p><p>And, of course, the widely-used scripts and styles folders, which contain the JavaScript and CSS files used by the mobile app.</p><p>(Note: To learn more about how to create this application using Wakanda Studio and pre-package it to be accepted by PhoneGap, take a look to <a
href="http://doc.wakanda.org/Quick-Start/Quick-Start.100-695763.en.html" target="_blank">this guide</a> and <a
href="http://hackanda.wordpress.com/" target="_blank">this blog</a>.)</p><h3>The HTML5 Interface</h3><p>The HTML5 page is generated using the Wakanda Studio GUI Designer with the dragging and dropping of widgets and careful styling using the properties tabs. Below is an example of a Wakanda HTML5 interface in progress; lets go through the surprisingly-easy process of designing the interface for our mobile app.</p><p
style="text-align: center"><img
class="aligncenter  wp-image-5574" alt="properties-tab" src="http://buildmobile.com/files/2013/03/properties-tab.png" width="598" height="307" /></p><h4>Step 1</h4><p>After installing the Wakanda Studio version 3, open the studio by double clicking its icon. Click on the &#8220;Create New Solution&#8221; button.</p><p
style="text-align: center"><img
class="aligncenter  wp-image-5575" alt="solution-button" src="http://buildmobile.com/files/2013/03/solution-button.png" width="598" height="249" /></p><h4 style="text-align: left">Step 2</h4><p
style="text-align: left">Give a name to your solution e.g. “CreateHTML5Page.” Check the “Add a blank project to the solution” checkbox and click the &#8220;OK&#8221; button.</p><p
style="text-align: center"><img
class="aligncenter  wp-image-5576" alt="ok-button" src="http://buildmobile.com/files/2013/03/ok-button.png" width="473" height="376" /></p><h3>Step 3</h3><p>Now, click on the “WebFolder” folder and double-click on the index.html file.</p><p
style="text-align: center"><img
class="aligncenter  wp-image-5577" alt="index-file" src="http://buildmobile.com/files/2013/03/index-file.png" width="315" height="431" /></p><h3>Step 4</h3><p>Go to the right side of the studio; you will find an arrow to choose between platforms: desktop, tablet, or smartphone. Choose the smartphone page.</p><p
style="text-align: center"><img
class="aligncenter  wp-image-5578" alt="smartphone-page" src="http://buildmobile.com/files/2013/03/smartphone-page.png" width="599" height="325" /></p><h4>Step 5</h4><p>At this step, the page is empty and should be designed using the widget tab on the left and the properties tab on the right. First, we will add a navigation widget to the page by dragging and dropping the desired widget onto the page.</p><p
style="text-align: center"><img
class="aligncenter  wp-image-5579" alt="widget" src="http://buildmobile.com/files/2013/03/widget.png" width="598" height="521" /></p><h4>Step 6</h4><p>After that, we must add some views (navigation options) to the navigation views widget using the properties tab of this widget.</p><p
style="text-align: center"><img
class="aligncenter  wp-image-5580" alt="widget-tab" src="http://buildmobile.com/files/2013/03/widget-tab.png" width="501" height="461" /></p><h4>Step 7</h4><p>Now, we will add a pair of buttons to the first view.</p><p
style="text-align: center"><img
class="aligncenter  wp-image-5581" alt="first-view" src="http://buildmobile.com/files/2013/03/first-view.png" width="599" height="369" /></p><p>You could modify the button titles and other properties (width, height, color, etc.) using the properties tab on the right side.</p><h4 style="text-align: left">Step 8</h4><p
style="text-align: left">To specify an event to the button, we should click on the events button on the right side tab and choose the “onClick” event.</p><p
style="text-align: center"><img
class="aligncenter  wp-image-5582" alt="onclick" src="http://buildmobile.com/files/2013/03/onclick.png" width="599" height="369" /></p><h4>Step 9</h4><p>For example, we could add code that allows switching between views. We will use the navigation view method “goToNextView”, so when we click on this button we will go to the View number 2. Look below for clarity.</p><p
style="text-align: center"><img
class="aligncenter  wp-image-5583" alt="view2" src="http://buildmobile.com/files/2013/03/view2.png" width="587" height="331" /></p><pre class="brush: jscript; title: ; notranslate">
button1.click = function button1_click (event)
{
$$(&quot;navigationView3&quot;).goToNextView();
}
</pre><p>(Note: To learn more on how to create a mobile web app using Wakanda Studio, take a look to <a
href="http://www.youtube.com/watch?v=GZKWZbWF7g4">this video</a> for a step-by-step description of how to create and test mobile apps on an iPod.)</p><p>After creating a page, we should pre-package (prepare it to be packaged by PhoneGap build) it using the step-by-step described in <a
href="http://hackanda.wordpress.com/">this blog</a>.</p><h3>Retrieving Contacts Using the PhoneGap Contact API<strong></strong></h3><p>The following JavaScript code will be executed when the &#8220;Get contacts from phone&#8221; button is clicked.</p><pre class="brush: jscript; title: ; notranslate">
var options = new ContactFindOptions(), name, phoneNumber;
options.filter = &quot;&quot;;
options.multiple = true;
var fields = [&quot;name&quot;, &quot;phoneNumbers&quot;];
function onSuccess(contacts) {
var res = &quot;&quot;;
for(var index = 0, len = contacts.length; index &lt; len; index++) { name = contacts[index].name; name = name != null ? name.formatted : &quot;&quot;; phoneNumber = contacts[index].phoneNumbers; phoneNumber = phoneNumber != null &amp;&amp; phoneNumber.length &gt; 0 ? phoneNumber[0].value : &quot;&quot;;
res += name + &quot;   : &quot; + phoneNumber + &quot;n&quot;;
}
$$('textField2').setValue(res);
navView.goToView(3);
}
function onError() {
alert('onError!');
}
navigator.contacts.find(fields, onSuccess, onError, options);
</pre><p>For  more details about this code, take a look to <a
href="http://docs.phonegap.com/en/1.0.0/phonegap_contacts_contacts.md.html">the PhoneGap contact API</a>. <b></b></p><h3>Package the App Using PhoneGap Build</h3><p><a
href="http://www.youtube.com/watch?v=1TyMqnfrDFo">This video</a> will show you how to package the web app, starting by uploading the .zip file to getting the .ipa file. For the complete description, we&#8217;ll start by downloading the .zip file offered at the beginning of this article and unzipping it.</p><p>Take the &#8220;Client_Side&#8221; folder within the .zip file and zip it to get the desired input file for the PhoneGap build service.</p><p><img
class="aligncenter size-full wp-image-5584" alt="phonegap-build" src="http://buildmobile.com/files/2013/03/phonegap-build.png" width="488" height="261" /></p><p>You should have an account on PhoneGap build to upload and build the application, so if you don&#8217;t have an account yet, you could create one.</p><p>After creating an account, go to the apps page, upload the zip file (Client_Side.zip), and build it! Look below for clarity.<b></b></p><p
style="text-align: center"><img
class="aligncenter  wp-image-5585" alt="zip-file" src="http://buildmobile.com/files/2013/03/zip-file.png" width="598" height="355" /></p><h3>Setting Up Server-Side Elements<b></b></h3><p><b> </b>For the server-side application, you should take the &#8220;Server_Side&#8221; folder and run it on Wakanda 3 Server, using a command line or Wakanda Studio. The command line is:</p><p><b>&#8220;C:Wakanda Server.exe&#8221;  &#8221;C:Download the applicationServer_SidegetPhoneContact SolutiongetPhoneContact.waSolution&#8221;  </b><b></b></p><p>After that, you should go to the &#8220;Client_Side&#8221; folder, and within the &#8220;scripts&#8221; folder, open the index-smartphone.js and add the IP address of the machine where you have hosted your Wakanda application on the following lines:</p><pre class="brush: jscript; title: ; notranslate">
WAF.config.baseURL = &quot;http://@IP_of_the_Wakanda_Server:8081&quot;;
WAF.core.restConnect.defaultService = 'cors';
WAF.core.restConnect.baseURL = &quot;http://@IP_of_the_Wakanda_Server:8081&quot;;
WAF.onAfterInit = function onAfterInit() { // @lock
// @region namespaceDeclaration// @startlock
var documentEvent = {}; // @document
var button2 = {}; // @button
var button1 = {}; // @button
</pre><p>Now, you could access the Wakanda DataStore remotely using the WAF API. <b> </b></p><p>(Note: To build the .ipa for your iPhone, you should provide a provisioning key and the password of your Apple store account.)</p><h3>Conclusion</h3><p>This application is a simple demonstration of Wakanda Studio, as well as a much greater testament to the capabilities of HTML5, JavaScript, and CSS3 for the creation of powerful mobile apps. Using the process of development used in this example (from HTML5, JavaScript, and CSS to native app), we could deliver a cross-platform native mobile application in very little time, so by using PhoneGap, a developer with little background in Java or Objective-C can start developing native mobile apps for many mobile platforms simultaneously. Developing this application, testing it, and packaging it using PhoneGap build took be less than a day&#8217;s work.</p><div
class='after-content-widget-1'><div
id="sitepointcontextualcontentmanagerwidget-5" class="widget widget_sitepointcontextualcontentmanagerwidget"><div
class="dfp-ad show-desktop"><div
id="div-gpt-ad-1340873946991-4" style="width: 728px; height: 90px;"> <script type="text/javascript">googletag.cmd.push(function() { googletag.display("div-gpt-ad-1340873946991-4"); });</script> </div></div></div></div>]]></content:encoded> <wfw:commentRss>http://www.sitepoint.com/build-contacts-app-with-html5-css-javascript-wakanda-studio/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>Build a Currency Converter with jQuery Mobile and Cordova: Finishing The App</title><link>http://www.sitepoint.com/build-a-currency-converter-with-jquery-mobile-and-cordova-finishing-the-app/</link> <comments>http://www.sitepoint.com/build-a-currency-converter-with-jquery-mobile-and-cordova-finishing-the-app/#comments</comments> <pubDate>Tue, 05 Mar 2013 16:42:54 +0000</pubDate> <dc:creator>Aurelio De Rosa</dc:creator> <category><![CDATA[Mobile]]></category> <category><![CDATA[Mobile Web Development]]></category> <category><![CDATA[Mobile Web Tutorials]]></category> <category><![CDATA[jquery mobile]]></category> <category><![CDATA[mobile]]></category> <category><![CDATA[Tutorials]]></category> <guid
isPermaLink="false">http://buildmobile.com/?p=5561</guid> <description><![CDATA[In the previous part of this series, I showed several other functions of the functions.js file, highlighting their key points. In this sixth and final part, I&#8217;ll describe the last function left and the Cordova configuration file that we will use to set properties for our project and define several directives for the Adobe PhoneGap [...]]]></description> <content:encoded><![CDATA[<p></p><p>In <a
title="Build a Currency Converter with jQuery Mobile and Cordova: Rate Updates" href="http://buildmobile.com/build-a-currency-converter-with-jquery-mobile-and-cordova-rate-updates/" target="_blank">the previous part of this series</a>, I showed several other functions of the <code>functions.js</code> file, highlighting their key points. In this sixth and final part, I&#8217;ll describe the last function left and the Cordova configuration file that we will use to set properties for our project and define several directives for the <a
href="http://build.phonegap.com/" target="_blank">Adobe PhoneGap Build service</a>.<br
/> <span
id="more-65957"></span></p><h3>Initializing the Application</h3><p>First, within the <code>index.html</code> file, I&#8217;ll attach the function, <code>initApplication()</code>—which I&#8217;ll describe in a few moments—to the <code>deviceready</code> event, which is fired when Cordova is fully loaded.</p><pre class="brush: jscript; title: ; notranslate">
$(document).one('deviceready', initApplication);
</pre><p>Once started, the function translates the multi-language written copy described in <a
title="Build a Currency Converter with jQuery Mobile and Cordova: Translation and Conversion Logic" href="http://buildmobile.com/build-a-currency-converter-with-jquery-mobile-and-cordova-part-4/" target="_blank">Build a Currency Converter with jQuery Mobile and Cordova: Translation and Conversion Logic</a>, calling the <code>translateMainPage()</code> function if the user&#8217;s preferred spoken language is available. Then, it calls the <code>openLinksInApp()</code> function to manage external links, as described in <a
title="Build a Currency Converter with jQuery Mobile and Cordova: Rate Updates" href="http://buildmobile.com/build-a-currency-converter-with-jquery-mobile-and-cordova-rate-updates/" target="_blank">part 5</a>. These two actions are independent from the rest of the application, even if the device doesn&#8217;t satisfy the requirements.<div
id='div-gpt-ad-1328644474660-10' style='width:728px; height:90px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1328644474660-10'); });</script> </div></p><pre class="brush: jscript; title: ; notranslate">
translateMainPage();
openLinksInApp();
</pre><p>After running the two operations mentioned above, &#8220;Currency Converter&#8221; tests the device against the requirements (discussed in <a
title="Build a Currency Converter with jQuery Mobile and Cordova: Translation and Conversion Logic" href="http://buildmobile.com/build-a-currency-converter-with-jquery-mobile-and-cordova-part-4/" target="_blank">part 4</a>), and if they aren&#8217;t satisfied, it disables the &#8220;Convert&#8221; button and exits the function.</p><pre class="brush: jscript; title: ; notranslate">
if (checkRequirements() === false)
{
  $('#submit-button').button('disable');
  return;
}
</pre><p>Now that the basic operations have been executed, we can run the other and more heavy (actually, they&#8217;re not really that heavy) functions. So, to give the user a feeling that something is happening behind the scenes, one function displays the loader widget. Then, it continues updating the interface, filling the two select boxes with the stored currency values by calling <code>fillCurrenciesSelection()</code>, the function to update the rates, <code>updateExchangeRates()</code>, and the final function that updates the labels by reading the date and time of the last currency exchange rate update, <code>updateLastUpdate()</code>.</p><pre class="brush: jscript; title: ; notranslate">
$.mobile.loading('show');
fillCurrenciesSelection();
updateExchangeRates();
updateLastUpdate();
</pre><p>At this point, all the necessary processes have been called, and we need to attach handlers to some of the pages&#8217; elements and events. The first handler will update the rates as soon as the <code>online</code> event is fired. The latter, as you may guess, fires when a Cordova application detects that it&#8217;s connected to the Internet.</p><pre class="brush: jscript; title: ; notranslate">
$(document).on('online', updateExchangeRates);
</pre><p>The next handler is very important, since it&#8217;s the one the execute the money conversion and because it&#8217;s attached to the &#8220;Convert&#8221; button. After it has retrieved the values of the money and the two currencies selected from the interface, it calls the <code>convert()</code> method of the <code>Currency</code> class to made the conversion calculation. Then, it calls the <code>numberToString()</code> to localize the result based on the user preferences and injects the end result into the page. Finally, it updates the app settings with the last currencies chosen by the user.</p><pre class="brush: jscript; title: ; notranslate">
$('#submit-button').click(function(event) {
  event.preventDefault();
  // Convert the value
  var result = Currency.convert(
    $('#from-value').val(),
    $('#from-type').val(),
    $('#to-type').val()
  );
   // Localize the result
   navigator.globalization.numberToString(
    result,
    function(number)
    {
      $('#result').text(number.value);
    },
    function()
    {
      $('#result').text(result);
    }
  );
  // Update settings
  var settings = Settings.getSettings();
  if ($.isEmptyObject(settings))
    settings = new Settings();
  settings.fromCurrency = $('#from-type').val();
  settings.toCurrency = $('#to-type').val();
  settings.save();
});
</pre><p>Having finished the &#8220;Convert&#8221; button functionality, we can now move on to the &#8220;Reset&#8221; button. Its behavior is quite straightforward. If the user clicks it, we set the input field for the money to convert and the conversion result to zero. We also reset the last chosen currencies by changing the selected currency types for both the select boxes to the first currencies listed.</p><pre class="brush: jscript; title: ; notranslate">
$('#reset-button').click(function(event) {
  event.preventDefault();
  $('#from-value').val(0);
  $('#form-converter select').prop('selectedIndex', 0).selectmenu('refresh');
  $('#result').text(0);
});
</pre><p>The last handler we need to put in place is for the &#8220;Update data&#8221; button—the one at the top-right of the main screen. The attached function simply tests for an Internet connection, and if it&#8217;s found, runs the <code>updateExchangeRates()</code> function. Otherwise it notifies the user that it&#8217;s not connected to the Internet.</p><pre class="brush: jscript; title: ; notranslate">
$('#update-button').click(function(event) {
  event.preventDefault();
  if (navigator.network.connection.type === Connection.NONE)
  {
    console.log('The connection is off. Can't update exchange rates.');
    navigator.notification.alert(
      'Your device has the connections disabled. Can't update exchange rates.',
      function(){},
      'Error'
    );
  }
  else
    updateExchangeRates();
});
</pre><p>Now that all of the pieces are in their place, we can hide the loading widget from the user so that they&#8217;ll know that that all background operations are finished.</p><pre class="brush: jscript; title: ; notranslate">
$.mobile.loading('hide');
</pre><p>As a conclusion of the whole discussion, here is a screenshot of our &#8220;Currency Converter&#8221; app:</p><p><a
href="http://buildmobile.com/build-a-currency-converter-with-jquery-mobile-and-cordova-finishing-the-app/currency-converter-main-page/" rel="attachment wp-att-5563"><img
class="alignnone size-medium wp-image-5563" alt="Currency Converter main page" src="http://buildmobile.com/files/2013/03/Currency-Converter-main-page-200x300.png" width="200" height="300" /></a></p><h3>Create the Cordova Configuration</h3><p>Since we&#8217;ll use the <a
href="http://build.phonegap.com" target="_blank">Adobe PhoneGap Build</a> service to package our project, in order to set its metadata (the version, the name, the author, and so on), we&#8217;ll use a configuration file called <code>config.xml</code>. Explaining the format in detail is outside the scope of this article, but I&#8217;ll highlight the main concepts and focus on the important <code>&lt;access&gt;</code> tag. To have an in-depth look of what you can do with this file, you can read the <a
title="Using config.xml" href="https://build.phonegap.com/docs/config-xml" target="_blank">official documentation page</a>.</p><p>The cited file follows the <a
title="W3C widget specification" href="http://www.w3.org/TR/widgets/" target="_blank">W3C widget specification</a> and must reside in the root of the project files, at the same level as the <code>index.html</code> file. The root of the whole document is a <code>&lt;widget&gt;</code> tag that has several attributes, but the mains ones are <code>id</code> (the unique identifier of the app) and <code>version</code> (that specifies the version of the app). Inside the <code>&lt;widget&gt;</code> tag, you can include several elements:</p><ul><li><strong>name</strong> (required): Specify the name of the application. It doesn&#8217;t have to be unique.</li><li><strong>description</strong> (required): Specify the description of your work. This will be shown in the app&#8217;s marketplace listing.</li><li><strong>author</strong> (optional): The app&#8217;s author. Unfortunately, you can only specify one author, so you can&#8217;t have details for multiple authors.</li><li><strong>icon</strong> (optional): The icon to display on the devices that will install your app. If you do not specify it, the Cordova logo will be used.</li><li><strong>feature</strong> (optional): Specify the features you want to use. Some operating systems, before installing the app, ask the user to provide permissions for those features. In &#8220;Currency Converter&#8221;, the only required feature is access to the Internet connection.</li><li><strong>preference</strong> (optional): A set of preferences you want to apply, such as the Cordova version, to use when packaging the project.</li><li><strong>splash</strong> (optional): This tag sets the splash screen of the application—the image to show while it&#8217;s loading.</li></ul><p>The <code>&lt;access&gt;</code> tag is very important because, citing <a
href="https://build.phonegap.com/docs/config-xml" target="_blank">the documentation</a>, it <q
cite="https://build.phonegap.com/docs/config-xml">provides your app with access to resources on other domains—in particular, it allows your app to load pages from external domains that can take over your entire webview.</q> Recalling what we discussed in the section &#8220;Managing External Links&#8221; of <a
title="Build a Currency Converter with jQuery Mobile and Cordova: Rate Updates" href="http://buildmobile.com/build-a-currency-converter-with-jquery-mobile-and-cordova-rate-updates/" target="_blank">the previous part</a>, in order to open the external links in the Cordova WebView, we must add them to the app whitelist. Using the <code>&lt;access&gt;</code> tag, you have several ways to add links. In fact, you can specify each link you want to add individually. Consider the following example:</p><p><code>&lt;access origin="https://www.audero.it" /&gt;</code><br
/> <code>&lt;access origin="https://www.buildmobile.com" /&gt;</code></p><p>For each of the above approved domains, you can also include all the subdomains using the <code>subdomains</code> attribute:</p><p><code>&lt;access origin="https://www.audero.it" subdomains="true" /&gt;</code></p><p>Since our app won&#8217;t retrieve links from external and unsafe sources, we can shorten the process allowing for any external resource using the <code>*</code> special character like the following example:</p><p><code>&lt;access origin="*" /&gt;</code></p><p>Now that I&#8217;ve pointed out the key points of the format, you can understand the source of the configuration file of our project. The complete file is below.</p><pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;widget xmlns     = &quot;http://www.w3.org/ns/widgets&quot;
        xmlns:gap	= &quot;http://phonegap.com/ns/1.0&quot;
        id        = &quot;com.audero.free.utility.currencyconverter&quot;
        version   = &quot;1.0.0&quot;&gt;
   &lt;name&gt;Currency converter&lt;/name&gt;
   &lt;description&gt;Currency converter is a simple app that helps you convert from a currency to another. You can update the exchange rates anytime you want so you'll have always an up-to-date conversion.&lt;/description&gt;
   &lt;author href=&quot;http://www.audero.it&quot; email=&quot;aurelioderosa@gmail.com&quot;&gt;Aurelio De Rosa&lt;/author&gt;
   &lt;feature name=&quot;http://api.phonegap.com/1.0/network&quot;/&gt;
   &lt;preference name=&quot;phonegap-version&quot; value=&quot;2.3.0&quot; /&gt;
   &lt;preference name=&quot;target-device&quot; value=&quot;universal&quot; /&gt;
   &lt;access origin=&quot;*&quot; /&gt;
   &lt;!-- Icons --&gt;
   &lt;icon src=&quot;icon.png&quot; width=&quot;64&quot; height=&quot;64&quot; gap:role=&quot;default&quot; /&gt;
   &lt;icon src=&quot;images/icon-72x72.png&quot; width=&quot;72&quot; height=&quot;72&quot; gap:platform=&quot;android&quot; gap:density=&quot;hdpi&quot; /&gt;
   &lt;icon src=&quot;images/icon-96x96.png&quot; width=&quot;96&quot; height=&quot;96&quot; gap:platform=&quot;android&quot; gap:density=&quot;xhdpi&quot; /&gt;
   &lt;icon src=&quot;images/icon-72x72.png&quot; width=&quot;72&quot; height=&quot;72&quot; gap:platform=&quot;ios&quot; /&gt;
   &lt;!-- Splash Screens --&gt;
   &lt;gap:splash src=&quot;splash.png&quot; /&gt;
   &lt;gap:splash src=&quot;images/splash-160x220.png&quot; gap:platform=&quot;android&quot; gap:density=&quot;ldpi&quot; /&gt;
   &lt;gap:splash src=&quot;splash.png&quot; gap:platform=&quot;android&quot; gap:density=&quot;mdpi&quot; /&gt;
   &lt;gap:splash src=&quot;images/splash-450x650.png&quot; gap:platform=&quot;android&quot; gap:density=&quot;hdpi&quot; /&gt;
&lt;/widget&gt;
</pre><h3>Conclusion</h3><p>I have to compliment those of you who completed the whole series. The growing number of hybrid apps released, including the one we just built, prove that you can build amazing games and utilities using web technologies that you&#8217;ve already mastered. There are pros and cons in choosing to develop a hybrid app, but this is definitively one additional tool in your development tool belt. My last contribution is giving you the link to the <a
href="https://bitbucket.org/AurelioDeRosa/currency-converter" target="_blank" class="broken_link">Currency Converter repository</a>. Here you&#8217;ll find and download the full and ready-to-work package. For those of you that are too lazy to build the app, I have also created <a
title="Download Currency Converter installers" href="https://build.phonegap.com/apps/327164/share" target="_blank">a public page</a> where you can download the installer for every platform supported by the <a
href="http://build.phonegap.com/" target="_blank">Adobe Build PhoneGap service</a>. As a final note, <a
href="https://bitbucket.org/AurelioDeRosa/currency-converter" target="_blank" class="broken_link">Currency Converter</a> is released under the CC BY 3.0 (&#8220;Creative Commons Attribution 3.0&#8243;) license.</p><p>I hope you enjoyed the series and have more comfort and confidence with hybrid apps. Thanks for following!</p><div
class='after-content-widget-1'><div
id="sitepointcontextualcontentmanagerwidget-5" class="widget widget_sitepointcontextualcontentmanagerwidget"><div
class="dfp-ad show-desktop"><div
id="div-gpt-ad-1340873946991-4" style="width: 728px; height: 90px;"> <script type="text/javascript">googletag.cmd.push(function() { googletag.display("div-gpt-ad-1340873946991-4"); });</script> </div></div></div></div>]]></content:encoded> <wfw:commentRss>http://www.sitepoint.com/build-a-currency-converter-with-jquery-mobile-and-cordova-finishing-the-app/feed/</wfw:commentRss> <slash:comments>2</slash:comments> <series:name><![CDATA[Build a Currency Converter with jQuery Mobile and Cordova]]></series:name> </item> <item><title>Build a Currency Converter with jQuery Mobile and Cordova: Rate Updates</title><link>http://www.sitepoint.com/build-a-currency-converter-with-jquery-mobile-and-cordova-rate-updates/</link> <comments>http://www.sitepoint.com/build-a-currency-converter-with-jquery-mobile-and-cordova-rate-updates/#comments</comments> <pubDate>Fri, 01 Mar 2013 01:07:15 +0000</pubDate> <dc:creator>Aurelio De Rosa</dc:creator> <category><![CDATA[Mobile]]></category> <category><![CDATA[Mobile Web Development]]></category> <category><![CDATA[Mobile Web Tutorials]]></category> <category><![CDATA[jquery mobile]]></category> <category><![CDATA[mobile]]></category> <category><![CDATA[Tutorials]]></category> <guid
isPermaLink="false">http://buildmobile.com/?p=5510</guid> <description><![CDATA[In the previous article in this series, I described the classes and functions needed to perform currency conversions within our app. I also illustrated the Cordova Globalization API and how we can use it to translate the written instructions on the main page of &#8220;Currency Converter.&#8221; In this next installment, I&#8217;ll show you the remaining [...]]]></description> <content:encoded><![CDATA[<p></p><p>In <a
title="Build a Currency Converter with jQuery Mobile and Cordova: Translation and Conversion Logic" href="http://buildmobile.com/build-a-currency-converter-with-jquery-mobile-and-cordova-part-4/" target="_blank">the previous article in this series</a>, I described the classes and functions needed to perform currency conversions within our app. I also illustrated the <a
href="http://docs.phonegap.com/en/2.3.0/cordova_globalization_globalization.md.html#Globalization" target="_blank">Cordova Globalization API</a> and how we can use it to translate the written instructions on the main page of &#8220;Currency Converter.&#8221; In this next installment, I&#8217;ll show you the remaining functions of the <code>functions.js</code> file and a brief overview of the Cordova <a
title="Cordova Connection API" href="http://docs.phonegap.com/en/2.3.0/cordova_connection_connection.md.html#Connection" target="_blank">Connection</a> and <a
title="Cordova InAppBrowser API" href="http://docs.phonegap.com/en/2.3.0/cordova_inappbrowser_inappbrowser.md.html#InAppBrowser" target="_blank">InAppBrowser</a> APIs.<br
/> <span
id="more-5510"></span></p><h3>Utility Functions</h3><h4>Updating the &#8220;Last Update&#8221; Label</h4><p><a
title="Build a Currency Converter with jQuery Mobile and Cordova: Introduction" href="http://buildmobile.com/build-a-currency-converter-with-jquery-mobile-and-cordova/" target="_blank">In the introductory article</a> of this series, I explained that our project will store the downloaded currency rates so that the user can use the application offline. Since the currency exchange rates change every day, it&#8217;s important to notify the user of how old his exchange rates are. If he feels that they are too old, he can run an update and download the latest. For this reason, the main page has the following code:<div
id='div-gpt-ad-1328644474660-10' style='width:728px; height:90px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1328644474660-10'); });</script> </div></p><pre class="brush: xml; title: ; notranslate">
&lt;label id=&quot;last-update-label&quot;&gt;Last update of exchange rates:&lt;/label&gt;
&lt;span id=&quot;last-update&quot;&gt;&lt;/span&gt;
</pre><p>The <code>&lt;span&gt;</code> having <code>id="last-update"</code> is where we&#8217;ll inject the date of the last update. Th date will be written in the format that best suits the user preferences determined by the <a
title="Globalization API official documentation" href="http://docs.phonegap.com/en/2.3.0/cordova_globalization_globalization.md.html#Globalization" target="_blank">Globalization API</a>, which I explained in <a
title="Build a Currency Converter with jQuery Mobile and Cordova: Translation and Conversion Logic" href="http://buildmobile.com/build-a-currency-converter-with-jquery-mobile-and-cordova-part-4/" target="_blank">the previous article</a>. Recalling <a
title="Build a Currency Converter with jQuery Mobile and Cordova: JavaScript and User Settings" href="http://buildmobile.com/build-a-currency-converter-with-jquery-mobile-and-cordova-part-3/" target="_blank">the third article</a> where we talked about the user settings, you should recall that we update and save the date each time the user request an exchange rates update via the <code>Settings</code> class and its methods.</p><p>The function that updates the text of the above <code>&lt;span&gt;</code> tag is <code>updateLastUpdate(),</code> and its markup is the following:</p><pre class="brush: jscript; title: ; notranslate">
function updateLastUpdate()
{
  if (typeof Settings.getSettings().lastUpdate === 'undefined')
  {
    $('#last-update').text('-');
    return;
  }
  // Show the last time the rates have been updated
  navigator.globalization.dateToString(
    new Date(Settings.getSettings().lastUpdate),
    function (date)
    {
      $('#last-update').text(date.value);
    },
    function ()
    {
      $('#last-update').text('-');
    }
  );
}
</pre><h4>Updating the Rates</h4><p>The method that deals with the actual updating is <code>updateExchangeRates()</code>. At the very beginning of the method, there is a test to verify whether the device is connected to the Internet or not. The test is done using the Cordova Connection API—an object that gives access to the device’s cellular and wifi connection information. It has one property called <code>type</code> that checks the active network connection that is being used and can assume the following values (as constants):</p><ul><li>Connection.UNKNOWN</li><li>Connection.ETHERNET</li><li>Connection.WIFI</li><li>Connection.CELL_2G</li><li>Connection.CELL_3G</li><li>Connection.CELL_4G</li><li>Connection.NONE</li></ul><p>If the device has an active connection, the function makes a call to the European Central Bank RSS feed to retrieve the rates using the jQuery <code>ajax()</code> method. Once retrieved, the rates are stored using the <code>Currency</code> class, and the <code>lastUpdate</code> data of the user&#8217;s settings is updated as well, so the user knows that they&#8217;re working with the latest currency exchange rates.</p><p>The two select boxes and the &#8220;last update&#8221; label of the main page are updated using this current data. Then, the two select menus are filled using a function called <code>fillCurrenciesSelection()</code>, which I&#8217;ll describe in a few moments. As a final note, if the rate update fails, the user is notified with an alert of this failure shown using the Cordova Notification API.</p><p>So, what exactly will happen if the first test fails? Well, if the device does not have an active Internet connection, the app will check if there are any stored rates. If there are no stored currency exchange rates, the user is notified of the issue, and the &#8220;Convert&#8221; button is disabled, because there aren&#8217;t any ways to run any currency conversions.</p><p>The code that implements this functionality is listed below:</p><pre class="brush: jscript; title: ; notranslate">
/**
 * Update the exchange rates using the ECB web service
 */
function updateExchangeRates()
{
  if (navigator.network.connection.type !== Connection.NONE)
  {
    $.mobile.loading(
      'show',
      {
        text: 'Updating rates...',
        textVisible: true
      }
    );
    $.get(
      'http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml',
      null,
      function(data)
      {
        var $currenciesElements = $(data).find('Cube[currency]');
        // The EURO is the default currency, so it isn't in the retrieved data
        var currencies = [new Currency('EUR', '1')];
        var i;
        for(i = 0; i &lt; $currenciesElements.length; i++)
        {
          currencies.push(
            new Currency(
              $($currenciesElements[i]).attr('currency'),
              $($currenciesElements[i]).attr('rate')
            )
          );
        }
        currencies.sort(Currency.compare);
        // Store the data
        for(i = 0; i &lt; currencies.length; i++)
          currencies[i].save();
        // Update settings
        var settings = Settings.getSettings();
        if ($.isEmptyObject(settings))
          settings = new Settings();
        settings.lastUpdate = new Date();
        settings.save();
        fillCurrenciesSelection();
        updateLastUpdate();
        $('#submit-button').button('enable');
      },
      'XML'
    )
    .error(function() {
      console.log('Unable to retrieve exchange rates from the provider.');
      navigator.notification.alert(
        'Unable to retrieve exchange rates from the provider.',
        function(){},
        'Error'
      );
      if (Currency.getCurrencies().length === 0)
        $('#submit-button').button('disable');
    })
    .complete(function() {
      $.mobile.loading('hide');
    });
  }
  // Check if there are data into the local storage
  else if (Currency.getCurrencies().length === 0)
  {
    console.log('The connection is off and there aren't rates previously stored.');
    navigator.notification.alert(
      'Your device has the connection disabled and there aren't rates previously stored.n' +
      'Please turn on your connection.',
      function(){},
      'Error'
    );
    $('#submit-button').button('disable');
  }
}
</pre><h4>Filling the Select Boxes</h4><p>The function to update the select boxes isn&#8217;t very hard to grasp. It simply retrieves the stored currencies using the <code>getCurrencies()</code> method of the <code>Currency</code> class and then insert each of them using the jQuery <code>append()</code> method. It&#8217;s worth noting that after all the currencies are inserted, this function searches for the last origin and destination currencies saved within the user preferences If these last used currencies are found, they are automatically selected. In this scenario, the listview widget needs to be refreshed, which accomplished using the method <code>selectmenu()</code> and passing the string <code>refresh</code> to it.</p><p>The complete source of <code>fillCurrenciesSelection()</code> is listed below:</p><pre class="brush: jscript; title: ; notranslate">
/**
 * Use the stored currencies to update the selection lists
 */
function fillCurrenciesSelection()
{
  var currencies = Currency.getCurrencies();
  var $fromCurrencyType = $('#from-type');
  var $toCurrencyType = $('#to-type');
  // Empty elements
  $fromCurrencyType.empty();
  $toCurrencyType.empty();
  // Load all the stored currencies
  for(var i = 0; i &lt; currencies.length; i++)
  {
    $fromCurrencyType.append('
' +      currencies[i].abbreviation + '
');
    $toCurrencyType.append('
' +      currencies[i].abbreviation + '
');
  }
  // Update the selected option using the last currencies used
  var settings = Settings.getSettings();
  if (!$.isEmptyObject(settings))
  {
    var currency = $fromCurrencyType.find('[value=&quot;' + settings.fromCurrency + '&quot;]');
    if (currency !== null)
      $(currency).attr('selected', 'selected');
    currency = $toCurrencyType.find('[value=&quot;' + settings.toCurrency + '&quot;]');
    if (currency !== null)
      $(currency).attr('selected', 'selected');
  }
  $fromCurrencyType.selectmenu('refresh');
  $toCurrencyType.selectmenu('refresh');
}
</pre><h4>Managing External Links</h4><p>As you&#8217;ve seen in <a
title="Build a Currency Converter with jQuery Mobile and Cordova: Constructing The Interface" href="http://buildmobile.com/build-a-currency-converter-with-jquery-mobile-and-cordova-part-2/" target="_blank">the interface design</a> of &#8220;Currency Converter&#8221;, the <code>aurelio.html</code> file have several external links within it. Those links aren&#8217;t very useful, but I do need to explain an important concept.</p><p>Until a few versions ago, Cordova opened external links in the same Cordova WebView that was running the application. So, once it opened a link, when the user clicked the &#8220;back&#8221; button, the last project&#8217;s page was shown exactly as it was before the user left it. But, in the most recent release of the framework, this behavior was changed; now, the external links are opened by default using the Cordova WebView if the URL is in your app&#8217;s whitelist. URLs that aren&#8217;t on your whitelist are opened using the InAppBrowser API.</p><p>Citing the official documentation, <q
cite="http://docs.phonegap.com/en/2.3.0/cordova_inappbrowser_inappbrowser.md.html#InAppBrowser">the InAppBrowser is a web-browser that is shown in your app when you use the window.open call.</q> This API has three methods: <code>addEventListener()</code>, <code>removeEventListener()</code>, and <code>close()</code>. The first allows you to listen for three events (<code>loadstart</code>, <code>loadstop</code>, and <code>exit)</code> and allows you to attach a function that runs as soon as those events are fired. The second method, as you might guess, is used to remove a previously-attached listener. Finally, the <code>close()</code> method is used to close the InAppBrowser window.</p><p>If the user opens a link that is shown in the InAppBrowser or the system browser and then goes &#8220;back&#8221; to the application, all the CSS and jQuery Mobile enhancements are lost. This happens because the external link doesn&#8217;t the reference the cited files and when the user goes back into the app; the file is loaded as it were requested for the first time, but without passing through the main page. Obviously, this is something you&#8217;ll want to avoid, which highlights the importance of the the whitelist within the Cordova configuration file and the next function come in help.</p><p>The aim of the <code>openLinksInApp()</code> function is to catch the clicks on all the external links (recognized by using the <code>target="_blank"</code> attribute), preventing the unwanted default behavior and opening them using the <code>window.open()</code> method. As you&#8217;ll see in the code shown below, I&#8217;ll use the <code>_target</code> parameter so that the links will be opened using the WebView, because I&#8217;ll put these URLs in the Cordova whitelist. Using this technique, we&#8217;ll avoid the issues described above, and your app will continue to look and function as expected.</p><pre class="brush: jscript; title: ; notranslate">
/**
 * Open all the links as internals
 */
function openLinksInApp()
{
   $(&quot;a[target=&quot;_blank&quot;]&quot;).on('click', function(event) {
      event.preventDefault();
      window.open($(this).attr('href'), '_target');
   });
}
</pre><h3>Conclusion</h3><p>In this article, I described several other functions of the <code>functions.js</code> file, highlighting the key points of each. I also explained the Cordova Connection and the InAppBrowser API and how they work. As we&#8217;ve seen, dealing with external links is extremely important when you&#8217;re using jQuery Mobile to build your mobile app interface. In the next and final article in this series, I&#8217;ll show you the function that initializes the application, called <code>initApplication()</code>, and the Cordova configuration file that we will use alongside the <a
href="http://build.phonegap.com/" target="_blank">Adobe PhoneGap Build</a> service to package our &#8220;Currency Converter&#8221; app.</p><div
class='after-content-widget-1'><div
id="sitepointcontextualcontentmanagerwidget-5" class="widget widget_sitepointcontextualcontentmanagerwidget"><div
class="dfp-ad show-desktop"><div
id="div-gpt-ad-1340873946991-4" style="width: 728px; height: 90px;"> <script type="text/javascript">googletag.cmd.push(function() { googletag.display("div-gpt-ad-1340873946991-4"); });</script> </div></div></div></div>]]></content:encoded> <wfw:commentRss>http://www.sitepoint.com/build-a-currency-converter-with-jquery-mobile-and-cordova-rate-updates/feed/</wfw:commentRss> <slash:comments>0</slash:comments> <series:name><![CDATA[Build a Currency Converter with jQuery Mobile and Cordova]]></series:name> </item> <item><title>Build a Currency Converter with jQuery Mobile and Cordova: Translation and Conversion Logic</title><link>http://www.sitepoint.com/build-a-currency-converter-with-jquery-mobile-and-cordova-part-4/</link> <comments>http://www.sitepoint.com/build-a-currency-converter-with-jquery-mobile-and-cordova-part-4/#comments</comments> <pubDate>Mon, 18 Feb 2013 17:28:15 +0000</pubDate> <dc:creator>Aurelio De Rosa</dc:creator> <category><![CDATA[Mobile]]></category> <category><![CDATA[Mobile Web Development]]></category> <category><![CDATA[Mobile Web Tutorials]]></category> <category><![CDATA[jquery mobile]]></category> <category><![CDATA[mobile]]></category> <category><![CDATA[Tutorials]]></category> <guid
isPermaLink="false">http://buildmobile.com/?p=5502</guid> <description><![CDATA[In the previous article of this series, I described the jQuery Mobile custom configuration for our app and highlighted the importance of allowing cross-domain requests to download up-to-the-moment currency exchange rates. I also described a class that will help us translate the app into multiple spoken languages, and I outlined a second class to manage [...]]]></description> <content:encoded><![CDATA[<p></p><p>In <a
title="Build a Currency Converter with jQuery Mobile and Cordova: JavaScript and User Settings" href="http://buildmobile.com/build-a-currency-converter-with-jquery-mobile-and-cordova-part-3/" target="_blank">the previous article</a> of this series, I described the <a
title="Articles about jQuery Mobile" href="http://buildmobile.com/tag/jquery-mobile/" target="_blank">jQuery Mobile</a> custom configuration for our app and highlighted the importance of allowing cross-domain requests to download up-to-the-moment currency exchange rates. I also described a class that will help us translate the app into multiple spoken languages, and I outlined a second class to manage user settings. In this fourth article, I&#8217;ll show you the classes that save, load, and complete currency operations, as well as the one that unifies all of the different components of our app.</p><h3>The Currency Class</h3><p>When I talked about the <code>Settings</code> class, I described the aim of the <code>_db</code> and <code>_tableName</code> variables. The <code>Currency</code> class has these variables too, and it shares the same purpose. Of course, the value of <code>_tableName</code> is different, as are the &#8220;currencies.&#8221; Keep in mind that we&#8217;re not storing an object—we&#8217;re storing an array containing <code>Currency</code> instances. We have to store data beyond the last update or the last currencies used; we also need to save the name of the currency (actually its abbreviation) and the conversion rate itself.<div
id='div-gpt-ad-1328644474660-10' style='width:728px; height:90px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1328644474660-10'); });</script> </div></p><p>We&#8217;re retrieving the rates from the European Central Bank, and they use the Euro as the reference money. So, when you parse the feed, you won&#8217;t find the Euro rate itself (a rate of 1.00 is assumed), and the rates you&#8217;ll are all relative to the Euro. This leads to a tricky method to make non-Euro currency comparisons, which I&#8217;ll explain in detail when I describe the <code>convert()</code> method.</p><p>Based on what I stated so far, the beginning of the <code>Currency</code> class is the following:</p><pre class="brush: jscript; title: ; notranslate">
function Currency(abbreviation, rate)
{
  var _db = window.localStorage;
  var _tableName = 'currencies';
  this.abbreviation = abbreviation;
  this.rate = rate;
}
</pre><p>Just like the <code>Settings</code> class, we&#8217;ll have the <code>save()</code> and the <code>load()</code> methods. The latter is identical to the one already discussed, while the former is quietly different because we&#8217;re managing an array. Since we don&#8217;t want duplicated currencies, we need to check if a given currency is already stored before adding to the array. If the currency is already present, we&#8217;ll just update the conversion rate. Otherwise, we&#8217;ll push the whole object into the array. To achieve this goal, I&#8217;ll create a static method called <code>getIndex()</code>, which returns the index of the currency if it&#8217;s found or returns <code>false</code> otherwise. Just like you&#8217;ve seen for the <code>Settings</code> class, I&#8217;ll write a utility static method to retrieve the array containing <code>Currency</code> instances called <code>getCurrencies()</code>.</p><p>Now that you&#8217;re aware of this tricky situation, I can show you the code of the <code>save()</code> and <code>load()</code> methods.</p><pre class="brush: jscript; title: ; notranslate">
this.save = function()
{
 var currencyIndex = Currency.getIndex(this.abbreviation);
 var currencies = Currency.getCurrencies();
 if (currencyIndex === false)
   currencies.push(this);
 else
   currencies[currencyIndex] = this;
 _db.setItem(_tableName, JSON.stringify(currencies));
}
this.load = function()
{
 return JSON.parse(_db.getItem(_tableName));
}
</pre><p>And, below is the code for the two static methods:</p><pre class="brush: jscript; title: ; notranslate">
Currency.getCurrencies = function()
{
  var currencies = new Currency().load();
  return (currencies === null) ? [] : currencies;
}
Currency.getIndex = function(abbreviation)
{
  var currencies = Currency.getCurrencies();
  for(var i = 0; i &lt; currencies.length; i++)
  {
    if (currencies[i].abbreviation.toUpperCase() === abbreviation.toUpperCase())
      return i;
  }
  return false;
}
</pre><p>Now that we&#8217;re able to save and load currencies, we need a method to do mathematical currency conversions. Before showing you the code of the methods, I should highlight one thing. As I said, the feed uses the Euro as the reference currency, so you won&#8217;t store distinct conversion rates for each and every currency—this would be a waste of memory. What we&#8217;ll devise is a method to convert from Euro to other currencies for each desired currency type.</p><p>Now, suppose that you want to convert from USD to AUD, what you can do? The solution is that you first convert to Euro and then into the currency you truly need.</p><p>To achieve this goal, you need to first divide by the starting rate and then multiply by the goal currency rate. The <code>convert()</code> method requires three parameters: the value to convert, the starting currency, and the goal currency. This method relies on another method, called <code>getRate()</code>, which, using <code>abbreviation</code> (the abbreviation of the currency name), retrieves the appropriate conversion rate. <code>getRate()</code> relies on a method that I haven&#8217;t explained yet called <code>getCurrency()</code>. As you might imagine, it&#8217;s very similar to <code>getCurrencies()</code>, except that it accepts an abbreviation as a parameter and returns a <code>Currency</code> instance if the search succeed or <code>null</code> return if it failed.</p><p>The source code of these three methods is listed below:</p><pre class="brush: jscript; title: ; notranslate">
Currency.getCurrency = function(abbreviation)
{
  var index = Currency.getIndex(abbreviation);
  return (index === false) ? null : Currency.getCurrencies()[index];
}
Currency.getRate = function(abbreviation)
{
  var currency = Currency.getCurrency(abbreviation);
  return (currency === null) ? 0 : currency.rate;
}
Currency.convert = function(value, from, to)
{
  // Round up to the 2nd decimal
  return Math.round(value / Currency.getRate(from) * Currency.getRate(to) * 100) / 100;
}
</pre><p>The last two methods are those that will be used during the update of the select boxes to select the currencies to sort them alphabetically. Their names are <code>compareTo()</code> and <code>compare()</code>, and their code is the following:</p><pre class="brush: jscript; title: ; notranslate">
Currency.prototype.compareTo = function(other)
{
  return Currency.compare(this, other);
}
Currency.compare = function(currency, other)
{
  if (other == null)
    return 1;
  else if (currency == null)
    return -1;
  return currency.abbreviation.localeCompare(other.abbreviation);
}
</pre><h3>Utility Functions</h3><p>In this section, I&#8217;ll explain the utility functions contained in the <code>functions.js</code> file. Please note that I&#8217;ll avoid explaining <code>updateIcons()</code>, because it has already been discussed and provided in a previous series. So, if you want to understand what it does, you can read the section called &#8220;Update Icons Based on the Screen Size&#8221; from <a
title="Build a Location-Based Mobile App With HTML5 and Javascript: Part 4" href="http://buildmobile.com/build-a-location-based-mobile-app-with-html5-and-javascript-part-4/" target="_blank">Build a Location-Based Mobile App With HTML5 and Javascript: Part 4</a>.</p><h4>Testing for Requirements</h4><p>&#8220;Currency Converter&#8221; doesn&#8217;t have a lot of requirements. In fact, the only mandatory condition we need is the possibility to store data using the Web Storage API. While the ability to connect to the Internet is important, it&#8217;s only needed the first time the user runs the application, because he&#8217;ll need to download the latest rates from the European Central Bank RSS feed. But, after that, the user can continue to work offline with slightly outdated currency conversion rates. Obviously, without the Internet connection enabled, we won&#8217;t be able to update the rates.</p><p>To test for requirements, I&#8217;ll create a function called <code>checkRequirements()</code>, which will test for Web Storage API support. If the device doesn&#8217;t support it, the app notifies the user using the Cordova Notification API and returns <code>false</code>, so the button to update the currency conversions can be disabled. The code of this function is shown below.</p><pre class="brush: jscript; title: ; notranslate">
function checkRequirements()
{
  if (typeof window.localStorage === 'undefined')
  {
    console.log('The database is not supported.');
    navigator.notification.alert(
      'Your device does not support the database used by this app.',
      function(){},
      'Error'
    );
    return false;
  }
  return true;
}
</pre><p>As you can see I also wrote a <code>console.log()</code> instruction to help you debug the project in case you need to. Remember, using <code>alert()</code> is not a best practice.</p><h4>Translating Pages</h4><p>To translate the elements of <code>index.html</code>, I&#8217;ll use the <a
title="Globalization API documentation" href="http://docs.phonegap.com/en/2.3.0/cordova_globalization_globalization.md.html#Globalization" target="_blank">Globalization API</a>, introduced in Cordova 2.2.0., which allows you to get information about user&#8217;s locale and timezone, thanks specifically to methods like <code>getPreferredLanguage()</code> (which gets the client&#8217;s current spoken language) and <code>getLocaleName()</code> (which retrieves the identifier code of the client&#8217;s current locale setting e.g. en_US or it_IT).</p><p>In addition, this API has methods to perform operations like converting dates and numbers into strings using the proper local format based on the user&#8217;s settings. The methods that implement these conversions are <code>dateToString()</code> and <code>numberToString()</code> respectively. Please note that like the other Cordova APIs, these methods are asynchronous, so they use success and failure callback functions.</p><p>In our project, we&#8217;ll use some of the previously-cited methods, specifically: <code>getLocaleName()</code>, <code>dateToString()</code>, and <code>numberToString()</code>. This API is very important, because it allows you to move the user experience one step forward compared what you could do in previous versions. Please note that currently the supported platforms are Android, BlackBerry WebWorks (OS 5.0+), iOS, and Windows Phone 8.</p><p>As you&#8217;ll see in the code below, I used the <code>getLocaleName()</code> method to retrieve the language identifier, which I&#8217;ll use to get the right language from within the <code>Translation</code> object. Once retrieved, I&#8217;ll iterate over the text strings to translate the various instructional elements. Now, you should finally understand why I used the elements&#8217; id as properties&#8217; name. You&#8217;ll also note the use of Audero Text Changer to change the elements&#8217; text, which I illustrated in the first part of this series.</p><pre class="brush: jscript; title: ; notranslate">
/**
 * Translate the main page
 */
function translateMainPage()
{
  navigator.globalization.getLocaleName(
    function(locale)
    {
      var translation = Translation[locale.value.substring(0, 2)];
      if (typeof translation === 'undefined')
        return;
      for(var key in translation)
        $('#' + key).auderoTextChanger(translation[key]);
    },
    function()
    {
      console.log('An error has occurred with the translation');
    }
  );
}
</pre><h3>Conclusion</h3><p>In this fourth article, I described the <code>Currency</code> class and all of its methods. As you learned, it has several utility methods that allow you to write new methods with very few lines of code. I also showed how to test for the minimum app requirements and gave a brief overview of the Globalization API, as well as the specific the methods used in our project. To help us manage the translation of interface elements, I used the <a
title="Customize Your jQuery Mobile Interface with Specialized Plugins" href="http://buildmobile.com/how-to-change-texts-in-your-jquery-mobile-apps-without-breaking-widgets/" target="_blank">Audero Text Changer</a> plugin. In the next part of the series, I&#8217;ll show you the remaining functions of the <code>functions.js</code> file to complete the discussion.</p><div
class='after-content-widget-1'><div
id="sitepointcontextualcontentmanagerwidget-5" class="widget widget_sitepointcontextualcontentmanagerwidget"><div
class="dfp-ad show-desktop"><div
id="div-gpt-ad-1340873946991-4" style="width: 728px; height: 90px;"> <script type="text/javascript">googletag.cmd.push(function() { googletag.display("div-gpt-ad-1340873946991-4"); });</script> </div></div></div></div>]]></content:encoded> <wfw:commentRss>http://www.sitepoint.com/build-a-currency-converter-with-jquery-mobile-and-cordova-part-4/feed/</wfw:commentRss> <slash:comments>0</slash:comments> <series:name><![CDATA[Build a Currency Converter with jQuery Mobile and Cordova]]></series:name> </item> <item><title>Build a Currency Converter with jQuery Mobile and Cordova: JavaScript and User Settings</title><link>http://www.sitepoint.com/build-a-currency-converter-with-jquery-mobile-and-cordova-part-3/</link> <comments>http://www.sitepoint.com/build-a-currency-converter-with-jquery-mobile-and-cordova-part-3/#comments</comments> <pubDate>Wed, 13 Feb 2013 16:45:02 +0000</pubDate> <dc:creator>Aurelio De Rosa</dc:creator> <category><![CDATA[Mobile]]></category> <category><![CDATA[Mobile Web Development]]></category> <category><![CDATA[Mobile Web Tutorials]]></category> <category><![CDATA[jquery mobile]]></category> <category><![CDATA[mobile]]></category> <category><![CDATA[Tutorials]]></category> <guid
isPermaLink="false">http://buildmobile.com/?p=5477</guid> <description><![CDATA[In the second part of the series, I showed you the code of the two HTML pages and the custom CSS file of our &#8220;Currency Converter&#8221; app. In this article, I&#8217;ll show you the jQuery Mobile custom configuration and some of the JavaScript files that implement the business logic. While describing the JavaScript files, I&#8217;ll [...]]]></description> <content:encoded><![CDATA[<p></p><p>In <a
title="Build a Currency Converter with jQuery Mobile and Cordova: Constructing The Interface" href="http://buildmobile.com/build-a-currency-converter-with-jquery-mobile-and-cordova-part-2/" target="_blank">the second part of the series</a>, I showed you the code of the two HTML pages and the custom CSS file of our &#8220;Currency Converter&#8221; app. In this article, I&#8217;ll show you the jQuery Mobile custom configuration and some of the JavaScript files that implement the business logic. While describing the JavaScript files, I&#8217;ll also demonstrate the Cordova APIs in detail.<br
/> <span
id="more-65953"></span></p><h3>jQuery Mobile Custom Configuration</h3><p>jQuery Mobile has a default configuration that is usually good enough for most of the projects with basic requirements. However, you may still need to set up some specific custom rules to fit your app&#8217;s requirements. As I said in <a
title="Build a Currency Converter with jQuery Mobile and Cordova: Introduction" href="http://buildmobile.com/build-a-currency-converter-with-jquery-mobile-and-cordova/" target="_blank">the first part of the series</a> when I presented the list of the files that make up our app, we have a file called <code>jquery.mobile.config.js</code>, which is exactly where we would specify a configuration. In this section, I&#8217;ll show you what options I&#8217;ll change.<div
id='div-gpt-ad-1328644474660-10' style='width:728px; height:90px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1328644474660-10'); });</script> </div></p><p>(Please note that when you create a file like this, you must include it <strong>before</strong> the library files itself. In fact, when jQuery Mobile starts, it fires an event called <code>mobileinit</code>, which is used to override the default settings.)</p><p>You have two different ways to specify the settings, but I&#8217;ll use the method that changes the properties of the <code>$.mobile</code> object. I&#8217;ll change just some of them, but if you need an overview of all of the jQuery Mobile properties, you can read the <a
href="http://jquerymobile.com/demos/1.2.0/docs/api/globalconfig.html" target="_blank">jQuery Mobile configuration docs</a>. Our file will change the options concerning the page loader widget, the theme, and those that allow cross-domain requests. The settings to allow cross-domain requests are the most interesting ones and well worth a discussion.</p><p>As you learned in the app requirements, &#8220;Currency Converter&#8221; will make a call to the European Central Bank RSS feed to update the currencies rates, so we need to be able to do HTTP requests to an external source. When you use the Cordova framework in conjunction with jQuery Mobile, to be able to make cross-domain requests, you need to set one property in the <code>config.xml</code> file of for first framework (Cordova) and two properties for the second (jQuery Mobile).</p><p>The jQuery Mobile properties to change are <code>$.support.cors</code> and <code>$.mobile.allowCrossDomainPages</code>. The first is a boolean that you need to set to <code>true</code> in order to tell the browser to support cross-domain requests. The project also has links to external pages (in the credits page) so, we must also set the <code>$.mobile.allowCrossDomainPages</code> property to <code>true</code>. In fact, when jQuery Mobile tries to load an external page, the request runs through the <code>$.mobile.loadPage()</code> method, which will only allow cross-domain requests if the cited property is set to <code>true</code>. By default, its value is <code>false</code>, because, according to the documentation, the <q
cite="http://jquerymobile.com/demos/1.2.0/docs/pages/phonegap.html">framework tracks what page is being viewed within the browser&#8217;s location hash, so it is possible for a cross-site scripting (XSS) attack to occur if the XSS code in question can manipulate the hash and set it to a cross-domain URL of its choice</q>. This option must be set before the requests are made, and the documentation suggests putting it into the initial configuration. We&#8217;ll act accordingly.</p><p>Now that you know the meaning of these options, you&#8217;re ready to see the full source of <code>jquery.mobile.config.js</code>.</p><pre class="brush: jscript; title: ; notranslate">
$(document).on(
  'mobileinit',
  function()
  {
    // Page Loader Widget
    $.mobile.loader.prototype.options.text = 'Loading...';
    $.mobile.loader.prototype.options.textVisible = true;
    // Bypass Access-Control-Allow-Origin
    $.support.cors = true;
    $.mobile.allowCrossDomainPages = true;
    // Theme
    $.mobile.page.prototype.options.theme  = 'b';
    $.mobile.page.prototype.options.headerTheme = 'b';
    $.mobile.page.prototype.options.contentTheme = 'b';
    $.mobile.page.prototype.options.footerTheme = 'b';
    $.mobile.page.prototype.options.backBtnTheme = 'b';
  }
);
</pre><h3>The Translation Class</h3><p>Recalling the project&#8217;s requirements, you&#8217;ll remember that &#8220;Currency Converter&#8221; is a multi-language app. Since its most important part is <code>index.html</code>, I&#8217;ll create translations for that page and ignore translations for <code>aurelio.html</code>. I think that having the credits solely in English is adequate.</p><p>To store the strings of the different languages within the <code>translation.js</code> file, I used an object calling the variable <code>Translation</code>. This object has as many properties as the spoken languages that you want support. So, since we&#8217;ll translate it into Italian, French, and Spanish, we&#8217;ll have three properties whose values are objects containing the strings. To simplify the translation process, these objects have the id of the elements that will be translated as their property names, and the string to change as their values. To understand how <code>Translation</code> is made, it&#8217;s enough to see one language, so I&#8217;ll show you just the Italian, but you&#8217;ll find the others will be supported within the app repository.</p><pre class="brush: jscript; title: ; notranslate">
var Translation = {
  'it': {
    'app-description': 'Currency Converter è una semplice applicazione che ti aiuta a convertire da una valuta ad un'altra. È anche possibile aggiornare i tassi di cambio ogni volta che si desidera così da avere sempre dei tassi di conversione aggiornati.',
    'convert-title': 'Converti',
    'from-value-label': 'Valore:',
    'from-type-label': 'Da Valuta:',
    'to-type-label': 'A Valuta:',
    'result-title': 'Risultato',
    'copyright-title': 'Creata da Aurelio De Rosa',
    'credits-button': 'Crediti',
    'update-button': 'Aggiorna dati',
    'submit-button': 'Converti',
    'reset-button': 'Azzera dati',
    'last-update-label': 'Ultimo aggiornamento cambi:'
  }
  // other languages here
}
</pre><h3>The User Settings</h3><p>In the introductory article of this series, I stated:</p><blockquote
cite="http://buildmobile.com/build-a-currency-converter-with-jquery-mobile-and-cordova/"><p>The app will save the last currency used for a conversion, so at the next start of the application, the user will find their last-used currency. In addition, the date and time of the last update will be stored too, so that the user knows how recent (or old) his conversion rates are.</p></blockquote><p>Thus, we need to manage and store these data. To achieve this goal, we&#8217;ll use the <a
href="http://docs.phonegap.com/en/2.3.0/cordova_storage_storage.md.html#Storage" target="_blank">Cordova Storage API</a>, which is built on the top of the <a
href="http://dev.w3.org/html5/webstorage/" target="_blank">Web Storage API</a> and Cordova. For the devices that have built-in support, it uses the native implementation instead of its own, which is compatible with the W3C specs.</p><p>In this section, I&#8217;m going to describe the file called <code>settings.js</code> that contains the class called <code>Settings</code>. Let&#8217;s take a closer look at this file.</p><p>As you already know, this class has three public properties: <code>lastUpdate</code>, <code>fromCurrency</code>, and <code>toCurrency</code>. It also has two private ones: <code>_db</code> and <code>_tableName</code>. The aim of the first three properties should be self-evident so I&#8217;ll skip their explanation. <code>_db</code> is a reference to the <code>window.localStorage</code> property that will be used to call the Web Storage API&#8217;s method to store and retrieve the data from the browser (or, in the case of our hybrid app, from the device). Keep in mind that this API doesn&#8217;t use real tables like a DBMS does. Instead, it has a set of properties whose values are a basic type (like a string or a number) or a JSON-encoded object. Having said that, it should be clear that <code>_tableName</code> isn&#8217;t a property having as its value a string containing the name of a real table, but rather the name of the property where we&#8217;ll store the JSON-encoded object containing the user settings.</p><p>The following code shows what I&#8217;ve explained so far.</p><pre class="brush: jscript; title: ; notranslate">
function Settings(lastUpdate, fromCurrency, toCurrency)
{
  var _db = window.localStorage;
  var _tableName = 'settings';
  this.lastUpdate = lastUpdate;
  this.fromCurrency = fromCurrency;
  this.toCurrency = toCurrency;
}
</pre><p>Now, we need two methods: one to store the data, and one to retrieve them. In another one of my astonishingly-creative moments, I named these methods <code>save()</code> and <code>load()</code> respectively. These methods do nothing but wrap the call the <code>getItem()</code> and <code>setItem()</code> methods, as you can see by looking at their code below.</p><pre class="brush: jscript; title: ; notranslate">
this.save = function()
{
  _db.setItem(_tableName, JSON.stringify(this));
}
this.load = function()
{
  return JSON.parse(_db.getItem(_tableName));
}
</pre><p>Some of you who have have already used the Web Storage API might wonder why I used <code>setItem()</code> and <code>getItem()</code> instead of using the dot notation. The reason is that Windows Phone 7 doesn&#8217;t support the latter, so to ensure the compatibility across all the operating systems, we&#8217;ve got to use the former.</p><p>This class has another method to discuss that is more of a utility than a must-have method. It&#8217;s called <code>getSettings()</code> and it&#8217;s a static method. When you use <code>load()</code>, the retrieved object isn&#8217;t an instance of the <code>Settings</code> class but of the <code>Object</code> equivalent. Now, suppose that you want to change the current user&#8217;s settings based on the ones you stored. In this case, it&#8217;s a lot easier to have a <code>Settings</code> instance, so that you can modify the properties and then call the <code>save()</code> method directly. For this reason, I created <code>getSettings()</code>, which calls <code>load()</code> and then converts the result into a <code>Settings</code> instance. The source of this utility is the following:</p><pre class="brush: jscript; title: ; notranslate">
Settings.getSettings = function()
{
  var settings = new Settings().load();
  return (settings === null) ?
     {} :
     new Settings(
       settings.lastUpdate,
       settings.fromCurrency,
       settings.toCurrency
     );
}
</pre><h3>Conclusion</h3><p>In this third article of the series, I described the custom configuration of &#8220;Currency Converter&#8221; and the importance of the options to allow cross-domain requests. Additionally, I showed the class used to translate the application and the class used to save the user settings. In the next part of the series, I&#8217;ll illustrate the other two remaining JavaScript files: <code>functions.js</code> (which has the functions to retrieve the rates, update the currencies select boxes, and initialize the application), and <code>currency.js</code>, the file that contains the class to store, load, sort, and convert the retrieved currencies.</p><div
class='after-content-widget-1'><div
id="sitepointcontextualcontentmanagerwidget-5" class="widget widget_sitepointcontextualcontentmanagerwidget"><div
class="dfp-ad show-desktop"><div
id="div-gpt-ad-1340873946991-4" style="width: 728px; height: 90px;"> <script type="text/javascript">googletag.cmd.push(function() { googletag.display("div-gpt-ad-1340873946991-4"); });</script> </div></div></div></div>]]></content:encoded> <wfw:commentRss>http://www.sitepoint.com/build-a-currency-converter-with-jquery-mobile-and-cordova-part-3/feed/</wfw:commentRss> <slash:comments>2</slash:comments> <series:name><![CDATA[Build a Currency Converter with jQuery Mobile and Cordova]]></series:name> </item> <item><title>Responsive Web Design: Custom Grid Layouts</title><link>http://www.sitepoint.com/responsive-web-design-grid-layouts/</link> <comments>http://www.sitepoint.com/responsive-web-design-grid-layouts/#comments</comments> <pubDate>Tue, 12 Feb 2013 13:00:45 +0000</pubDate> <dc:creator>Annarita Tranfici</dc:creator> <category><![CDATA[Mobile]]></category> <category><![CDATA[Mobile Web Development]]></category> <guid
isPermaLink="false">http://buildmobile.com/?p=5465</guid> <description><![CDATA[In the last few parts of the responsive design series, I have introduced the characteristics of fluid layouts and I have described how to use fonts responsively. In this article, I want to introduce grid layouts, a widespread and popular design practice. While grid systems have seen significant use in printed media, interest from web [...]]]></description> <content:encoded><![CDATA[<p></p><p>In the last few parts of the responsive design series, I have introduced the characteristics of <a
title="Fluid Layouts" href="http://buildmobile.com/responsive-web-design-fluid-layouts/">fluid layouts</a> and I have described <a
title="How to use fonts responsively" href="http://buildmobile.com/understanding-responsive-web-design-how-to-manage-fonts/">how to use fonts responsively</a>. In this article, I want to introduce grid layouts, a widespread and popular design practice. While grid systems have seen significant use in printed media, interest from web and mobile developers has been a very recent development.</p><p>A grid is a two-dimensional structure made up of intersecting vertical and horizontal divisions used to structure content. Grids serve as the framework on which a designer can organize text and images into a rational, easy-to-absorb interface. A well-built and properly-implemented grid system increases scalability and improves the readability of the content on a website or within a mobile application.</p><p>The advantages of grid layouts are numerous; a grid structure&#8230;</p><ul><li>gives order, originality, and harmony to the presentation of content;</li><li>allows users to predict where to find the information they need;</li><li>makes it easier to add new content without having it looking disjointed or marginalized.</li></ul><p>To develop a well-built grid layout, the first step is to create the canvas structure itself. It&#8217;s the canvas&#8217; size that determines the grid&#8217;s frame: it is divided into the number of columns the designer wants (3,5,9,12) and this is the starting point to work on your interface or layout.<div
id='div-gpt-ad-1328644474660-10' style='width:728px; height:90px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1328644474660-10'); });</script> </div></p><p>The size of a grid does not have to be defined with fixed parameters. A common and proper practice of design for this type of layout is to let the content define the space occupied by the grid, and <em>not</em> vice versa. In this case, &#8220;content&#8221; does not refer solely to the text; it also refers to everything that has value within an interface, including images, video, text, ads, links, and more. Rather than trying to hammer a variety of content sizes and types into a predetermined grid, you should design your grid around the size and nature of your content. Within your customized grid structure, the layout is divided with vertical and/or horizontal guidelines that provide a consistent organization of space. Once you define the margins and the spacing for columns, your grid will become a clear, logical, and useful organizational schema for your multifaceted mobile content.</p><h3>Online Tools</h3><p>Web design frameworks built upon HTML and CSS had become quite popular before newer, more robust frameworks popularized the use of grid-based layouts. The Internet is full of useful models and frameworks with CSS rules that help designers to create a simple, fast, and efficient grid layout for almost any purpose. Some layouts are flexible, others are quite rigid (after all, they are designed to constrain content). Some of them have between three and five columns maximum, while others have between 12 and 16 columns. I bring up the variety of grid frameworks to emphasize that they&#8217;re not all the same, and further, there are grids that are inherently <em>better</em> than others. However, to fully understand the benefits of a grid-based approach, you should consider a unique pattern and purpose for each project you have to develop. You should not be afraid to try a variety; remember, simplicity is often the winning design.</p><p>On the web, there are many useful grid resources to help you build a properly-proportioned layout or interface for your projects.</p><ul><li><a
title="Grid System 960" href="http://960.gs/">Grid System 960</a>: A tool that lets you create websites using a grid of 960 pixels. This number was chosen because it allows easy division into a variety of columns and rows.</li><li><a
title="Gridr Buildrrr" href="http://gridr.atomeye.com/">Gridr Buildrrr</a>: A tool that offers precise control over borders, margins, and box contents for custom projects.</li><li><a
title="Design by Grid" href="http://www.designbygrid.com/">Design by Grid</a>: A magazine that publishes articles and tutorials on the creation of grid-based designs.</li></ul><h3>A Grid Layout Markup</h3><p>If you&#8217;d like to try to develop a grid structure with your own hand-written code instead, determine an interface width and the size of the spacing between the various columns. Remember that in order to obtain a balanced effect, it&#8217;s important that the various horizontal spacings are of equal size. As discussed before, <em>study your content first</em>, think about how it should be positioned and arranged, and keep these ideas in practice throughout your grid development process.</p><p>Add the main elements of your app or mobile website (header, main content, sidebar, and footer) in a wrapper, like this:</p><pre class="brush: xml; title: ; notranslate">
&lt;div id=&quot;wrapper&quot;&gt;
  &lt;div id=&quot;header&quot;&gt;Header&lt;/div&gt;
  &lt;div id=&quot;content&quot;&gt;Content&lt;/div&gt;
  &lt;div id=&quot;sidebar&quot;&gt;Sidebar&lt;/div&gt;
  &lt;div id=&quot;footer&quot;&gt;Footer&lt;/div&gt;
&lt;/div&gt;
</pre><p>At this point, your content and your sidebar will be divided into sections, all of which will be assigned a class named Grid1, Grid2, Grid3, and so on (it depends on the number of grids that you&#8217;ve decided to build). Within each grid cell, there can be as many subsections as you would like to include.</p><pre class="brush: xml; title: ; notranslate">
&lt;div class=&quot;griglia1&quot;&gt;
  &lt;div&gt;Subsection 1&lt;/div&gt;
  &lt;div&gt;Subsection 2&lt;/div&gt;
  &lt;div&gt;Subsection 3&lt;/div&gt;
&lt;/div&gt;
</pre><p>As for the CSS, almost everything is based on the proper application of the <em>float</em> CSS property. For the correct positioning of the most prominent area of your grid design (that is, the grid&#8217;s main containers, which in turn contain subsections) you employ the so-called &#8220;opposite float&#8221; technique. For the grids and the horizontal spacings between them, you have to first create several self-contained sections of columns, and secondly, you have to assign each a float and a fixed width. I&#8217;ve applied this technique using the following CSS:</p><pre class="brush: css; title: ; notranslate">
div.grid1
{
  float: left;
  width: 290px;
}
</pre><p>Afterward, you&#8217;ll apply the same float rule within the sections in multiple columns, giving a specific size to the width and to the right margin (10 pixels in this case) to separate them, like this:</p><pre class="brush: css; title: ; notranslate">
div.grid2 div
{
  float: left;
  width: 250px;
  margin-right: 10px;
}
</pre><p>To add an additional level of modularity, enabling a section to occupy the space of two or more columns, let&#8217;s use so-called joint columns: you simply need to assign to an element a class of type ext2, ext3, ext4, or ext5 to have a section that occupies 2, 3, 4, or 5 columns instead of having a unitary width.</p><h3>Conclusion</h3><p>This article was intended to point out another possible technique for the design and development of a responsive layout or interface. If there&#8217;s one principle to remember about grids, it&#8217;s this: Don&#8217;t try to cram your content into an ill-fitting grid. If popular solutions don&#8217;t suit your needs, design your own grid tailored perfectly for your content. It can be done quickly and easily using a few columns, rows, and CSS declarations.</p><p><em>Want to learn more about Responsive Web Design? Check out SitePoint&#8217;s new book, <a
href="http://www.sitepoint.com/books/responsive1/" target="_blank">Jump Start Responsive Web Design</a>!</em></p><div
class='after-content-widget-1'><div
id="sitepointcontextualcontentmanagerwidget-5" class="widget widget_sitepointcontextualcontentmanagerwidget"><div
class="dfp-ad show-desktop"><div
id="div-gpt-ad-1340873946991-4" style="width: 728px; height: 90px;"> <script type="text/javascript">googletag.cmd.push(function() { googletag.display("div-gpt-ad-1340873946991-4"); });</script> </div></div></div></div>]]></content:encoded> <wfw:commentRss>http://www.sitepoint.com/responsive-web-design-grid-layouts/feed/</wfw:commentRss> <slash:comments>1</slash:comments> <series:name><![CDATA[Understanding Responsive Web Design]]></series:name> </item> <item><title>Build a Currency Converter with jQuery Mobile and Cordova: Constructing The Interface</title><link>http://www.sitepoint.com/build-a-currency-converter-with-jquery-mobile-and-cordova-part-2/</link> <comments>http://www.sitepoint.com/build-a-currency-converter-with-jquery-mobile-and-cordova-part-2/#comments</comments> <pubDate>Sun, 10 Feb 2013 23:26:37 +0000</pubDate> <dc:creator>Aurelio De Rosa</dc:creator> <category><![CDATA[Mobile]]></category> <category><![CDATA[Mobile Web Development]]></category> <category><![CDATA[Mobile Web Tutorials]]></category> <category><![CDATA[jquery mobile]]></category> <category><![CDATA[mobile]]></category> <category><![CDATA[Tutorials]]></category> <guid
isPermaLink="false">http://buildmobile.com/?p=5447</guid> <description><![CDATA[In the introductory article of this series, I showed the requirements of the soon-to-be-built &#8220;Currency Converter&#8221; app and the technologies involved. I also built out a file structure and outlined each component of the app and its purpose. In this article, we&#8217;ll delve deeper into the layout and functionality of our app, and I&#8217;ll show [...]]]></description> <content:encoded><![CDATA[<p></p><p>In <a
title="Build a Currency Converter with jQuery Mobile and Cordova: Introduction" href="http://buildmobile.com/build-a-currency-converter-with-jquery-mobile-and-cordova/" target="_blank">the introductory article of this series</a>, I showed the requirements of the soon-to-be-built &#8220;Currency Converter&#8221; app and the technologies involved. I also built out a file structure and outlined each component of the app and its purpose. In this article, we&#8217;ll delve deeper into the layout and functionality of our app, and I&#8217;ll show you the source of both the two HTML pages and the CSS file that govern our app&#8217;s interface.<br
/> <span
id="more-65951"></span></p><h3>The Homepage</h3><p>By default, the interface loads the pages differently from the first initial page load using AJAX; That&#8217;s why we have to include all the JavaScript and CSS files. As I pointed out in the first article, the app we&#8217;re developing is very simple; the entry point is <code>index.html</code>, and it&#8217;s also the only page that the user will really interact with. It contains the form the user will use to convert money from one currency to another. The form will have the field to write the monetery amount, the currency to convert from, and the currency to convert into.<div
id='div-gpt-ad-1328644474660-10' style='width:728px; height:90px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1328644474660-10'); });</script> </div></p><p>I&#8217;ll use the new HTML5 tags where possible, and the <em>amount</em> field is ideal to use the new <code>&lt;input type="number"&gt;</code>. Apart from the new input type, I&#8217;ll take advantage of the <code>min</code> by setting it to zero, because we won&#8217;t be converting negative amounts of currency. I&#8217;ll also use the attribute <code>pattern</code> and set it with the value range <code>[0-9]*</code> . As a result, when the user puts &#8220;focus&#8221; on this field (by touching it), the numbers keyboard will be shown instead of the alphabetical one. You can see this specific part of code that creates this streamlined functionality below:</p><pre class="brush: xml; title: ; notranslate">
&lt;input type=&quot;number&quot; id=&quot;from-value&quot; name=&quot;from-value&quot; pattern=&quot;[0-9]*&quot; value=&quot;0&quot; min=&quot;0&quot; max=&quot;999999999999999&quot; /&gt;
</pre><p>The remaining two fields are implemented using the classic <code>&lt;select&gt;</code> tag. They will be filled dynamically using a JavaScript function that I&#8217;ll describe in the next parts of the series.</p><p>For the output of the currency calculation, I used the new <code>&lt;output&gt;</code> element. This has a very interesting attribute (at least for me), called <code>for</code>, which allows you to specify what elements are involved in the calculation to obtain the result you have. Thus, I specify the id of the amount, the &#8220;from&#8221; currency and the &#8220;to&#8221; currency fields, as you can see in the following snippet.</p><pre class="brush: xml; title: ; notranslate">
&lt;output id=&quot;result&quot; name=&quot;result&quot; for=&quot;from-currency-value from-currency-type to-currency-type&quot;&gt;0&lt;/output&gt;
</pre><p>The last interesting twist is the <a
title="jQuery Mobile Layout Grids" href="http://jquerymobile.com/demos/1.2.0/docs/content/content-grids.html" target="_blank">layout grid system</a> that I applied to style the reset and the submit buttons. By default, the framework styles the buttons to take all the space and not allowing to have other elements on the same line. However, I wanted those two buttons to be on the same horizontal line and to divide the total width. To build this two-column layout in jQuery Mobile, you must create a wrapper having class <code>ui-grid-a</code>, and then apply to its children the class <code>ui-block-a</code> for the first column and <code>ui-block-b</code> for the second. Consider the following example:</p><pre class="brush: xml; title: ; notranslate">
&lt;div class=&quot;ui-grid-a&quot;&gt;
  &lt;div class=&quot;ui-block-a&quot;&gt;
    &lt;input id=&quot;reset-button&quot; type=&quot;reset&quot; value=&quot;Reset&quot; data-icon=&quot;delete&quot; data-theme=&quot;c&quot; /&gt;
  &lt;/div&gt;
  &lt;div class=&quot;ui-block-b&quot;&gt;
    &lt;input id=&quot;submit-button&quot; type=&quot;submit&quot; value=&quot;Convert&quot; data-icon=&quot;check&quot; /&gt;
  &lt;/div&gt;
&lt;/div&gt;
</pre><p>Now, you&#8217;re probably wondering why I added two additional containers. The reason is that since an <code>&lt;input&gt;</code> field is wrapped with other elements by jQuery Mobile to add aesthetic enhancements (which take up space), so if the buttons take up 50% of the width each, the added width from the styling forces the buttons onto different lines, as you can see in the following screenshot.</p><p><a
href="http://buildmobile.com/build-a-currency-converter-with-jquery-mobile-and-cordova-part-2/buttons-wrong-alignment/" rel="attachment wp-att-5452"><img
class="alignnone size-medium wp-image-5452" alt="Buttons wrong alingment" src="http://buildmobile.com/files/2013/02/buttons-wrong-alignment.png" /></a></p><p>Now that you know all the main elements of the page, it&#8217;s time to show you the page&#8217;s whole code.</p><pre class="brush: xml; title: ; notranslate">
&lt;!DOCTYPE html&gt;
&lt;html&gt;
  &lt;head&gt;
    &lt;meta charset=&quot;UTF-8&quot; /&gt;
    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt;
    &lt;title&gt;Currency converter&lt;/title&gt;
    &lt;link rel=&quot;stylesheet&quot; href=&quot;css/jquery.mobile-1.2.0.min.css&quot; type=&quot;text/css&quot; media=&quot;all&quot; /&gt;
    &lt;link rel=&quot;stylesheet&quot; href=&quot;css/style.css&quot; type=&quot;text/css&quot; media=&quot;all&quot; /&gt;
    &lt;script src=&quot;js/jquery-1.8.3.min.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;js/jquery.mobile.config.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;js/jquery.mobile-1.2.0.min.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;cordova.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;js/jquery.auderoTextChanger.min.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;js/translation.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;js/currency.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;js/settings.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;js/functions.js&quot;&gt;&lt;/script&gt;
    &lt;script&gt;
      $(document).on('pagebeforecreate orientationchange', updateIcons);
      $(document).one('deviceready', initApplication);
    &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;div id=&quot;home-page&quot; data-role=&quot;page&quot;&gt;
      &lt;header data-role=&quot;header&quot;&gt;
        &lt;h1&gt;Currency converter&lt;/h1&gt;
        &lt;a href=&quot;#&quot; id=&quot;update-button&quot; data-icon=&quot;refresh&quot; data-iconpos=&quot;notext&quot; class=&quot;ui-btn-right&quot;&gt;Update data&lt;/a&gt;
      &lt;/header&gt;
      &lt;div data-role=&quot;content&quot;&gt;
        &lt;p id=&quot;app-description&quot;&gt;
          Currency Converter is a simple app that helps you convert from a currency to another. You can
          update the exchange rates every time you want so you'll have always an up-to-date conversion.
        &lt;/p&gt;
        &lt;label id=&quot;last-update-label&quot;&gt;Last update rates:&lt;/label&gt;
        &lt;span id=&quot;last-update&quot;&gt;&lt;/span&gt;
        &lt;form id=&quot;form-converter&quot; name=&quot;form-converter&quot; action=&quot;#&quot;&gt;
          &lt;h2 id=&quot;convert-title&quot;&gt;Convert&lt;/h2&gt;
          &lt;div data-role=&quot;fieldcontain&quot;&gt;
            &lt;label for=&quot;from-value&quot; id=&quot;from-value-label&quot;&gt;Value:&lt;/label&gt;
            &lt;input type=&quot;number&quot; id=&quot;from-value&quot; name=&quot;from-value&quot; pattern=&quot;[0-9]*&quot; value=&quot;0&quot; min=&quot;0&quot; max=&quot;999999999999999&quot; /&gt;
          &lt;/div&gt;
          &lt;div data-role=&quot;fieldcontain&quot;&gt;
            &lt;label for=&quot;from-type&quot; id=&quot;from-type-label&quot;&gt;From Currency:&lt;/label&gt;
            &lt;select id=&quot;from-type&quot;&gt;
            &lt;/select&gt;
          &lt;/div&gt;
          &lt;div data-role=&quot;fieldcontain&quot;&gt;
            &lt;label for=&quot;to-type&quot; id=&quot;to-type-label&quot;&gt;To Currency:&lt;/label&gt;
            &lt;select id=&quot;to-type&quot;&gt;
            &lt;/select&gt;
          &lt;/div&gt;
          &lt;h2 id=&quot;result-title&quot;&gt;Result&lt;/h2&gt;
          &lt;output id=&quot;result&quot; name=&quot;result&quot; for=&quot;from-value from-type to-type&quot;&gt;0&lt;/output&gt;
          &lt;div class=&quot;ui-grid-a&quot;&gt;
            &lt;div class=&quot;ui-block-a&quot;&gt;
              &lt;input id=&quot;reset-button&quot; type=&quot;reset&quot; value=&quot;Reset&quot; data-icon=&quot;delete&quot; data-theme=&quot;c&quot; /&gt;
            &lt;/div&gt;
            &lt;div class=&quot;ui-block-b&quot;&gt;
              &lt;input id=&quot;submit-button&quot; type=&quot;submit&quot; value=&quot;Convert&quot; data-icon=&quot;check&quot; /&gt;
            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/form&gt;
      &lt;/div&gt;
      &lt;footer data-role=&quot;footer&quot;&gt;
        &lt;h3 id=&quot;copyright-title&quot;&gt;Created by Aurelio De Rosa&lt;/h3&gt;
        &lt;a id=&quot;credits-button&quot; href=&quot;aurelio.html&quot; data-icon=&quot;info&quot; data-iconpos=&quot;notext&quot; data-prefetch=&quot;prefetch&quot; data-transition=&quot;flip&quot; class=&quot;ui-btn-right&quot;&gt;Credits&lt;/a&gt;
      &lt;/footer&gt;
    &lt;/div&gt;
  &lt;/body&gt;
&lt;/html&gt;
</pre><p>In addition to what I&#8217;ve already outlined for the header and the footer, I&#8217;ve used the new HTML5 <code>&lt;header&gt;</code> and <code>&lt;footer&gt;</code> tags instead of generic <code>&lt;div&gt; </code>tags. Each of those two elements has a link inside: the header&#8217;s link will execute the currencies rate update, while the footer&#8217;s will simply take the user to the credits page (<code>aurelio.html</code>), which is nothing special but a <del>spam</del> page about&#8230;well, me.</p><p>Additionally, the link inside the <code>&lt;header&gt;</code>, as well as the one inside the <code>&lt;footer&gt;</code>, uses the attribute <code>data-iconpos="notext"</code>. This tells to jQuery Mobile to hide the link&#8217;s text, because on small screens it could require too space. However, as you can see at line 19, I attached a handler, called <code>updateIcons()</code>, to the <code>pagebeforecreate</code> and the <code>orientationchange</code> events. This function will programmatically test the screen&#8217;s width, and if a larger enough screen is found, the attribute will be removed and the element&#8217;s text will be displayed.</p><p>The last thing you should know about this page is the use of a handler, <code>initApplication()</code>, for the <code>deviceready</code> event, which is fired when Cordova is fully loaded. It&#8217;s the function that will set up the application, but its functionality will be illustrated in the next parts of this article series.</p><h3>The Credits Page</h3><p>Although the page <code>aurelio.html</code> is very simple, there are a couple of facts worth mentioning. The first is the use of two new HTML5 tags: <code>&lt;figure&gt;</code>, and <code>&lt;article&gt;</code>. Of course, explaining HTML5 is beyond the scope of this series, so I&#8217;ll give you a very brief summary. The <code>&lt;figure&gt;</code> element <q
cite="http://dev.w3.org/html5/markup/figure.html">represents a unit of content, optionally with a caption, that is self-contained.</q> The caption described is provided using the element <code>&lt;figcaption&gt;</code>. Regarding the <code>&lt;article&gt;</code> element, it <q
cite="http://www.w3.org/TR/html5/sections.html#the-article-element">represents a component of a page that consists of a self-contained composition in a document, page, application, or site.</q> The second fact to highlight is the use of the attribute <code>target="_blank"</code> applied to all the links of the contact listings on the page. It will be used to attach a handler to all those links; the <em>how</em> and the <em>why</em> will be explained in the next article of this series.</p><p>The full source of the credits page is below.</p><pre class="brush: xml; title: ; notranslate">
&lt;!DOCTYPE html&gt;
&lt;html&gt;
  &lt;head&gt;
    &lt;meta charset=&quot;UTF-8&quot; /&gt;
    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt;
    &lt;title&gt;Aurelio De Rosa&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;div id=&quot;aurelio-page&quot; data-role=&quot;page&quot;&gt;
      &lt;header data-role=&quot;header&quot;&gt;
        &lt;a href=&quot;#&quot; data-icon=&quot;back&quot; data-iconpos=&quot;notext&quot; data-rel=&quot;back&quot; title=&quot;Go back&quot;&gt;Back&lt;/a&gt;
        &lt;h1&gt;Aurelio De Rosa&lt;/h1&gt;
      &lt;/header&gt;
      &lt;div id=&quot;content&quot; data-role=&quot;content&quot;&gt;
        &lt;div class=&quot;person&quot;&gt;
          &lt;figure class=&quot;photo&quot;&gt;
            &lt;img src=&quot;images/aurelio-de-rosa.png&quot; alt=&quot;Photo of Aurelio De Rosa&quot; /&gt;
            &lt;figcaption&gt;Aurelio De Rosa&lt;/figcaption&gt;
          &lt;/figure&gt;
          &lt;article&gt;
            &lt;p&gt;
              I'm an Italian web and app developer who have a bachelor degree in Computer Science and more than
              5 years' experience programming for the web using HTML5, CSS3, JavaScript, and PHP. I mainly use the
              LAMP stack and frameworks like jQuery, jQuery Mobile, Cordova (PhoneGap), and Zend Framework.
              My interests also include web security, web accessibility, SEO, and WordPress.
            &lt;/p&gt;
            &lt;p&gt;
              Currently I'm self-employed working with the cited technologies, and I'm also a regular contributor to the
              SitePoint network, where I write articles about the topics I usually work with and more. The articles can
              be found on the following websites of the network:
              &lt;a href=&quot;http://buildmobile.com/author/aderosa/&quot; target=&quot;_blank&quot;&gt;BuildMobile.com&lt;/a&gt;,
              &lt;a href=&quot;http://phpmaster.com/author/aderosa/&quot; target=&quot;_blank&quot;&gt;PHPMaster.com&lt;/a&gt;,
              &lt;a href=&quot;http://jspro.com/author/aderosa/&quot; target=&quot;_blank&quot;&gt;JSPro.com&lt;/a&gt; and
              &lt;a href=&quot;http://www.sitepoint.com/author/aderosa/&quot; target=&quot;_blank&quot;&gt;SitePoint.com&lt;/a&gt;.
            &lt;/p&gt;
          &lt;/article&gt;
          &lt;article&gt;
            &lt;h2&gt;Contacts&lt;/h2&gt;
            &lt;ul data-role=&quot;listview&quot; data-inset=&quot;true&quot;&gt;
              &lt;li&gt;
                &lt;a href=&quot;http://www.audero.it&quot; target=&quot;_blank&quot;&gt;
                  &lt;img src=&quot;images/website-icon.png&quot; alt=&quot;Website icon&quot; /&gt;
                  Visit my website: www.audero.it
                &lt;/a&gt;
              &lt;/li&gt;
              &lt;li&gt;
                &lt;a href=&quot;mailto:aurelioderosa@gmail.com&quot; target=&quot;_blank&quot;&gt;
                  &lt;img src=&quot;images/email-icon.png&quot; alt=&quot;Email icon&quot; /&gt;
                  Drop me an email: aurelioderosa@gmail.com
                &lt;/a&gt;
              &lt;/li&gt;
              &lt;li&gt;
                &lt;a href=&quot;mailto:a.derosa@audero.it&quot; target=&quot;_blank&quot;&gt;
                  &lt;img src=&quot;images/email-icon.png&quot; alt=&quot;Email icon&quot; /&gt;
                  Drop me an email (alternative address): a.derosa@audero.it
                &lt;/a&gt;
              &lt;/li&gt;
              &lt;li&gt;
                &lt;a href=&quot;https://twitter.com/AurelioDeRosa&quot; target=&quot;_blank&quot;&gt;
                  &lt;img src=&quot;images/twitter-icon.png&quot; alt=&quot;Twitter icon&quot; /&gt;
                  Follow me on Twitter (@AurelioDeRosa)
                &lt;/a&gt;
              &lt;/li&gt;
              &lt;li&gt;
                &lt;a href=&quot;http://it.linkedin.com/in/aurelioderosa/en&quot; target=&quot;_blank&quot;&gt;
                  &lt;img src=&quot;images/linkedin-icon.png&quot; alt=&quot;LinkedIn icon&quot; /&gt;
                  View my profile on LinkedIn
                &lt;/a&gt;
              &lt;/li&gt;
              &lt;li&gt;
                &lt;a href=&quot;https://bitbucket.org/AurelioDeRosa&quot; target=&quot;_blank&quot;&gt;
                  &lt;img src=&quot;images/bitbucket-icon.png&quot; alt=&quot;BitBucket icon&quot; /&gt;
                  Visit my repository on BitBucket (AurelioDeRosa)
                &lt;/a&gt;
              &lt;/li&gt;
            &lt;/ul&gt;
          &lt;/article&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/body&gt;
&lt;/html&gt;
</pre><h3>Style Tuning</h3><p>By default, jQuery Mobile will truncate long titles inside the <code>&lt;header&gt;</code> and the <code>&lt;footer&gt;</code>, adding an ellipsis at the end of the truncated text. However, this method also applies to other kind of elements like buttons. I don&#8217;t like this behavior very much, so in the very short stylesheet, called <code>style.css</code>, which I mentioned in <a
title="Build a Currency Converter with jQuery Mobile and Cordova: Introduction" href="http://buildmobile.com/build-a-currency-converter-with-jquery-mobile-and-cordova/" target="_blank">the previous article</a>, I changed it by applying the rule <code>white-space: normal !important;</code>. Apart from that, I just centered my photo in the credits page and applied some styles to the result of the calculation.</p><p>The source of the stylesheet is the following:</p><pre class="brush: css; title: ; notranslate">.ui-header .ui-title,
.ui-footer .ui-title,
.ui-btn-inner *
{
   white-space: normal !important;
}
.photo
{
   text-align: center;
}
#result-title
{
   margin-bottom: 0.2em
}
#result
{
   display: block;
   font-size: 1.5em;
   text-align: center;
}</pre><h3>Conclusion</h3><p>In this second part of the series, I described the two essential HTML pages and outlined the key points of each. Although the app is very small, the markup is semantic and rich thanks to the use of several new HTML5 tags and attributes. Apart from these elements, the most important feature is probably the <a
title="jQuery Mobile Layout Grids" href="http://jquerymobile.com/demos/1.2.0/docs/content/content-grids.html" target="_blank">jQuery Mobile layout grid system</a> that allows you to create responsive and equally-spaced multi-column layouts. Due to the fact that the business logic isn&#8217;t yet complete, the files aren&#8217;t very useful at the moment. Additionally, if you try to wrap them using Cordova, as soon as you visit one of the external links in <code>aurelio.html</code>, and then go back using the back button, you&#8217;ll see that the credit page will lose the framework&#8217;s style enhancements, as well as any custom styles applied. This issue will be discussed in the next articles of the series, where I&#8217;ll show you the solution to these problems, and I&#8217;ll also describe some of the JavaScript files that power the &#8220;Currency Converter&#8221; app.</p><div
class='after-content-widget-1'><div
id="sitepointcontextualcontentmanagerwidget-5" class="widget widget_sitepointcontextualcontentmanagerwidget"><div
class="dfp-ad show-desktop"><div
id="div-gpt-ad-1340873946991-4" style="width: 728px; height: 90px;"> <script type="text/javascript">googletag.cmd.push(function() { googletag.display("div-gpt-ad-1340873946991-4"); });</script> </div></div></div></div>]]></content:encoded> <wfw:commentRss>http://www.sitepoint.com/build-a-currency-converter-with-jquery-mobile-and-cordova-part-2/feed/</wfw:commentRss> <slash:comments>2</slash:comments> <series:name><![CDATA[Build a Currency Converter with jQuery Mobile and Cordova]]></series:name> </item> <item><title>Build a Currency Converter with jQuery Mobile and Cordova: Introduction</title><link>http://www.sitepoint.com/build-a-currency-converter-with-jquery-mobile-and-cordova/</link> <comments>http://www.sitepoint.com/build-a-currency-converter-with-jquery-mobile-and-cordova/#comments</comments> <pubDate>Fri, 08 Feb 2013 00:02:14 +0000</pubDate> <dc:creator>Aurelio De Rosa</dc:creator> <category><![CDATA[Mobile]]></category> <category><![CDATA[Mobile Web Development]]></category> <category><![CDATA[Mobile Web Tutorials]]></category> <category><![CDATA[jquery mobile]]></category> <category><![CDATA[mobile]]></category> <category><![CDATA[Tutorials]]></category> <guid
isPermaLink="false">http://buildmobile.com/?p=5433</guid> <description><![CDATA[Earlier this year, I ran a series of articles on how to Build a Location-Based Mobile App With HTML5 and Javascript. If you enjoyed that series, you can follow this new series, which will teach you how to build a currency converter with some of the technologies that you may already have in your mobile [...]]]></description> <content:encoded><![CDATA[<p></p><p>Earlier this year, I ran a series of articles on how to <a
href="http://buildmobile.com/series/build-a-location-based-mobile-app-with-html5-and-javascript/" target="_blank">Build a Location-Based Mobile App With HTML5 and Javascript.</a> If you enjoyed that series, you can follow this new series, which will teach you how to build a currency converter with some of the technologies that you may already have in your mobile development arsenal. Like the previous project, this will be a hybrid application built with HTML, CSS, and JavaScript with the support of several frameworks like jQuery, jQuery Mobile, and Cordova (also known as PhoneGap). In a very imaginative moment of inspiration, I gave this app the highly-creative title &#8220;Currency Converter.&#8221;<br
/> <span
id="more-65950"></span><br
/> For those of you that don&#8217;t have a precise understanding of what a <em>hybrid app</em> is, it is <q
cite="http://buildmobile.com/native-hybrid-or-web-apps/">built using web technologies, and then wrapped in a platform-specific shell that allows the it to be installed just like a native app.</q> For an in-depth overview on this subject and the differences between native, hybrid, and web apps, take a look at <a
href="http://buildmobile.com/native-hybrid-or-web-apps/" target="_blank">Native, Hybrid or Web Apps?</a>.<div
id='div-gpt-ad-1328644474660-10' style='width:728px; height:90px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1328644474660-10'); });</script> </div></p><p>The goal of this series isn&#8217;t to copy the previous one with a different kind of app. While we will cover Web Storage and the Notification API, this series will feature two new Cordova APIs: the Globalization and the InAppBrowser API. The first has been introduced in the release 2.2.0, while the second was included in the last stable version (2.3.0). For more about the 2.2.0 version, read <a
title="What’s New in PhoneGap 2.2?" href="http://buildmobile.com/whats-new-in-phonegap-2-2/" target="_blank">What&#8217;s New in PhoneGap 2.2?</a></p><p>In this first and introductory article, I&#8217;ll explain the app features, the technologies used, and its structure.</p><h3>The App Requirements</h3><p>As I said, this app is very small and easy to understand. We&#8217;re developing a currency converter that allows developers to update the conversions rates as needed based on the European Central Bank (<abbr
title="European Central Bank">ECB</abbr>) currency RSS feed. One of the most important feature is that, once retrieved, the currency conversion rates are saved using the Web Storage API, so the user can use the application offline. Additionally, as soon as the user launches &#8220;Currency Converter,&#8221; the app will check for an Internet connection, and if one is unavailable, the app will search for previously-stored rates.</p><p>Being based on the <abbr
title="European Central Bank">ECB</abbr> feed, I want to emphasize that it&#8217;ll support only the currencies provided by the feed and nothing else. To enhance the user experience, the app will save the last currency used for a conversion, so at the next start of the application, the user will find their last-used currency. In addition, the date and time of the last update will be stored too, so that the user knows how recent (or old) his conversion rates are.</p><p>By default, the text will be shown in English, but it will be developed to support others languages (which is obviously important when developing an international currency app). If the mobile device uses a language supported by &#8220;Currency Converter,&#8221; the app will be automatically translated as soon as the app initializes. Apart from English, the final repository will also support Italian, French, and Spanish. I&#8217;m sorry but I&#8217;m unable to translate into other languages. However, once I&#8217;ll publish the repository, you&#8217;ll be free to contribute additional translations using other languages.</p><h3>The Technologies Involved</h3><p>In the introduction, I described which technologies will be used to create the code, however the following list will give you a more detailed understanding of what we&#8217;ll be utilizing:</p><ul><li><strong>HTML5</strong>: Used to create the markup of the pages.</li><li><strong>CSS</strong>: Most of the CSS enhancements will be done by jQuery Mobile, so I&#8217;ll use just few lines of custom CSS code.</li><li><strong>JavaScript</strong>: This is the language used to write the business logic, so this is really a must-have skill to understand this series.</li><li><strong>jQuery</strong>: It&#8217;ll be used mainly to select elements and attach event handlers.</li><li><strong>jQuery Mobile</strong>: This framework is used to automatically enhance the application interface.</li><li><strong>Cordova (PhoneGap)</strong>: Cordova will be used to wrap the files, so you can compile them and install the result just like a native app.</li></ul><p>Since version 1.3.0 of jQuery Mobile isn&#8217;t yet stable (at the time of writing, however, it&#8217;s in &#8220;release candidate&#8221; status), I&#8217;ll use the version 1.2.0. If you need a reminder of the differences between these versions, I described them at length in the articles <a
title="What’s New in jQuery Mobile 1.2.0?" href="http://buildmobile.com/whats-new-in-jquery-mobile-1-2-0/" target="_blank">What’s New in jQuery Mobile 1.2.0?</a> and <a
title="Build Lists and Popups in Minutes Using jQuery Mobile" href="http://buildmobile.com/working-with-jquery-mobile-1-2-0/" target="_blank">Build Lists and Popups in Minutes Using jQuery Mobile</a>. The Cordova version used will be version 2.3.0 to use the following new APIs:</p><ul><li><strong>Globalization API</strong>: It provides <q
cite="http://docs.phonegap.com/en/2.3.0/cordova_globalization_globalization.md.html#Globalization">an object to obtain information and perform operations specific to the user&#8217;s locale and timezone.</q> For example, it provides the <code>getPreferredLanguage()</code> method to get the string identifier for the client&#8217;s current language and the <code>numberToString()</code> method that returns a number formatted as a string according to the client&#8217;s user preferences. More on this API in the <a
href="http://docs.phonegap.com/en/2.3.0/cordova_globalization_globalization.md.html#Globalization" target="_blank">Globalization official doc</a>.</li><li><strong>InAppBrowser API</strong>: It&#8217;s <q
cite="http://docs.phonegap.com/en/2.3.0/cordova_inappbrowser_inappbrowser.md.html#InAppBrowser">a web-browser that is shown in your app when you use the <code>window.open</code> call</q>. You can find more information on this API by reading the <a
href="http://docs.phonegap.com/en/2.3.0/cordova_inappbrowser_inappbrowser.md.html#InAppBrowser" target="_blank">InAppBrowser official doc</a>.</li><li><strong>Web Storage API</strong>: This provides access to the devices storage options. If you want an in-depth explanation, read <a
title="An Overview of the Web Storage API" href="http://www.sitepoint.com/an-overview-of-the-web-storage-api/" target="_blank">An Overview of the Web Storage API</a>.</li></ul><p>Just like the previous series, &#8220;Currency Converter&#8221; will be developed with the assumption that the compilation will be done using the Adobe cloud service, called <a
title="Adobe PhoneGap Build" href="http://build.phonegap.com" target="_blank">Adobe PhoneGap Build</a>. It will be the service itself that includes the correct Cordova library for each platform at compiling time. To discover the reasoning behind using this technology, take a look at the discussion provided in <a
title="Build a Location-Based Mobile App With HTML5 and Javascript: Part 1" href="http://buildmobile.com/build-a-location-based-mobile-app-with-html5-and-javascript-part-1/" target="_blank">the first part of the series</a>. The link to the final, completed source code will be given in the final part of the series and hosted on <a
title="Aurelio De Rosa's repository" href="https://bitbucket.org/AurelioDeRosa" target="_blank">BitBucket repository</a>.</p><h3>The Project&#8217;s Structure</h3><p>To start the project, create a folder and rename it &#8220;currency-converter&#8221;. Now. create three sub-folders within this main folder: css, images, and js. Now download the jQuery (I&#8217;ll use version 1.8.3) and jQuery Mobile libraries. Put the jQuery and the JavaScript file of jQuery Mobile inside of the &#8220;js&#8221; folder, and then place the jQuery Mobile CSS file inside of the &#8220;css&#8221; folder. Finally, put the jQuery Mobile bundled images into the &#8220;images&#8221; folder.</p><p>In the root of the project folder I&#8217;ll create the HTML files, the <a
title="Adobe PhoneGap Build configuration file" href="https://build.phonegap.com/docs/config-xml" target="_blank">Adobe PhoneGap Build configuration file</a>, the default splash screen, and the application&#8217;s icon. Apart from the files we already put in place, we&#8217;ll write the following:</p><ul><li><strong>index.html</strong>: This is the entry point of &#8220;Currency Converter&#8221; and the only page that the user will interact with. Being the entry point, I&#8217;ll put links to the libraries used inside the <code>&lt;head&gt;</code> section of the index.html file. It will have the button to update the conversion rates, as well as the button to access the credits page.</li><li><strong>aurelio.html</strong>: This is the credits page, so nothing special here.</li><li><strong>style.css</strong>: The file containing the few custom lines of CSS used by the app.</li><li><strong>jquery.mobile.config.js</strong>: It&#8217;ll contain the custom configuration of the jQuery Mobile framework.</li><li><strong>currency.js</strong>: This file represents a currency object and will have the methods to retrieve, save, and load the currencies using the Web Storage API. In addition, it will have a compare method that will be used for sorting.</li><li><strong>functions.js</strong>: This will contain the function to initialize the project, translate the <code>index.html</code> page, update the conversion rates, and some other utility functions that I&#8217;ll explain further in the next articles in the series.</li><li><strong>settings.js</strong>: This file will be used to save and load the app settings mentioned before, including the last currencies used and the time of the last currency conversion rate update.</li><li><strong>translation.js</strong>: This will contain the object having the strings to translate the <code>index.html</code> page.</li><li><strong>config.xml</strong>: This XML file will have the metadata of the applications and will be used by the Adobe cloud service to store settings like the app version number and the package contents.</li></ul><p>Apart from this list, &#8220;Currency Converter&#8221; will have some additional images stored within the &#8220;images&#8221; folder, as well as one of the plugins I developed called <a
title="Audero Text Changer official repository" href="https://bitbucket.org/AurelioDeRosa/audero-text-changer" target="_blank" class="broken_link">Audero Text Changer</a>. It&#8217;s a very lightweight jQuery Mobile plugin that allows you to easily change the text of elements on your pages without breaking the enhancements made by the framework. So, as you might guess, I&#8217;ll use this plugin to translate the application into various spoken languages. If you need more information about this plugin, I wrote about it in <a
title="Customize Your jQuery Mobile Interface with Specialized Plugins" href="http://buildmobile.com/how-to-change-texts-in-your-jquery-mobile-apps-without-breaking-widgets/" target="_blank">Customize Your jQuery Mobile Interface with Specialized Plugins</a>.</p><h3>Conclusion</h3><p>In this first part, I illustrated the features and the structure of &#8220;Currency Converter.&#8221; I also showed you the technologies that will be involved for its implementation. Now that you know what you need to follow the rest of the series, take the time to study the technologies, so that you&#8217;ll be ready for the next part of the series, where I&#8217;ll dive into the code and describe how to create the HTML pages.</p><div
class='after-content-widget-1'><div
id="sitepointcontextualcontentmanagerwidget-5" class="widget widget_sitepointcontextualcontentmanagerwidget"><div
class="dfp-ad show-desktop"><div
id="div-gpt-ad-1340873946991-4" style="width: 728px; height: 90px;"> <script type="text/javascript">googletag.cmd.push(function() { googletag.display("div-gpt-ad-1340873946991-4"); });</script> </div></div></div></div>]]></content:encoded> <wfw:commentRss>http://www.sitepoint.com/build-a-currency-converter-with-jquery-mobile-and-cordova/feed/</wfw:commentRss> <slash:comments>5</slash:comments> <series:name><![CDATA[Build a Currency Converter with jQuery Mobile and Cordova]]></series:name> </item> <item><title>Responsive Web Design: Fluid Layouts</title><link>http://www.sitepoint.com/responsive-web-design-fluid-layouts/</link> <comments>http://www.sitepoint.com/responsive-web-design-fluid-layouts/#comments</comments> <pubDate>Tue, 29 Jan 2013 01:55:56 +0000</pubDate> <dc:creator>Annarita Tranfici</dc:creator> <category><![CDATA[Mobile]]></category> <category><![CDATA[Mobile Web Development]]></category> <guid
isPermaLink="false">http://buildmobile.com/?p=5346</guid> <description><![CDATA[After focusing on general concepts and how to use fonts responsively in the first two articles of the responsive web design series, let&#8217;s delve into fluid layouts. In this third part of the series, I&#8217;ll demonstrate when fluid layouts are really needed, as well as when you could opt for a different solution that isn&#8217;t necessarily [...]]]></description> <content:encoded><![CDATA[<p></p><p>After focusing on general concepts and how to use fonts responsively in <a
href="http://buildmobile.com/series/understanding-responsive-web-design/" target="_blank">the first two articles of the responsive web design series</a>, let&#8217;s delve into fluid layouts. In this third part of the series, I&#8217;ll demonstrate when fluid layouts are really needed, as well as when you could opt for a different solution that isn&#8217;t necessarily responsive. Let&#8217;s look at a few specific techniques and applications.</p><p>To understand whether or not a flexible layout is the right choice for your project, you have know, understand, and consider the other solutions available. In fact, only by evaluating the strengths and weaknesses of each method will you have the opportunity to validate your layout choice.</p><p>There are four different layout types: <strong>fixed-width layouts</strong>, <strong>liquid</strong> (or fluid) <strong>layouts</strong>, <strong>elastic layouts</strong>, and <strong>hybrid layouts</strong>. Let&#8217;s analyze them one by one.</p><h3>Fixed-Width Layouts</h3><p>In fixed-width layouts, the width of the site is bound to a certain number of pixels. Generally, the measure chosen is 960 pixels. This is because with the passing of time, developers have found 960 pixels to be the best size for grid layouts, because the number is easily divisible by 3, 4, 5, 6, 8, 10, 12 and 15.<div
id='div-gpt-ad-1328644474660-10' style='width:728px; height:90px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1328644474660-10'); });</script> </div></p><p>Even today, fixed-width layouts are among the most commonly used in the web, most likely because the rigidity of the layout provides a sense of stability and control. If you know the width of your site across all browsers and devices, you can create graphics with precise, complete control over the result.</p><p>However, the fixed-width layouts have some disadvantages. As I have said in the <a
href="http://buildmobile.com/series/understanding-responsive-web-design/" target="_blank">previous articles</a>, designers who want to create a fixed-width website have to keep in mind that every aspect of their work has to be usable and clearly visible to a large number of screens, browsers, and devices. The wide variety of devices on the market at this time, as well as the consequently great variability of screen sizes makes creating one-size-fits-all content quite a challenging task, and arguably a challenge that outweighs the precision and control of fixed-width design.</p><p>A common example of fixed-width websites gone wrong involves screens smaller than 960 pixels, which are surprisingly common. The site will not be fully displayed, and you&#8217;ll see a very awkward (and unattractive) horizontal scrollbar. The fact that these small screens are usually operated with fingertips instead of cursors only compounds the width woes.</p><p>Problems occur also in the opposite situation, when the screen size is greater than 960 pixels. In these cases, the website layout is surrounded by a large amount of white space and, obviously, this would certainly not be the solution that a good web designer aspires to see. Designers and users would rather make the most of the generous width of larger screens.</p><h3>Liquid Layouts</h3><p>The first basic difference between the fixed-width type of layout we&#8217;ve just analyzed and liquid layouts is the measurements of their size. The fixed-width layouts are measured in pixels, but for liquid or fluid layouts, dimensions are defined in percentages, and as you might expect, this affords greater malleability and fluidity. In other words, by setting a percentage, you won&#8217;t have to think about device size or screen width, and consequently, you can find a reasonable solution for each case because your design&#8217;s size will adapt to the size of the device used.</p><p>Liquid layouts are closely linked to media queries and special styles for optimization. Percentage-based widths alone will likely not be enough to accommodate your design for a large variety of display sizes. We will see later how to get a perfect result from liquid layouts.</p><h3>Elastic Layouts</h3><p>Elastic layouts are somewhat similar to liquid layouts. The main difference is once again the unit of measurement for size. The size indicator for elastic layouts is neither in pixels nor percentages; it&#8217;s measured in <em>ems</em>.</p><p>An <em>em</em> is the equivalent of the size (in pixels) defined in the <em>font-size</em> CSS rule. For example, if we style our text with a <em>font-size</em> of 20 pixels, 1 em would be equal to 20 pixels, 2 ems would correspond to 40, and so on.</p><p>This type of layout gives the developer strong typographic control. Since the vast majority of layouts are predominantly populated with text, the precision of type treatments makes elastic layouts a strong contender for many projects. However, even with this type of solution, there is a risk of an unpleasant and unaesthetic horizontal scroll bar in some rare cases.</p><h3>Hybrid Layouts</h3><p>Finally, as the term suggests, there are hybrid layouts, which combine the characteristics of two or more of the layouts discussed above. For example, the designer might decide to assign a fixed size (in pixels) to certain elements of the page (a sidebar or a footer) while for the remaining (for example the <code></code><code></code>that contains the main content) choosing a variable width (in percentages or ems).</p><p>Obviously, this approach has its own set of limitations and disadvantages—if you assign a sidebar a fixed width of 200 pixels and set a value of 80% for the rest of the content, you might find a horizontal scrollbar on screens smaller than 1000 pixels, since the main column does not have the space necessary to expand itself. In lesser cases, you&#8217;ll just have an elements that are unusually large or unusually small for their intended purposes. But you can easily address all of these issues, as we&#8217;ll see later.</p><h3>Conclusion</h3><p>At this point, you may be wondering what the best solution is for your specific projects, and which of the four types of layouts listed above is best suited for the responsive approach. As you might guess, each layout type has its advantages and disadvantages. It all depends on the needs you want to fulfill and the characteristics of your personal project.</p><p>It would be easy to make a knee-jerk, reactionary declaration that one of these layout options is universally superior to the others, but they shouldn&#8217;t be considered mutually-exclusive options or competitors. Rather, they should be considered techniques that can be used in conjunction. Many of these techniques aren&#8217;t possible without the others. For example, <em>ems</em> are meaningless without a fixed declaration of <em>font-size</em>. Similarly, media queries will be ineffective without inferring precise widths and making accommodations for popular screen sizes.</p><p>We&#8217;ll get into some real-world applications of all of these techniques in the next article in the series.</p><p><em>Want to learn more about Responsive Web Design? Check out SitePoint&#8217;s new book, <a
href="http://www.sitepoint.com/books/responsive1/" target="_blank">Jump Start Responsive Web Design</a>!</em></p><div
class='after-content-widget-1'><div
id="sitepointcontextualcontentmanagerwidget-5" class="widget widget_sitepointcontextualcontentmanagerwidget"><div
class="dfp-ad show-desktop"><div
id="div-gpt-ad-1340873946991-4" style="width: 728px; height: 90px;"> <script type="text/javascript">googletag.cmd.push(function() { googletag.display("div-gpt-ad-1340873946991-4"); });</script> </div></div></div></div>]]></content:encoded> <wfw:commentRss>http://www.sitepoint.com/responsive-web-design-fluid-layouts/feed/</wfw:commentRss> <slash:comments>10</slash:comments> <series:name><![CDATA[Understanding Responsive Web Design]]></series:name> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using memcached
Database Caching 49/81 queries in 0.105 seconds using memcached
Object Caching 2234/2404 objects using memcached

Served from: www.sitepoint.com @ 2013-05-13 14:46:02 --