cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From za...@apache.org
Subject [02/12] Manual tests fixed
Date Tue, 10 Jun 2014 10:00:54 GMT
http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/a7c88d8f/inappbrowser/index.html
----------------------------------------------------------------------
diff --git a/inappbrowser/index.html b/inappbrowser/index.html
index b0c1ad0..b06ed11 100644
--- a/inappbrowser/index.html
+++ b/inappbrowser/index.html
@@ -28,177 +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 called when page has finished loading.
-     */
-    function init() {
-        document.addEventListener("deviceready", function() {
-                deviceReady = true;
-                console.log("Device="+device.platform+" "+device.version);
-            }, false);
-        function updateUserAgent() {
-            document.getElementById("user-agent").textContent = navigator.userAgent;
-        }
-        updateUserAgent();
-        window.setInterval(updateUserAgent, 1500);
-        window.setTimeout(function() {
-        	if (!deviceReady) {
-        		alert("Error: Apache Cordova did not initialize.  Demo will not run correctly.");
-        	}
-        },1000);
-    }
-
-    function doOpen(url, target, params, numExpectedRedirects) {
-        numExpectedRedirects = numExpectedRedirects || 0;
-        var iab = window.open(url, target, params);
-        if (!iab) {
-            alert('window.open returned ' + iab);
-            return;
-        }
-        var counts;
-        var lastLoadStartURL;
-        var wasReset = false;
-        function reset()  {
-            counts = {
-                'loaderror': 0,
-                'loadstart': 0,
-                'loadstop': 0,
-                'exit': 0
-            };
-            lastLoadStartURL = '';
-        }
-        reset();
-
-        function logEvent(e) {
-            console.log('IAB event=' + JSON.stringify(e));
-            counts[e.type]++;
-            // Verify that event.url gets updated on redirects.
-            if (e.type == 'loadstart') {
-                if (e.url == lastLoadStartURL) {
-                    alert('Unexpected: loadstart fired multiple times for the same URL.');
-                }
-                lastLoadStartURL = e.url;
-            }
-            // Verify the right number of loadstart events were fired.
-            if (e.type == 'loadstop' || e.type == 'loaderror') {
-                if (e.url != lastLoadStartURL) {
-                    alert('Unexpected: ' + e.type + ' event.url != loadstart\'s event.url');
-                }
-                if (numExpectedRedirects === 0 && counts['loadstart'] !== 1) {
-                    // Do allow a loaderror without a loadstart (e.g. in the case of an invalid URL).
-                    if (!(e.type == 'loaderror' && counts['loadstart'] === 0)) {
-                        alert('Unexpected: got multiple loadstart events. (' + counts['loadstart'] + ')');
-                    }
-                } else if (numExpectedRedirects > 0 && counts['loadstart'] < (numExpectedRedirects+1)) {
-                    alert('Unexpected: should have got at least ' + (numExpectedRedirects+1) + ' loadstart events, but got ' + counts['loadstart']);
-                }
-                wasReset = true;
-                numExpectedRedirects = 0;
-                reset();
-            }
-            // Verify that loadend / loaderror was called.
-            if (e.type == 'exit') {
-                var numStopEvents = counts['loadstop'] + counts['loaderror'];
-                if (numStopEvents === 0 && !wasReset) {
-                    alert('Unexpected: browser closed without a loadstop or loaderror.')
-                } else if (numStopEvents > 1) {
-                    alert('Unexpected: got multiple loadstop/loaderror events.');
-                }
-            }
-        }
-        iab.addEventListener('loaderror', logEvent);
-        iab.addEventListener('loadstart', logEvent);
-        iab.addEventListener('loadstop', logEvent);
-        iab.addEventListener('exit', logEvent);
-
-        return iab;
-    }
-
-    function openWithStyle(url, cssUrl, useCallback) {
-        var iab = doOpen(url, '_blank', 'location=yes');
-        var callback = function(results) {
-            if (results && results.length === 0) {
-                alert('Results verified');
-            } else {
-                console.log(results);
-                alert('Got: ' + typeof(results) + '\n' + JSON.stringify(results));
-            }
-        };
-        if (cssUrl) {
-            iab.addEventListener('loadstop', function(event) {
-                iab.insertCSS({file: cssUrl}, useCallback && callback);
-            });
-        } else {
-            iab.addEventListener('loadstop', function(event) {
-                iab.insertCSS({code:'#style-update-literal { \ndisplay: block !important; \n}'},
-                              useCallback && callback);
-            });
-        }
-    }
-
-    function openWithScript(url, jsUrl, useCallback) {
-        var iab = doOpen(url, '_blank', 'location=yes');
-        if (jsUrl) {
-            iab.addEventListener('loadstop', function(event) {
-                iab.executeScript({file: jsUrl}, useCallback && function(results) {
-                    if (results && results.length === 0) {
-                        alert('Results verified');
-                    } else {
-                        console.log(results);
-                        alert('Got: ' + typeof(results) + '\n' + JSON.stringify(results));
-                    }
-                });
-            });
-        } else {
-            iab.addEventListener('loadstop', function(event) {
-                var code = '(function(){\n' +
-                  '    var header = document.getElementById("header");\n' +
-                  '    header.innerHTML = "Script literal successfully injected";\n' +
-                  '    return "abc";\n' +
-                  '})()';
-                iab.executeScript({code:code}, useCallback && function(results) {
-                    if (results && results.length === 1 && results[0] === 'abc') {
-                        alert('Results verified');
-                    } else {
-                        console.log(results);
-                        alert('Got: ' + typeof(results) + '\n' + JSON.stringify(results));
-                    }
-                });
-            });
-        }
-    }
-    var hiddenwnd=null;
-    var loadlistener = function(event) { alert('background window loaded ' ); };
-    function openHidden(url, startHidden) {
-        var shopt =(startHidden) ? 'hidden=yes' : '';
-        hiddenwnd = window.open(url,'random_string',shopt);
-        if (!hiddenwnd) {
-            alert('window.open returned ' + hiddenwnd);
-            return;
-        }
-        if(startHidden) hiddenwnd.addEventListener('loadstop', loadlistener);
-    }
-    function showHidden() {
-        if(!!hiddenwnd ) {
-            hiddenwnd.show();
-        }
-    }
-    function closeHidden() {
-       if(!!hiddenwnd ) {
-           hiddenwnd.removeEventListener('loadstop',loadlistener);
-           hiddenwnd.close();
-           hiddenwnd=null;
-       }
-    }
-    </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>InAppBrowser</h1>
     <div id="info">
@@ -206,199 +38,199 @@
         Make sure http://www.apple.com is not in the white list.</br>  In iOS, starred <span style="vertical-align:super">*</span> tests will put the app in a state with no way to return.  </br>
         <h4>User-Agent: <span id="user-agent"> </span></h4>
     </div>
-    <div class="btn small" onclick="backHome();">Back</div>
+    <div class="btn small backBtn">Back</div>
 
     <h1>Local URL</h1>
-    <div class="btn large" onclick="doOpen('local.html');">target = Default</div>
+    <div class="btn large openLocal">target = Default</div>
     Expected result: opens successfully in CordovaWebView.
 
     <p/>
-    <div class="btn large" onclick="doOpen('local.html', '_self');">target=_self</div>
+    <div class="btn large openLocalSelf">target=_self</div>
     Expected result: opens successfully in CordovaWebView.
 
     <p/>
-    <div class="btn large" onclick="doOpen('local.html', '_system');">target=_system</div>
+    <div class="btn large openLocalSystem">target=_system</div>
     Expected result: fails to open.
 
     <p/>
-    <div class="btn large" onclick="doOpen('local.html', '_blank');">target=_blank</div>
+    <div class="btn large openLocalBlank">target=_blank</div>
     Expected result: opens successfully in InAppBrowser with locationBar at top.
 
     <p/>
-    <div class="btn large" onclick="doOpen('local.html', 'random_string', 'location=no,disallowoverscroll=yes');">target=Random, location=no,disallowoverscroll=yes</div>
+    <div class="btn large openLocalRandomNoLocation">target=Random, location=no,disallowoverscroll=yes</div>
     Expected result: opens successfully in InAppBrowser without locationBar.
 
     <p/>
-    <div class="btn large" onclick="doOpen('local.html', 'random_string', 'toolbarposition=bottom');">target=Random, toolbarposition=bottom</div>
+    <div class="btn large openLocalRandomToolBarBottom">target=Random, toolbarposition=bottom</div>
     Expected result: opens successfully in InAppBrowser with locationBar. On iOS the toolbar is at the bottom.
 
     <p/>
-    <div class="btn large" onclick="doOpen('local.html', 'random_string', 'toolbarposition=top');">target=Random, toolbarposition=top</div>
+    <div class="btn large openLocalRandomToolBarTop">target=Random, toolbarposition=top</div>
     Expected result: opens successfully in InAppBrowser with locationBar. On iOS the toolbar is at the top.
 
     <p/>
-    <div class="btn large" onclick="doOpen('local.html', 'random_string', 'toolbarposition=top,location=no');">target=Random, toolbarposition=top,location=no</div>
+    <div class="btn large openLocalRandomToolBarTopNoLocation">target=Random, toolbarposition=top,location=no</div>
     Expected result: opens successfully in InAppBrowser with no locationBar. On iOS the toolbar is at the top.
 
     <h1>White Listed URL</h1>
 
-    <div class="btn large" onclick="doOpen('http://www.google.com');">target=Default<span style="vertical-align:super">*</span></div>
+    <div class="btn large openWhiteListed">target=Default<span style="vertical-align:super">*</span></div>
     Expected result: open successfully in CordovaWebView to www.google.com.
 
     <p/>
-    <div class="btn large" onclick="doOpen('http://www.google.com', '_self');">target=_self<span style="vertical-align:super">*</span></div>
+    <div class="btn large openWhiteListedSelf">target=_self<span style="vertical-align:super">*</span></div>
     Expected result: open successfully in CordovaWebView to www.google.com.
 
     <p/>
-    <div class="btn large" onclick="doOpen('http://www.google.com', '_system');">target=_system</div>
+    <div class="btn large openWhiteListedSystem">target=_system</div>
     Expected result: open successfully in system browser to www.google.com.
 
     <p/>
-    <div class="btn large" onclick="doOpen('http://www.google.com', '_blank');">target=_blank</div>
+    <div class="btn large openWhiteListedBlank">target=_blank</div>
     Expected result: open successfully in InAppBrowser to www.google.com.
 
     <p/>
-    <div class="btn large" onclick="doOpen('http://www.google.com', 'random_string');">target=Random</div>
+    <div class="btn large openWhiteListedRandom">target=Random</div>
     Expected result: open successfully in InAppBrowser to www.google.com.
 
     <p/>
-    <div class="btn large" onclick="doOpen('http://www.google.com', 'random_string', 'location=no');">target=Random, no location bar<span style="vertical-align:super">*</span></div>
+    <div class="btn large openWhiteListedRandomNoLocation">target=Random, no location bar<span style="vertical-align:super">*</span></div>
     Expected result: open successfully in InAppBrowser to www.google.com with no location bar.
 
     <h1>Non White Listed URL</h1>
 
-    <div class="btn large" onclick="doOpen('http://www.apple.com');">target=Default</div>
+    <div class="btn large openNonWhiteListed">target=Default</div>
     Expected result: open successfully in InAppBrowser to apple.com (_self enforces whitelist).
 
     <p/>
-    <div class="btn large" onclick="doOpen('http://www.apple.com', '_self');">target=_self</div>
+    <div class="btn larg openNonWhiteListedSelf">target=_self</div>
     Expected result: open successfully in InAppBrowser to apple.com (_self enforces whitelist).
 
     <p/>
-    <div class="btn large" onclick="doOpen('http://www.apple.com', '_system');">target=_system</div>
+    <div class="btn large openNonWhiteListedSystem">target=_system</div>
     Expected result: open successfully in system browser to apple.com.
 
     <p/>
-    <div class="btn large" onclick="doOpen('http://www.apple.com', '_blank');">target=_blank</div>
+    <div class="btn large openNonWhiteListedBlank">target=_blank</div>
     Expected result: open successfully in InAppBrowser to apple.com.
 
     <p/>
-    <div class="btn large" onclick="doOpen('http://www.apple.com', 'random_string');">target=Random</div>
+    <div class="btn large openNonWhiteListedRandom">target=Random</div>
     Expected result: open successfully in InAppBrowser to apple.com.
 
     <p/>
-    <div class="btn large" onclick="doOpen('http://www.apple.com', 'random_string', 'location=no');">target=Random, no location bar<span style="vertical-align:super">*</span></div>
+    <div class="btn large openNonWhiteListedRandomNoLocation">target=Random, no location bar<span style="vertical-align:super">*</span></div>
     Expected result: open successfully in InAppBrowser to apple.com without locationBar.
 
     <h1>Page with redirect</h1>
 
-    <div class="btn large" onclick="doOpen('http://google.com', 'random_string', '', 1);">http://google.com</div>
+    <div class="btn large openRedirect301">http://google.com</div>
     Expected result: should 301 and open successfully in InAppBrowser to www.google.com.
 
     <p/>
-    <div class="btn large" onclick="doOpen('http://goo.gl/pUFqg', 'random_string', '', 2);">http://goo.gl/pUFqg</div>
+    <div class="btn large openRedirect302">http://goo.gl/pUFqg</div>
     Expected result: should 302 and open successfully in InAppBrowser to www.zhihu.com/answer/16714076.
 
     <h1>PDF URL</h1>
 
-    <div class="btn large" onclick="doOpen('http://www.stluciadance.com/prospectus_file/sample.pdf');">Remote URL</div>
+    <div class="btn large openPDF">Remote URL</div>
     Expected result: InAppBrowser opens. PDF should render on iOS.
 
     <p/>
-    <div class="btn large" onclick="doOpen('local.pdf', '_blank');">Local URL</div>
+    <div class="btn large openPDFBlank">Local URL</div>
     Expected result: InAppBrowser opens. PDF should render on iOS.
 
     <h1>Invalid URL</h1>
 
-    <div class="btn large" onclick="doOpen('x-ttp://www.invalid.com/', '_blank');">Invalid Scheme</div>
+    <div class="btn large openInvalidScheme">Invalid Scheme</div>
     Expected result: fail to load in InAppBrowser.
 
     <p/>
-    <div class="btn large" onclick="doOpen('http://www.inv;alid.com/', '_blank');">Invalid Host</div>
+    <div class="btn large openInvalidHost">Invalid Host</div>
     Expected result: fail to load in InAppBrowser.
 
     <p/>
-    <div class="btn large" onclick="doOpen('nonexistent.html', '_blank');">Missing Local File</div>
+    <div class="btn large openInvalidMissing">Missing Local File</div>
     Expected result: fail to load in InAppBrowser (404).
 
     <h1>CSS / JS Injection</h1>
 
-    <div class="btn large" onclick="doOpen('inject.html', '_blank');">Original Document</div>
+    <div class="btn large openOriginalDocument">Original Document</div>
     Expected result: open successfully in InAppBrowser without text "Style updated from..."
 
     <p/> 
-    <div class="btn large" onclick="openWithStyle('inject.html','inject.css');">CSS File Injection</div>
+    <div class="btn large openCSSInjection">CSS File Injection</div>
     Expected result: open successfully in InAppBrowser with "Style updated from file".
 
     <p/>
-    <div class="btn large" onclick="openWithStyle('inject.html','inject.css', true);">CSS File Injection (callback)</div>
+    <div class="btn large openCSSInjectionCallback">CSS File Injection (callback)</div>
     Expected result: open successfully in InAppBrowser with "Style updated from file", and alert dialog with text "Results verified".
 
     <p/>
-    <div class="btn large" onclick="openWithStyle('inject.html');">CSS Literal Injection</div>
+    <div class="btn large openCSSLiteralInjection">CSS Literal Injection</div>
     Expected result: open successfully in InAppBrowser with "Style updated from literal".
 
     <p/>
-    <div class="btn large" onclick="openWithStyle('inject.html', null, true);">CSS Literal Injection (callback)</div>
+    <div class="btn large openCSSLiteralInjectionCallback">CSS Literal Injection (callback)</div>
     Expected result: open successfully in InAppBrowser with "Style updated from literal", and alert dialog with text "Results verified".
 
     <p/>
-    <div class="btn large" onclick="openWithScript('inject.html', 'inject.js');">Script File Injection</div>
+    <div class="btn large openScriptInjection">Script File Injection</div>
     Expected result: open successfully in InAppBrowser with text "Script file successfully injected".
 
     <p/>
-    <div class="btn large" onclick="openWithScript('inject.html', 'inject.js', true);">Script File Injection (callback)</div>
+    <div class="btn large openScriptInjectionCallback">Script File Injection (callback)</div>
     Expected result: open successfully in InAppBrowser with text "Script file successfully injected" and alert dialog with the text "Results verified".
 
     <p/>
-    <div class="btn large" onclick="openWithScript('inject.html');">Script Literal Injection</div>
+    <div class="btn large openScriptLiteralInjection">Script Literal Injection</div>
     Expected result: open successfully in InAppBrowser with the text "Script literal successfully injected" .
 
     <p/>
-    <div class="btn large" onclick="openWithScript('inject.html', null, true);">Script Literal Injection (callback)</div>
+    <div class="btn large openScriptLiteralInjectionCallback">Script Literal Injection (callback)</div>
     Expected result: open successfully in InAppBrowser with the text "Script literal successfully injected" and alert dialog with the text "Results verified".
 
     <h1>Open Hidden </h1>
-    <div class="btn large" onclick="openHidden('http://google.com',true);">create hidden</div>
+    <div class="btn large openHidden">create hidden</div>
     Expected result: no additional browser window. Alert appears with the text "background window loaded".
 
     <p/>
-    <div class="btn large" onclick="showHidden();">show hidden</div>
+    <div class="btn large showHidden">show hidden</div>
     Expected result: after first clicking on previous test "create hidden", open successfully in InAppBrowser to google.com.
 
     <p/>
-    <div class="btn large" onclick="closeHidden();">close hidden</div>
+    <div class="btn large closeHidden">close hidden</div>
     Expected result: no output. But click on "show hidden" again and nothing should be shown.
 
     <p/>
-    <div class="btn large" onclick="openHidden('http://google.com',false);">google.com not hidden</div>
+    <div class="btn large openHiddenShow">google.com not hidden</div>
     Expected result: open successfully in InAppBrowser to www.google.com
 
     <h1>Clearing Cache</h1>
 
-    <div class="btn large" onclick="doOpen('http://www.google.com', '_blank', 'clearcache=yes');">Clear Browser Cache</div>
+    <div class="btn large openClearCache">Clear Browser Cache</div>
     Expected result: ?
 
     <p/>
-    <div class="btn large" onclick="doOpen('http://www.google.com', '_blank', 'clearsessioncache=yes');">Clear Session Cache</div>
+    <div class="btn large openClearSessionCache">Clear Session Cache</div>
     Expected result: ?
 
     <h1>Video tag</h1>
 
-    <div class="btn large" onclick="doOpen('video.html', '_blank');">remote video</div>
+    <div class="btn large openRemoteVideo">remote video</div>
     Expected result: open successfully in InAppBrowser with an embedded video that works after clicking the "play" button.
 
     <h1>Local with anchor tag</h1>
 
-    <div class="btn large" onclick="doOpen('local.html#anchor1', '_blank');">Anchor1</div>
+    <div class="btn large openAnchor1">Anchor1</div>
     Expected result: open successfully in InAppBrowser to the local page, scrolled to the top.
 
     <p/>
-    <div class="btn large" onclick="doOpen('local.html#anchor2', '_blank');">Anchor2</div>
+    <div class="btn large openAnchor2">Anchor2</div>
     Expected result: open successfully in InAppBrowser to the local page, scrolled to the beginning of the tall div with border.
     
     <p/>
-    <div class="backBtn" onclick="backHome();">Back</div>
+    <div class="backBtn">Back</div>
 
   </body>
 </html>

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/a7c88d8f/inappbrowser/index.js
----------------------------------------------------------------------
diff --git a/inappbrowser/index.js b/inappbrowser/index.js
new file mode 100644
index 0000000..a08c30d
--- /dev/null
+++ b/inappbrowser/index.js
@@ -0,0 +1,242 @@
+var deviceReady = false;
+
+/**
+ * Function called when page has finished loading.
+ */
+function init() {
+    document.addEventListener("deviceready", function() {
+            deviceReady = true;
+            console.log("Device="+device.platform+" "+device.version);
+        }, false);
+    function updateUserAgent() {
+        document.getElementById("user-agent").textContent = navigator.userAgent;
+    }
+    updateUserAgent();
+    window.setInterval(updateUserAgent, 1500);
+    window.setTimeout(function() {
+      if (!deviceReady) {
+        alert("Error: Apache Cordova did not initialize.  Demo will not run correctly.");
+      }
+    },1000);
+}
+
+function doOpen(url, target, params, numExpectedRedirects) {
+    numExpectedRedirects = numExpectedRedirects || 0;
+    var iab = window.open(url, target, params);
+    if (!iab) {
+        alert('window.open returned ' + iab);
+        return;
+    }
+    var counts;
+    var lastLoadStartURL;
+    var wasReset = false;
+    function reset()  {
+        counts = {
+            'loaderror': 0,
+            'loadstart': 0,
+            'loadstop': 0,
+            'exit': 0
+        };
+        lastLoadStartURL = '';
+    }
+    reset();
+
+    function logEvent(e) {
+        console.log('IAB event=' + JSON.stringify(e));
+        counts[e.type]++;
+        // Verify that event.url gets updated on redirects.
+        if (e.type == 'loadstart') {
+            if (e.url == lastLoadStartURL) {
+                alert('Unexpected: loadstart fired multiple times for the same URL.');
+            }
+            lastLoadStartURL = e.url;
+        }
+        // Verify the right number of loadstart events were fired.
+        if (e.type == 'loadstop' || e.type == 'loaderror') {
+            if (e.url != lastLoadStartURL) {
+                alert('Unexpected: ' + e.type + ' event.url != loadstart\'s event.url');
+            }
+            if (numExpectedRedirects === 0 && counts['loadstart'] !== 1) {
+                // Do allow a loaderror without a loadstart (e.g. in the case of an invalid URL).
+                if (!(e.type == 'loaderror' && counts['loadstart'] === 0)) {
+                    alert('Unexpected: got multiple loadstart events. (' + counts['loadstart'] + ')');
+                }
+            } else if (numExpectedRedirects > 0 && counts['loadstart'] < (numExpectedRedirects+1)) {
+                alert('Unexpected: should have got at least ' + (numExpectedRedirects+1) + ' loadstart events, but got ' + counts['loadstart']);
+            }
+            wasReset = true;
+            numExpectedRedirects = 0;
+            reset();
+        }
+        // Verify that loadend / loaderror was called.
+        if (e.type == 'exit') {
+            var numStopEvents = counts['loadstop'] + counts['loaderror'];
+            if (numStopEvents === 0 && !wasReset) {
+                alert('Unexpected: browser closed without a loadstop or loaderror.')
+            } else if (numStopEvents > 1) {
+                alert('Unexpected: got multiple loadstop/loaderror events.');
+            }
+        }
+    }
+    iab.addEventListener('loaderror', logEvent);
+    iab.addEventListener('loadstart', logEvent);
+    iab.addEventListener('loadstop', logEvent);
+    iab.addEventListener('exit', logEvent);
+
+    return iab;
+}
+
+function openWithStyle(url, cssUrl, useCallback) {
+    var iab = doOpen(url, '_blank', 'location=yes');
+    var callback = function(results) {
+        if (results && results.length === 0) {
+            alert('Results verified');
+        } else {
+            console.log(results);
+            alert('Got: ' + typeof(results) + '\n' + JSON.stringify(results));
+        }
+    };
+    if (cssUrl) {
+        iab.addEventListener('loadstop', function(event) {
+            iab.insertCSS({file: cssUrl}, useCallback && callback);
+        });
+    } else {
+        iab.addEventListener('loadstop', function(event) {
+            iab.insertCSS({code:'#style-update-literal { \ndisplay: block !important; \n}'},
+                          useCallback && callback);
+        });
+    }
+}
+
+function openWithScript(url, jsUrl, useCallback) {
+    var iab = doOpen(url, '_blank', 'location=yes');
+    if (jsUrl) {
+        iab.addEventListener('loadstop', function(event) {
+            iab.executeScript({file: jsUrl}, useCallback && function(results) {
+                if (results && results.length === 0) {
+                    alert('Results verified');
+                } else {
+                    console.log(results);
+                    alert('Got: ' + typeof(results) + '\n' + JSON.stringify(results));
+                }
+            });
+        });
+    } else {
+        iab.addEventListener('loadstop', function(event) {
+            var code = '(function(){\n' +
+              '    var header = document.getElementById("header");\n' +
+              '    header.innerHTML = "Script literal successfully injected";\n' +
+              '    return "abc";\n' +
+              '})()';
+            iab.executeScript({code:code}, useCallback && function(results) {
+                if (results && results.length === 1 && results[0] === 'abc') {
+                    alert('Results verified');
+                } else {
+                    console.log(results);
+                    alert('Got: ' + typeof(results) + '\n' + JSON.stringify(results));
+                }
+            });
+        });
+    }
+}
+var hiddenwnd=null;
+var loadlistener = function(event) { alert('background window loaded ' ); };
+function openHidden(url, startHidden) {
+    var shopt =(startHidden) ? 'hidden=yes' : '';
+    hiddenwnd = window.open(url,'random_string',shopt);
+    if (!hiddenwnd) {
+        alert('window.open returned ' + hiddenwnd);
+        return;
+    }
+    if(startHidden) hiddenwnd.addEventListener('loadstop', loadlistener);
+}
+function showHidden() {
+    if(!!hiddenwnd ) {
+        hiddenwnd.show();
+    }
+}
+function closeHidden() {
+   if(!!hiddenwnd ) {
+       hiddenwnd.removeEventListener('loadstop',loadlistener);
+       hiddenwnd.close();
+       hiddenwnd=null;
+   }
+}
+
+window.onload = function() {
+  addListenerToClass('openLocal', doOpen, 'local.html');
+  addListenerToClass('openLocalSelf', doOpen, ['local.html', '_self']);
+  addListenerToClass('openLocalSystem', doOpen, ['local.html', '_system']);
+  addListenerToClass('openLocalBlank', doOpen, ['local.html', '_blank']);
+  addListenerToClass('openLocalRandomNoLocation', doOpen, 
+      ['local.html', 'random_string', 'location=no,disallowoverscroll=yes']);
+  addListenerToClass('openLocalRandomToolBarBottom', doOpen,
+      ['local.html', 'random_string', 'toolbarposition=bottom']);
+  addListenerToClass('openLocalRandomToolBarTop', doOpen, 
+      ['local.html', 'random_string', 'toolbarposition=top']);
+  addListenerToClass('openLocalRandomToolBarTopNoLocation', doOpen, 
+      ['local.html', 'random_string', 'toolbarposition=top,location=no']);
+  addListenerToClass('openWhiteListed', doOpen, 'http://www.google.com');
+  addListenerToClass('openWhiteListedSelf', doOpen, 
+      ['http://www.google.com', '_self']);
+  addListenerToClass('openWhiteListedSystem', doOpen,
+      ['http://www.google.com', '_system']);
+  addListenerToClass('openWhiteListedBlank', doOpen, 
+      ['http://www.google.com', '_blank']);
+  addListenerToClass('openWhiteListedRandom', doOpen,
+      ['http://www.google.com', 'random_string']);
+  addListenerToClass('openWhiteListedRandomNoLocation', doOpen,
+      ['http://www.google.com', 'random_string', 'location=no']);
+  addListenerToClass('openNonWhiteListed', doOpen, 'http://www.apple.com');
+  addListenerToClass('openNonWhiteListedSelf', doOpen, 
+      ['http://www.apple.com', '_self']);
+  addListenerToClass('openNonWhiteListedSystem', doOpen, 
+      ['http://www.apple.com', '_system']);
+  addListenerToClass('openNonWhiteListedBlank', doOpen, 
+      ['http://www.apple.com', '_blank']);
+  addListenerToClass('openNonWhiteListedRandom', doOpen,
+      ['http://www.apple.com', 'random_string']);
+  addListenerToClass('openNonWhiteListedRandomNoLocation', doOpen, 
+      ['http://www.apple.com', 'random_string', 'location=no']);
+  addListenerToClass('openRedirect301', doOpen, 
+      ['http://google.com', 'random_string', '', 1]);
+  addListenerToClass('openRedirect302', doOpen, 
+      ['http://goo.gl/pUFqg', 'random_string', '', 2]);
+  addListenerToClass('openPDF', doOpen, 'http://www.stluciadance.com/prospectus_file/sample.pdf');
+  addListenerToClass('openPDFBlank', doOpen, ['local.pdf', '_blank']);
+  addListenerToClass('openInvalidScheme', doOpen, 
+      ['x-ttp://www.invalid.com/', '_blank']);
+  addListenerToClass('openInvalidHost', doOpen, 
+      ['http://www.inv;alid.com/', '_blank']);
+  addListenerToClass('openInvalidMissing', doOpen, ['nonexistent.html', '_blank']);
+  addListenerToClass('openOriginalDocument', doOpen, ['inject.html', '_blank']);
+  addListenerToClass('openCSSInjection', openWithStyle, 
+      ['inject.html','inject.css']);
+  addListenerToClass('openCSSInjectionCallback', openWithStyle, 
+      ['inject.html','inject.css', true]);
+  addListenerToClass('openCSSLiteralInjection', openWithStyle, 'inject.html');
+  addListenerToClass('openCSSLiteralInjectionCallback', openWithStyle, 
+    ['inject.html', null, true]);
+  addListenerToClass('openScriptInjection', openWithScript, 
+    ['inject.html', 'inject.js']);
+  addListenerToClass('openScriptInjectionCallback', openWithScript, 
+    ['inject.html', 'inject.js', true]);
+  addListenerToClass('openScriptLiteralInjection', openWithScript, 'inject.html');
+  addListenerToClass('openScriptLiteralInjectionCallback', openWithScript, 
+    ['inject.html', null, true]);
+  addListenerToClass('openHidden', openHidden, ['http://google.com', true]);
+  addListenerToClass('showHidden', showHidden);
+  addListenerToClass('closeHidden', closeHidden);
+  addListenerToClass('openHiddenShow', openHidden, ['http://google.com', false]);
+  addListenerToClass('openClearCache', doOpen, 
+    ['http://www.google.com', '_blank', 'clearcache=yes']);
+  addListenerToClass('openClearSessionCache', doOpen, 
+    ['http://www.google.com', '_blank', 'clearsessioncache=yes']);
+  addListenerToClass('openRemoteVideo', doOpen, ['video.html', '_blank']);
+  addListenerToClass('openAnchor1', doOpen, ['local.html#anchor1', '_blank']);
+  addListenerToClass('openAnchor2', doOpen, ['local.html#anchor2', '_blank']);
+
+
+  addListenerToClass('backBtn', backHome);
+  init();
+}

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/a7c88d8f/index.html
----------------------------------------------------------------------
diff --git a/index.html b/index.html
index 314d847..86b1173 100644
--- a/index.html
+++ b/index.html
@@ -31,7 +31,7 @@
 	  <script type="text/javascript" charset="utf-8" src="main.js"></script>
 
   </head>
-  <body onload="init();" id="stage" class="theme">
+  <body id="stage" class="theme">
     <h1>Apache Cordova Tests</h1>
     <div id="info">
         <h4>cordova.version: <span id="cordova"> </span></h4>

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/a7c88d8f/keyboard/index.html
----------------------------------------------------------------------
diff --git a/keyboard/index.html b/keyboard/index.html
index 23b47a3..9a66add 100644
--- a/keyboard/index.html
+++ b/keyboard/index.html
@@ -64,53 +64,11 @@
     }
 
     </style>
-    <script>
-        window.onerror = function(err,fn,ln) {alert("ERROR:" + err + ", " + fn + ":" + ln);};
-    </script>
+    <script type="text/javascript" charset="utf-8" src="./window-onerror.js"></script>      
     <script type="text/javascript" charset="utf-8" src="../cordova-incl.js"></script>      
-    
-    <script type="text/javascript" charset="utf-8">
-
-    var deviceReady = false;
-    var keyboardPlugin = null;
-    
-    /**
-     * Function called when page has finished loading.
-     */
-    function init() {
-        document.addEventListener("deviceready", function() {
-                deviceReady = true;
-                keyboardPlugin = window.Keyboard; // for now, before plugin re-factor
-                                  
-                if (keyboardPlugin == null) {
-                    var msg = 'The plugin org.apache.cordova.keyboard was not found. Check that you have it installed.';
-                    alert(msg);
-                }
-
-            }, false);
-        window.setTimeout(function() {
-        	if (!deviceReady) {
-                var msg = 'Error: Apache Cordova did not initialize.  Demo will not run correctly.';
-                alert(msg);
-        	}
-        },1000);
-    }
-    
-    function setShrinkView_hideFormAccessoryBar_andDisableScrollingInShrinkView(shrinkView, hideFormAccessoryBar, disableScrollingInShrinkView)
-    {
-        keyboardPlugin.shrinkView(shrinkView);
-        document.getElementById("shrinkView-arg").innerHTML = shrinkView;
-        
-        keyboardPlugin.hideFormAccessoryBar(hideFormAccessoryBar);
-        document.getElementById("hideFormAccessoryBar-arg").innerHTML = hideFormAccessoryBar;
-
-        keyboardPlugin.disableScrollingInShrinkView(disableScrollingInShrinkView);
-        document.getElementById("disableScrollingInShrinkView-arg").innerHTML = disableScrollingInShrinkView;
-    }
-
-    </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>Keyboard (iOS)</h1>
 
@@ -121,7 +79,7 @@
 
     <h1>isVisible</h1>
     <br />
-    <div class="btn large" onclick="alert('Keyboard.isVisible: ' + Keyboard.isVisible);">Keyboard.isVisible</div>
+    <div class="btn large keyboardIsVisible">Keyboard.isVisible</div>
     
     <h1>API Tests</h1>
     <br />
@@ -143,7 +101,7 @@
         </tr>
         <tr>
             <td class="highlight-w">
-                <div class="btn small" onclick="setShrinkView_hideFormAccessoryBar_andDisableScrollingInShrinkView(false, false, false)">1</div>
+                <div class="btn small set_1">1</div>
             </td>
             <td>&#x2717;</td>
             <td>&#x2717;</td>
@@ -151,7 +109,7 @@
         </tr>
         <tr>
             <td class="highlight-w">
-                <div class="btn small" onclick="setShrinkView_hideFormAccessoryBar_andDisableScrollingInShrinkView(false, false, true)">2</div>
+                <div class="btn small set_2">2</div>
             </td>
             <td>&#x2717;</td>
             <td>&#x2717;</td>
@@ -159,7 +117,7 @@
         </tr>
         <tr>
             <td class="highlight-w">
-                <div class="btn small" onclick="setShrinkView_hideFormAccessoryBar_andDisableScrollingInShrinkView(false, true, true)">3</div>
+                <div class="btn small set_3">3</div>
             </td>
             <td>&#x2717;</td>
             <td class="highlight-w">&#10004;</td>
@@ -167,7 +125,7 @@
         </tr>
         <tr>
             <td class="highlight-w">
-                <div class="btn small" onclick="setShrinkView_hideFormAccessoryBar_andDisableScrollingInShrinkView(false, true, false)">4</div>
+                <div class="btn small set_4">4</div>
             </td>
             <td>&#x2717;</td>
             <td class="highlight-w">&#10004;</td>
@@ -175,7 +133,7 @@
         </tr>
         <tr>
             <td class="highlight-w">
-                <div class="btn small" onclick="setShrinkView_hideFormAccessoryBar_andDisableScrollingInShrinkView(true, false, false)">5</div>
+                <div class="btn small set_5">5</div>
             </td>
             <td class="highlight-w">&#10004;</td>
             <td>&#x2717;</td>
@@ -183,7 +141,7 @@
         </tr>
         <tr>
             <td class="highlight-w">
-                <div class="btn small" onclick="setShrinkView_hideFormAccessoryBar_andDisableScrollingInShrinkView(true, false, true)">6</div>
+                <div class="btn small set_6">6</div>
             </td>
             <td class="highlight-w">&#10004;</td>
             <td>&#x2717;</td>
@@ -191,7 +149,7 @@
         </tr>
         <tr>
             <td class="highlight-w">
-                <div class="btn small" onclick="setShrinkView_hideFormAccessoryBar_andDisableScrollingInShrinkView(true, true, true)">7</div>
+                <div class="btn small set_7">7</div>
             </td>
             <td class="highlight-w">&#10004;</td>
             <td class="highlight-w">&#10004;</td>
@@ -199,7 +157,7 @@
         </tr>
         <tr>
             <td class="highlight-w">
-                <div class="btn small" onclick="setShrinkView_hideFormAccessoryBar_andDisableScrollingInShrinkView(true, true, false)">8</div>
+                <div class="btn small set_8">8</div>
             </td>
             <td class="highlight-w">&#10004;</td>
             <td class="highlight-w">&#10004;</td>
@@ -211,7 +169,7 @@
         <input type="text" placeholder="touch to see keyboard" /><button class="btn-dismiss">dismiss</button>
     </div>
     <br />
-    <div class="backBtn" onclick="backHome();">Back</div>
+    <div class="backBtn">Back</div>
     
   </body>
 </html>

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/a7c88d8f/keyboard/index.js
----------------------------------------------------------------------
diff --git a/keyboard/index.js b/keyboard/index.js
new file mode 100644
index 0000000..2302f31
--- /dev/null
+++ b/keyboard/index.js
@@ -0,0 +1,69 @@
+
+var deviceReady = false;
+var keyboardPlugin = null;
+
+/**
+ * Function called when page has finished loading.
+ */
+function init() {
+    document.addEventListener("deviceready", function() {
+            deviceReady = true;
+            keyboardPlugin = window.Keyboard; // for now, before plugin re-factor
+                              
+            if (keyboardPlugin == null) {
+                var msg = 'The plugin org.apache.cordova.keyboard was not found. Check that you have it installed.';
+                alert(msg);
+            }
+
+        }, false);
+    window.setTimeout(function() {
+      if (!deviceReady) {
+            var msg = 'Error: Apache Cordova did not initialize.  Demo will not run correctly.';
+            alert(msg);
+      }
+    },1000);
+}
+
+function setShrinkView_hideFormAccessoryBar_andDisableScrollingInShrinkView(shrinkView, hideFormAccessoryBar, disableScrollingInShrinkView)
+{
+    keyboardPlugin.shrinkView(shrinkView);
+    document.getElementById("shrinkView-arg").innerHTML = shrinkView;
+    
+    keyboardPlugin.hideFormAccessoryBar(hideFormAccessoryBar);
+    document.getElementById("hideFormAccessoryBar-arg").innerHTML = hideFormAccessoryBar;
+
+    keyboardPlugin.disableScrollingInShrinkView(disableScrollingInShrinkView);
+    document.getElementById("disableScrollingInShrinkView-arg").innerHTML = disableScrollingInShrinkView;
+}
+
+window.onload = function() {
+  addListenerToClass('keyboardIsVisible', function() {
+    alert('Keyboard.isVisible: ' + Keyboard.isVisible);
+  });
+  addListenerToClass('set_1', function() {
+    setShrinkView_hideFormAccessoryBar_andDisableScrollingInShrinkView(false, false, false)
+  });
+  addListenerToClass('set_2', function() {
+    setShrinkView_hideFormAccessoryBar_andDisableScrollingInShrinkView(false, false, true)
+  });
+  addListenerToClass('set_3', function() {
+    setShrinkView_hideFormAccessoryBar_andDisableScrollingInShrinkView(false, true, true)
+  });
+  addListenerToClass('set_4', function() {
+    setShrinkView_hideFormAccessoryBar_andDisableScrollingInShrinkView(false, true, false)
+  });
+  addListenerToClass('set_5', function() {
+    setShrinkView_hideFormAccessoryBar_andDisableScrollingInShrinkView(true, false, false)
+  });
+  addListenerToClass('set_6', function() {
+    setShrinkView_hideFormAccessoryBar_andDisableScrollingInShrinkView(true, false, true)
+  });
+  addListenerToClass('set_7', function() {
+    setShrinkView_hideFormAccessoryBar_andDisableScrollingInShrinkView(true, true, true)
+  });
+  addListenerToClass('set_8', function() {
+    setShrinkView_hideFormAccessoryBar_andDisableScrollingInShrinkView(true, true, false)
+  });
+  addListenerToClass('backBtn', backHome);
+  init();
+}

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/a7c88d8f/keyboard/window-onerror.js
----------------------------------------------------------------------
diff --git a/keyboard/window-onerror.js b/keyboard/window-onerror.js
new file mode 100644
index 0000000..f833882
--- /dev/null
+++ b/keyboard/window-onerror.js
@@ -0,0 +1 @@
+window.onerror = function(err,fn,ln) {alert("ERROR:" + err + ", " + fn + ":" + ln);};

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/a7c88d8f/lazyloadjs/do-not-write-cordova-script.js
----------------------------------------------------------------------
diff --git a/lazyloadjs/do-not-write-cordova-script.js b/lazyloadjs/do-not-write-cordova-script.js
new file mode 100644
index 0000000..0f20c76
--- /dev/null
+++ b/lazyloadjs/do-not-write-cordova-script.js
@@ -0,0 +1 @@
+_doNotWriteCordovaScript = true;

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/a7c88d8f/lazyloadjs/index.html
----------------------------------------------------------------------
diff --git a/lazyloadjs/index.html b/lazyloadjs/index.html
index 7a0c06f..5816349 100644
--- a/lazyloadjs/index.html
+++ b/lazyloadjs/index.html
@@ -27,27 +27,15 @@
     <meta http-equiv="Content-type" content="text/html; charset=utf-8"> <!-- ISO-8859-1 -->
     <title>Lazy-Loading of cordova-incl.js test</title>
     <link rel="stylesheet" href="../master.css" type="text/css" media="screen" title="no title" charset="utf-8"/>
-    <script>_doNotWriteCordovaScript = true</script>
+    <script type="text/javascript" charset="utf-8" src="./do-not-write-cordova-script.js"></script>      
     <script type="text/javascript" charset="utf-8" src="../cordova-incl.js"></script>
-<script type="text/javascript" charset="utf-8">
-    function init() {
-        document.addEventListener("deviceready", function() {
-            console.log("Device="+device.platform+" "+device.version);
-            document.getElementById('info').innerHTML = 'Cordova loaded just fine.';
-        }, false);
-        window.setTimeout(function() {
-            var s = document.createElement('script');
-            s.src = cordovaPath;
-            document.body.appendChild(s);
-        }, 0);
-    }
-</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>Lazy-Loading of cordova-incl.js</h1>
     <div id="info">
       onDeviceReady has not yet fired.
     </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/lazyloadjs/index.js
----------------------------------------------------------------------
diff --git a/lazyloadjs/index.js b/lazyloadjs/index.js
new file mode 100644
index 0000000..6559319
--- /dev/null
+++ b/lazyloadjs/index.js
@@ -0,0 +1,16 @@
+function init() {
+    document.addEventListener("deviceready", function() {
+        console.log("Device="+device.platform+" "+device.version);
+        document.getElementById('info').innerHTML = 'Cordova loaded just fine.';
+    }, false);
+    window.setTimeout(function() {
+        var s = document.createElement('script');
+        s.src = cordovaPath;
+        document.body.appendChild(s);
+    }, 0);
+}
+
+window.onload = function() {
+  addListenerToClass('backBtn', backHome);
+  init();
+}

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/a7c88d8f/location/index.html
----------------------------------------------------------------------
diff --git a/location/index.html b/location/index.html
index 542f264..f0cc7de 100644
--- a/location/index.html
+++ b/location/index.html
@@ -28,130 +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 origGeolocation = null;
-    var newGeolocation = null;
-
-    //-------------------------------------------------------------------------
-    // Location
-    //-------------------------------------------------------------------------
-    var watchLocationId = null;
-
-    /**
-     * Start watching location
-     */
-    var watchLocation = function(usePlugin) {
-        var geo = usePlugin ? newGeolocation : origGeolocation;
-        if (!geo) {
-            alert('geolocation object is missing. usePlugin = ' + usePlugin);
-            return;
-        }
-
-        // Success callback
-        var success = function(p){
-              console.log('watch location success');
-              setLocationDetails(p);
-        };
-
-        // Fail callback
-        var fail = function(e){
-            console.log("watchLocation fail callback with error code "+e);
-            stopLocation(geo);
-        };
-
-        // Get location
-        watchLocationId = geo.watchPosition(success, fail, {enableHighAccuracy: true});
-        setLocationStatus("Running");
-    };
-
-    /**
-     * Stop watching the location
-     */
-    var stopLocation = function(usePlugin) {
-        var geo = usePlugin ? newGeolocation : origGeolocation;
-        if (!geo) {
-            alert('geolocation object is missing. usePlugin = ' + usePlugin);
-            return;
-        }
-        setLocationStatus("Stopped");
-        if (watchLocationId) {
-            geo.clearWatch(watchLocationId);
-            watchLocationId = null;
-        }
-    };
-
-    /**
-     * Get current location
-     */
-    var getLocation = function(usePlugin, opts) {
-        var geo = usePlugin ? newGeolocation : origGeolocation;
-        if (!geo) {
-            alert('geolocation object is missing. usePlugin = ' + usePlugin);
-            return;
-        }
-
-        // Stop location if running
-        stopLocation(geo);
-
-        // Success callback
-        var success = function(p){
-            console.log('get location success');
-            setLocationDetails(p);
-            setLocationStatus("Done");
-        };
-
-        // Fail callback
-        var fail = function(e){
-            console.log("getLocation fail callback with error code "+e.code);
-            setLocationStatus("Error: "+e.code);
-        };
-
-        setLocationStatus("Retrieving location...");
-
-        // Get location
-        geo.getCurrentPosition(success, fail, opts || {enableHighAccuracy: true}); //, {timeout: 10000});
-
-    };
-
-    /**
-     * Set location status
-     */
-    var setLocationStatus = function(status) {
-        document.getElementById('location_status').innerHTML = status;
-    };
-var setLocationDetails = function(p) {
-var date = (new Date(p.timestamp));
-            document.getElementById('latitude').innerHTML = p.coords.latitude;
-            document.getElementById('longitude').innerHTML = p.coords.longitude;
-            document.getElementById('altitude').innerHTML = p.coords.altitude;
-            document.getElementById('accuracy').innerHTML = p.coords.accuracy;
-            document.getElementById('heading').innerHTML = p.coords.heading;
-            document.getElementById('speed').innerHTML = p.coords.speed;
-            document.getElementById('altitude_accuracy').innerHTML = p.coords.altitudeAccuracy;
-            document.getElementById('timestamp').innerHTML =  date.toDateString() + " " + date.toTimeString();
-    }
-    
-    /**
-     * Function called when page has finished loading.
-     */
-    function init() {
-        document.addEventListener("deviceready", function() {
-            newGeolocation = navigator.geolocation;
-            origGeolocation = cordova.require('cordova/modulemapper').getOriginalSymbol(window, 'navigator.geolocation');
-            if (!origGeolocation) {
-                origGeolocation = newGeolocation;
-                newGeolocation = null;
-            }
-        }, false);
-    }
-
-</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>Location</h1>
     <div id="info">
@@ -205,15 +84,15 @@ var date = (new Date(p.timestamp));
     </div>
     <h2>Action</h2>
     <h3>Use Built-in WebView navigator.geolocation</h3>
-    <a href="javascript:" class="btn large" onclick="getLocation(false);">Get Location</a>
-    <a href="javascript:" class="btn large" onclick="watchLocation(false);">Start Watching Location</a>
-    <a href="javascript:" class="btn large" onclick="stopLocation(false);">Stop Watching Location</a>
-    <a href="javascript:" class="btn large" onclick="getLocation(false, {maximumAge:30000});">Get Location Up to 30 Seconds Old</a>
+    <a href="javascript:" class="btn large getWebViewLocation">Get Location</a>
+    <a href="javascript:" class="btn large watchWebViewLocation">Start Watching Location</a>
+    <a href="javascript:" class="btn large stopWebViewLocation">Stop Watching Location</a>
+    <a href="javascript:" class="btn large getWebViewLocation30">Get Location Up to 30 Seconds Old</a>
     <h3>Use Cordova Geolocation Plugin</h3>
-    <a href="javascript:" class="btn large" onclick="getLocation(true);">Get Location</a>
-    <a href="javascript:" class="btn large" onclick="watchLocation(true);">Start Watching Location</a>
-    <a href="javascript:" class="btn large" onclick="stopLocation(true);">Stop Watching Location</a>
-    <a href="javascript:" class="btn large" onclick="getLocation(true, {maximumAge:30000});">Get Location Up to 30 Seconds Old</a>
-    <h2>&nbsp;</h2><a href="javascript:" class="backBtn" onclick="backHome();">Back</a>    
+    <a href="javascript:" class="btn large getLocation">Get Location</a>
+    <a href="javascript:" class="btn large watchLocation">Start Watching Location</a>
+    <a href="javascript:" class="btn large stopLocation">Stop Watching Location</a>
+    <a href="javascript:" class="btn large getLocation30">Get Location Up to 30 Seconds Old</a>
+    <h2>&nbsp;</h2><a href="javascript:" class="backBtn"">Back</a>    
   </body>
 </html>      

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/a7c88d8f/location/index.js
----------------------------------------------------------------------
diff --git a/location/index.js b/location/index.js
new file mode 100644
index 0000000..242919d
--- /dev/null
+++ b/location/index.js
@@ -0,0 +1,128 @@
+var origGeolocation = null;
+var newGeolocation = null;
+
+//-------------------------------------------------------------------------
+// Location
+//-------------------------------------------------------------------------
+var watchLocationId = null;
+
+/**
+ * Start watching location
+ */
+var watchLocation = function(usePlugin) {
+    var geo = usePlugin ? newGeolocation : origGeolocation;
+    if (!geo) {
+        alert('geolocation object is missing. usePlugin = ' + usePlugin);
+        return;
+    }
+
+    // Success callback
+    var success = function(p){
+          console.log('watch location success');
+          setLocationDetails(p);
+    };
+
+    // Fail callback
+    var fail = function(e){
+        console.log("watchLocation fail callback with error code "+e);
+        stopLocation(geo);
+    };
+
+    // Get location
+    watchLocationId = geo.watchPosition(success, fail, {enableHighAccuracy: true});
+    setLocationStatus("Running");
+};
+
+/**
+ * Stop watching the location
+ */
+var stopLocation = function(usePlugin) {
+    var geo = usePlugin ? newGeolocation : origGeolocation;
+    if (!geo) {
+        alert('geolocation object is missing. usePlugin = ' + usePlugin);
+        return;
+    }
+    setLocationStatus("Stopped");
+    if (watchLocationId) {
+        geo.clearWatch(watchLocationId);
+        watchLocationId = null;
+    }
+};
+
+/**
+ * Get current location
+ */
+var getLocation = function(usePlugin, opts) {
+    var geo = usePlugin ? newGeolocation : origGeolocation;
+    if (!geo) {
+        alert('geolocation object is missing. usePlugin = ' + usePlugin);
+        return;
+    }
+
+    // Stop location if running
+    stopLocation(geo);
+
+    // Success callback
+    var success = function(p){
+        console.log('get location success');
+        setLocationDetails(p);
+        setLocationStatus("Done");
+    };
+
+    // Fail callback
+    var fail = function(e){
+        console.log("getLocation fail callback with error code "+e.code);
+        setLocationStatus("Error: "+e.code);
+    };
+
+    setLocationStatus("Retrieving location...");
+
+    // Get location
+    geo.getCurrentPosition(success, fail, opts || {enableHighAccuracy: true}); //, {timeout: 10000});
+
+};
+
+/**
+ * Set location status
+ */
+var setLocationStatus = function(status) {
+    document.getElementById('location_status').innerHTML = status;
+};
+var setLocationDetails = function(p) {
+var date = (new Date(p.timestamp));
+        document.getElementById('latitude').innerHTML = p.coords.latitude;
+        document.getElementById('longitude').innerHTML = p.coords.longitude;
+        document.getElementById('altitude').innerHTML = p.coords.altitude;
+        document.getElementById('accuracy').innerHTML = p.coords.accuracy;
+        document.getElementById('heading').innerHTML = p.coords.heading;
+        document.getElementById('speed').innerHTML = p.coords.speed;
+        document.getElementById('altitude_accuracy').innerHTML = p.coords.altitudeAccuracy;
+        document.getElementById('timestamp').innerHTML =  date.toDateString() + " " + date.toTimeString();
+}
+
+/**
+ * Function called when page has finished loading.
+ */
+function init() {
+    document.addEventListener("deviceready", function() {
+        newGeolocation = navigator.geolocation;
+        origGeolocation = cordova.require('cordova/modulemapper').getOriginalSymbol(window, 'navigator.geolocation');
+        if (!origGeolocation) {
+            origGeolocation = newGeolocation;
+            newGeolocation = null;
+        }
+    }, false);
+}
+
+window.onload = function() {
+  addListenerToClass('getWebViewLocation', getLocation, [false]);
+  addListenerToClass('watchWebViewLocation', watchLocation, [false]);
+  addListenerToClass('stopWebViewLocation', stopLocation, [false]);
+  addListenerToClass('getWebViewLocation30', getLocation, [false, {maximumAge:30000}]);
+  addListenerToClass('getLocation', getLocation, [true]);
+  addListenerToClass('watchLocation', watchLocation, [true]);
+  addListenerToClass('stopLocation', stopLocation, [true]);
+  addListenerToClass('getLocation30', getLocation, [true, {maximumAge:30000}]);
+  addListenerToClass('backBtn', backHome);
+  init();
+}

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/a7c88d8f/main.js
----------------------------------------------------------------------
diff --git a/main.js b/main.js
index 9508770..42e9edd 100644
--- a/main.js
+++ b/main.js
@@ -161,3 +161,5 @@ function init() {
     document.addEventListener("deviceready", deviceInfo, true);
     document.getElementById("user-agent").textContent = navigator.userAgent;
 }
+
+window.onload = init;

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/a7c88d8f/misc/index.html
----------------------------------------------------------------------
diff --git a/misc/index.html b/misc/index.html
index 2245ed9..0ebb217 100644
--- a/misc/index.html
+++ b/misc/index.html
@@ -28,43 +28,16 @@
     <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;
