Giter VIP home page Giter VIP logo

backbone.js-jquerymobile-boilerplate-template's Introduction

Current Status

24.March.2013

For more information about this project, more explanations and updates go to

https://github.com/raDiesle/backbone-fundamentals/blob/gh-pages/chapters/10-mobile-applications.md

as well as

https://github.com/raDiesle/backbone-fundamentals/tree/gh-pages/practicals/todo-jqm-app

which was already merged with the trunk and will be released in the book.

Backbone and jquerymobile JQM Boilerplate code

This project provides a bulletproof template + build process to develop an application by using jQuery mobile and backbone.js The aim is to provide it in Addy Osmanis Backbone Fundamentals

It consists of:

  • Backbone.js 0.9.2

  • extended super call (supports multiple hierarchies of inerheritance)

  • Lodash ( performance improved version of underscore + AMD support) 0.5

  • jQuery Toolkit 1.8.0

  • jQuery Mobile 1.1.1

  • Require.js (as an AMD loader) 2.0.5

  • Handlebars.js ( instead, underscore js or any other template engine can be used) 1.0.beta.6

  • Grunt.js as build tool, like ant or maven, to precompile handlebars.js templates, and r.js optimizer tasks

  • Grunt bbb a collection of tasks, containing grunt-contrib task collection

  • code structure and super-classes for clean code and easy reuse

Table of contents

Quick start

Preparations:

  • Checkout from git with your favourite tool or cmd. For those who are new, I would recommand usage of Eclipse Git, Webstorm or Tortoise Git
  • Open your command line tool
  • cd to the project folder "backbone.js-jquerymobile-boilerplate-template"
  • Download and install node.js for your os system and run in your project folder:
Installation setup

// Installation setup, 0.4.0 grunt required npm uninstall -g grunt npm install -g grunt-cli npm install grunt --save-dev npm install -g bbb

// To install grunt-tasks e.g.: npm install grunt-release --save-dev npm install grunt-contrib --save-dev npm install grunt-contrib-connect --save-dev ...

Run application

// Run the application grunt server

// While developing to recreate handlebar templates: grunt liveload

// Manual update handlebars templates grunt handlebars

// first steps to create prod release files grunt release

###General

###Abstract classes for simple usage

Use case:

For any jQuery mobile page view. (To e.g. support transparent dialogs, the page will be removed from the DOM when the same page is requested again)

How to use:
  • getSpecificTemplateValues() is an abstract method. The json values are used for the handlebars.js context variables.
  • id is the pageID, which will automatically load the name of the template
  • if you want to use your own page template ( instead of "basic_page_simple"), override getTemplateID in your class
Examples:

An example usage for a simple JQM page:

ConcreteExampleView = BasicView.extend({
    id: "content",
    getSpecificTemplateValues : function(){
  		return "something"
  	}
});
Use case:

It will render the page as dialog with or without validation. The previous page will be displayed transparent.

How to use
  • Define transparentBackgroundPageElID, which is the previous pageID
  • Define this.model.settings.validation.rules as validation rules. (see jQuery.Validation for more information)
  • Override onSuccessfulValidation : function(){}, which will be called, per default, if the form was submitted and validation is successful.
.transparent {
    background-color: orange;
    zoom: 1;
    filter: alpha(opacity = 50);
    opacity: 0.5;
}

.ui-dialog-background {
    opacity: 0.5;
    display: block !important;
    -webkit-transition: opacity 0.5s ease-in;
}
Examples
define([
    "backbone", "modules/view/abstract/BasicDialog"],
    function (Backbone, BasicDialog) {
        return BasicDialog.extend({
            id : "editTodoDialog",
            model : new Backbone.Model.extend({
                settings : {
                  validation : {
                    rules : {
                      title : {
                        "required" : true,
                        "min" : 5
                      }
                    }
                  }
                },
            }),
            headerTitle : "Edit Todo",
            transparentBackgroundPageElID : "Todos",
            getSpecificTemplateValues : function () {
                return this.model.toJSON();
            },
            onSuccessfulValidation : function () {
                this.model.save({title : $("#edit_title", this.el).val()});
                window.location = ""; // route to another page(close dialog)
            }
        });
    });

Extending Validateable will use the jquery.validate plugin with jquery mobile like described here: http://www.elijahmanor.com/2011/02/jquery-mobile-form-validation.html

Use case

Pages, where validation has to be applied. The validate rules are part of the model under this property this.model.settings.validation.rules

How to use
  • Define this.model.settings.validation.rules as validation rules. (see jQuery.Validation for more information)
  • Override onSuccessfulValidation : function(){}, which will be called, per default, if the form was submitted and validation is successful.
