You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by za...@apache.org on 2014/06/10 12:00:55 UTC

[03/12] Manual tests fixed

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/a7c88d8f/camera/index.html
----------------------------------------------------------------------
diff --git a/camera/index.html b/camera/index.html
index b74dabb..4f48190 100644
--- a/camera/index.html
+++ b/camera/index.html
@@ -28,341 +28,10 @@
     <title>Cordova Mobile Spec</title>
     <link rel="stylesheet" href="../master.css" type="text/css" media="screen" title="no title" charset="utf-8">
     <script type="text/javascript" charset="utf-8" src="../cordova-incl.js"></script>
-
-
-<script type="text/javascript" charset="utf-8">
-
-    var deviceReady = false;
-    var platformId = cordova.require('cordova/platform').id;
-    var pictureUrl = null;
-    var fileObj = null;
-    var fileEntry = null;
-    var pageStartTime = +new Date();
-    
-    //default camera options
-    var camQualityDefault = ['quality value', 50];
-    var camDestinationTypeDefault = ['FILE_URI', 1];
-    var camPictureSourceTypeDefault = ['CAMERA', 1];
-    var camAllowEditDefault = ['allowEdit', false];
-    var camEncodingTypeDefault = ['JPEG', 0];
-    var camMediaTypeDefault = ['mediaType', 0];
-    var camCorrectOrientationDefault = ['correctOrientation', false];
-    var camSaveToPhotoAlbumDefault = ['saveToPhotoAlbum', true];
-    
-
-    //-------------------------------------------------------------------------
-    // Camera
-    //-------------------------------------------------------------------------
-
-    function log(value) {
-        console.log(value);
-        document.getElementById('camera_status').textContent += (new Date() - pageStartTime) / 1000 + ': ' + value + '\n';
-    }
-
-    function clearStatus() {
-        document.getElementById('camera_status').innerHTML = '';
-        document.getElementById('camera_image').src = 'about:blank';
-        var canvas = document.getElementById('canvas');
-        canvas.width = canvas.height = 1;
-        pictureUrl = null;
-        fileObj = null;
-        fileEntry = null;
-    }
-
-    function setPicture(url, callback) {
-		try {
-			window.atob(url);
-			// if we got here it is a base64 string (DATA_URL)
-			url = "data:image/jpeg;base64," + url;
-		} catch (e) {
-			// not DATA_URL
-		    log('URL: ' + url.slice(0, 100));
-		}    
-    
-        pictureUrl = url;
-        var img = document.getElementById('camera_image');
-        var startTime = new Date();
-        img.src = url;
-        img.onloadend = function() {
-            log('Image tag load time: ' + (new Date() - startTime));
-            callback && callback();
-        };
-    }
-
-    function onGetPictureError(e) {
-        log('Error getting picture: ' + e.code);
-    }
-
-    function getPictureWin(data) {
-        setPicture(data);
-        // TODO: Fix resolveLocalFileSystemURI to work with native-uri.
-        if (pictureUrl.indexOf('file:') == 0 || pictureUrl.indexOf('content:') == 0) {
-            resolveLocalFileSystemURI(data, function(e) {
-                fileEntry = e;
-                logCallback('resolveLocalFileSystemURI()', true)(e.toURL());
-            }, logCallback('resolveLocalFileSystemURI()', false));
-        } else if (pictureUrl.indexOf('data:image/jpeg;base64' == 0)) {
-        	// do nothing
-        } else {
-            var path = pictureUrl.replace(/^file:\/\/(localhost)?/, '').replace(/%20/g, ' ');
-            fileEntry = new FileEntry('image_name.png', path);
-        }
-    }
-
-    function getPicture() {
-        clearStatus();
-        var options = extractOptions();
-        log('Getting picture with options: ' + JSON.stringify(options));
-        var popoverHandle = navigator.camera.getPicture(getPictureWin, onGetPictureError, options);
-
-        // Reposition the popover if the orientation changes.
-        window.onorientationchange = function() {
-            var newPopoverOptions = new CameraPopoverOptions(0, 0, 100, 100, 0);
-            popoverHandle.setPosition(newPopoverOptions);
-        }
-    }
-
-    function uploadImage() {
-        var ft = new FileTransfer(),
-            uploadcomplete=0,
-            progress = 0,
-            options = new FileUploadOptions();
-        options.fileKey="photo";
-        options.fileName='test.jpg';
-        options.mimeType="image/jpeg";
-        ft.onprogress = function(progressEvent) {
-            log('progress: ' + progressEvent.loaded + ' of ' + progressEvent.total);
-        };
-        var server = "http://cordova-filetransfer.jitsu.com";
-
-        ft.upload(pictureUrl, server + '/upload', win, fail, options);
-        function win(information_back){
-            log('upload complete');
-        }
-        function fail(message) {
-            log('upload failed: ' + JSON.stringify(message));
-        }
-    }
-
-    function logCallback(apiName, success) {
-        return function() {
-            log('Call to ' + apiName + (success ? ' success: ' : ' failed: ') + JSON.stringify([].slice.call(arguments)));
-        };
-    }
-
-    /**
-     * Select image from library using a NATIVE_URI destination type
-     * This calls FileEntry.getMetadata, FileEntry.setMetadata, FileEntry.getParent, FileEntry.file, and FileReader.readAsDataURL.
-     */
-    function readFile() {
-        function onFileReadAsDataURL(evt) {
-            var img = document.getElementById('camera_image');
-            img.style.visibility = "visible";
-            img.style.display = "block";
-            img.src = evt.target.result;
-            log("FileReader.readAsDataURL success");
-        };
-
-        function onFileReceived(file) {
-            log('Got file: ' + JSON.stringify(file));
-            fileObj = file;
-
-            var reader = new FileReader();
-            reader.onload = function() {
-                log('FileReader.readAsDataURL() - length = ' + reader.result.length);
-            };
-            reader.onerror = logCallback('FileReader.readAsDataURL', false);
-            reader.readAsDataURL(file);
-        };
-        // Test out onFileReceived when the file object was set via a native <input> elements.
-        if (fileObj) {
-            onFileReceived(fileObj);
-        } else {
-            fileEntry.file(onFileReceived, logCallback('FileEntry.file', false));
-        }
-    }
-    function getFileInfo() {
-        // Test FileEntry API here.
-        fileEntry.getMetadata(logCallback('FileEntry.getMetadata', true), logCallback('FileEntry.getMetadata', false));
-        fileEntry.setMetadata(logCallback('FileEntry.setMetadata', true), logCallback('FileEntry.setMetadata', false), { "com.apple.MobileBackup": 1 });
-        fileEntry.getParent(logCallback('FileEntry.getParent', true), logCallback('FileEntry.getParent', false));
-        fileEntry.getParent(logCallback('FileEntry.getParent', true), logCallback('FileEntry.getParent', false));
-    };
-
-    /**
-     * Copy image from library using a NATIVE_URI destination type
-     * This calls FileEntry.copyTo and FileEntry.moveTo.
-     */
-    function copyImage() {
-        var onFileSystemReceived = function(fileSystem) {
-            var destDirEntry = fileSystem.root;
-
-            // Test FileEntry API here.
-            fileEntry.copyTo(destDirEntry, 'copied_file.png', logCallback('FileEntry.copyTo', true), logCallback('FileEntry.copyTo', false));
-            fileEntry.moveTo(destDirEntry, 'moved_file.png', logCallback('FileEntry.moveTo', true), logCallback('FileEntry.moveTo', false));
-        };
-
-        window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, onFileSystemReceived, null);
-    };
-
-    /**
-     * Write image to library using a NATIVE_URI destination type
-     * This calls FileEntry.createWriter, FileWriter.write, and FileWriter.truncate.
-     */
-    function writeImage() {
-        var onFileWriterReceived = function(fileWriter) {
-            fileWriter.onwrite = logCallback('FileWriter.write', true);
-            fileWriter.onerror = logCallback('FileWriter.write', false);
-            fileWriter.write("some text!");
-        };
-
-        var onFileTruncateWriterReceived = function(fileWriter) {
-            fileWriter.onwrite = logCallback('FileWriter.truncate', true);
-            fileWriter.onerror = logCallback('FileWriter.truncate', false);
-            fileWriter.truncate(10);
-        };
-
-        fileEntry.createWriter(onFileWriterReceived, logCallback('FileEntry.createWriter', false));
-        fileEntry.createWriter(onFileTruncateWriterReceived, null);
-    };
-
-    function displayImageUsingCanvas() {
-        var canvas = document.getElementById('canvas');
-        var img = document.getElementById('camera_image');
-        var w = img.width;
-        var h = img.height;
-        h = 100 / w * h;
-        w = 100;
-        canvas.width = w;
-        canvas.height= h;
-        var context = canvas.getContext('2d');
-        context.drawImage(img, 0, 0, w, h);
-    };
-
-    /**
-     * Remove image from library using a NATIVE_URI destination type
-     * This calls FileEntry.remove.
-     */
-    function removeImage() {
-        fileEntry.remove(logCallback('FileEntry.remove', true), logCallback('FileEntry.remove', false));
-    };
-
-    function testInputTag(inputEl) {
-        clearStatus();
-        // iOS 6 likes to dead-lock in the onchange context if you
-        // do any alerts or try to remote-debug.
-        window.setTimeout(function() {
-            testNativeFile2(inputEl);
-        }, 0);
-    };
-
-    function testNativeFile2(inputEl) {
-        if (!inputEl.value) {
-            alert('No file selected.');
-            return;
-        }
-        fileObj = inputEl.files[0];
-        if (!fileObj) {
-            alert('Got value but no file.');
-            return;
-        }
-        var URLApi = window.URL || window.webkitURL;
-        if (URLApi) {
-            var blobURL = URLApi.createObjectURL(fileObj);
-            if (blobURL) {
-                setPicture(blobURL, function() {
-                    URLApi.revokeObjectURL(blobURL);
-                });
-            } else {
-                log('URL.createObjectURL returned null');
-            }
-        } else {
-            log('URL.createObjectURL() not supported.');
-        }
-    }
-
-    function extractOptions() {
-        var els = document.querySelectorAll('#image-options select');
-        var ret = {};
-        for (var i = 0, el; el = els[i]; ++i) {
-            var value = el.value;
-            if (value === '') continue;
-            if (el.isBool) {
-                ret[el.keyName] = !!+value;
-            } else {
-                ret[el.keyName] = +value;
-            }
-        }
-        return ret;
-    }
-
-    function createOptionsEl(name, values, selectionDefault) {
-        var container = document.createElement('div');
-        container.style.display = 'inline-block';
-        container.appendChild(document.createTextNode(name + ': '));
-        var select = document.createElement('select');
-        select.keyName = name;
-        container.appendChild(select);
-        
-        // if we didn't get a default value, insert the blank <default> entry
-        if (selectionDefault == undefined) {
-            var opt = document.createElement('option');
-            opt.value = '';
-            opt.text = '<default>';
-            select.appendChild(opt);
-        }
-        
-        select.isBool = typeof values == 'boolean';
-        if (select.isBool) {
-            values = {'true': 1, 'false': 0};
-        }
-        
-        for (var k in values) {
-            var opt = document.createElement('option');
-            opt.value = values[k];
-            opt.textContent = k;
-            if (selectionDefault) {
-                if (selectionDefault[0] == k) {
-                    opt.selected = true;
-                }
-            }
-            select.appendChild(opt);
-        }
-        var optionsDiv = document.getElementById('image-options');
-        optionsDiv.appendChild(container);
-    }
-
-    /**
-     * Function called when page has finished loading.
-     */
-    function init() {
-        document.addEventListener("deviceready", function() {
-            deviceReady = true;
-            console.log("Device="+device.platform+" "+device.version);
-            createOptionsEl('sourceType', Camera.PictureSourceType, camPictureSourceTypeDefault);
-            createOptionsEl('destinationType', Camera.DestinationType, camDestinationTypeDefault);
-            createOptionsEl('encodingType', Camera.EncodingType, camEncodingTypeDefault);
-            createOptionsEl('mediaType', Camera.MediaType, camMediaTypeDefault);
-            createOptionsEl('quality', {'0': 0, '50': 50, '80': 80, '100': 100}, camQualityDefault);
-            createOptionsEl('targetWidth', {'50': 50, '200': 200, '800': 800, '2048': 2048});
-            createOptionsEl('targetHeight', {'50': 50, '200': 200, '800': 800, '2048': 2048});
-            createOptionsEl('allowEdit', true, camAllowEditDefault);
-            createOptionsEl('correctOrientation', true, camCorrectOrientationDefault);
-            createOptionsEl('saveToPhotoAlbum', true, camSaveToPhotoAlbumDefault);
-            createOptionsEl('cameraDirection', Camera.Direction);
-                          
-        }, false);
-        window.setTimeout(function() {
-            if (!deviceReady) {
-                alert("Error: Apache Cordova did not initialize.  Demo will not run correctly.");
-            }
-        },1000);
-    };
-
-</script>
+    <script type="text/javascript" charset="utf-8" src="./index.js"></script>      
 
   </head>