-    }
-    
-    /**
-     * 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>Display Other Content</h1>
     <div id="info">
     </div>
     <h2>Action</h2>
-    <div class="btn large" onclick="document.location='tel:5551212';" >Call 411</div>
+    <div class="btn large telLocation">Call 411</div>
     <a href="mailto:bob@abc.org?subject=My Subject&body=This is the body.%0D%0ANew line." class="btn large">Send Mail</a>
     <a href="sms:5125551234?body=The SMS message." class="btn large">Send SMS</a>
     <a href="http://www.google.com" class="btn large">Load Web Site</a>
@@ -82,6 +55,6 @@
     <a href="market://search?q=google" class="btn large">Search Android market</a>
     <a href="content://media/external/images/media" class="btn large">View image app</a>
 
-    <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/misc/index.js
----------------------------------------------------------------------
diff --git a/misc/index.js b/misc/index.js
new file mode 100644
index 0000000..e38ade7
--- /dev/null
+++ b/misc/index.js
@@ -0,0 +1,30 @@
+var deviceReady = false;
+
+function roundNumber(num) {
+    var dec = 3;
+    var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
+    return result;
+}
+
+/**
+ * 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('telLocation', function() {
+    document.location='tel:5551212';
+  });
+  addListenerToClass('backBtn', backHome);
+  init();
+}

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/a7c88d8f/misc/page2.html
----------------------------------------------------------------------
diff --git a/misc/page2.html b/misc/page2.html
index 6b4eba1..1d370a9 100644
--- a/misc/page2.html
+++ b/misc/page2.html
@@ -29,6 +29,7 @@
     <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" src="../main.js"></script>
+    <script type="text/javascript" charset="utf-8" src="./page2.js"></script>      
     <style>
       iframe, .iframe_container {
         height:100px;
@@ -36,7 +37,7 @@
       }
     </style>
   </head>
-  <body onload="init();" id="stage" class="theme">
+  <body id="stage" class="theme">
     <h1>Page2 App</h1>
     <h2>This is page 2 of a Apache Cordova app</h2>
     <div id="info">
@@ -58,15 +59,6 @@
      <div class="iframe_container">
        <iframe src="" id="apacheiframe"></iframe>
      </div>
-     <div><button class="backBtn" onclick="backHome();">Back</button></div>
+     <div><button class="backBtn">Back</button></div>
   </body>
-  <script>
-    setTimeout(function() {
-        console.log('loading iframe after timeout.');
-        document.querySelector('#apacheiframe').src = 'http://apache.org';
-    }, 2000);
-    document.addEventListener("deviceready", function() {
-        document.getElementById('info').textContent += '\nDevice is ready.';
-    }, false);
-  </script>
 </html>

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/a7c88d8f/misc/page2.js
----------------------------------------------------------------------
diff --git a/misc/page2.js b/misc/page2.js
new file mode 100644
index 0000000..1f489c2
--- /dev/null
+++ b/misc/page2.js
@@ -0,0 +1,12 @@
+setTimeout(function() {
+    console.log('loading iframe after timeout.');
+    document.querySelector('#apacheiframe').src = 'http://apache.org';
+}, 2000);
+document.addEventListener("deviceready", function() {
+    document.getElementById('info').textContent += '\nDevice is ready.';
+}, false);
+
+window.onload = function() {
+  addListenerToClass('backBtn', backHome);
+  init();
+}

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/a7c88d8f/misc/page3.html
----------------------------------------------------------------------
diff --git a/misc/page3.html b/misc/page3.html
index da90d39..6677677 100644
--- a/misc/page3.html
+++ b/misc/page3.html
@@ -27,35 +27,7 @@
     <meta http-equiv="Content-type" content="text/html; charset=utf-8">
     <title>Cordova Mobile Spec</title>
     <link rel="stylesheet" href="../master.css" type="text/css" media="screen" title="no title" charset="utf-8">
-    <script>
-      console.log('Changing hash #1.');
-      if (location.search.indexOf('hash1') != -1) {
-        location.hash = 'a';
-      } else if (location.search.indexOf('hash2') != -1) {
-        location.replace('#replaced');
-      }
-      var hashCount = 0;
-      function changeHash() {
-        hashCount += 1;
-        if (hashCount % 1) {
-          location.hash = hashCount;
-        } else {
-          location.replace('#' + hashCount);
-        }
-      }
-      if (location.search.indexOf('changeURL') != -1) {
-        history.replaceState(null, null, 'fakepage.html');
-      }
-      function loadFrame() {
-        var ifr = document.createElement('iframe');
-        ifr.src="data:text/html;base64,PGh0bWw+";
-        document.body.appendChild(ifr);
-      }
-      function reload() {
-        // Test that iOS CDVWebViewDelegate doesn't ignore changes when URL doesn't change.
-        location.reload();
-      }
-    </script>
+    <script type="text/javascript" charset="utf-8" src="./page3A.js"></script>      
     <script type="text/javascript" charset="utf-8" src="../cordova-incl.js"></script>
     <script type="text/javascript" charset="utf-8" src="../main.js"></script>
   </head>

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/a7c88d8f/misc/page3A.js
----------------------------------------------------------------------
diff --git a/misc/page3A.js b/misc/page3A.js
new file mode 100644
index 0000000..8efad58
--- /dev/null
+++ b/misc/page3A.js
@@ -0,0 +1,27 @@
+console.log('Changing hash #1.');
+if (location.search.indexOf('hash1') != -1) {
+  location.hash = 'a';
+} else if (location.search.indexOf('hash2') != -1) {
+  location.replace('#replaced');
+}
+var hashCount = 0;
+function changeHash() {
+  hashCount += 1;
+  if (hashCount % 1) {
+    location.hash = hashCount;
+  } else {
+    location.replace('#' + hashCount);
+  }
+}
+if (location.search.indexOf('changeURL') != -1) {
+  history.replaceState(null, null, 'fakepage.html');
+}
+function loadFrame() {
+  var ifr = document.createElement('iframe');
+  ifr.src="data:text/html;base64,PGh0bWw+";
+  document.body.appendChild(ifr);
+}
+function reload() {
+  // Test that iOS CDVWebViewDelegate doesn't ignore changes when URL doesn't change.
+  location.reload();
+}

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/a7c88d8f/network/index.html
----------------------------------------------------------------------
diff --git a/network/index.html b/network/index.html
index 2902849..b750f6c 100644
--- a/network/index.html
+++ b/network/index.html
@@ -28,48 +28,11 @@
     <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">
-
-
-    function eventOutput(s) {
-        var el = document.getElementById("results");
-        el.innerHTML = el.innerHTML + s + "<br>";
-    }
-
-    function printNetwork() {
-        eventOutput("navigator.connection.type=" + navigator.connection.type);
-        eventOutput("navigator.network.connection.type=" + navigator.network.connection.type);
-    }
-
-    /**
-     * Function called when page has finished loading.
-     */
-    function init() {
-        var deviceReady = false;
-        function onEvent(e) {
-            eventOutput('Event of type: ' + e.type);
-            printNetwork();
-        }
-        document.addEventListener('online', onEvent, false);
-        document.addEventListener('offline', onEvent, false);
-        document.addEventListener("deviceready", function() {
-            deviceReady = true;
-            eventOutput("Device="+device.platform+" "+device.version);
-            printNetwork();
-        }, false);
-        window.setTimeout(function() {
-            if (!deviceReady) {
-                alert("Error: Cordova did not initialize.  Demo will not run correctly.");
-            }
-        }, 1000);
-    }
-
+    <script type="text/javascript" charset="utf-8" src="./index.js"></script>      
 </script>
 
   </head>
-  <body onload="init();" id="stage" class="theme">
+  <body id="stage" class="theme">
   
     <h1>Network Events and State</h1>
     <div id="info">
@@ -78,8 +41,8 @@
     </div>
 
     <h2>Action</h2>
-    <div class="btn large" onclick="printNetwork();">Show Network Connection</div>
-    <h2> </h2><div class="backBtn" onclick="backHome();">Back</div>
+    <div class="btn large printNetwork">Show Network Connection</div>
+    <h2> </h2><div class="backBtn">Back</div>
   </body>
 </html>
 

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/a7c88d8f/network/index.js
----------------------------------------------------------------------
diff --git a/network/index.js b/network/index.js
new file mode 100644
index 0000000..41c2c47
--- /dev/null
+++ b/network/index.js
@@ -0,0 +1,38 @@
+function eventOutput(s) {
+    var el = document.getElementById("results");
+    el.innerHTML = el.innerHTML + s + "<br>";
+}
+
+function printNetwork() {
+    eventOutput("navigator.connection.type=" + navigator.connection.type);
+    eventOutput("navigator.network.connection.type=" + navigator.network.connection.type);
+}
+
+/**
+ * Function called when page has finished loading.
+ */
+function init() {
+    var deviceReady = false;
+    function onEvent(e) {
+        eventOutput('Event of type: ' + e.type);
+        printNetwork();
+    }
+    document.addEventListener('online', onEvent, false);
+    document.addEventListener('offline', onEvent, false);
+    document.addEventListener("deviceready", function() {
+        deviceReady = true;
+        eventOutput("Device="+device.platform+" "+device.version);
+        printNetwork();
+    }, false);
+    window.setTimeout(function() {
+        if (!deviceReady) {
+            alert("Error: Cordova did not initialize.  Demo will not run correctly.");
+        }
+    }, 1000);
+}
+
+window.onload = function() {
+  addListenerToClass('printNetwork', printNetwork);
+  addListenerToClass('backBtn', backHome);
+  init();
+}

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/a7c88d8f/notification/index.html
----------------------------------------------------------------------
diff --git a/notification/index.html b/notification/index.html
index 16aad7d..ab648df 100644
--- a/notification/index.html
+++ b/notification/index.html
@@ -28,112 +28,24 @@
     <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;
