Nomination mobile - part 1

This post its a part of a series about creating an app with node.js and express for Facebook... this time for mobile browsers

Version en espaƱol

Desktop version:

Part 10

Now that we have our beta version of nomination, lets create the mobile version so the mobile users can see it and we will help us later for pass this to phonegap

In this case we will use jquery-mobile (jqm) to create our mobile layouts
Our initial mockup is something like this:





Good, lets create our layout with jade, first lets upload everything we need to work with jquery-mobile to our project, upload the css, js and the images to our public folder in the project, dont forget to update the css to point where the images are in your setup...

Lets start with the "layoutm.jade" that describes the layout for mobile, this file goes into views

!!! 5
//if lt IE 7
  | <html class="no-js ie6 oldie" lang="en">
//if IE 7
  | <html class="no-js ie7 oldie" lang="en">
//if IE 8
  | <html class="no-js ie8 oldie" lang="en">
//if gte IE 9
  | <html class="no-js" lang="en">
  title= t('app.name')
  meta(name='description', content='Nomination')
  meta(name='author', content='mrpix')
  meta(name="viewport", content="width=device-width, initial-scale=1")
  link(rel="shortcut icon", href="/images/favicon.ico")
  link(rel="apple-touch-icon", href="/images/apple-touch-icon.png")
  // CSS
  link(rel="stylesheet", href="/stylesheets/jqm.css", type="text/css")
  - if (type === 'dashboard')
    link(rel="stylesheet", href="/stylesheets/dashboard.css", type="text/css")
  - else
    link(rel="stylesheet", href="/stylesheets/index.css", type="text/css")
     window.jQuery \|\| document.write("<script src='/javascripts/lib/jquery-1.7.1.min.js'>\\x3C/script>")
  != body
  script(defer, src='i18next/i18next.js', type='text/javascript')
  - if (type === 'dashboard')
    script(defer, src="/javascripts/mscript.js")
    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'UA-XXXXXXXX-X']);

    (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);

Here we are loading the css and the js for mobile, i18next and our functionality with mscript.js and at the end the google analytics part

OK, lets create the index mobile version in "indexm.jade" also in views folder

- var login = "/login";
- if (invited)
    - login = "/login?invited="+invited;
div(data-role="page", data-theme="d")
    div(data-role="header", data-theme="b")
        h1= t('app.name')

                    th= t('index.features')
                    td= t('index.feature1')
                    td= t('index.feature2')
                    td= t('index.feature3')
                    td= t('index.feature4')
                    td= t('index.feature5')
        a(href="#{login}", rel="external")
        - if (error)
            .error #{t(error)}
        img(src="/images/ipn.png", width="90px")
    div(data-role="footer", data-theme="b")
        h4 © Ivan Torres -MrPix

Line 1-3: check for any invited user

4: Create our page with the 'data-role="page"' attribute, with this we tell jqm that this div its a page container with the theme "d"

5-6: The hader div will have the title and "b" theme, the header style in jqm will put the title in the center and as a bar at the top of the page

8-29: the content of the page is defined with `data-role="content"`, in this case its just a table with the lsit of features and our login with facebook btn

30-31: page footer just have the copyright announcement and its rendered with "b" theme, applied with `data-role="footer"`

Sweet, lets update our route manager to test for mobile and if we have a mobile visitor send it to our new layout, lets update "roues/index.js"

Lets load our new module create in our past post, remember to install it with "npm install node-bowser" or update the package.json and do "npm install -d", problems with this let me know in the comments...

Load the module in line 5 and add a variable

bowser = require('node-bowser'),

In our main route lets use the module to decide with views we need to show

bt = new bowser(req);
if (bt.isMobile() || bt.isTablet()){
                    error : req.param('error'), 
                    type: 'index', 
                    invited: req.param('invited'),
                    layout: 'layoutm'
                    error : req.param('error'), 
                    type: 'index', 
                    invited: req.param('invited')

If its mobile or tablet we will show the mobile version if not our regular desktop version

Its enough for now, later posts we will add pages and functionality

Fork the code in github:


No comments:

Post a Comment