-  <body onload="init();" id="stage" class="theme">
+  <body id="stage" class="theme">
 
     <h1>Camera</h1>
     <div id="info" style="white-space: pre-wrap">
@@ -372,20 +41,20 @@
     </div>
     <h2>Cordova Camera API</h2>
     <div id="image-options"></div>
-    <div class="btn large" onclick="getPicture();">camera.getPicture()</div>
+    <div class="btn large getPicture">camera.getPicture()</div>
     <h2>Native File Inputs</h2>
-    <div>input type=file <input type="file" onchange="testInputTag(this)"></div>
-    <div>capture=camera <input type="file" accept="image/*;capture=camera" onchange="testInputTag(this)"></div>
-    <div>capture=camcorder <input type="file" accept="video/*;capture=camcorder" onchange="testInputTag(this)"></div>
-    <div>capture=microphone <input type="file" accept="audio/*;capture=microphone" onchange="testInputTag(this)"></div>
+    <div>input type=file <input type="file" class="testInputTag"></div>
+    <div>capture=camera <input type="file" accept="image/*;capture=camera" class="testInputTag"></div>
+    <div>capture=camcorder <input type="file" accept="video/*;capture=camcorder" class="testInputTag"></div>
+    <div>capture=microphone <input type="file" accept="audio/*;capture=microphone" class="testInputTag"></div>
     <h2>Actions</h2>
