Creating Cordova jQuery Mobile Apps Rapidly

Cordova jQuery npm plugin allows you to add jQuery mobile’s ready-made templates to your existing Apache Cordova app using a neat easy-to-use CLI.

You can install Cordova jQuery npm plugin using the following npm command:
npm install -g cordova-jquery

Once you install it, you can start using it by executing cordova-jquery command from your Apache Cordova app’s root directory. The next six videos shows you how to create six Cordova jQuery mobile apps with different templates (Multipages, Header Navigation Bar, Persistent Navigation Bar, External Panel, Accordion, and ListView).

As shown in the videos below, after executing cordova-jquery command, all what you need to do is to choose the template you would like to apply to your existing Cordova app. All of the examples below work on Apache Cordova version 5.1.1 (The latest Cordova release until the moment).

Cordova jQuery plugin supports the following templates.

  1. Multiple Pages
    This template will apply a simple two page jQuery mobile template to your index.html file.
  2. Header Navbar
    This template will apply a three page jQuery mobile template to your index.html file that includes a header navbar for the header on each page.
  3. Persistent Navbar
    This template will apply a three page jQuery mobile template to your index.html file that includes a persistent navbar for the footer on each page.
  4. External Panel
    This template will apply an external panel to jQuery mobile. When this option is selected you will also be prompted for additional information such as which side of the page you’d like the panel to open on (left, right) and which reveal style would you like (reveal, push, overlay)
  5. Accordion
    This template will apply three sections’ jQuery mobile accordion template to your index.html file. Your existing content will be placed as part of the first section. It is important to note that you have to make sure that your existing content parent element does not use CSS “absolute” position in order to be controlled by the accordion section.
  6. List View
    This template will apply a jQuery mobile list view template to your index.html file. The first item of the list view points to your existing content page, and the second and the third items of the list view point to two placeholder pages.

The main objective of this plugin is to facilitate the usage of the jQuery Mobile in Apache Cordova, so feel free to use it and submit any issues you are facing to:
https://github.com/Open-I-Beam/cordova-jquery-npm/issues

Related Plugin Videos:

Tip #4: Storing Media Files Properly in Cordova iOS apps

In order to avoid being surprised by the loss of your recorded audio file in iOS, you should be aware of how to properly record and store a media file in Cordova iOS.
Generally, in order to record an audio file in Apache Cordova, you can use the Cordova Media object as follows:

var recordingMedia = new Media(mediaFilePath, recordingSuccess, recordingError);

// Start Recording Audio
recordingMedia.startRecord();

// Stop Recording Audio
recordingMedia.stopRecord();

// Release Media resource
recordingMedia.release();

As shown in the code above, in order to record an audio file in Apache Cordova, you need to do the following:

  1. Create a Media object (recordingMedia) and specify mediaFilePath (the path of the audio file), recordingSuccess (the success callback which will be called if the media operation succeeds), recordingError (the error callback which will be called if the media operation fails).
  2. Start recording the audio by calling recordingMedia.startRecord().
  3. After completing the audio recording, call recordingMedia.stopRecord() and then release the used Media object by calling recordingMedia.release()

In iOS, if you set mediaFilePath to the audio file name only without specifying any path (e.g "test.wav"), you may be surprised to find your audio file stored under the iOS app’s tmp directory (which is located under the iOS app’s sandbox directory). It is very important to be aware that the iOS app’s tmp directory content can be deleted automatically by iOS at anytime by iOS.

In order to avoid losing your app’s recorded files, just place the "documents://" prefix before the audio file name as follows.

var recordingMedia = new Media("documents://test.wav", recordingSuccess, recordingError);

Doing this will make the recorded audio file stored under the iOS app’s Documents directory. The iOS app’s Documents directory is located under the app’s sandbox directory and is suitable for storing the app files.

Reference:

“JavaScript Mobile Application Development” Book:

Tip #2: Boosting Cordova’s jQuery Mobile Apps Performance

One of the common issues when you use jQuery Mobile with Apache Cordova in many of the platforms especially in the old versions Android platform is that you feel that the transitions between the app pages are slow.

The solution for this problem is to disable jQuery mobile transition effects as follows when the jQuery mobile is loaded as follows.

    $.mobile.defaultPageTransition   = 'none';
    $.mobile.defaultDialogTransition = 'none';

Disabling transition effects will dramatically boost your Cordova’s jQuery mobile app’s transition performance.

Do not believe people who say jQuery Mobile is slow with Apache Cordova.

Reference:

“JavaScript Mobile Application Development” Book: