Porting WebWorks Applications to Cordova

Follow these steps to convert a WebWorks application to Cordova for use with the QNX CAR platform.

  1. Install the QNX SDK for HTML5, which is available as a downloadable .zip archive from the QNX Download Center. You'll find instructions for setting up the SDK in the archive installation note (html5sdk_archive_install.html) as well as in a README file included with the SDK.
    Note:

    If you already have the native packaging tools (e.g. blackberry-nativepackager), you can simply download Cordova for QNX CAR from GitHub:

    https://github.com/qnxcar/cordova-qnxcar

    If you use any WebWorks extensions for the QNX CAR platform, you can also download the equivalent Cordova plugins from GitHub:

    https://github.com/qnxcar/cordova-qnxcar-plugins

  2. In your application's index.html file, locate the script tag that references webworks.js and replace it with the following:

    <script src="local:///cordova.js" type="text/javascript" charset="utf-8"></script>

  3. Your WebWorks apps may have used a listener to notify you when the document was loaded:

    document.addEventListener("webworksready", ready);

    Replace that listener with the following:

    document.addEventListener("deviceready", ready);

    Note: This listener should be added from a function called in the body's load event. For example:
    [...]
      <script>
      function onLoad() {
        document.addEventListener("deviceready", ready);
      }
      </script>
    </head>
    <body onload="onLoad()">
    [...]
    
    
  4. Change all of your WebWorks event listeners. If you were using extensions (known as plugins in Cordova) with asynchronous events, you'll need to update your listeners. Change all instances of this:

    blackberry.event.addEventListener("eventname", callback());

    to this:

    document.addEventListener("eventname", callback());

  5. Set up a Cordova-style config.xml file. Here's an example you can follow:
    <?xml version='1.0' encoding='utf-8'?>
    <widget id="sampleapp" version="1.0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:rim="http://www.blackberry.com/ns/widgets">
        <name>Sample App</name>
        <author>QNX Software Systems Limited</author>
        <content src="index.html" />
        <icon src="icon.png" />
        <rim:permissions>
            <rim:permit>access_shared</rim:permit>
        </rim:permissions>
        <access uri="http://google.com.com" subdomains="true" />
        <feature name="com.qnx.car.sensors" required="true" version="1.0.0"/>
    </widget>
    
Note: For instructions on creating plugins, see "Creating Your Own Cordova Plugin" in the HTML5 Developer's Guide, which is included in the documentation for the QNX SDK for Apps and Media.