label.error {
    color: red;
    font-size: 16px;
    font-weight: normal;
    line-height: 1.4;
    margin-top: 0.5em;
    width: 100%;
    float: none;
}
Examples
define([
    "backbone", "modules/view/abstract/Validateable"],
    function (Backbone, Validateable) {
        return Validateable.extend({
            id : "editTodoDialog",
            model : new Backbone.Model.extend({
               settings : {
                  validation : {
                    rules : {
                      title : {
                        "required" : true,
                        "min" : 5
                    }
                  }
                }
              },
            }),
            headerTitle : "Edit Todo",
            getSpecificTemplateValues : function () {
                return this.model.toJSON();
            },
            onSuccessfulValidation : function () {
                this.model.save({title : $("#edit_title", this.el).val()});
            }
        });
    });

run to compile all templates found in app/templates to dist/debug/ Partials will be registered to Handlebars.partials, Templates to window.JST['templateName'] by default.

bbb handlebars or bbb watch

dynamic scripting and jQuery Mobile

see jQuery Mobile documentation There are two ways to render HTML code (loaded by template) to jQuery Mobile HTML code:

GRUNT:

  • concat - Concatenate files.
  • init - Generate project scaffolding from a predefined template.
  • lint - Validate files with JSHint.
  • min - Minify files with UglifyJS.
  • qunit - Run QUnit unit tests in a headless PhantomJS instance.
  • server - Start a static web server.
  • test - Run unit tests with nodeunit.
  • watch - Run predefined tasks whenever watched files change.

clean - Clear files and folders.

coffee - Compile CoffeeScript files into JavaScript.

compress - Compress files and folders using gzip or zip.

handlebars - Compile handlebars templates to JST file.

jade - Compile Jade templates to HTML.

jst - Compile underscore templates to JST file.

less - Compile LESS files to CSS.

mincss - Minify CSS files.

requirejs - Optimize RequireJS projects using r.js.

stylus - Compile Stylus files into CSS.

To support right behavior in e.g. navigation and use default backbone.js routing, use the following properties:

   $(document).bind("mobileinit", function(){
        $.mobile.ajaxEnabled = false;
        $.mobile.hashListeningEnabled = false;
        $.mobile.pushStateEnabled = false;
        $.mobile.linkBindingEnabled = false;
        $.mobile.defaultPageTransition = "none";
        $.mobile.page.prototype.options.degradeInputs.date = true; // optional
        $.mobile.page.prototype.options.domCache = false; // optional
        $.mobile.defaultDialogTransition = "none"; // optional depends on performance
   });

If you want to enable transitions per device ( where you expect good performance) you can use logic per device like described here http://backbonefu.com/2012/01/jquery-mobile-and-backbone-js-the-ugly/:

var iosDevice = ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) ? true : false;
 
  $.extend(  $.mobile , {
    slideText :  (iosDevice) ? "slide" : "none",
    slideUpText :  (iosDevice) ? "slideup" : "none",
    defaultPageTransition:(iosDevice) ? "slide" : "none",
    defaultDialogTransition:(iosDevice) ? "slide" : "none"
  });

Backbone.history.start({ pushState: false }); is used to work properly with forward/back buttons pushState: true will only work with modern browsers( fails for some mobile browsers as well)

  • Make an Addy Osmani TodoMVC application out of it. -> ongoing
  • Implement good back button functionality e.g. for dialog
  • add subview support with jQuery Mobile and backbone -> partly
  • Extend documentation
  • Write a chapter in Addy Osmani Backbone fundamentals about this project
  • Add tests ( jasmine + sinon.js + + phantom.js ? + continous integration with jstestdriver and jenkins)
  • Make a mobile + desktop app out of it, using common code

uses the jQuery Mobile Router plugin ( extends/manipulates the existing backbone.js routing)

The knowledge about how to run JQM with backbone is partially derived by results of several resources:

http://stackoverflow.com/questions/10904433/jquery-mobile-require-js-and-backbone

http://addyosmani.github.com/backbone-fundamentals/

http://coenraets.org/blog/2012/03/using-backbone-js-with-jquery-mobile/

https://github.com/azicchetti/jquerymobile-router

https://github.com/buildmobile/backbone.js/tree/master/js

Thanks for them !

backbone.js-jquerymobile-boilerplate-template's People

Contributors

andho avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

backbone.js-jquerymobile-boilerplate-template's Issues

Missing handlebars

In the app/config.js, you have this entry:

    'handlebars.compiled':"../dist/debug/handlebars_packaged"

Can you check in the js file, or describe how to create the 'dist' locally.

thanks!

error in handlebars_packaged.js