-
-    //-------------------------------------------------------------------------
-    // Notifications
-    //-------------------------------------------------------------------------
-
-    var beep = function(){
-        navigator.notification.beep(3);
-    };
-
-    var alertDialog = function(message, title, button) {
-        console.log("alertDialog()");
-        navigator.notification.alert(message,
-            function(){
-                console.log("Alert dismissed.");
-            },
-            title, button);
-        console.log("After alert");
-    };
-
-    var confirmDialogA = function(message, title, buttons) {
-        navigator.notification.confirm(message,
-            function(r) {
-                if(r===0){
-                    console.log("Dismissed dialog without making a selection.");
-                    alert("Dismissed dialog without making a selection.");
-                }else{
-                    console.log("You selected " + r);
-                    alert("You selected " + (buttons.split(","))[r-1]);
-                }
-            },
-            title,
-            buttons);
-    };
-
-    var confirmDialogB = function(message, title, buttons) {
-        navigator.notification.confirm(message,
-            function(r) {
-                if(r===0){
-                    console.log("Dismissed dialog without making a selection.");
-                    alert("Dismissed dialog without making a selection.");
-                }else{
-                    console.log("You selected " + r);
-                    alert("You selected " + buttons[r-1]);
-                }
-            },
-            title,
-            buttons);
-    };
-
-    var promptDialog = function(message, title, buttons) {
-        navigator.notification.prompt(message,
-            function(r) {
-                if(r && r.buttonIndex===0){
-                    var msg = "Dismissed dialog";
-                    if( r.input1 ){
-                        msg+=" with input: " + r.input1
-                    }
-                    console.log(msg);
-                    alert(msg);
-                }else{
-                    console.log("You selected " + r.buttonIndex + " and entered: " + r.input1);
-                    alert("You selected " + buttons[r.buttonIndex-1] + " and entered: " + r.input1);
-                }
-            },
-            title,
-            buttons);
-    };
-    /**
-     * 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>Notifications and Dialogs</h1>
     <div id="info">
     </div>
     
     <h2>Action</h2>
-    <div class="btn large" onclick="beep();">Beep</div>
-    <div class="btn large" onclick="alertDialog('You pressed alert.', 'Alert Dialog', 'Continue');">Alert Dialog</div>
-    <div class="btn large" onclick="confirmDialogA('You pressed confirm.', 'Confirm Dialog', 'Yes,No,Maybe');">Confirm Dialog - Deprecated</div>
-    <div class="btn large" onclick="confirmDialogB('You pressed confirm.', 'Confirm Dialog', ['Yes', 'No', 'Maybe, Not Sure']);">Confirm Dialog</div>
-    <div class="btn large" onclick="promptDialog('You pressed prompt.', 'Prompt Dialog', ['Yes', 'No', 'Maybe, Not Sure']);">Prompt Dialog</div>
+    <div class="btn large beep">Beep</div>
+    <div class="btn large alertDialog">Alert Dialog</div>
+    <div class="btn large confirmDialogA">Confirm Dialog - Deprecated</div>
+    <div class="btn large confirmDialogB">Confirm Dialog</div>
+    <div class="btn large promptDialog">Prompt Dialog</div>
     
-    <div class="btn large" onclick="alert('You pressed alert.');">Built-in Alert Dialog</div>
-    <div class="btn large" onclick="confirm('You selected confirm');">Built-in Confirm Dialog</div>
-    <div class="btn large" onclick="prompt('This is a prompt.', 'Default value');">Built-in Prompt Dialog</div>
-    <h2> </h2><div class="backBtn" onclick="backHome();">Back</div>
+    <div class="btn large builtInAlert">Built-in Alert Dialog</div>
+    <div class="btn large builtInConfirm">Built-in Confirm Dialog</div>
+    <div class="btn large builtInPrompt">Built-in Prompt Dialog</div>
+    <h2> </h2><div class="backBtn">Back</div>
   </body>
 </html>      

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/a7c88d8f/notification/index.js
----------------------------------------------------------------------
diff --git a/notification/index.js b/notification/index.js
new file mode 100644
index 0000000..12e672f
--- /dev/null
+++ b/notification/index.js
@@ -0,0 +1,100 @@
+var deviceReady = false;
+
+//-------------------------------------------------------------------------
+// Notifications
+//-------------------------------------------------------------------------
+
+var beep = function(){
+    navigator.notification.beep(3);
+};
+
+var alertDialog = function(message, title, button) {
+    console.log("alertDialog()");
+    navigator.notification.alert(message,
+        function(){
+            console.log("Alert dismissed.");
+        },
+        title, button);
+    console.log("After alert");
+};
+
+var confirmDialogA = function(message, title, buttons) {
+    navigator.notification.confirm(message,
+        function(r) {
+            if(r===0){
+                console.log("Dismissed dialog without making a selection.");
+                alert("Dismissed dialog without making a selection.");
+            }else{
+                console.log("You selected " + r);
+                alert("You selected " + (buttons.split(","))[r-1]);
+            }
+        },
+        title,
+        buttons);
+};
+
+var confirmDialogB = function(message, title, buttons) {
+    navigator.notification.confirm(message,
+        function(r) {
+            if(r===0){
+                console.log("Dismissed dialog without making a selection.");
+                alert("Dismissed dialog without making a selection.");
+            }else{
+                console.log("You selected " + r);
+                alert("You selected " + buttons[r-1]);
+            }
+        },
+        title,
+        buttons);
+};
+
+var promptDialog = function(message, title, buttons) {
+    navigator.notification.prompt(message,
+        function(r) {
+            if(r && r.buttonIndex===0){
+                var msg = "Dismissed dialog";
+                if( r.input1 ){
+                    msg+=" with input: " + r.input1
+                }
+                console.log(msg);
+                alert(msg);
+            }else{
+                console.log("You selected " + r.buttonIndex + " and entered: " + r.input1);
+                alert("You selected " + buttons[r.buttonIndex-1] + " and entered: " + r.input1);
+            }
+        },
+        title,
+        buttons);
+};
+/**
+ * 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('beep', beep);
+  addListenerToClass('alertDialog', alertDialog, 
+      ['You pressed alert.', 'Alert Dialog', 'Continue']);
+  addListenerToClass('confirmDialogA', confirmDialogA, 
+      ['You pressed confirm.', 'Confirm Dialog', 'Yes,No,Maybe']);
+  addListenerToClass('confirmDialogB', confirmDialogB,
+      ['You pressed confirm.', 'Confirm Dialog', ['Yes', 'No', 'Maybe, Not Sure']]);
+  addListenerToClass('promptDialog', promptDialog,
+      ['You pressed prompt.', 'Prompt Dialog', ['Yes', 'No', 'Maybe, Not Sure']]);
+  addListenerToClass('builtInAlert', alert, 'You pressed alert.');
+  addListenerToClass('builtInConfirm', confirm, 'You selected confirm');
+  addListenerToClass('builtInPrompt', prompt, ['This is a prompt.', 'Default value']);
+
+  addListenerToClass('backBtn', backHome);
+  init();
+}

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/a7c88d8f/sql/index.html
----------------------------------------------------------------------
diff --git a/sql/index.html b/sql/index.html
index 5827521..da0d809 100644
--- a/sql/index.html
+++ b/sql/index.html
@@ -28,126 +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">
-
-    //-------------------------------------------------------------------------
-    // HTML5 Database
-    //-------------------------------------------------------------------------
-    var dbs = [];
-    var quotas = [2000000, 2000000];
-    var names = ['mydb', 'rand' + Math.random()];
-    function openDb(index) {
-        try {
-            databaseOutput('Openning db with name: ' + names[index]);
-            return openDatabase(names[index], "1.0", "Apache Cordova Demo", quotas[index]);
-        } catch (e) {
-            databaseOutput('Got exception: ' + e);
-        }
-    }
-
-    var callDatabase = function(index) {
-        var db = dbs[index] = openDb(index);
-        if (!db) {
-            return;
-        }
-        databaseOutput("Database opened.");
-        db.transaction(function (tx) {
-            tx.executeSql('DROP TABLE IF EXISTS DEMO');
-            tx.executeSql('CREATE TABLE IF NOT EXISTS DEMO (id unique, data)', [],
-                 function(tx,results) { console.log("Created table"); },
-                 function(tx,err) { alert("Error creating table: "+err.message); });
-            tx.executeSql('INSERT INTO DEMO (id, data) VALUES (1, "First row")', [],
-                 function(tx,results) { console.log("Insert row1 success"); },
-                 function(tx,err) { alert("Error adding 1st row: "+err.message); });
-            tx.executeSql('INSERT INTO DEMO (id, data) VALUES (2, "Second row")', [],
-                 function(tx,results) { console.log("Insert row2 success"); },
-                 function(tx,err) { alert("Error adding 2nd row: "+err.message); });
-            databaseOutput("Data written to DEMO table.");
-            console.log("Data written to DEMO table.");
-
-            tx.executeSql('SELECT * FROM DEMO', [], function (tx, results) {
-                var len = results.rows.length;
-                var text = "DEMO table: " + len + " rows found.<br>";
-                text = text + "<table border='1'><tr><td>Row</td><td>Data</td></tr>";
-                for (var i=0; i<len; i++){
-                    text = text + "<tr><td>" + i + "</td><td>" + results.rows.item(i).id + ", " + results.rows.item(i).data + "</td></tr>";
-                }
-                text = text + "</table>";
-                databaseOutput(text);
-            }, function(tx, err) {
-                alert("Error processing SELECT * SQL: "+err.message);
-            });
-            tx.executeSql('SELECT ID FROM DEMO', [], function (tx, results) {
-                var len = results.rows.length;
-                var text = "DEMO table: " + len + " rows found.<br>";
-                text = text + "<table border='1'><tr><td>Row</td><td>Data</td></tr>";
-                for (var i=0; i<len; i++){
-                    text = text + "<tr><td>" + i + "</td><td>" + results.rows.item(i).id + "</td></tr>";
-                }
-                text = text + "</table>";
-                databaseOutput(text);
-            }, function(tx, err) {
-                alert("Error processing SELECT ID SQL: "+err.message);
-            });
-            
-        },
-        function(err) {
-            console.log("Transaction failed: " + err.message);
-        });
-
-
-    };
-
-    var readDatabase = function(index) {
-        var db = dbs[index];
-    	if (!db) {
-            db = dbs[index] = openDb(index);
-            if (!db) {
-                return;
-            }
-        }
-        db.transaction(function (tx) {
-            tx.executeSql('SELECT * FROM DEMO WHERE id=2', [], function (tx, results) {
-                var len = results.rows.length;
-                var text = "DEMO table: " + len + " rows found.<br>";
-                text = text + "<table border='1'><tr><td>Row</td><td>Data</td></tr>";
-                for (var i=0; i<len; i++){
-                    text = text + "<tr><td>" + i + "</td><td>" + results.rows.item(i).id + ", " + results.rows.item(i).data + "</td></tr>";
-                }
-                text = text + "</table>";
-                databaseOutput(text);
-            }, function(tx, err) {
-                alert("Error processing SELECT * WHERE id=2 SQL: "+err.message);
-            });
-        });
-    }
-
-    function increaseQuota(index) {
-        quotas[index] *= 2;
-        databaseOutput('quota ' + index + ' is now ' + quotas[index]);
-    }
-
-    var databaseOutput = function(s) {
-        var el = document.getElementById("database_results");
-        el.innerHTML = el.innerHTML + s + "<br>";
-        el.scrollByLines(20000);
-    };
-    
-    /**
-     * Function called when page has finished loading.
-     */
-    function init() {
-        document.addEventListener("deviceready", function() {
-            console.log("Device="+device.platform+" "+device.version);
-        }, false);
-    }
-
-</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>HTML5 Database</h1>   
     <div id="info">
@@ -155,13 +38,13 @@
         <span id="database_results"></span>
     </div>
     <h2>Action</h2>
-    <div class="btn large" onclick="callDatabase(0);">Create, Add, Read Database (Constant name)</div>
-    <div class="btn large" onclick="readDatabase(0);">Read Database (Constant name)</div>
-    <div class="btn large" onclick="increaseQuota(0);">Increase Quota (Constant name)</div>
-    <div class="btn large" onclick="callDatabase(1);">Create, Add, Read Database (Random Name)</div>
-    <div class="btn large" onclick="readDatabase(1);">Read Database (Random Name)</div>
-    <div class="btn large" onclick="increaseQuota(1);">Increase Quota (Random Name)</div>
-    <div class="btn large" onclick="location = location.href">Reload Page</div>
-    <h2> </h2><div class="backBtn" onclick="backHome();">Back</div>    
+    <div class="btn large callDatabase0">Create, Add, Read Database (Constant name)</div>
+    <div class="btn large readDatabase0">Read Database (Constant name)</div>
+    <div class="btn large increaseQuota0">Increase Quota (Constant name)</div>
+    <div class="btn large callDatabase1">Create, Add, Read Database (Random Name)</div>
+    <div class="btn large readDatabase1">Read Database (Random Name)</div>
+    <div class="btn large increaseQuota1">Increase Quota (Random Name)</div>
+    <div class="btn large reloadPage">Reload Page</div>
+    <h2> </h2><div class="backBtn">Back</div>    
   </body>
 </html>      


Mime
View raw message