
In this tutorial, you create a fully functional employee directory application with PhoneGap. You will learn:
- How to use different local data storage strategies.
- How to use several PhoneGap APIs such as Geolocation, Contacts, and Camera.
- How to handle specific mobile problems such as touch events, scrolling, styling, page transitions, etc.
- How to build an application using a single page architecture and HTML templates.
- How to build (compile and package) an application for 6 platforms using PhoneGap Build.
To complete this tutorial, all you need is a code editor, a modern browser, and a connection to the Internet. A working knowledge of HTML and JavaScript is assumed, but you don’t need to be a JavaScript guru.
Setting Up
- Download the assets for the workshop here.
- Unzip the file anywhere on your file system.
- If your code editor allows you to “open a directory”, open the phonegap-workshop-master directory.
- Follow the instructions below.
Part 1: Choosing a Local Storage Option
Step 1: Explore different persistence mechansisms
Open the following files in phonegap-workshop-master/js/storage, and explore the different persistence stores they define:
- memory-store.js (MemoryStore)
- ls-store.js (LocalStorageStore)
- websql-store.js (WebSqlStore)
Step 2: Test the application with different persistence mechanisms
To change the local persistence mechanism for the application:
- In index.html: add a script tag for the corresponding .js file: memory-store.js, ls-store.js, or websql-store.js.
- In js/main.js: Instantiate the specific store in the initialize() function of the app object: MemoryStore, LocalStorageStore, or WebSqlStore.
- To test the application, open index.html in your browser, or simply double-click index.html on your file system. Type a few characters in the search box to search employees by name. Clicking an employee link doesn’t produce any result at this time.
Part 2: Building with PhoneGap Build
- If you don’t already have one, create an account on http://build.phonegap.com.
- Click the “new app” button to create a new application on PhoneGap Build.
- Either point to a GitHub repository where you push your code for this workshop, or zip up your phonegap-workshop directory and upload it to PhoneGap Build.
- Click the Ready to build button.
The iOS button will immediately turn red because the iOS build requires that you upload your Apple Developer certificate and an application provisioning profile. You can find more information here if you haven’t already signed up for the Apple Developer Program. If you don’t have an iOS device, or if you are not ready to upload your developer certificate, you can skip step 5 and keep running the application in the browser or a non iOS device.
- To upload your Apple developer certificate and your application provisioning profile:
- Click the red iOS button.
- Select “add a key” in the “No key selected” dropdown.
- Provide a title for your developer certificate/provisioning profile combination (for example: EmployeeDirectory), select your developer certificate and provisioning profile, enter your developer certificate password, and click “submit key”.
- Go back to the list of apps. Click the iOS button for your application again. Select your newly added key in the iOS dropdown. The iOS build will start automatically.
- When the build process completes, use a QR Code reader app to install the Employee Directory application on your device.
To fine tune your build preferences:
- In the phonegap-workshop directory, create a file namedconfig.xml file defined as follows (make the necessary adjustments for id, author, etc.):
<?xml version="1.0" encoding="UTF-8"?> <widget xmlns = "http://www.w3.org/ns/widgets" xmlns:gap = "http://phonegap.com/ns/1.0" id = "org.coenraets.employeedirectory" versionCode = "10" version = "1.1.0"> <name>Employee Directory</name> <description> A simple employee directory application </description> <author href="http://coenraets.org" email="ccoenraets@gmail.com"> Christophe Coenraets </author> <feature name="http://api.phonegap.com/1.0/camera"/> <feature name="http://api.phonegap.com/1.0/contacts"/> <feature name="http://api.phonegap.com/1.0/file"/> <feature name="http://api.phonegap.com/1.0/geolocation"/> <feature name="http://api.phonegap.com/1.0/media"/> <feature name="http://api.phonegap.com/1.0/network"/> <feature name="http://api.phonegap.com/1.0/notification"/> </widget> - If you used the GitHub approach, sync with GitHub and click the Update Code button in PhoneGap Build.
If you used the zip file approach, zip up your phonegap-workshop directory and upload the new version to PhoneGap Build
Part 3: Using Native Notification
A default webview alert gives away the fact that your application is not native. In this section, we set up the basic infrastructure to display native alerts when the application is running on a device, and fall back to default browser alerts when running in the browser.
- In index.html, add the following script tag (as the first script tag at the bottom of the body):
<script src="phonegap.js"></script>
This instructs PhoneGap Build to inject a platform specific version of phonegap.js at build time. In other words, phonegaps.js doesn’t need to be (and shouldn’t be) present in your project folder.
- In main.js, define a function named showAlert() inside the app object. If navigator.notification is available, use its alert() function. Otherwise, use the default browser alert() function.
showAlert: function (message, title) { if (navigator.notification) { navigator.notification.alert(message, null, title, 'OK'); } else { alert(title ? (title + ": " + message) : message); } }, - Test the notification logic by displaying a message when the application store has been initialized: Pass an anonymous callback function as an argument to the constructor of the persistence store (the store will call this function after it has successfully initialized). In the anonymous function, invoke the showAlert() function.
initialize: function() { var self = this; this.store = new MemoryStore(function() { self.showAlert('Store Initialized', 'Info'); }); $('.search-key').on('keyup', $.proxy(this.findByName, this)); } - Test the application: When you run the application in the browser, you should see a standard browser alert. When you run the application on your device, you should see a native alert.
Part 4: Setting Up a Single Page Application
A single page application is a web application that lives within a single HTML page. The “views” of the application are injected into- and removed from the DOM as needed as the user navigates through the app. A single page application architecture is particularly well suited for mobile apps:
- The absence of continual page refreshes provides a more fluid / closer to native experience.
- The UI is entirely created at the client-side with no dependency on a server to create the UI, making it an ideal architecture for applications that work offline.
In this section, we set up the basic infrastructure to turn Employee Directory into a single page application.
- In index.html: remove the HTML markup inside the body tag (with the exception of the script tags).
- In main.js, define a function named renderHomeView() inside the app object. Implement the function to programmatically add the Home View markup to the body element.
renderHomeView: function() { var html = "<div class='header'><h1>Home</h1></div>" + "<div class='search-view'>" + "<input class='search-key'/>" + "<ul class='employee-list'></ul>" + "</div>" $('body').html(html); $('.search-key').on('keyup', $.proxy(this.findByName, this)); }, - Modify the initialize() function of the app object. In the anonymous callback function of the store constructor, call the renderHomeView() function to programmatically display the Home View.
initialize: function() { var self = this; this.store = new MemoryStore(function() { self.renderHomeView(); }); }
Part 5: Using Handlebar Templates
Writing HTML fragments in JavaScript and programmatically inserting them into the DOM is tedious. It makes your application harder to write and harder to maintain. HTML templates address this issue by decoupling the UI definition (HTML markup) from your code. There are a number of great HTML template solutions: Mustache.js, Handlebar.js, and Underscore.js to name a few.
In this section, we create two templates to streamline the code of the Employee Directory application. We use Handlebar.js but the smae result can be achieved using the other HTML template solutions.
Modify index.html as follows:
- Add a script tag to include the handlebar.js library:
<script src="lib/handlebars.js"></script>
- Create an HTML template to render the Home View. Add this script tag as the first child of the body tag:
<script id="home-tpl" type="text/x-handlebars-template"> <div class='header'><h1>Home</h1></div> <div class='search-bar'><input class='search-key' type="text"/></div> <ul class='employee-list'></ul> </script> - Create an HTML template to render the employee list items. Add this script tag immediately after the previous one:
<script id="employee-li-tpl" type="text/x-handlebars-template"> {{#.}} <li><a href="#employees/{{this.id}}">{{this.firstName}} {{this.lastName}}<br/>{{this.title}}</a></li> {{/.}} </script>
Modify main.js as follows:
- In the initialize() function of the app object, add the code to compile the two templates defined above:
this.homeTpl = Handlebars.compile($("#home-tpl").html()); this.employeeLiTpl = Handlebars.compile($("#employee-li-tpl").html()); - Modify renderHomeView() to use the homeTpl template instead of the inline HTML:
renderHomeView: function() { $('body').html(this.homeTpl()); $('.search-key').on('keyup', $.proxy(this.findByName, this)); }, - Modify findByName() to use the employeeLiTpl template instead of the inline HTML:
findByName: function() { var self = this; this.store.findByName($('.search-key').val(), function(employees) { $('.employee-list').html(self.employeeLiTpl(employees)); }); }, - Test the application.
Part 6: Creating a View Class
It’s time to provide our application with some structure. If we keep adding all the core functions of the application to the app object, it will very quickly grow out of control. In this section we create a HomeView object that encapsulates the logic to create and render the Home view.
Step 1: Create the HomeView Class
- Create a file called HomeView.js in the js directory, and define a HomeView class implemented as follows:
var HomeView = function(store) { } - Add the two templates as static members of HomeView.
var HomeView = function(store) { } HomeView.template = Handlebars.compile($("#home-tpl").html()); HomeView.liTemplate = Handlebars.compile($("#employee-li-tpl").html()); - Define an initialize() function inside the HomeView class. Define a div wrapper for the view. The div wrapper is used to attach the view-related events. Invoke the initialize() function inside the HomeView constructor function.
var HomeView = function(store) { this.initialize = function() { // Define a div wrapper for the view. The div wrapper is used to attach events. this.el = $('<div/>'); this.el.on('keyup', '.search-key', this.findByName); }; this.initialize(); } HomeView.template = Handlebars.compile($("#home-tpl").html()); HomeView.liTemplate = Handlebars.compile($("#employee-li-tpl").html()); - Move the renderHomeView() function from the app object to the HomeView class. To keep the view reusable, attach the html to the div wrapper (this.el) instead of the document body. Because the function is now encapsulated in the HomeView class, you can also rename it from renderHomeView() to just render().
this.render = function() { this.el.html(HomeView.template()); return this; }; - Move the findByName() function from the app object to the HomeView class.
this.findByName = function() { store.findByName($('.search-key').val(), function(employees) { $('.employee-list').html(HomeView.liTemplate(employees)); }); };
Step 2: Using the HomeView class
- In index.html, add a script tag to include HomeView.js (just before the script tag for main.js):
<script src="js/HomeView.js"></script>
- Remove the renderHomeView() function from the app object.
- Remove the findByName() function from the app object.
- Modify the initialize function() to display the Home View using the HomeView class:
initialize: function() { var self = this; this.store = new MemoryStore(function() { $('body').html(new HomeView(self.store).render().el); }); }
Part 7: Adding Styles and Touch-Based Scrolling
Step 1: Style the Application
- Add the Source Sans Pro font definition to the head of index.html
<script src="css/source-sans-pro.js"></script>
Source Sans Pro is part of the free Adobe Edge Web Fonts.
- Add styles.css to the head of index.html
<link href="css/styles.css" rel="stylesheet">
- In index.html, modify the home-tpl template: change the search-key input type from text to search.
- Test the application. Specifically, test the list behavior when the list is bigger than the browser window (or the screen)
Step 2: Native Scrolling Approach
- Modify the home-tpl template in index.html. Add a div wrapper with a scroll class around the ul element with a scroll:
<script id="home-tpl" type="text/x-handlebars-template"> <div class='header'><h1>Home</h1></div> <div class='search-bar'><input class='search-key' type="search"/></div> <div class="scroll"><ul class='employee-list'></ul></div> </script> - Add the following class definition to css/styles.css:
.scroll { overflow: auto; -webkit-overflow-scrolling: touch; position: absolute; top: 84px; bottom: 0px; left: 0px; right: 0px; }
Step 3: iScroll Approach
- Add a script tag to include the iscroll.js library:
<script src="lib/iscroll.js"></script>
- In HomeView.js, modify the findByName() function: Instantiate an iScroll object to scroll the list of employees returned. If the iScroll object already exists (), simply refresh it to adapt it to the new size of the list.
this.findByName = function() { store.findByName($('.search-key').val(), function(employees) { $('.employee-list').html(HomeView.liTemplate(employees)); if (self.iscroll) { console.log('Refresh iScroll'); self.iscroll.refresh(); } else { console.log('New iScroll'); self.iscroll = new iScroll($('.scroll', self.el)[0], {hScrollbar: false, vScrollbar: false }); } }); };
Part 8: Highlighting Tapped or Clicked UI Elements
- In styles.css, add a tappable-active class definition for tapped or clicked list item links. The class simply highlights the item with a blue background:
li>a.tappable-active { color: #fff; background-color: #4286f5; } - In main.js, define a registerEvents() function inside the app object. Add a the tappable_active class to the selected (tapped or clicked) list item:
registerEvents: function() { var self = this; // Check of browser supports touch events... if (document.documentElement.hasOwnProperty('ontouchstart')) { // ... if yes: register touch event listener to change the "selected" state of the item $('body').on('touchstart', 'a', function(event) { $(event.target).addClass('tappable-active'); }); $('body').on('touchend', 'a', function(event) { $(event.target).removeClass('tappable-active'); }); } else { // ... if not: register mouse events instead $('body').on('mousedown', 'a', function(event) { $(event.target).addClass('tappable-active'); }); $('body').on('mouseup', 'a', function(event) { $(event.target).removeClass('tappable-active'); }); } }, - Invoke the registerEvents() function from within the app object’s initialize() function.
- Test the application.
Part 9: View Routing
In this section, we add an employee details view. Since the application now has more than one view, we also add a simple view routing mechanism that uses the hash tag to determine whether to display the home view or the details view for a specific employee.
Step 1: Create the employee template
Open index.html and add a template to render a detailed employee view:
<script id="employee-tpl" type="text/x-handlebars-template">
<div class='header'><a href='#' class="button header-button header-button-left">Back</a><h1>Details</h1></div>
<div class='details'>
<img class='employee-image' src='img/{{firstName}}_{{lastName}}.jpg' />
<h1>{{firstName}} {{lastName}}</h1>
<h2>{{title}}</h2>
<span class="location"></span>
<ul>
<li><a href="tel:{{officePhone}}">Call Office<br/>{{officePhone}}</a></li>
<li><a href="tel:{{cellPhone}}">Call Cell<br/>{{cellPhone}}</a></li>
<li><a href="sms:{{cellPhone}}">SMS<br/>{{cellPhone}}</a></li>
</ul>
</div>
</script>
Step 2: Create the EmployeeView class
- Create a file called EmployeeView.js in the js directory, and define an EmployeeView class implemented as follows:
var EmployeeView = function() { } - Add the template as a static member of EmployeeView.
var EmployeeView = function() { } EmployeeView.template = Handlebars.compile($("#employee-tpl").html()); - Define an initialize() function inside the HomeView class. Define a div wrapper for the view. The div wrapper is used to attach the view related events. Invoke the initialize() function inside the HomeView constructor function.
var EmployeeView = function(employee) { this.initialize = function() { this.el = $('<div/>'); }; this.initialize(); } EmployeeView.template = Handlebars.compile($("#employee-tpl").html()); - Define a render() function implemented as follows:
this.render = function() { this.el.html(EmployeeView.template(employee)); return this; }; - In index.html, add a script tag to include EmployeeView.js (just before the script tag for main.js):
<script src="js/EmployeeView.js"></script>
Step 3: Implement View Routing
- In the app’s initialize() function, define a regular expression that matches employee details urls.
this.detailsURL = /^#employees\/(\d{1,})/; - In the app’s registerEvents() function, add an event listener to listen to URL hash tag changes:
$(window).on('hashchange', $.proxy(this.route, this)); - In the app object, define a route() function to route requests to the appropriate view:
- If there is no hash tag in the URL: display the HomeView
- If there is a has tag matching the pattern for an employee details URL: display an EmployeeView for the specified employee.
route: function() { var hash = window.location.hash; if (!hash) { $('body').html(new HomeView(this.store).render().el); return; } var match = hash.match(app.detailsURL); if (match) { this.store.findById(Number(match[1]), function(employee) { $('body').html(new EmployeeView(employee).render().el); }); } } - Modify the initialize() function to call the route() function:
initialize: function() { var self = this; this.detailsURL = /^#employees\/(\d{1,})/; this.registerEvents(); this.store = new MemoryStore(function() { self.route(); }); } - Test the application.
Part 10: Using the Location API
In this section, we add the ability to tag an employee with his/her location information. In this sample application, we display the raw information (longitude/latitude) in the employee view. In a real-life application, we would typically save the location in the database as part of the employee information and show it on a map.
- In index.html, add the following list item to the employee-tpl template:
<li><a href="#" class="add-location-btn">Add Location</a></li>
- In the initialize() function of EmployeeView, register an event listener for the click event of the Add Location list item:
this.el.on('click', '.add-location-btn', this.addLocation); - In EmployeeView, define the addLocation event handler as follows:
this.addLocation = function(event) { event.preventDefault(); console.log('addLocation'); navigator.geolocation.getCurrentPosition( function(position) { $('.location', this.el).html(position.coords.latitude + ',' + position.coords.longitude); }, function() { alert('Error getting location'); }); return false; }; - Test the Application
Part 11: Using the Contacts API
In this section, we use the PhoneGap Contacts API to provide the user with the ability to add an employee to the device’s contact list.
- In index.html, add the following list item to the employee template:
<li><a href="#" class="add-contact-btn">Add to Contacts</a></li>
- In the initialize() function of EmployeeView, register an event listener for the click event of the Add to Contacts list item:
this.el.on('click', '.add-contact-btn', this.addToContacts); - In EmployeeView, define the addToContacts event handler as follows:
this.addToContacts = function(event) { event.preventDefault(); console.log('addToContacts'); if (!navigator.contacts) { app.showAlert("Contacts API not supported", "Error"); return; } var contact = navigator.contacts.create(); contact.name = {givenName: employee.firstName, familyName: employee.lastName}; var phoneNumbers = []; phoneNumbers[0] = new ContactField('work', employee.officePhone, false); phoneNumbers[1] = new ContactField('mobile', employee.cellPhone, true); // preferred number contact.phoneNumbers = phoneNumbers; contact.save(); return false; }; - Test the Application
Part 12: Using the Camera API
In this section, we use the PhoneGap Camera API to provide the user with the ability to take a picture of an employee, and use that picture as the employee’s picture in the application. We do not persist that picture in this sample application.
- In index.html, add the following list item to the employee template:
<li><a href="#" class="change-pic-btn">Change Picture</a></li>
- In the initialize() function of EmployeeView, register an event listener for the click event of the Change Picture list item:
this.el.on('click', '.change-pic-btn', this.changePicture); - In EmployeeView, define the changePicture event handler as follows:
this.changePicture = function(event) { event.preventDefault(); if (!navigator.camera) { app.showAlert("Camera API not supported", "Error"); return; } var options = { quality: 50, destinationType: Camera.DestinationType.DATA_URL, sourceType: 1, // 0:Photo Library, 1=Camera, 2=Saved Photo Album encodingType: 0 // 0=JPG 1=PNG }; navigator.camera.getPicture( function(imageData) { $('.employee-image', this.el).attr('src', "data:image/jpeg;base64," + imageData); }, function() { app.showAlert('Error taking picture', 'Error'); }, options); return false; }; - Test the Application
Part 13: Sliding Pages with CSS Transitions
- Add the following classes to styles.css:
.page { position: absolute; width: 100%; height: 100%; -webkit-transform:translate3d(0,0,0); } .stage-center { top: 0; left: 0; } .stage-left { left: -100%; } .stage-right { left: 100%; } .transition { -moz-transition-duration: .375s; -webkit-transition-duration: .375s; -o-transition-duration: .375s; } - Inside the app object, define a slidePage() function implemented as follows:
slidePage: function(page) { var currentPageDest, self = this; // If there is no current page (app just started) -> No transition: Position new page in the view port if (!this.currentPage) { $(page.el).attr('class', 'page stage-center'); $('body').append(page.el); this.currentPage = page; return; } // Cleaning up: remove old pages that were moved out of the viewport $('.stage-right, .stage-left').not('.homePage').remove(); if (page === app.homePage) { // Always apply a Back transition (slide from left) when we go back to the search page $(page.el).attr('class', 'page stage-left'); currentPageDest = "stage-right"; } else { // Forward transition (slide from right) $(page.el).attr('class', 'page stage-right'); currentPageDest = "stage-left"; } $('body').append(page.el); // Wait until the new page has been added to the DOM... setTimeout(function() { // Slide out the current page: If new page slides from the right -> slide current page to the left, and vice versa $(self.currentPage.el).attr('class', 'page transition ' + currentPageDest); // Slide in the new page $(page.el).attr('class', 'page stage-center transition'); self.currentPage = page; }); }, - Modify the route() function as follows:
route: function() { var self = this; var hash = window.location.hash; if (!hash) { if (this.homePage) { this.slidePage(this.homePage); } else { this.homePage = new HomeView(this.store).render(); this.slidePage(this.homePage); } return; } var match = hash.match(this.detailsURL); if (match) { this.store.findById(Number(match[1]), function(employee) { self.slidePage(new EmployeeView(employee).render()); }); } },
Awesome!
very nice tutorial, very simple and clear. I am in the process of adding transition to my apps, and find part 8, part 13 is very useful.
In my case, css a:active would be better than part8 touchstart, touchend event hack on the mobile device. The later one will have a problem if you touch the button or anchor, and hold it, move to other place and release it. The css class “tappable-active” will not be removed.
Hello Christophe.
A great job you’re doing, thank you.
We miss you in the Flex World :)
excellent tutorial – best I have seen on creating a good phonegap application architecture
I haven’t made it all the way through yet but I have found a couple of items that may be of use to others:
1) Step #4 is missing ending “;” for html var declaration statement – this renders in Chrome desktop browser but not on Android
2) Step #5.1 tag needs to be placed before the app.js tag (maybe obvious but..)
also I should mention that I am using PhoneGap 2.2 in Eclipse development environment
again thanks for the tutorial and architecture example!
Thank you for this great job!
Very nice tutorial.. Thanks a lot (y)
Thanks for the great tutorial! Question: After selecting an employee and “sliding” back to the homepage, the search box seems to be disabled. Anyone know why? Thanks.
I have the same issue. Anyone can help us? Thanks!
This is great tutorial, i had pleasure reading and following. There is some code which didn’t work for me, like calling methods within event handlers. So I had to wrap them within anonymous functions and also give them context. For example this event handler this.el.on(‘keyup’, ‘.search-key’, this.findByName); had to be written llike var that = this; this.el.on(‘keyup’, ‘.search-key’, function(){that.findByName();});
My question is there a particular name for this pattern in JavaScript ? It reminds me some of BackboneJS structuring. Were you inspired by it?
It would be also great to see some ajax layers and how would that fit into a whole thing.
Awesome tutorial once again, thanks!
I had the same experience. Original code caused an error within jQuery. Vlad’s code worked.
Similarly in step 11.2 this is what worked for me:
this.el.on(‘click’, ‘.add-location-btn’, function(){that.addLocation(event);});
notice in particular that the event needed to be passed along to the addLocation function.
that should be section 10.2 – Using the Location API
Great tutorials. I’ve learned a lot.
How come in the websql-store.js you always drop the table and repopulate it? How come you don’t check the version first and not install it if there are no changes?
Christophe, very nice tutorial. I have a question for you. ;)
Windows Phone doesn’t support WebSQL. Can lawnchair be a valid alternative to store big size data? Please, advice.
Regarding to the search box disabled when going back to the home page, I solved it setting the id of the div element in HomeView.js to “homePage” and changing … not(‘.homePage’) … to … not(‘#homePage’) … in main.js.
That’s a great shout.
Thank you very much!
Very good tutorial. Now I have an idea of phonegap to see if it fits my needs.
Thanks for the best tutorial on Cordova/PhoneGap I have seen.
I’m having trouble with this function:
this.store.findById(Number(match[1]), function(employee)
In step 3.3.
I’m using memoryStore, and when I trace the callback there the parameters seem to be right. I’m using Cordova 2.30.
Check that you have the ‘employee’ in Part 9, step 2.
var EmployeeView = function(employee) { … }
It’s there in step 2.3, but not in step 2.1 – 2.2
Would just like to know if you are using jQuery? It looks like it in some examples code.
Hi,
is it possible to customize the splash screen and use the builder to build everything? For example creating the resource folder and put it in there and then upload it to phonegap builder?
Thanks in advance
“If you don’t have an iOS device, or if you are not ready to upload your developer certificate, you can skip step 5 and keep running the application in the browser or a non iOS device.”
However, I can not figure out how to skip step 5(upload apple developer certificate). The whole process just stopped.
ps: I’m using the sample code from this tutorial.
Thanks!
resolved!
It need about one hour to finish compiling and go to next step.
Thanks for this insightful tutorial!
Just one question: How can i import and use this code in eclipse?
thanks
Hi Christophe,
Thank you very much for posting this very well organized tutorial. This is by far the best working tutorial I have come across for native mobile app development.
Regards
Wow, native development?? Hardly, this is web development without the benefit of serving UI remotely. Just because it compiles into an “app” doesn’t make it “native”. It’s still depends on a browser, inferior JS engines and JS APIs, and HTML code.
Small typos: Part 9, Step 2, Para 3. HomeView should be EmployeeView, twice.
thanks¡¡¡¡¡¡ served me a lot to understand the framework
Hi, thank you for writing this tutorial.
The resulting app, after building it with PhoneGap Build, is really slow on my Nexus S. (No other apps are running in background)
Is there an active debug flag or something else, that should be unset for production release?
Or is this what we can expect, concerning performance?
Thx
Can we display images & details from json(other site) details,
for example
can display food item images, details from dynamic site(mysql)
Any example there?
Thank you for sharing so many excellent implementation tutorials! I figured I would have to go hunt for examples of these individually
Thanks for this awesome tuto !
if it can help : in HomeView.js, you must declare render() and findByName() functions BEFORE initialize() !
if not, you must use the Vladimir hack
… and if the search function not work after use back button, you can do that.
in main.js, slidePage() function, add an ID to homePage then, test it after to not delete this view
slidePage : function(page){
var currentPageDest,
self = this;
if(!this.currentPage){
$(page.el)
.attr(‘class’, ‘page stage-center’)
.attr(‘id’, ‘homePage’); // add ID !
$(‘body’).append(page.el);
this.currentPage = page;
return;
}
$(‘.stage-right, .stage-left’).not(‘#homePage’).remove(); // exclusion of the home page with the ID !
thanks a lot.
now, i can start my final task from college.
Thanks for this good tutorial..
Thank you! Awesomely done!
Hi,
Great tips.
I read here https://groups.google.com/forum/?fromgroups=#!searchin/phonegap/translate3d/phonegap/SlNAA9EOpxA/MAdTuFex4vMJ that ’3D CSS transforms don’t work on Android 2.x or Android 3.x at all.’!!
So your part 13 is limited to Android 4, correct?
Kind regards
J
When following your tutorials, I get the following error:
Uncaught SyntaxError: Unexpected token u Insertion.js:1
(anonymous function) Insertion.js:1
module.exports.send ripple.js:37
module.exports.initialize ripple.js:38
_baton.pass ripple.js:13
_baton.pass ripple.js:13
(anonymous function)
This is when I have created my own files and using your solution files. I am viewing the code via the cordova/phonegap emulator with ripple in chrome.
Any ideas?
Phonegap is easy to use and easy to rock. Thanks mr. Conraets for your great article !
I was made app because your tutorial is help me so much. :D
Will it work for the latest version? If not do you have some tutorial for the latest version of Phonegap?
What I need to do, If I want those animations works smoothly? If I tap the back button or simply choose person from list, animation is pathetic, even on quadcore devices.
Someone essentially help to make seriously posts I would state. This is the very first time I frequented your web page and thus far? I amazed with the research you made to create this particular publish amazing. Great job!
I almost never leave remarks, however i did some searching and
wound up here Tutorial: Developing a PhoneGap Application |
Christophe Coenraets. And I actually do have a couple of questions for you
if you tend not to mind. Could it be only me or does it seem like a few of these comments appear like written by brain dead individuals?
:-P And, if you are writing at additional online social sites, I would
like to follow everything new you have to post. Would you list of all of
all your social pages like your twitter feed, Facebook page or linkedin profile?
A wonderful tutorial – I learned many things and this helped me covered lots of new areas with JS based development for mobile phone..
Looking forward to see more from you. Wish you luck!
Hi Christophe,
Thanks a lot for this wonderful tutorial : it has been very helpful to me.
I have a little question : what should I do when phonegap build tells me that “This app isn’t using the latest version of PhoneGap. We recommend upgrading to 2.7.0″ ? Should I download latest version of phonegap to package my app instead of doing it online ?
Best regards,
NR
Hi, very nice tutorial, was a great help for me!
I have one question, the transitions between pages does some weird shit.
the moment I click a link, the transitions start, but the content of the first page suddenly jumps down
the content fades away, but is suddenly 50-100pixels lower before leaving the screen
transition left or right, it’s the same problem
Any idea?
Nevermind, fixed it…
Other question, anyone here who knows how to work with iScroll? The scrolling works but the content jumps back to the top as soon as I release my finger?
This is a completely useless tutorial
Getting this crappy technology to work with eclipse is impossible unless you just want to write “hello
world” .
Phonegap is a far greater problem and more of a hassle than actually learning android .
Don’t waste your time with this joke of a “technology” .
But wait ! They have a solution – give away your idea and thus create a thousand clone apps on Github and they will compile it for you.
That’s sweet.
Christophe, I am curious if there is some benefit to replacing all content within the body tag rather than say just the html inside a container div with main content, in turn keeping the header bar in place. Of course this would eliminate the use of the page slide effect as well but that’s not something I really need. A coworker of mine suggested that it may be a performance issue manipulating the DOM but if the entire HTML content of the body tag is being replaced, isn’t that DOM manipulation as well?
One thing that got me confused is that the chapter “Part 7: Adding Styles and Touch-Based Scrolling”
didn’t really affect the way the page looked, until I replaced
- $(‘body’).html(new HomeView(self.store).render().el);
+ $(‘body’).append(new HomeView(self.store).render().el);
(this change is spelled out much later in the last chapter but was not given at part 7 where it changes the entire “look”)
please address all the comments in this tutorial to make it awesomer :)
some parts of the code could be cleaned up. e.g:
if (this.homePage) {
this.slidePage(this.homePage);
} else {
this.homePage = new HomeView(this.store).render();
this.slidePage(this.homePage);
}
could be replaced by
if (!this.homePage) {
this.homePage = new HomeView(this.store).render();
}
this.slidePage(this.homePage);