-    <div class="btn large" onclick="getFileInfo();">Get File Metadata</div>
-    <div class="btn large" onclick="readFile();">Read with FileReader</div>
-    <div class="btn large" onclick="copyImage();">Copy Image</div>
-    <div class="btn large" onclick="writeImage();">Write Image</div>
-    <div class="btn large" onclick="uploadImage();">Upload Image</div>
-    <div class="btn large" onclick="displayImageUsingCanvas();">Draw Using Canvas</div>
-    <div class="btn large" onclick="removeImage();">Remove Image</div>
-    <h2> </h2><div class="backBtn" onclick="backHome();">Back</div>
+    <div class="btn large getFileInfo">Get File Metadata</div>
+    <div class="btn large readFile">Read with FileReader</div>
+    <div class="btn large copyImage">Copy Image</div>
+    <div class="btn large writeImage">Write Image</div>
+    <div class="btn large uploadImage">Upload Image</div>
+    <div class="btn large displayImageUsingCanvas">Draw Using Canvas</div>
+    <div class="btn large removeImage">Remove Image</div>
+    <h2> </h2><div class="backBtn">Back</div>
   </body>
 </html>

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/a7c88d8f/camera/index.js
----------------------------------------------------------------------
diff --git a/camera/index.js b/camera/index.js
new file mode 100644
index 0000000..f9435d0
--- /dev/null
+++ b/camera/index.js
@@ -0,0 +1,344 @@
+var deviceReady = false;
+var platformId = cordova.require('cordova/platform').id;
+var pictureUrl = null;
+var fileObj = null;
+var fileEntry = null;
+var pageStartTime = +new Date();
+
+//default camera options
+var camQualityDefault = ['quality value', 50];
+var camDestinationTypeDefault = ['FILE_URI', 1];
+var camPictureSourceTypeDefault = ['CAMERA', 1];
+var camAllowEditDefault = ['allowEdit', false];
+var camEncodingTypeDefault = ['JPEG', 0];
+var camMediaTypeDefault = ['mediaType', 0];
+var camCorrectOrientationDefault = ['correctOrientation', false];
+var camSaveToPhotoAlbumDefault = ['saveToPhotoAlbum', true];
+
+
+//-------------------------------------------------------------------------
+// Camera
+//-------------------------------------------------------------------------
+
+function log(value) {
+    console.log(value);
+    document.getElementById('camera_status').textContent += (new Date() - pageStartTime) / 1000 + ': ' + value + '\n';
+}
+
+function clearStatus() {
+    document.getElementById('camera_status').innerHTML = '';
+    document.getElementById('camera_image').src = 'about:blank';
+    var canvas = document.getElementById('canvas');
+    canvas.width = canvas.height = 1;
+    pictureUrl = null;
+    fileObj = null;
+    fileEntry = null;
+}
+
+function setPicture(url, callback) {
+try {
+  window.atob(url);
+  // if we got here it is a base64 string (DATA_URL)
+  url = "data:image/jpeg;base64," + url;
+} catch (e) {
+  // not DATA_URL
+    log('URL: ' + url.slice(0, 100));
+}    
+
+    pictureUrl = url;
+    var img = document.getElementById('camera_image');
+    var startTime = new Date();
+    img.src = url;
+    img.onloadend = function() {
+        log('Image tag load time: ' + (new Date() - startTime));
+        callback && callback();
+    };
+}
+
+function onGetPictureError(e) {
+    log('Error getting picture: ' + e.code);
+}
+
+function getPictureWin(data) {
+    setPicture(data);
+    // TODO: Fix resolveLocalFileSystemURI to work with native-uri.
+    if (pictureUrl.indexOf('file:') == 0 || pictureUrl.indexOf('content:') == 0) {
+        resolveLocalFileSystemURI(data, function(e) {
+            fileEntry = e;
+            logCallback('resolveLocalFileSystemURI()', true)(e.toURL());
+        }, logCallback('resolveLocalFileSystemURI()', false));
+    } else if (pictureUrl.indexOf('data:image/jpeg;base64' == 0)) {
+      // do nothing
+    } else {
+        var path = pictureUrl.replace(/^file:\/\/(localhost)?/, '').replace(/%20/g, ' ');
+        fileEntry = new FileEntry('image_name.png', path);
+    }
+}
+
+function getPicture() {
+    clearStatus();
+    var options = extractOptions();
+    log('Getting picture with options: ' + JSON.stringify(options));
+    var popoverHandle = navigator.camera.getPicture(getPictureWin, onGetPictureError, options);
+
+    // Reposition the popover if the orientation changes.
+    window.onorientationchange = function() {
+        var newPopoverOptions = new CameraPopoverOptions(0, 0, 100, 100, 0);
+        popoverHandle.setPosition(newPopoverOptions);
+    }
+}
+
+function uploadImage() {
+    var ft = new FileTransfer(),
+        uploadcomplete=0,
+        progress = 0,
+        options = new FileUploadOptions();
+    options.fileKey="photo";
+    options.fileName='test.jpg';
+    options.mimeType="image/jpeg";
+    ft.onprogress = function(progressEvent) {
+        log('progress: ' + progressEvent.loaded + ' of ' + progressEvent.total);
+    };
+    var server = "http://cordova-filetransfer.jitsu.com";
+
+    ft.upload(pictureUrl, server + '/upload', win, fail, options);
+    function win(information_back){
+        log('upload complete');
+    }
+    function fail(message) {
+        log('upload failed: ' + JSON.stringify(message));
+    }
+}
+
+function logCallback(apiName, success) {
+    return function() {
+        log('Call to ' + apiName + (success ? ' success: ' : ' failed: ') + JSON.stringify([].slice.call(arguments)));
+    };
+}
+
+/**
+ * Select image from library using a NATIVE_URI destination type
+ * This calls FileEntry.getMetadata, FileEntry.setMetadata, FileEntry.getParent, FileEntry.file, and FileReader.readAsDataURL.
+ */
+function readFile() {
+    function onFileReadAsDataURL(evt) {
+        var img = document.getElementById('camera_image');
+        img.style.visibility = "visible";
+        img.style.display = "block";
+        img.src = evt.target.result;
+        log("FileReader.readAsDataURL success");
+    };
+
+    function onFileReceived(file) {
+        log('Got file: ' + JSON.stringify(file));
+        fileObj = file;
+
+        var reader = new FileReader();
+        reader.onload = function() {
+            log('FileReader.readAsDataURL() - length = ' + reader.result.length);
+        };
+        reader.onerror = logCallback('FileReader.readAsDataURL', false);
+        reader.readAsDataURL(file);
+    };
+    // Test out onFileReceived when the file object was set via a native <input> elements.
+    if (fileObj) {
+        onFileReceived(fileObj);
+    } else {
+        fileEntry.file(onFileReceived, logCallback('FileEntry.file', false));
+    }
+}
+function getFileInfo() {
+    // Test FileEntry API here.
+    fileEntry.getMetadata(logCallback('FileEntry.getMetadata', true), logCallback('FileEntry.getMetadata', false));
+    fileEntry.setMetadata(logCallback('FileEntry.setMetadata', true), logCallback('FileEntry.setMetadata', false), { "com.apple.MobileBackup": 1 });
+    fileEntry.getParent(logCallback('FileEntry.getParent', true), logCallback('FileEntry.getParent', false));
+    fileEntry.getParent(logCallback('FileEntry.getParent', true), logCallback('FileEntry.getParent', false));
+};
+
+/**
+ * Copy image from library using a NATIVE_URI destination type
+ * This calls FileEntry.copyTo and FileEntry.moveTo.
+ */
+function copyImage() {
+    var onFileSystemReceived = function(fileSystem) {
+        var destDirEntry = fileSystem.root;
+
+        // Test FileEntry API here.
+        fileEntry.copyTo(destDirEntry, 'copied_file.png', logCallback('FileEntry.copyTo', true), logCallback('FileEntry.copyTo', false));
+        fileEntry.moveTo(destDirEntry, 'moved_file.png', logCallback('FileEntry.moveTo', true), logCallback('FileEntry.moveTo', false));
+    };
+
+    window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, onFileSystemReceived, null);
+};
+
+/**
+ * Write image to library using a NATIVE_URI destination type
+ * This calls FileEntry.createWriter, FileWriter.write, and FileWriter.truncate.
+ */
+function writeImage() {
+    var onFileWriterReceived = function(fileWriter) {
+        fileWriter.onwrite = logCallback('FileWriter.write', true);
+        fileWriter.onerror = logCallback('FileWriter.write', false);
+        fileWriter.write("some text!");
+    };
+
+    var onFileTruncateWriterReceived = function(fileWriter) {
+        fileWriter.onwrite = logCallback('FileWriter.truncate', true);
+        fileWriter.onerror = logCallback('FileWriter.truncate', false);
+        fileWriter.truncate(10);
+    };
+
+    fileEntry.createWriter(onFileWriterReceived, logCallback('FileEntry.createWriter', false));
+    fileEntry.createWriter(onFileTruncateWriterReceived, null);
+};
+
+function displayImageUsingCanvas() {
+    var canvas = document.getElementById('canvas');
+    var img = document.getElementById('camera_image');
+    var w = img.width;
+    var h = img.height;
+    h = 100 / w * h;
+    w = 100;
+    canvas.width = w;
+    canvas.height= h;
+    var context = canvas.getContext('2d');
+    context.drawImage(img, 0, 0, w, h);
+};
+
+/**
+ * Remove image from library using a NATIVE_URI destination type
+ * This calls FileEntry.remove.
+ */
+function removeImage() {
+    fileEntry.remove(logCallback('FileEntry.remove', true), logCallback('FileEntry.remove', false));
+};
+
+function testInputTag(inputEl) {
+    clearStatus();
+    // iOS 6 likes to dead-lock in the onchange context if you
+    // do any alerts or try to remote-debug.
+    window.setTimeout(function() {
+        testNativeFile2(inputEl);
+    }, 0);
+};
+
+function testNativeFile2(inputEl) {
+    if (!inputEl.value) {
+        alert('No file selected.');
+        return;
+    }
+    fileObj = inputEl.files[0];
+    if (!fileObj) {
+        alert('Got value but no file.');
+        return;
+    }
+    var URLApi = window.URL || window.webkitURL;
+    if (URLApi) {
+        var blobURL = URLApi.createObjectURL(fileObj);
+        if (blobURL) {
+            setPicture(blobURL, function() {
+                URLApi.revokeObjectURL(blobURL);
+            });
+        } else {
+            log('URL.createObjectURL returned null');
+        }
+    } else {
+        log('URL.createObjectURL() not supported.');
+    }
+}
+
+function extractOptions() {
+    var els = document.querySelectorAll('#image-options select');
+    var ret = {};
+    for (var i = 0, el; el = els[i]; ++i) {
+        var value = el.value;
+        if (value === '') continue;
+        if (el.isBool) {
+            ret[el.keyName] = !!+value;
+        } else {
+            ret[el.keyName] = +value;
+        }
+    }
+    return ret;
+}
+
+function createOptionsEl(name, values, selectionDefault) {
+    var container = document.createElement('div');
+    container.style.display = 'inline-block';
+    container.appendChild(document.createTextNode(name + ': '));
+    var select = document.createElement('select');
+    select.keyName = name;
+    container.appendChild(select);
+    
+    // if we didn't get a default value, insert the blank <default> entry
+    if (selectionDefault == undefined) {
+        var opt = document.createElement('option');
+        opt.value = '';
+        opt.text = '<default>';
+        select.appendChild(opt);
+    }
+    
+    select.isBool = typeof values == 'boolean';
+    if (select.isBool) {
+        values = {'true': 1, 'false': 0};
+    }
+    
+    for (var k in values) {
+        var opt = document.createElement('option');
+        opt.value = values[k];
+        opt.textContent = k;
+        if (selectionDefault) {
+            if (selectionDefault[0] == k) {
+                opt.selected = true;
+            }
+        }
+        select.appendChild(opt);
+    }
+    var optionsDiv = document.getElementById('image-options');
+    optionsDiv.appendChild(container);
+}
+
+/**
+ * Function called when page has finished loading.
+ */
+function init() {
+    document.addEventListener("deviceready", function() {
+        deviceReady = true;
+        console.log("Device="+device.platform+" "+device.version);
+        createOptionsEl('sourceType', Camera.PictureSourceType, camPictureSourceTypeDefault);
+        createOptionsEl('destinationType', Camera.DestinationType, camDestinationTypeDefault);
+        createOptionsEl('encodingType', Camera.EncodingType, camEncodingTypeDefault);
+        createOptionsEl('mediaType', Camera.MediaType, camMediaTypeDefault);
+        createOptionsEl('quality', {'0': 0, '50': 50, '80': 80, '100': 100}, camQualityDefault);
+        createOptionsEl('targetWidth', {'50': 50, '200': 200, '800': 800, '2048': 2048});
+        createOptionsEl('targetHeight', {'50': 50, '200': 200, '800': 800, '2048': 2048});
+        createOptionsEl('allowEdit', true, camAllowEditDefault);
+        createOptionsEl('correctOrientation', true, camCorrectOrientationDefault);
+        createOptionsEl('saveToPhotoAlbum', true, camSaveToPhotoAlbumDefault);
+        createOptionsEl('cameraDirection', Camera.Direction);
+                      
+    }, false);
+    window.setTimeout(function() {
+        if (!deviceReady) {
+            alert("Error: Apache Cordova did not initialize.  Demo will not run correctly.");
+        }
+    },1000);
+};
+
+window.onload = function() {
+  addListenerToClass('getPicture', getPicture);
+  addListenerToClass('testInputTag', function(e) {
+    testInputTag(e.target);
+  }, null, 'change', true);
+  addListenerToClass('getFileInfo', getFileInfo);
+  addListenerToClass('readFile', readFile);
+  addListenerToClass('copyImage', copyImage);
+  addListenerToClass('writeImage', writeImage);
+  addListenerToClass('uploadImage', uploadImage);
+  addListenerToClass('displayImageUsingCanvas', displayImageUsingCanvas);
+  addListenerToClass('removeImage', removeImage);
+
+  addListenerToClass('backBtn', backHome);
+  init();
+}
+

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/a7c88d8f/capture/index.html
----------------------------------------------------------------------
diff --git a/capture/index.html b/capture/index.html
index 67c35e3..9543341 100644
--- a/capture/index.html
+++ b/capture/index.html
@@ -28,142 +28,9 @@
     <title>Cordova Mobile Spec</title>
     <link rel="stylesheet" href="../master.css" type="text/css" media="screen" title="no title" charset="utf-8">
     <script type="text/javascript" charset="utf-8" src="../cordova-incl.js"></script>
