Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Structuring a PhoneGap jQuery Mobile Application

I am currently building a game in phonegap using jQuery Mobile frame work. What i have ended up with is lots of spaghetti code with one html and several js classes.

I was interested to know if there are any good guides to create a structured jQuery Mobile Application that follows MVC pattern.

I found a good guide for creating a MVC App with Sencha Touch. I was looking for something similar with jQuery Mobile.

like image 413
Nithin Avatar asked Nov 08 '11 00:11

Nithin


2 Answers

I have a rather large application and this is how I have it structured

css
    -- all css files
images
    -- all image files
js
    controller.js -- page events and element actions. Also contains PhoneGap specific methods
    core
        forms.js -- working with forms, saving info
        mobile.js -- basic definitions, AJAX communications
        encrypt.js -- encryption
        global.js   -- helper functions
        storage.js  -- database storage wrapper
    cw
        client.js -- a client object, > 400 lines of js code
        Objects.js -- all other needed objects with <50 lines of js code each
        question.js  -- a question object, > 500 lines of js code
        service.js    -- a service object, > 700 lines of js code
    jq
        jquery-ui.min.js
        jquery.min.js
        jquery.mobile.min.js
        phonegap-1.1.0.js

add_client.html
clients.html
client_list.html
index.html            -- the only file that is structured like a real full html file
manager.html
schedule.html
service.html

aside for my index.html file, all other .html files are stubs. They only contain the <div data-role='page'></div> and other needed html elements that define the page and its intended functionality.

I develop the app on VS2010, using Chrome as my debugger. When I feel good with my progress, I copy everything over to my mac to a folder in an Eclipse project ( for Android devices ) which is also a linked reference in my xCode project ( for iOS devices ).

I have been working on this project for about 3-4 months now and once I got past the learning curve of jQM and PhoneGap, have been making very good progress with this structure.

like image 175
Sage Avatar answered Oct 28 '22 19:10

Sage


Have you seen the wiki entry?

http://wiki.phonegap.com/w/page/36868306/UI%20Development%20using%20jQueryMobile#GettingstartedwithJQueryMobile

and to see some code have a look @

Sample Application using jQuery Mobile and PhoneGap http://coenraets.org/blog/2011/10/sample-application-with-jquery-mobile-and-phonegap/

like image 3
Stephen Gennard Avatar answered Oct 28 '22 17:10

Stephen Gennard