I followed the setup instructions but when I start the server and go to the page, I see the following error in the console:

handlebars_packaged.js:89
Uncaught TypeError: Cannot read property 'helperMissing' of undefined

I found a couple of other instances of this bug cropping up:
gruntjs/grunt-contrib#47
handlebars-lang/handlebars.js#60

I'm also getting this error:

jquery.js:8214
GET http://127.0.0.1:8000/assets/js/libs/require.js?_=1349901991863 404 (Not Found)

I'm thinking it might be an issue of using a more recent version of grunt-contrib. I'm using 2012.09.10, v0.2.0

jqm.config.js + SELECT widget with many options

There's a problem with jqm-config.js + SELECT widget with many options.
JQM renders SELECT widget in different ways depending on their sizes [see http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.js line 8553] . If the widget is too big JQM creates a new page and goes to it. When the execution gets line 3928 JQM tries to call active.url.indexOf( dialogHashKey ) , but active.url is undefined.

grunt release

in Gruntfile the task:
grunt.registerTask("release", ["clean", "handlebars", "requirejs", "concat", "copy"]);
when "requirejs" task completed, all requeired libs and app combined to /dist/debug/require.js,
but in "concat" and "copy" task all dependent libs are also copy to release folder, in index.html files :
script data-main="/app/config" src="/assets/js/libs/require.js"
also repeatly require every libs ,what 's why ? why not only need require.js file?

Build fails

Cannot run boilerplate.

I think there is something wrong in the handlebars build.
In handlebar_packaged.js I get:
this['JST']['app/templates/basic/template_basic_page_simple.handlebars']
and should be getting this['JST']['template_basic_page_simple']

Also, grunt debug build fails while running "requirejs:mainConfigFile" (requirejs) task

Error: Missing either an "out" or "dir" config value. If using "appDir" for a
full project optimization, use "dir". If you want to optimize to one file,
use "out".

Any clue?

Todos template broken

Did you mean to include the {{> welcome_partial}} instead of the missing {{> _header}} partial?

Also, check you have an incomplete input tag.

Thanks and cheers!

Error when executing "bbb handlebars"

Hi there,

I have follow your installation instructions, but when I get to the handlebars precompilation step I got this error:
Error: TypeError: Object # has no method 'options'
at Object.module.exports (/var/www/sparked/cab-mobile/node_modules/grunt-contrib/node_modules/grunt-contrib-handlebars/tasks/handlebars.js:35:24)
at Object.task.registerMultiTask.thisTask (/usr/lib/node_modules/bbb/node_modules/grunt/lib/grunt/task.js:109:15)
at Object.task.registerTask.thisTask.fn (/usr/lib/node_modules/bbb/node_modules/grunt/lib/grunt/task.js:58:16)
at Task. (/usr/lib/node_modules/bbb/node_modules/grunt/lib/util/task.js:343:36)
at Task. (/usr/lib/node_modules/bbb/node_modules/grunt/lib/util/task.js:319:9)
at Task. (/usr/lib/node_modules/bbb/node_modules/grunt/lib/util/task.js:346:11)
at Task.start (/usr/lib/node_modules/bbb/node_modules/grunt/lib/util/task.js:359:5)
at Object.grunt.tasks (/usr/lib/node_modules/bbb/node_modules/grunt/lib/grunt.js:143:8)
at Object.module.exports as cli
at Object. (/usr/lib/node_modules/bbb/bbb.js:98:7)

Could it be due to a change in bbb contrib?

Many thanks for your awesome work!

Project status?

Hi there. I just came across this project and was wondering if you were interested in continuing working on it. It's a great start for something that could end up in Backbone Fundamentals.

I'm currently looking for someone that might be interested in taking ownership of redoing the chapter on mobile development with Backbone/TodoMVC app using jQuery mobile (that works around common issues like routing) would be really great to have in the book.

Basically, a tutorial for the app that highlights some of the challenges of getting both working together a little like our existing tutorials. Would you be interested in that? You'd get a credit at the start of the chapter in both the online and physical version of the book.

JQM dialog integration

If you open a dialog from the index and then close it with jquerymobile close button (not the one on the template instantly navigates), the dialog gets first dismissed and afterwards the navigation is made from index to index.
The jqm page gets removed from dom, then recreated, and then $.mobile.changePage fails because its trying to make a transition from a page that no longer exists to the one recently created.
This has to do with jqm dialog dismiss button.

I have another issue about dialog usage. If included as a route outcome, a dialog page is retained in the navigation history.
A dialog only relates to the page that created it; back a forth navigation should bypass a dialog.
I am not sure what would be the right approach to solve this issue, what do you think?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.