-
-
-<script type="text/javascript" charset="utf-8">
-
-    var deviceReady = false;
-    var platformId = cordova.require('cordova/platform').id;
-    var pageStartTime = +new Date();
-
-    //-------------------------------------------------------------------------
-    // Camera
-    //-------------------------------------------------------------------------
-
-    function log(value) {
-        console.log(value);
-        document.getElementById('camera_status').textContent += (new Date() - pageStartTime) / 1000 + ': ' + value + '\n';
-    }
-
-    function captureAudioWin(mediaFiles){
-        var path = mediaFiles[0].fullPath;
-        log('Audio captured: ' + path);
-        var m = new Media(path);
-        m.play(); 
-    }
-    
-    function captureAudioFail(e){
-        log('Error getting audio: ' + e.code);
-    }
-    
-    function getAudio(){
-        clearStatus();
-        var options = { limit: 1, duration: 10};
-        navigator.device.capture.captureAudio(captureAudioWin, captureAudioFail, options);
-    }
-    
-    function captureImageWin(mediaFiles){
-        var path = mediaFiles[0].fullPath;
-        log('Image captured: ' + path);    
-        document.getElementById('camera_image').src = path;    
-    }
-    
-    function captureImageFail(e){
-        log('Error getting image: ' + e.code);
-    }
-    
-    function getImage(){
-        clearStatus();
-        var options = { limit: 1 };
-        navigator.device.capture.captureImage(captureImageWin, captureImageFail, options);    
-    }    
-    
-    function captureVideoWin(mediaFiles){
-        var path = mediaFiles[0].fullPath;
-        log('Video captured: ' + path);
-        
-        // need to inject the video element into the html
-        // doesn't seem to work if you have a pre-existing video element and
-        // add in a source tag
-        var vid = document.createElement('video');
-        vid.id="theVideo";
-        vid.width = "320";
-        vid.height= "240";
-        vid.controls = "true";
-        var source_vid = document.createElement('source');
-        source_vid.id = "theSource";
-        source_vid.src = path;
-        vid.appendChild(source_vid);
-        document.getElementById('video_container').appendChild(vid);    
-    }
-    
-    function captureVideoFail(e){
-        log('Error getting video: ' + e.code);
-    }
-    
-    function getVideo(){
-        clearStatus();
-        var options = { limit: 1, duration: 10 };
-        navigator.device.capture.captureVideo(captureVideoWin, captureVideoFail, options);      
-    }
-
-    function resolveMediaFileURL(mediaFile, callback) {
-        resolveLocalFileSystemURL(mediaFile.localURL, function(entry) {
-            log("Resolved by URL: " + mediaFile.localURL);
-            if (callback) callback();
-        }, function(err) {
-            log("Failed to resolve by URL: " + mediaFile.localURL);
-            log("Error: " + JSON.stringify(err));
-            if (callback) callback();
-        });
-    }
-
-    function resolveMediaFile(mediaFile, callback) {
-        resolveLocalFileSystemURL(mediaFile.fullPath, function(entry) {
-            log("Resolved by path: " + mediaFile.fullPath);
-            if (callback) callback();
-        }, function(err) {
-            log("Failed to resolve by path: " + mediaFile.fullPath);
-            log("Error: " + JSON.stringify(err));
-            if (callback) callback();
-        });
-    }
-        
-    function resolveVideo() {
-        clearStatus();
-        var options = { limit: 1, duration: 5 };
-        navigator.device.capture.captureVideo(function(mediaFiles) {
-            captureVideoWin(mediaFiles);
-            resolveMediaFile(mediaFiles[0], function() {
-                resolveMediaFileURL(mediaFiles[0]);
-            });
-        }, captureVideoFail, options);      
-    }
-    
-    function clearStatus() {
-        document.getElementById('camera_status').innerHTML = '';
-        document.getElementById('camera_image').src = 'about:blank';
-    }
-
-    /**
-     * Function called when page has finished loading.
-     */
-    function init() {
-        document.addEventListener("deviceready", function() {
-            deviceReady = true;
-            console.log("Device="+device.platform+" "+device.version);
-        }, false);
-        window.setTimeout(function() {
-            if (!deviceReady) {
-                alert("Error: Apache Cordova did not initialize.  Demo will not run correctly.");
-            }
-        },1000);
-    };
-    
-</script>
-
+    <script type="text/javascript" charset="utf-8" src="./index.js"></script>      
   </head>
-  <body onload="init();" id="stage" class="theme">
+  <body id="stage" class="theme">
 
     <h1>Capture</h1>
     <div id="info" style="white-space: pre-wrap">
@@ -176,10 +43,10 @@
     <div id="image-options"></div>
 
     <h2>Actions</h2>
-    <div class="btn large" onclick="getAudio();">Capture 10 secs of audio and play</div>
-    <div class="btn large" onclick="getImage();">Capture 1 image</div>
-    <div class="btn large" onclick="getVideo();">Capture 10 secs of video</div>
-    <div class="btn large" onclick="resolveVideo();">Capture 5 secs of video and resolve</div>
-    <h2> </h2><div class="backBtn" onclick="backHome();">Back</div>
+    <div class="btn large getAudio">Capture 10 secs of audio and play</div>
+    <div class="btn large getImage">Capture 1 image</div>
+    <div class="btn large getVideo">Capture 10 secs of video</div>
+    <div class="btn large resolveVideo">Capture 5 secs of video and resolve</div>
+    <h2> </h2><div class="backBtn">Back</div>
   </body>
 </html>

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/a7c88d8f/capture/index.js
----------------------------------------------------------------------
diff --git a/capture/index.js b/capture/index.js
new file mode 100644
index 0000000..0f98549
--- /dev/null
+++ b/capture/index.js
@@ -0,0 +1,137 @@
+var deviceReady = false;
+var platformId = cordova.require('cordova/platform').id;
+var pageStartTime = +new Date();
+
+//-------------------------------------------------------------------------
+// Camera
+//-------------------------------------------------------------------------
+
+function log(value) {
+    console.log(value);
+    document.getElementById('camera_status').textContent += (new Date() - pageStartTime) / 1000 + ': ' + value + '\n';
+}
+
+function captureAudioWin(mediaFiles){
+    var path = mediaFiles[0].fullPath;
+    log('Audio captured: ' + path);
+    var m = new Media(path);
+    m.play(); 
+}
+
+function captureAudioFail(e){
+    log('Error getting audio: ' + e.code);
+}
+
+function getAudio(){
+    clearStatus();
+    var options = { limit: 1, duration: 10};
+    navigator.device.capture.captureAudio(captureAudioWin, captureAudioFail, options);
+}
+
+function captureImageWin(mediaFiles){
+    var path = mediaFiles[0].fullPath;
+    log('Image captured: ' + path);    
+    document.getElementById('camera_image').src = path;    
+}
+
+function captureImageFail(e){
+    log('Error getting image: ' + e.code);
+}
+
+function getImage(){
+    clearStatus();
+    var options = { limit: 1 };
+    navigator.device.capture.captureImage(captureImageWin, captureImageFail, options);    
+}    
+
+function captureVideoWin(mediaFiles){
+    var path = mediaFiles[0].fullPath;
+    log('Video captured: ' + path);
+    
+    // need to inject the video element into the html
+    // doesn't seem to work if you have a pre-existing video element and
+    // add in a source tag
+    var vid = document.createElement('video');
+    vid.id="theVideo";
+    vid.width = "320";
+    vid.height= "240";
+    vid.controls = "true";
+    var source_vid = document.createElement('source');
+    source_vid.id = "theSource";
+    source_vid.src = path;
+    vid.appendChild(source_vid);
+    document.getElementById('video_container').appendChild(vid);    
+}
+
+function captureVideoFail(e){
+    log('Error getting video: ' + e.code);
+}
+
+function getVideo(){
+    clearStatus();
+    var options = { limit: 1, duration: 10 };
+    navigator.device.capture.captureVideo(captureVideoWin, captureVideoFail, options);      
+}
+
+function resolveMediaFileURL(mediaFile, callback) {
+    resolveLocalFileSystemURL(mediaFile.localURL, function(entry) {
+        log("Resolved by URL: " + mediaFile.localURL);
+        if (callback) callback();
+    }, function(err) {
+        log("Failed to resolve by URL: " + mediaFile.localURL);
+        log("Error: " + JSON.stringify(err));
+        if (callback) callback();
+    });
+}
+
+function resolveMediaFile(mediaFile, callback) {
+    resolveLocalFileSystemURL(mediaFile.fullPath, function(entry) {
+        log("Resolved by path: " + mediaFile.fullPath);
+        if (callback) callback();
+    }, function(err) {
+        log("Failed to resolve by path: " + mediaFile.fullPath);
+        log("Error: " + JSON.stringify(err));
+        if (callback) callback();
+    });
+}
+    
+function resolveVideo() {
+    clearStatus();
+    var options = { limit: 1, duration: 5 };
+    navigator.device.capture.captureVideo(function(mediaFiles) {
+        captureVideoWin(mediaFiles);
+        resolveMediaFile(mediaFiles[0], function() {
+            resolveMediaFileURL(mediaFiles[0]);
+        });
+    }, captureVideoFail, options);      
+}
+
+function clearStatus() {
+    document.getElementById('camera_status').innerHTML = '';
+    document.getElementById('camera_image').src = 'about:blank';
+}
+
+/**
+ * Function called when page has finished loading.
+ */
+function init() {
+    document.addEventListener("deviceready", function() {
+        deviceReady = true;
+        console.log("Device="+device.platform+" "+device.version);
+    }, false);
+    window.setTimeout(function() {
+        if (!deviceReady) {
+            alert("Error: Apache Cordova did not initialize.  Demo will not run correctly.");
+        }
+    },1000);
+};
+
+
+window.onload = function() {
+  addListenerToClass('getAudio', getAudio);
+  addListenerToClass('getImage', getImage);
+  addListenerToClass('getVideo', getVideo);
+  addListenerToClass('resolveVideo', resolveVideo);
+  addListenerToClass('backBtn', backHome);
+  init();
+}

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/a7c88d8f/compass/index.html
----------------------------------------------------------------------
diff --git a/compass/index.html b/compass/index.html
index 4d6af2c..1734caa 100644
--- a/compass/index.html
+++ b/compass/index.html
@@ -28,111 +28,9 @@
     <title>Cordova Mobile Spec</title>
     <link rel="stylesheet" href="../master.css" type="text/css" media="screen" title="no title" charset="utf-8">
     <script type="text/javascript" charset="utf-8" src="../cordova-incl.js"></script>      
-
-      
-<script type="text/javascript" charset="utf-8">
-
-    var deviceReady = false;
-
-    function roundNumber(num) {
-        var dec = 3;
-        var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
-        return result;
-    }
-
-    //-------------------------------------------------------------------------
-    // Compass
-    //-------------------------------------------------------------------------
-    var watchCompassId = null;
-
-    /**
-     * Start watching compass
-     */
-    var watchCompass = function() {
-        console.log("watchCompass()");
-
-        // Success callback
-        var success = function(a){
-            document.getElementById('compassHeading').innerHTML = roundNumber(a.magneticHeading);
-        };
-
-        // Fail callback
-        var fail = function(e){
-            console.log("watchCompass fail callback with error code "+e);
-            stopCompass();
-            setCompassStatus(e);
-        };
-
-        // Update heading every 1 sec
-        var opt = {};
-        opt.frequency = 1000;
-        watchCompassId = navigator.compass.watchHeading(success, fail, opt);
-
-        setCompassStatus("Running");
-    };
-
-    /**
-     * Stop watching the acceleration
-     */
-    var stopCompass = function() {
-        setCompassStatus("Stopped");
-        if (watchCompassId) {
-            navigator.compass.clearWatch(watchCompassId);
-            watchCompassId = null;
-        }
-    };
-
-    /**
-     * Get current compass
-     */
-    var getCompass = function() {
-        console.log("getCompass()");
-
-        // Stop compass if running
-        stopCompass();
-
-        // Success callback
-        var success = function(a){
-            document.getElementById('compassHeading').innerHTML = roundNumber(a.magneticHeading);
-        };
-
-        // Fail callback
-        var fail = function(e){
-            console.log("getCompass fail callback with error code "+e);
-            setCompassStatus(e);
-        };
-
-        // Make call
-        var opt = {};
-        navigator.compass.getCurrentHeading(success, fail, opt);
-    };
-
-    /**
-     * Set compass status
-     */
-    var setCompassStatus = function(status) {
-        document.getElementById('compass_status').innerHTML = status;
-    };
-    
-    /**
-     * Function called when page has finished loading.
-     */
-    function init() {
-        document.addEventListener("deviceready", function() {
-                deviceReady = true;
-                console.log("Device="+device.platform+" "+device.version);
-            }, false);
-        window.setTimeout(function() {
-        	if (!deviceReady) {
-        		alert("Error: Apache Cordova did not initialize.  Demo will not run correctly.");
-        	}
-        },1000);
-    }
-
-</script>
-
+    <script type="text/javascript" charset="utf-8" src="./index.js"></script>      
   </head>
-  <body onload="init();" id="stage" class="theme">
+  <body id="stage" class="theme">
   
     <h1>Compass</h1>
     <div id="info">
@@ -142,9 +40,9 @@
         </tr></table>
     </div>
     <h2>Action</h2>
-    <div class="btn large" onclick="getCompass();">Get Compass</div>
-    <div class="btn large" onclick="watchCompass();">Start Watching Compass</div>
-    <div class="btn large" onclick="stopCompass();">Stop Watching Compass</div>
-    <h2> </h2><div class="backBtn" onclick="backHome();">Back</div>
+    <div class="btn large getCompass">Get Compass</div>
+    <div class="btn large watchCompass">Start Watching Compass</div>
+    <div class="btn large stopCompass">Stop Watching Compass</div>
+    <h2> </h2><div class="backBtn">Back</div>
   </body>
 </html>      

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/a7c88d8f/compass/index.js
----------------------------------------------------------------------
diff --git a/compass/index.js b/compass/index.js
new file mode 100644
index 0000000..0735ab2
--- /dev/null
+++ b/compass/index.js
@@ -0,0 +1,104 @@
+var deviceReady = false;
+
+function roundNumber(num) {
+    var dec = 3;
+    var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
+    return result;
+}
+
+//-------------------------------------------------------------------------
+// Compass
+//-------------------------------------------------------------------------
+var watchCompassId = null;
+
+/**
+ * Start watching compass
+ */
+var watchCompass = function() {
+    console.log("watchCompass()");
+
+    // Success callback
+    var success = function(a){
+        document.getElementById('compassHeading').innerHTML = roundNumber(a.magneticHeading);
+    };
+
+    // Fail callback
+    var fail = function(e){
+        console.log("watchCompass fail callback with error code "+e);
+        stopCompass();
+        setCompassStatus(e);
+    };
+
+    // Update heading every 1 sec
+    var opt = {};
+    opt.frequency = 1000;
+    watchCompassId = navigator.compass.watchHeading(success, fail, opt);
+
+    setCompassStatus("Running");
+};
+
+/**
+ * Stop watching the acceleration
+ */
+var stopCompass = function() {
+    setCompassStatus("Stopped");
+    if (watchCompassId) {
+        navigator.compass.clearWatch(watchCompassId);
+        watchCompassId = null;
+    }
+};
+
+/**
+ * Get current compass
+ */
+var getCompass = function() {
+    console.log("getCompass()");
+
+    // Stop compass if running
+    stopCompass();
+
+    // Success callback
+    var success = function(a){
+        document.getElementById('compassHeading').innerHTML = roundNumber(a.magneticHeading);
+    };
+
+    // Fail callback
+    var fail = function(e){
+        console.log("getCompass fail callback with error code "+e);
+        setCompassStatus(e);
+    };
+
+    // Make call
+    var opt = {};
+    navigator.compass.getCurrentHeading(success, fail, opt);
+};
+
+/**
+ * Set compass status
+ */
+var setCompassStatus = function(status) {
+    document.getElementById('compass_status').innerHTML = status;
+};
+
+/**
+ * Function called when page has finished loading.
+ */
+function init() {
+    document.addEventListener("deviceready", function() {
+            deviceReady = true;
+            console.log("Device="+device.platform+" "+device.version);
+        }, false);
+    window.setTimeout(function() {
+      if (!deviceReady) {
+        alert("Error: Apache Cordova did not initialize.  Demo will not run correctly.");
+      }
+    },1000);
+}
+
+window.onload = function() {
+  addListenerToClass('getCompass', getCompass);
+  addListenerToClass('watchCompass', watchCompass);
+  addListenerToClass('stopCompass', stopCompass);
+  addListenerToClass('backBtn', backHome);
+  init();
+}

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/a7c88d8f/contacts/index.html
----------------------------------------------------------------------
diff --git a/contacts/index.html b/contacts/index.html
index b6a3a92..5782713 100644
--- a/contacts/index.html
+++ b/contacts/index.html
@@ -28,98 +28,10 @@
     <title>Cordova Mobile Spec</title>
     <link rel="stylesheet" href="../master.css" type="text/css" media="screen" title="no title" charset="utf-8">
     <script type="text/javascript" charset="utf-8" src="../cordova-incl.js"></script>      
-
-      
-<script type="text/javascript" charset="utf-8">
-
-    var deviceReady = false;
-
-    //-------------------------------------------------------------------------
-    // Contacts
-    //-------------------------------------------------------------------------
-    function getContacts() {
-        obj = new ContactFindOptions();
-        // show all contacts, so don't filter
-        obj.multiple = true;
-        navigator.contacts.find(
-            ["displayName", "name", "phoneNumbers", "emails", "urls", "note"],
-            function(contacts) {
-                var s = "";
-                if (contacts.length == 0) {
-                    s = "No contacts found";
-                }
-                else {
-                    s = "Number of contacts: "+contacts.length+"<br><table width='100%'><tr><th>Name</th><td>Phone</td><td>Email</td></tr>";
-                    for (var i=0; i<contacts.length; i++) {
-                        var contact = contacts[i];
-                        s = s + "<tr><td>" + contact.name.formatted + "</td><td>";
-                        if (contact.phoneNumbers && contact.phoneNumbers.length > 0) {
-                            s = s + contact.phoneNumbers[0].value;
-                        }
-                        s = s + "</td><td>"
-                        if (contact.emails && contact.emails.length > 0) {
-                            s = s + contact.emails[0].value;
-                        }
-                        s = s + "</td></tr>";
-                    }
-                    s = s + "</table>";
-                }
-                document.getElementById('contacts_results').innerHTML = s;
-            },
-            function(e) {
-                document.getElementById('contacts_results').innerHTML = "Error: "+e.code;
-            },
-            obj);
-    };
-
-    function addContact(){
-        console.log("addContact()");
-        try{
-            var contact = navigator.contacts.create({"displayName": "Dooney Evans"});
-            var contactName = {
-                formatted: "Dooney Evans",
-                familyName: "Evans",
-                givenName: "Dooney",
-                middleName: ""
-            };
-
-            contact.name = contactName;
-
-            var phoneNumbers = [1];
-            phoneNumbers[0] = new ContactField('work', '512-555-1234', true);
-            contact.phoneNumbers = phoneNumbers;
-
-            contact.save(
-                function() { alert("Contact saved.");},
-                function(e) { alert("Contact save failed: " + e.code); }
-            );
-            console.log("you have saved the contact");
-        }
-        catch (e){
-            alert(e);
-        }
-
-    };
-    
-    /**
-     * Function called when page has finished loading.
-     */
-    function init() {
-        document.addEventListener("deviceready", function() {
-                deviceReady = true;
-                console.log("Device="+device.platform+" "+device.version);
-            }, false);
-        window.setTimeout(function() {
-        	if (!deviceReady) {
-        		alert("Error: Apache Cordova did not initialize.  Demo will not run correctly.");
-        	}
-        },1000);
-    }
-
-</script>
+    <script type="text/javascript" charset="utf-8" src="./index.js"></script>      
 
   </head>
-  <body onload="init();" id="stage" class="theme">
+  <body id="stage" class="theme">
   
     <h1>Contacts</h1>    
     <div id="info">
@@ -127,8 +39,9 @@
         <span id="contacts_results"> </span>
     </div>
     <h2>Action</h2>
-    <div class="btn large" onclick="getContacts();">Get phone's contacts</div>
-    <div class="btn large" onclick="addContact();">Add a new contact 'Dooney Evans'</div>
-    <h2> </h2><div class="backBtn" onclick="backHome();">Back</div>
+
+    <div class="btn large getContacts">Get phone's contacts</div>
+    <div class="btn large addContact">Add a new contact 'Dooney Evans'</div>
+    <h2> </h2><div class="backBtn">Back</div>
   </body>
 </html>      

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/a7c88d8f/contacts/index.js
----------------------------------------------------------------------
diff --git a/contacts/index.js b/contacts/index.js
new file mode 100644
index 0000000..d3f3312
--- /dev/null
+++ b/contacts/index.js
@@ -0,0 +1,90 @@
+var deviceReady = false;
+
+//-------------------------------------------------------------------------
+// Contacts
+//-------------------------------------------------------------------------
+function getContacts() {
+    obj = new ContactFindOptions();
+    // show all contacts, so don't filter
+    obj.multiple = true;
+    navigator.contacts.find(
+        ["displayName", "name", "phoneNumbers", "emails", "urls", "note"],
+        function(contacts) {
+            var s = "";
+            if (contacts.length == 0) {
+                s = "No contacts found";
+            }
+            else {
+                s = "Number of contacts: "+contacts.length+"<br><table width='100%'><tr><th>Name</th><td>Phone</td><td>Email</td></tr>";
+                for (var i=0; i<contacts.length; i++) {
+                    var contact = contacts[i];
+                    s = s + "<tr><td>" + contact.name.formatted + "</td><td>";
+                    if (contact.phoneNumbers && contact.phoneNumbers.length > 0) {
+                        s = s + contact.phoneNumbers[0].value;
+                    }
+                    s = s + "</td><td>"
+                    if (contact.emails && contact.emails.length > 0) {
+                        s = s + contact.emails[0].value;
+                    }
+                    s = s + "</td></tr>";
+                }
+                s = s + "</table>";
+            }
+            document.getElementById('contacts_results').innerHTML = s;
+        },
+        function(e) {
+            document.getElementById('contacts_results').innerHTML = "Error: "+e.code;
+        },
+        obj);
+};
+
+function addContact(){
+    try{
+        var contact = navigator.contacts.create({"displayName": "Dooney Evans"});
+        var contactName = {
+            formatted: "Dooney Evans",
+            familyName: "Evans",
+            givenName: "Dooney",
+            middleName: ""
+        };
+
+        contact.name = contactName;
+
+        var phoneNumbers = [1];
+        phoneNumbers[0] = new ContactField('work', '512-555-1234', true);
+        contact.phoneNumbers = phoneNumbers;
+
+        contact.save(
+            function() { alert("Contact saved.");},
+            function(e) { alert("Contact save failed: " + e.code); }
+        );
+        console.log("you have saved the contact");
+    }
+    catch (e){
+        alert(e);
+    }
+
+};
+
+/**
+ * Function called when page has finished loading.
+ */
+function init() {
+    document.addEventListener("deviceready", function() {
+            deviceReady = true;
+            console.log("Device="+device.platform+" "+device.version);
+        }, false);
+    window.setTimeout(function() {
+      if (!deviceReady) {
+        alert("Error: Apache Cordova did not initialize.  Demo will not run correctly.");
+      }
+    },1000);
+}
+
+
+window.onload = function() {
+  addListenerToClass('getContacts', getContacts);
+  addListenerToClass('addContact', addContact);
+  addListenerToClass('backBtn', backHome);
+  init();
+}

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/a7c88d8f/cordova-incl.js
----------------------------------------------------------------------
diff --git a/cordova-incl.js b/cordova-incl.js
index 2712063..cc059b8 100644
--- a/cordova-incl.js
+++ b/cordova-incl.js
@@ -56,6 +56,28 @@ if (!window._doNotWriteCordovaScript) {
     }
 }
 
+function addListenerToClass(className, listener, argsArray, action, doNotWrap) {
+    if (!action) {
+      action='click';
+    }
+    var elements = document.getElementsByClassName(className);
+    // choose Event target as a scope (like inline scripts)
+    if (!doNotWrap) {
+      if (argsArray && !Array.isArray(argsArray)) {
+        argsArray = [argsArray];
+      }
+      function callListener(e) {
+        listener.apply(null, argsArray);
+      }
+    } else {
+      callListener = listener;
+    }
+    for (var i = 0; i < elements.length; ++i) {
+      var item = elements[i];  
+      item.addEventListener(action, callListener, false);
+    }
+};
+
 function backHome() {
     if (window.device && device.platform && (device.platform.toLowerCase() == 'android' || device.platform.toLowerCase() == 'amazon-fireos')) {
         navigator.app.backHistory();

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/a7c88d8f/events/index.html
----------------------------------------------------------------------
diff --git a/events/index.html b/events/index.html
index d2ad8d4..3f45021 100644
--- a/events/index.html
+++ b/events/index.html
@@ -28,60 +28,10 @@
     <title>Cordova Mobile Spec</title>
     <link rel="stylesheet" href="../master.css" type="text/css" media="screen" title="no title" charset="utf-8">
     <script type="text/javascript" charset="utf-8" src="../cordova-incl.js"></script>      
-
-      
-<script type="text/javascript" charset="utf-8">
-
-    var deviceReady = false;
-
-    function interceptBackbutton() {
-    	eventOutput("Back button intercepted");
-    }
-    function interceptMenubutton() {
-    	eventOutput("Menu button intercepted");
-    }
-    function interceptSearchbutton() {
-    	eventOutput("Search button intercepted");
-    }
-    function interceptResume() {
-      eventOutput("Resume event intercepted");
-    }
-    function interceptPause() {
-      eventOutput("Pause event intercepted");
-    }
-    function interceptOnline() {
-      eventOutput("Online event intercepted");
-    }
-    function interceptOffline() {
-      eventOutput("Offline event intercepted");
-    }
-    
-    var eventOutput = function(s) {
-        var el = document.getElementById("results");
-        el.innerHTML = el.innerHTML + s + "<br>";
-    };
-
-    
-    /**
-     * Function called when page has finished loading.
-     */
-    function init() {
-        document.addEventListener("deviceready", function() {
-                deviceReady = true;
-                console.log("Device="+device.platform+" "+device.version);
-                eventOutput("deviceready event: "+device.platform+" "+device.version);
-            }, false);
-        window.setTimeout(function() {
-        	if (!deviceReady) {
-        		alert("Error: Apache Cordova did not initialize.  Demo will not run correctly.");
-        	}
-        },1000);
-    }
-
-</script>
+    <script type="text/javascript" charset="utf-8" src="./index.js"></script>      
 
   </head>
-  <body onload="init();" id="stage" class="theme">
+  <body id="stage" class="theme">
   
     <h1>Events</h1>
     <div id="info">
@@ -90,21 +40,21 @@
     </div>
     <input type="text" value="Type here to test events when fields are focused" />
     <h2>Action</h2>
-    <div class="btn large" onclick="document.addEventListener('backbutton', interceptBackbutton, false);">Intercept backbutton</div>
-    <div class="btn large" onclick="document.removeEventListener('backbutton', interceptBackbutton, false);">Stop intercept of backbutton</div>
-    <div class="btn large" onclick="document.addEventListener('menubutton', interceptMenubutton, false);">Intercept menubutton</div>
-    <div class="btn large" onclick="document.removeEventListener('menubutton', interceptMenubutton, false);">Stop intercept of menubutton</div>
-    <div class="btn large" onclick="document.addEventListener('searchbutton', interceptSearchbutton, false);">Intercept searchbutton</div>
-    <div class="btn large" onclick="document.removeEventListener('searchbutton', interceptSearchbutton, false);">Stop intercept of searchbutton</div>
-    <div class="btn large" onclick="document.addEventListener('resume', interceptResume, false);">Intercept resume</div>
-    <div class="btn large" onclick="document.removeEventListener('resume', interceptResume, false);">Stop intercept of resume</div>
-    <div class="btn large" onclick="document.addEventListener('pause', interceptPause, false);">Intercept pause</div>
-    <div class="btn large" onclick="document.removeEventListener('pause', interceptPause, false);">Stop intercept of pause</div>
-    <div class="btn large" onclick="document.addEventListener('online', interceptOnline, false);">Intercept online</div>
-    <div class="btn large" onclick="document.removeEventListener('online', interceptOnline, false);">Stop intercept of online</div>
-    <div class="btn large" onclick="document.addEventListener('offline', interceptOffline, false);">Intercept offline</div>
-    <div class="btn large" onclick="document.removeEventListener('offline', interceptOffline, false);">Stop intercept of offline</div>
-
-    <h2> </h2><div class="backBtn" onclick="backHome();">Back</div>
+    <div class="btn large interceptBackButton">Intercept backbutton</div>
+    <div class="btn large stopInterceptOfBackButton">Stop intercept of backbutton</div>
+    <div class="btn large interceptMenuButton">Intercept menubutton</div>
+    <div class="btn large stopInterceptOfMenuButton">Stop intercept of menubutton</div>
+    <div class="btn large interceptSearchButton">Intercept searchbutton</div>
+    <div class="btn large stopInterceptOfSearchButton">Stop intercept of searchbutton</div>
+    <div class="btn large interceptResume">Intercept resume</div>
+    <div class="btn large stopInterceptOfResume">Stop intercept of resume</div>
+    <div class="btn large interceptPause">Intercept pause</div>
+    <div class="btn large stopInterceptOfPause">Stop intercept of pause</div>
+    <div class="btn large interceptOnline">Intercept online</div>
+    <div class="btn large stopInterceptOfOnline">Stop intercept of online</div>
+    <div class="btn large interceptOffline">Intercept offline</div>
+    <div class="btn large stopInterceptOfOffline">Stop intercept of offline</div>
+
+    <h2> </h2><div class="backBtn">Back</div>
   </body>
 </html>

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/a7c88d8f/events/index.js
----------------------------------------------------------------------
diff --git a/events/index.js b/events/index.js
new file mode 100644
index 0000000..e1bb922
--- /dev/null
+++ b/events/index.js
@@ -0,0 +1,94 @@
+var deviceReady = false;
+
+function interceptBackbutton() {
+  eventOutput("Back button intercepted");
+}
+function interceptMenubutton() {
+  eventOutput("Menu button intercepted");
+}
+function interceptSearchbutton() {
+  eventOutput("Search button intercepted");
+}
+function interceptResume() {
+  eventOutput("Resume event intercepted");
+}
+function interceptPause() {
+  eventOutput("Pause event intercepted");
+}
+function interceptOnline() {
+  eventOutput("Online event intercepted");
+}
+function interceptOffline() {
+  eventOutput("Offline event intercepted");
+}
+
+var eventOutput = function(s) {
+    var el = document.getElementById("results");
+    el.innerHTML = el.innerHTML + s + "<br>";
+};
+
+
+/**
+ * Function called when page has finished loading.
+ */
+function init() {
+    document.addEventListener("deviceready", function() {
+            deviceReady = true;
+            console.log("Device="+device.platform+" "+device.version);
+            eventOutput("deviceready event: "+device.platform+" "+device.version);
+        }, false);
+    window.setTimeout(function() {
+      if (!deviceReady) {
+        alert("Error: Apache Cordova did not initialize.  Demo will not run correctly.");
+      }
+    },1000);
+}
+
+
+window.onload = function() {
+  addListenerToClass('interceptBackButton', function() {
+    document.addEventListener('backbutton', interceptBackbutton, false);
+  });
+  addListenerToClass('stopInterceptOfBackButton', function() {
+    document.removeEventListener('backbutton', interceptBackbutton, false);
+  });
+  addListenerToClass('interceptMenuButton', function() {
+    document.addEventListener('menubutton', interceptMenubutton, false);
+  });
+  addListenerToClass('stopInterceptOfMenuButton', function() {
+    document.removeEventListener('menubutton', interceptMenubutton, false);
+  });
+  addListenerToClass('interceptSearchButton', function() {
+    document.addEventListener('searchbutton', interceptSearchbutton, false);
+  });
+  addListenerToClass('stopInterceptOfSearchButton', function() {
+    document.removeEventListener('searchbutton', interceptSearchbutton, false);
+  });
+  addListenerToClass('interceptResume', function() {
+    document.addEventListener('resume', interceptResume, false);
+  });
+  addListenerToClass('stopInterceptOfResume', function() {
+    document.removeEventListener('resume', interceptResume, false);
+  });
+  addListenerToClass('interceptPause', function() {
+    document.addEventListener('pause', interceptPause, false);
+  });
+  addListenerToClass('stopInterceptOfPause', function() {
+    document.removeEventListener('pause', interceptPause, false);
+  });
+  addListenerToClass('interceptOnline', function() {
+    document.addEventListener('online', interceptOnline, false);
+  });
+  addListenerToClass('stopInterceptOfOnline', function() {
+    document.removeEventListener('online', interceptOnline, false);
+  });
+  addListenerToClass('interceptOffline', function() {
+    document.addEventListener('offline', interceptOffline, false);
+  });
+  addListenerToClass('stopInterceptOfOffline', function() {
+    document.removeEventListener('offline', interceptOffline, false);
+  });
+
+  addListenerToClass('backBtn', backHome);
+  init();
+}

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/a7c88d8f/file/index.html
----------------------------------------------------------------------
diff --git a/file/index.html b/file/index.html
index 033b97d..8f00e86 100644
--- a/file/index.html
+++ b/file/index.html
@@ -28,162 +28,10 @@
     <title>Cordova Mobile Spec</title>
     <link rel="stylesheet" href="../master.css" type="text/css" media="screen" title="no title" charset="utf-8">
     <script type="text/javascript" charset="utf-8" src="../cordova-incl.js"></script>
-
-
-<script type="text/javascript" charset="utf-8">
-
-    var deviceReady = false;
-
-    var imageURL = "http://apache.org/images/feather-small.gif";
-    var videoURL = "http://techslides.com/demos/sample-videos/small.mp4";
-
-    /**
-     * Function called when page has finished loading.
-     */
-    function init() {
-        document.addEventListener("deviceready", function() {
-                deviceReady = true;
-                console.log("Device="+device.platform+" "+device.version);
-                bindEvents();
-                document.body.classList.add(device.platform.toLowerCase() + "-platform");
-            }, false);
-        window.setTimeout(function() {
-            if (!deviceReady) {
-                alert("Error: Apache Cordova did not initialize.  Demo will not run correctly.");
-            }
-        },1000);
-    }
-
-    function bindEvents() {
-        document.getElementById('downloadImgCDV').addEventListener('click', downloadImgCDV, false);
-        document.getElementById('downloadImgNative').addEventListener('click', downloadImgNative, false);
-        document.getElementById('downloadVideoCDV').addEventListener('click', downloadVideoCDV, false);
-        document.getElementById('downloadVideoNative').addEventListener('click', downloadVideoNative, false);
-        document.getElementById('testPrivateURL').addEventListener('click', testPrivateURL, false);
-        var fsButtons = document.querySelectorAll('.resolveFs');
-        for (var i=0; i < fsButtons.length; ++i) {
-            fsButtons[i].addEventListener('click', resolveFs, false);
-        }
-    }
-
-    function clearLog() {
-        var log = document.getElementById("log");
-        log.innerHTML = "";
-    }
-
-    function logMessage(message, color) {
-        var log = document.getElementById("log");
-        var logLine = document.createElement('div');
-        if (color) {
-            logLine.style.color = color;
-        }
-        logLine.innerHTML = message;
-        log.appendChild(logLine);
-    }
-
-    function logError(serviceName) {
-        return function(err) {
-            logMessage("ERROR: " + serviceName + " " + JSON.stringify(err), "red");
-        };
-    }
-
-    function downloadImgCDV(ev) {
-        ev.preventDefault();
-        ev.stopPropagation();
-        downloadImg(imageURL, function(entry) { return entry.toURL(); }, new Image());
-    }
-
-    function downloadImgNative(ev) {
-        ev.preventDefault();
-        ev.stopPropagation();
-        downloadImg(imageURL, function(entry) { return entry.toNativeURL(); }, new Image);
-    }
-
-    function downloadVideoCDV(ev) {
-        ev.preventDefault();
-        ev.stopPropagation();
-        var videoElement = document.createElement('video');
-        videoElement.controls = "controls";
-        downloadImg(videoURL, function(entry) { return entry.toURL(); }, videoElement);
-    }
-
-    function downloadVideoNative(ev) {
-        ev.preventDefault();
-        ev.stopPropagation();
-        var videoElement = document.createElement('video');
-        videoElement.controls = "controls";
-        downloadImg(videoURL, function(entry) { return entry.toNativeURL(); }, videoElement);
-    }
-
-    function downloadImg(source, urlFn, element) {
-        var filename = source.substring(source.lastIndexOf("/")+1);
-        function download(fileSystem) {
-            var ft = new FileTransfer();
-            logMessage("Starting download");
-            ft.download(source, fileSystem.root.toURL() + filename, function(entry) {
-                logMessage("Download complete")
-                element.src = urlFn(entry)
-                logMessage("Src URL is " + element.src, "green");
-                logMessage("Inserting element");
-                document.getElementById("output").appendChild(element);
-            }, logError("ft.download"));
-        }
-        clearLog();
-        logMessage("Requesting filesystem");
-        requestFileSystem(TEMPORARY, 0, function(fileSystem) {
-            logMessage("Checking for existing file");
-            fileSystem.root.getFile(filename, {create: false}, function(entry) {
-                logMessage("Removing existing file");
-                entry.remove(function() {
-                    download(fileSystem);
-                }, logError("entry.remove"));
-            }, function() {
-                download(fileSystem);
-            });
-        }, logError("requestFileSystem"));
-    }
-
-    function testPrivateURL(ev) {
-        ev.preventDefault();
-        ev.stopPropagation();
-        requestFileSystem(TEMPORARY, 0, function(fileSystem) {
-            logMessage("Temporary root is at " + fileSystem.root.toNativeURL());
-            fileSystem.root.getFile("testfile", {create: true}, function(entry) {
-                logMessage("Temporary file is at " + entry.toNativeURL());
-                if (entry.toNativeURL().substring(0,12) == "file:///var/") {
-                    logMessage("File starts with /var/, trying /private/var");
-                    var newURL = "file://localhost/private/var/" + entry.toNativeURL().substring(12) + "?and=another_thing";
-                    //var newURL = entry.toNativeURL();
-                    logMessage(newURL, 'blue');
-                    resolveLocalFileSystemURL(newURL, function(newEntry) {
-                        logMessage("Successfully resolved.", 'green');
-                        logMessage(newEntry.toURL(), 'blue');
-                        logMessage(newEntry.toNativeURL(), 'blue');
-                    }, logError("resolveLocalFileSystemURL"));
-                }
-            }, logError("getFile"));
-        }, logError("requestFileSystem"));
-    }
-
-    function resolveFs(ev) {
-        var fsURL = "cdvfile://localhost/" + ev.target.getAttribute('data-fsname') + "/";
-        logMessage("Resolving URL: " + fsURL);
-        resolveLocalFileSystemURL(fsURL, function(entry) {
-            logMessage("Success", 'green');
-            logMessage(entry.toURL(), 'blue');
-            logMessage(entry.toInternalURL(), 'blue');
-            logMessage("Resolving URL: " + entry.toURL());
-            resolveLocalFileSystemURL(entry.toURL(), function(entry2) {
-                logMessage("Success", 'green');
-                logMessage(entry2.toURL(), 'blue');
-                logMessage(entry2.toInternalURL(), 'blue');
-            }, logError("resolveLocalFileSystemURL"));
-        }, logError("resolveLocalFileSystemURL"));
-    }
-</script>
+    <script type="text/javascript" charset="utf-8" src="./index.js"></script>      
 
   </head>
-  <body onload="init();" id="stage" class="theme">
+  <body id="stage" class="theme">
 
     <h1>File and File Transfer</h1>
     <h2>File</h2>
@@ -219,6 +67,6 @@
 
     <div id="log"></div>
     <div id="output"></div>
-    <h2> </h2><div class="backBtn" onclick="backHome();">Back</div>
+    <h2> </h2><div class="backBtn">Back</div>
   </body>
 </html>

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/a7c88d8f/file/index.js
----------------------------------------------------------------------
diff --git a/file/index.js b/file/index.js
new file mode 100644
index 0000000..1f570dd
--- /dev/null
+++ b/file/index.js
@@ -0,0 +1,153 @@
+var deviceReady = false;
+
+var imageURL = "http://apache.org/images/feather-small.gif";
+var videoURL = "http://techslides.com/demos/sample-videos/small.mp4";
+
+/**
+ * Function called when page has finished loading.
+ */
+function init() {
+    document.addEventListener("deviceready", function() {
+            deviceReady = true;
+            console.log("Device="+device.platform+" "+device.version);
+            bindEvents();
+            document.body.classList.add(device.platform.toLowerCase() + "-platform");
+        }, false);
+    window.setTimeout(function() {
+        if (!deviceReady) {
+            alert("Error: Apache Cordova did not initialize.  Demo will not run correctly.");
+        }
+    },1000);
+}
+
+function bindEvents() {
+    document.getElementById('downloadImgCDV').addEventListener('click', downloadImgCDV, false);
+    document.getElementById('downloadImgNative').addEventListener('click', downloadImgNative, false);
+    document.getElementById('downloadVideoCDV').addEventListener('click', downloadVideoCDV, false);
+    document.getElementById('downloadVideoNative').addEventListener('click', downloadVideoNative, false);
+    document.getElementById('testPrivateURL').addEventListener('click', testPrivateURL, false);
+    var fsButtons = document.querySelectorAll('.resolveFs');
+    for (var i=0; i < fsButtons.length; ++i) {
+        fsButtons[i].addEventListener('click', resolveFs, false);
+    }
+}
+
+function clearLog() {
+    var log = document.getElementById("log");
+    log.innerHTML = "";
+}
+
+function logMessage(message, color) {
+    var log = document.getElementById("log");
+    var logLine = document.createElement('div');
+    if (color) {
+        logLine.style.color = color;
+    }
+    logLine.innerHTML = message;
+    log.appendChild(logLine);
+}
+
+function logError(serviceName) {
+    return function(err) {
+        logMessage("ERROR: " + serviceName + " " + JSON.stringify(err), "red");
+    };
+}
+
+function downloadImgCDV(ev) {
+    ev.preventDefault();
+    ev.stopPropagation();
+    downloadImg(imageURL, function(entry) { return entry.toURL(); }, new Image());
+}
+
+function downloadImgNative(ev) {
+    ev.preventDefault();
+    ev.stopPropagation();
+    downloadImg(imageURL, function(entry) { return entry.toNativeURL(); }, new Image);
+}
+
+function downloadVideoCDV(ev) {
+    ev.preventDefault();
+    ev.stopPropagation();
+    var videoElement = document.createElement('video');
+    videoElement.controls = "controls";
+    downloadImg(videoURL, function(entry) { return entry.toURL(); }, videoElement);
+}
+
+function downloadVideoNative(ev) {
+    ev.preventDefault();
+    ev.stopPropagation();
+    var videoElement = document.createElement('video');
+    videoElement.controls = "controls";
+    downloadImg(videoURL, function(entry) { return entry.toNativeURL(); }, videoElement);
+}
+
+function downloadImg(source, urlFn, element) {
+    var filename = source.substring(source.lastIndexOf("/")+1);
+    function download(fileSystem) {
+        var ft = new FileTransfer();
+        logMessage("Starting download");
+        ft.download(source, fileSystem.root.toURL() + filename, function(entry) {
+            logMessage("Download complete")
+            element.src = urlFn(entry)
+            logMessage("Src URL is " + element.src, "green");
+            logMessage("Inserting element");
+            document.getElementById("output").appendChild(element);
+        }, logError("ft.download"));
+    }
+    clearLog();
+    logMessage("Requesting filesystem");
+    requestFileSystem(TEMPORARY, 0, function(fileSystem) {
+        logMessage("Checking for existing file");
+        fileSystem.root.getFile(filename, {create: false}, function(entry) {
+            logMessage("Removing existing file");
+            entry.remove(function() {
+                download(fileSystem);
+            }, logError("entry.remove"));
+        }, function() {
+            download(fileSystem);
+        });
+    }, logError("requestFileSystem"));
+}
+
+function testPrivateURL(ev) {
+    ev.preventDefault();
+    ev.stopPropagation();
+    requestFileSystem(TEMPORARY, 0, function(fileSystem) {
+        logMessage("Temporary root is at " + fileSystem.root.toNativeURL());
+        fileSystem.root.getFile("testfile", {create: true}, function(entry) {
+            logMessage("Temporary file is at " + entry.toNativeURL());
+            if (entry.toNativeURL().substring(0,12) == "file:///var/") {
+                logMessage("File starts with /var/, trying /private/var");
+                var newURL = "file://localhost/private/var/" + entry.toNativeURL().substring(12) + "?and=another_thing";
+                //var newURL = entry.toNativeURL();
+                logMessage(newURL, 'blue');
+                resolveLocalFileSystemURL(newURL, function(newEntry) {
+                    logMessage("Successfully resolved.", 'green');
+                    logMessage(newEntry.toURL(), 'blue');
+                    logMessage(newEntry.toNativeURL(), 'blue');
+                }, logError("resolveLocalFileSystemURL"));
+            }
+        }, logError("getFile"));
+    }, logError("requestFileSystem"));
+}
+
+function resolveFs(ev) {
+    var fsURL = "cdvfile://localhost/" + ev.target.getAttribute('data-fsname') + "/";
+    logMessage("Resolving URL: " + fsURL);
+    resolveLocalFileSystemURL(fsURL, function(entry) {
+        logMessage("Success", 'green');
+        logMessage(entry.toURL(), 'blue');
+        logMessage(entry.toInternalURL(), 'blue');
+        logMessage("Resolving URL: " + entry.toURL());
+        resolveLocalFileSystemURL(entry.toURL(), function(entry2) {
+            logMessage("Success", 'green');
+            logMessage(entry2.toURL(), 'blue');
+            logMessage(entry2.toInternalURL(), 'blue');
+        }, logError("resolveLocalFileSystemURL"));
+    }, logError("resolveLocalFileSystemURL"));
+}
+
+window.onload = function() {
+  addListenerToClass('backBtn', backHome);
+  init();
+}