cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject [03/21] git commit: Updated Angular, Renamed InstallHandler -> Installer. Made a base class.
Date Thu, 24 Oct 2013 01:55:42 GMT
Updated Angular, Renamed InstallHandler -> Installer. Made a base class.


Project: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/commit/c3939e03
Tree: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/tree/c3939e03
Diff: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/diff/c3939e03

Branch: refs/heads/master
Commit: c3939e03de491e3ae70d729982df09bc100be516
Parents: d172011
Author: Andrew Grieve <agrieve@chromium.org>
Authored: Thu Oct 17 15:30:11 2013 -0400
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Wed Oct 23 21:55:17 2013 -0400

----------------------------------------------------------------------
 AppBundle/src/ios/AppBundle.m            |     6 +-
 www/cdvah_index.html                     |     7 +-
 www/cdvah_js/AppsService.js              |   131 +-
 www/cdvah_js/ContextMenuInjectScript.js  |     1 -
 www/cdvah_js/Installer.js                |    98 +
 www/cdvah_js/KnownExtensionDownloader.js |    22 -
 www/cdvah_js/ListCtrl.js                 |    12 +-
 www/cdvah_js/ServeCordovaJSHandler.js    |   111 -
 www/cdvah_js/ServeInstaller.js           |    87 +
 www/cdvah_js/app.js                      |     3 +-
 www/cdvah_js/libs/angular-route.js       |   860 ++
 www/cdvah_js/libs/angular.js             | 19141 ++++++++++++++++++++++++
 www/cdvah_js/libs/angular.min.js         |   173 -
 13 files changed, 20238 insertions(+), 414 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/c3939e03/AppBundle/src/ios/AppBundle.m
----------------------------------------------------------------------
diff --git a/AppBundle/src/ios/AppBundle.m b/AppBundle/src/ios/AppBundle.m
index 2f7b2e6..d24de5e 100644
--- a/AppBundle/src/ios/AppBundle.m
+++ b/AppBundle/src/ios/AppBundle.m
@@ -96,7 +96,6 @@ static RouteParams* gResetUrlParams = nil;
     }
 }
 
-
 - (void)addAlias:(CDVInvokedUrlCommand*)command {
     CDVPluginResult* pluginResult = nil;
     NSError* error = nil;
@@ -215,9 +214,7 @@ static RouteParams* gResetUrlParams = nil;
 }
 
 - (void)issueTopLevelRedirect:(NSURL*)url origURL:(NSURL*)origURL {
-    if([gWebView isLoading]) {
-        [gWebView stopLoading];
-    }
+    // BUG: Using loadData: clears the browser history stack. e.g. history.back() doesn't work.
     [gWebView loadData:[NSData dataWithContentsOfURL:url] MIMEType:@"text/html" textEncodingName:@"utf8" baseURL:origURL];
 }
 
@@ -233,6 +230,7 @@ static RouteParams* gResetUrlParams = nil;
     BOOL isTopLevelNavigation = [request.URL isEqual:request.mainDocumentURL];
     
     // iOS 6+ just gives "Frame load interrupted" when you try and feed it data via a URLProtocol.
+    // http://stackoverflow.com/questions/12058203/using-a-custom-nsurlprotocol-on-ios-for-file-urls-causes-frame-load-interrup/19432303
     if (isTopLevelNavigation) {
         [self issueTopLevelRedirect:newUrl origURL:[request URL]];
     } else if(params->_redirectToReplacedUrl) {

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/c3939e03/www/cdvah_index.html
----------------------------------------------------------------------
diff --git a/www/cdvah_index.html b/www/cdvah_index.html
index 9f0f82d..313c3b8 100644
--- a/www/cdvah_index.html
+++ b/www/cdvah_index.html
@@ -4,10 +4,12 @@
         <title>Cordova App Harness</title>
         <script type="text/javascript" src="cordova.js"></script>
         <script type="text/javascript" src="cdvah_js/libs/q.min.js"></script>
-        <script type="text/javascript" src="cdvah_js/libs/angular.min.js"></script>
+        <script type="text/javascript" src="cdvah_js/libs/angular.js"></script>
+        <script type="text/javascript" src="cdvah_js/libs/angular-route.js"></script>
         <script type="text/javascript" src="cdvah_js/app.js"></script>
         <script type="text/javascript" src="cdvah_js/ContextMenuInjectScript.js"></script>
-        <script type="text/javascript" src="cdvah_js/ServeCordovaJSHandler.js"></script>
+        <script type="text/javascript" src="cdvah_js/Installer.js"></script>
+        <script type="text/javascript" src="cdvah_js/ServeInstaller.js"></script>
         <script type="text/javascript" src="cdvah_js/ResourcesLoader.js"></script>
         <script type="text/javascript" src="cdvah_js/AppsService.js"></script>
         <script type="text/javascript" src="cdvah_js/AppBundleAlias.js"></script>
@@ -16,6 +18,7 @@
         <script type="text/javascript" src="cdvah_js/Notify.js"></script>
         <link rel="stylesheet" type="text/css" href="css/topcoat-mobile-light.min.css" />
         <link rel="stylesheet" type="text/css" href="css/style.css" />
+        <script>alert(1)</script>
     </head>
     <body>
         <div class="topcoat-navigation-bar">

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/c3939e03/www/cdvah_js/AppsService.js
----------------------------------------------------------------------
diff --git a/www/cdvah_js/AppsService.js b/www/cdvah_js/AppsService.js
index d5b53ec..4d152a2 100644
--- a/www/cdvah_js/AppsService.js
+++ b/www/cdvah_js/AppsService.js
@@ -4,20 +4,21 @@
     myApp.factory("AppsService", [ "ResourcesLoader", "INSTALL_DIRECTORY", "APPS_JSON", function(ResourcesLoader, INSTALL_DIRECTORY, APPS_JSON) {
 
         var platformId = cordova.platformId;
-        // Map of type -> handler.
-        var _installHandlerFactories = {};
+        // Map of type -> installer.
+        var _installerFactories = {};
 
-        var _installHandlers = null;
+        var _installers = null;
         var _lastLaunchedAppId = null;
 
         function createInstallHandlersFromJson(json) {
             var appList = json['appList'] || [];
             var ret = [];
             for (var i = 0, entry; entry = appList[i]; ++i) {
-                var factory = _installHandlerFactories[entry['appType']];
-                var handler = factory.createFromJson(entry['appUrl'], entry['appId']);
-                handler.lastUpdated = entry['lastUpdated'] && new Date(entry['lastUpdated']);
-                ret.push(handler);
+                var factory = _installerFactories[entry['appType']];
+                var installer = factory.createFromJson(entry['appUrl'], entry['appId']);
+                installer.lastUpdated = entry['lastUpdated'] && new Date(entry['lastUpdated']);
+                installer.installPath = entry['installPath'];
+                ret.push(installer);
             }
             return ret;
         }
@@ -35,14 +36,14 @@
         }
 
         function initHandlers() {
-            if (_installHandlers) {
+            if (_installers) {
                 return Q();
             }
 
             return readAppsJson()
             .then(function(appsJson) {
                 _lastLaunchedAppId  = appsJson['lastLaunched'];
-                _installHandlers = createInstallHandlersFromJson(appsJson);
+                _installers = createInstallHandlersFromJson(appsJson);
             });
         }
 
@@ -52,12 +53,13 @@
                 'appList': []
             };
             var appList = appsJson['appList'];
-            for (var i = 0, handler; handler = _installHandlers[i]; ++i) {
+            for (var i = 0, installer; installer = _installers[i]; ++i) {
                 appList.push({
-                    'appId' : handler.appId,
-                    'appType' : handler.type,
-                    'appUrl' : handler.url,
-                    'lastUpdated': handler.lastUpdated && +handler.lastUpdated
+                    'appId' : installer.appId,
+                    'appType' : installer.type,
+                    'appUrl' : installer.url,
+                    'lastUpdated': installer.lastUpdated && +installer.lastUpdated,
+                    'installPath': installer.installPath
                 });
             }
 
@@ -65,103 +67,46 @@
             return ResourcesLoader.writeFileContents(APPS_JSON, stringContents);
         }
 
-        function isUrlAbsolute(path){
-            return (path.match(/^[a-z0-9+.-]+:/) != null);
-        }
-
-        function getAppStartPageFromConfig(configFile) {
-            return ResourcesLoader.readFileContents(configFile)
-            .then(function(contents){
-                if(!contents) {
-                    throw new Error("Config file is empty. Unable to find a start page for your app.");
-                } else {
-                    var startLocation = 'index.html';
-                    var parser = new DOMParser();
-                    var xmlDoc = parser.parseFromString(contents, "text/xml");
-                    var els = xmlDoc.getElementsByTagName("content");
-
-                    if(els.length > 0) {
-                        // go through all "content" elements looking for the "src" attribute in reverse order
-                        for(var i = els.length - 1; i >= 0; i--) {
-                            var el = els[i];
-                            var srcValue = el.getAttribute("src");
-                            if (srcValue) {
-                                startLocation = srcValue;
-                                break;
-                            }
-                        }
-                    }
-
-                    return startLocation;
-                }
-            });
-        }
-
-        // On success, this function returns the following paths
-        // appInstallLocation - INSTALL_DIR/app/platform/
-        // platformWWWLocation - location containing the html, css and js files
-        // configLocation - location of config.xml
-        // startLocation - the path of the page to start the app with
-        function getAppPathsForHandler(handler) {
-            var appPaths = {};
-            var installPath = INSTALL_DIRECTORY + '/' + handler.appId;
-            appPaths.appInstallLocation = installPath;
-            appPaths.configLocation = installPath + "/config.xml";
-            appPaths.platformWWWLocation = installPath + "/www/";
-
-            return Q.fcall(function(){
-                return getAppStartPageFromConfig(appPaths.configLocation);
-            })
-            .then(function(startLocation) {
-                appPaths.startLocation = cordova.require('cordova/urlutil').makeAbsolute(startLocation);
-                return appPaths;
-            });
-        }
-
         return {
             // return promise with the array of apps
             getAppList : function() {
                 return initHandlers()
                 .then(function() {
-                    return _installHandlers.slice();
+                    return _installers.slice();
                 });
             },
 
-            launchApp : function(handler) {
-                _lastLaunchedAppId = handler.appId;
+            launchApp : function(installer) {
+                _lastLaunchedAppId = installer.appId;
                 return writeAppsJson()
-                .then(function(){
-                    return getAppPathsForHandler(handler);
+                .then(function() {
+                    var installPath = INSTALL_DIRECTORY + '/' + installer.appId;
+                    return installer.launch(installPath);
                 })
-                .then(function(appPaths){
-                    var installPath = INSTALL_DIRECTORY + '/' + handler.appId;
-                    return handler.prepareForLaunch(installPath, appPaths.startLocation)
-                    .then(function() {
-                        window.location = appPaths.startLocation;
-                    });
+                .then(function(launchUrl) {
+                    window.location = launchUrl;
                 });
             },
 
             addApp : function(installerType, appUrl) {
-                var handlerFactory = _installHandlerFactories[installerType];
+                var installerFactory = _installerFactories[installerType];
                 return Q.fcall(function(){
-                    return handlerFactory.createFromUrl(appUrl);
+                    return installerFactory.createFromUrl(appUrl);
                 })
-                .then(function(handler) {
-                    _installHandlers.push(handler);
+                .then(function(installer) {
+                    _installers.push(installer);
                     return writeAppsJson()
                     .then(function() {
-                        return handler;
+                        return installer;
                     });
                 });
             },
 
-            uninstallApp : function(handler) {
-                _installHandlers.splice(_installHandlers.indexOf(handler), 1);
-                return writeAppsJson()
+            uninstallApp : function(installer) {
+                return installer.deleteFiles()
                 .then(function() {
-                    var installPath = INSTALL_DIRECTORY + '/' + handler.appId;
-                    return ResourcesLoader.deleteDirectory(installPath);
+                    _installers.splice(_installers.indexOf(installer), 1);
+                    return writeAppsJson()
                 });
             },
 
@@ -169,16 +114,16 @@
                 throw new Error('Not implemented.');
             },
 
-            updateApp : function(handler){
+            updateApp : function(installer){
                 return Q.fcall(function() {
-                    var installPath = INSTALL_DIRECTORY + '/' + handler.appId;
-                    return handler.updateApp(installPath)
+                    var installPath = INSTALL_DIRECTORY + '/' + installer.appId;
+                    return installer.updateApp(installPath)
                     .then(writeAppsJson);
                 });
             },
 
-            registerInstallHandlerFactory : function(handlerFactory) {
-                _installHandlerFactories[handlerFactory.type] = handlerFactory;
+            registerInstallerFactory : function(installerFactory) {
+                _installerFactories[installerFactory.type] = installerFactory;
             }
         };
     }]);

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/c3939e03/www/cdvah_js/ContextMenuInjectScript.js
----------------------------------------------------------------------
diff --git a/www/cdvah_js/ContextMenuInjectScript.js b/www/cdvah_js/ContextMenuInjectScript.js
index 6084036..4ff261e 100644
--- a/www/cdvah_js/ContextMenuInjectScript.js
+++ b/www/cdvah_js/ContextMenuInjectScript.js
@@ -6,7 +6,6 @@
             document.addEventListener('deviceready', function() {
                 console.log("Injecting menu script");
                 var contextScript = document.createElement("script");
-                contextScript.setAttribute("type","text/javascript");
                 contextScript.setAttribute("src", "app-bundle:///ContextMenu.js");
                 window.__cordovaAppHarnessAppName = "appPlaceHolder";
                 document.getElementsByTagName("head")[0].appendChild(contextScript);

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/c3939e03/www/cdvah_js/Installer.js
----------------------------------------------------------------------
diff --git a/www/cdvah_js/Installer.js b/www/cdvah_js/Installer.js
new file mode 100644
index 0000000..d77971c
--- /dev/null
+++ b/www/cdvah_js/Installer.js
@@ -0,0 +1,98 @@
+(function(){
+    "use strict";
+    /* global myApp */
+    myApp.factory("Installer", ["AppBundle", "ResourcesLoader", "ContextMenuInjectScript", function(AppBundle, ResourcesLoader, ContextMenuInjectScript) {
+
+        function getAppStartPageFromConfig(configFile) {
+            return ResourcesLoader.readFileContents(configFile)
+            .then(function(contents) {
+                if(!contents) {
+                    throw new Error("Config file is empty. Unable to find a start page for your app.");
+                } else {
+                    var startLocation = 'index.html';
+                    var parser = new DOMParser();
+                    var xmlDoc = parser.parseFromString(contents, "text/xml");
+                    var els = xmlDoc.getElementsByTagName("content");
+
+                    if(els.length > 0) {
+                        // go through all "content" elements looking for the "src" attribute in reverse order
+                        for(var i = els.length - 1; i >= 0; i--) {
+                            var el = els[i];
+                            var srcValue = el.getAttribute("src");
+                            if (srcValue) {
+                                startLocation = srcValue;
+                                break;
+                            }
+                        }
+                    }
+
+                    return startLocation;
+                }
+            });
+        }
+
+        function Installer(url, appId) {
+            this.url = url;
+            this.appId = appId || '';
+            this.lastUpdated = null;
+            this.installPath = null;
+        }
+
+        Installer.prototype.type = '';
+
+        Installer.prototype.updateApp = function(installPath) {
+            this.installPath = installPath;
+            this.lastUpdated = new Date();
+        };
+
+        Installer.prototype.deleteFiles = function() {
+            var self = this;
+            return Q.fcall(function() {
+                self.lastUpdated = null;
+                if (self.installPath) {
+                    return ResourcesLoader.deleteDirectory(self.installPath);
+                }
+            });
+        };
+
+        Installer.prototype.launch = function() {
+            var installPath = this.installPath;
+            if (!installPath) {
+                throw new Error('App ' + this.appId + ' requires an update');
+            }
+            var configLocation = installPath + '/config.xml';
+
+            return getAppStartPageFromConfig(configLocation)
+            .then(function(rawStartLocation) {
+                var harnessUrl = cordova.require('cordova/urlutil').makeAbsolute(location.pathname);
+                var harnessDir = harnessUrl.replace(/\/[^\/]*$/, '');
+                var installUrl = cordova.require('cordova/urlutil').makeAbsolute(installPath);
+                var injectString = ContextMenuInjectScript.getInjectString();
+                // Inject the context menu script for all pages except the harness menu.
+                AppBundle.injectJsForUrl('^(?!' + harnessUrl + ')', injectString);
+                // Allow navigations back to the menu.
+                AppBundle.setResetUrl('^' + harnessUrl);
+                // Make any references to www/ point to the app's install location.
+                AppBundle.aliasUri('^' + harnessDir, '^' + harnessDir, installUrl + '/www', false /* redirect */);
+                // Override cordova.js and cordova_plugins.js.
+                AppBundle.aliasUri('/cordova\\.js.*', '.+', harnessDir + '/cordova.js', false /* redirect */);
+                AppBundle.aliasUri('/cordova_plugins\\.js.*', '.+', harnessDir + '/cordova_plugins.js', false /* redirect */);
+                // Set-up app-bundle: scheme to point at the harness.
+                AppBundle.aliasUri('^app-bundle:///cdvah_index.html', '^app-bundle://', harnessDir, true);
+                return AppBundle.aliasUri('^app-bundle:', '^app-bundle://', harnessDir, false)
+                .then(function() {
+                    var startLocation = cordova.require('cordova/urlutil').makeAbsolute(rawStartLocation);
+                    // On iOS, file:// URLs can't be re-routed via an NSURLProtocol for top-level navications.
+                    // http://stackoverflow.com/questions/12058203/using-a-custom-nsurlprotocol-on-ios-for-file-urls-causes-frame-load-interrup
+                    // The work-around (using loadData:) breaks history.back().
+                    // So, for file:// start pages, we just point to the install location.
+                    if (cordova.platformId == 'ios') {
+                        return startLocation.replace(harnessDir, installUrl + '/www')
+                    }
+                    return startLocation;
+                });
+            });
+        };
+        return Installer;
+    }]);
+})();

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/c3939e03/www/cdvah_js/KnownExtensionDownloader.js
----------------------------------------------------------------------
diff --git a/www/cdvah_js/KnownExtensionDownloader.js b/www/cdvah_js/KnownExtensionDownloader.js
deleted file mode 100644
index 1274ef1..0000000
--- a/www/cdvah_js/KnownExtensionDownloader.js
+++ /dev/null
@@ -1,22 +0,0 @@
-(function(){
-    "use strict";
-    /* global myApp */
-    myApp.run(["AppsService", "ResourcesLoader", function(AppsService, ResourcesLoader){
-
-        function isUri(pattern){
-            var regexUri = /^(?:([a-z0-9+.-]+:\/\/)((?:(?:[a-z0-9-._~!$&'()*+,;=:]|%[0-9A-F]{2})*)@)?((?:[a-z0-9-._~!$&'()*+,;=]|%[0-9A-F]{2})*)(:(?:\d*))?(\/(?:[a-z0-9-._~!$&'()*+,;=:@\/]|%[0-9A-F]{2})*)?|([a-z0-9+.-]+:)(\/?(?:[a-z0-9-._~!$&'()*+,;=:@]|%[0-9A-F]{2})+(?:[a-z0-9-._~!$&'()*+,;=:@\/]|%[0-9A-F]{2})*)?)(\?(?:[a-z0-9-._~!$&'()*+,;=:\/?@]|%[0-9A-F]{2})*)?(#(?:[a-z0-9-._~!$&'()*+,;=:\/?@]|%[0-9A-F]{2})*)?$/i;
-            var ret = (pattern.search(regexUri) !== -1);
-            return ret;
-        }
-
-        // Note the priority given has no meaning in and of itself. It is used solely to compare if any other component has higher priority.
-        AppsService.registerInstallHandler({
-            downloadFromPattern : function (appName, pattern, tempDirectory) {
-                var extension = grabExtensionFromUri(pattern);
-                var fileName = tempDirectory + appName + "." + extension;
-                return ResourcesLoader.downloadFromUrl(pattern, fileName);
-            }
-        });
-
-    }]);
-})();

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/c3939e03/www/cdvah_js/ListCtrl.js
----------------------------------------------------------------------
diff --git a/www/cdvah_js/ListCtrl.js b/www/cdvah_js/ListCtrl.js
index 566d134..2144fd1 100644
--- a/www/cdvah_js/ListCtrl.js
+++ b/www/cdvah_js/ListCtrl.js
@@ -16,7 +16,7 @@
                     .then(AppsService.launchApp, function(e){
                         e = e || {};
                         console.error("Error launching last run app: " + e);
-                        notifier.error("Error launching last run app. Please try again.");
+                        notifier.error('' + e);
                     });
                 }
                 else if($routeParams.updateLastLaunched) {
@@ -33,7 +33,7 @@
                     }, function(e){
                         e = e || {};
                         console.error("Error updating last run app: " + e);
-                        notifier.error("Error updating last run app. Please try again.");
+                        notifier.error('' + e);
                     });
                 }
                 else {
@@ -60,7 +60,7 @@
             }, function(error){
                 var str = "There was an error retrieving the apps list";
                 console.error(str + ": " + error);
-                notifier.error(str);
+                notifier.error('' + error);
             });
         };
 
@@ -68,7 +68,7 @@
             return AppsService.launchApp(app)
             .then(null, function(error){
                 console.error("Error during loading of app " + app.appId + ": " + error);
-                notifier.error("Something went wrong during the loading of the app. Please try again." + error);
+                notifier.error('' + error);
             });
         };
 
@@ -79,7 +79,7 @@
                 console.log('successfully updated');
             }, function(error){
                 console.error("Error during updating of app " + app.appId + ": " + error);
-                notifier.error("Something went wrong during the updating of the app. Please try again.");
+                notifier.error('' + error);
             });
         };
 
@@ -90,7 +90,7 @@
                 .then(function() { $scope.loadAppsList(true); },
                       function(error) {
                     console.error(error);
-                    notifier.error("Something went wrong during the uninstall of the app. Please try again.");
+                    notifier.error('' + error);
                 });
             }
         }

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/c3939e03/www/cdvah_js/ServeCordovaJSHandler.js
----------------------------------------------------------------------
diff --git a/www/cdvah_js/ServeCordovaJSHandler.js b/www/cdvah_js/ServeCordovaJSHandler.js
deleted file mode 100644
index 5026de6..0000000
--- a/www/cdvah_js/ServeCordovaJSHandler.js
+++ /dev/null
@@ -1,111 +0,0 @@
-(function(){
-    "use strict";
-    /* global myApp */
-    myApp.run(["$location", "AppBundle", "AppsService", "ResourcesLoader", "ContextMenuInjectScript", function($location, AppBundle, AppsService, ResourcesLoader, ContextMenuInjectScript){
-        var platformId = cordova.platformId;
-
-        function ServeHandler(url, appId) {
-            this.url = url;
-            this.appId = appId || '';
-            this.lastUpdated = null;
-            this._cachedProjectJson = null;
-            this._cachedConfigXml = null;
-        }
-
-        ServeHandler.prototype.type = 'serve';
-
-        ServeHandler.prototype._updateAppMeta = function() {
-            var self = this;
-            return ResourcesLoader.xhrGet(this.url + '/' + platformId + '/project.json')
-            .then(function(xhr) {
-                self._cachedProjectJson = JSON.parse(xhr.responseText);
-                return ResourcesLoader.xhrGet(self.url + self._cachedProjectJson['configPath']);
-            })
-            .then(function(xhr) {
-                self._cachedConfigXml = xhr.responseText;
-                var configXml = new DOMParser().parseFromString(self._cachedConfigXml, 'text/xml');
-                self.appId = configXml.firstChild.getAttribute('id');
-            });
-        };
-
-        // TODO: update should be more atomic. Maybe download to a new directory?
-        ServeHandler.prototype.updateApp = function(installPath) {
-            var self = this;
-            return this._updateAppMeta()
-            .then(function() {
-                var wwwPath = self._cachedProjectJson['wwwPath'];
-                var files = self._cachedProjectJson['wwwFileList'];
-                var i = 0;
-                function downloadNext() {
-                    // Don't download cordova.js. We want to use the version bundled with the harness.
-                    if (/\/cordova(?:_plugins)?.js$/.exec(files[i])) {
-                        ++i;
-                    }
-                    if (!files[i]) {
-                        self.lastUpdated = new Date();
-                        return;
-                    }
-                    console.log('now downloading ' + i + ' of ' + files.length);
-                    var sourceUrl = self.url + wwwPath + files[i];
-                    var destPath = installPath + '/www' + files[i];
-                    console.log(destPath);
-                    i += 1;
-                    return ResourcesLoader.downloadFromUrl(sourceUrl, destPath).then(downloadNext);
-                }
-                return ResourcesLoader.ensureDirectoryExists(installPath + '/config.xml')
-                .then(function() {
-                    return ResourcesLoader.writeFileContents(installPath + '/config.xml', self._cachedConfigXml)
-                })
-                .then(downloadNext);
-            });
-        };
-
-        ServeHandler.prototype.prepareForLaunch = function(installPath, launchUrl) {
-            var harnessUrl = cordova.require('cordova/urlutil').makeAbsolute(location.pathname);
-            var harnessDir = harnessUrl.replace(/\/[^\/]*$/, '');
-            var installUrl = cordova.require('cordova/urlutil').makeAbsolute(installPath);
-            var injectString = ContextMenuInjectScript.getInjectString()
-            // Inject the context menu script for all pages except the harness menu.
-            return AppBundle.injectJsForUrl('^(?!' + harnessUrl + ')', injectString)
-            .then(function() {
-                // Allow navigations back to the menu.
-                return AppBundle.setResetUrl('^' + harnessUrl);
-            })
-            .then(function() {
-                // Make any references to www/ point to the app's install location.
-                return AppBundle.aliasUri('^' + harnessDir, '^' + harnessDir, installUrl + '/www', false /* redirect */);
-            })
-            .then(function() {
-                return AppBundle.aliasUri('/cordova\\.js.*', '.+', harnessDir + '/cordova.js', false /* redirect */);
-            })
-            .then(function() {
-                return AppBundle.aliasUri('/cordova_plugins\\.js.*', '.+', harnessDir + '/cordova_plugins.js', false /* redirect */);
-            });
-        };
-
-        function createFromUrl(url) {
-            // Strip platform and trailing slash if they exist.
-            url = url.replace(/\/$/, '').replace(new RegExp(platformId + '$'), '').replace(/\/$/, '');
-            if (!/^http:/.test(url)) {
-                url = 'http://' + url;
-            }
-            if (!/:(\d)/.test(url)) {
-                url = url.replace(/(.*?\/\/[^\/]*)/, '$1:8000');
-            }
-            // Fetch config.xml.
-            var ret = new ServeHandler(url);
-
-            return ret._updateAppMeta().then(function() { return ret; });
-        }
-
-        function createFromJson(url, appId) {
-            return new ServeHandler(url, appId);
-        }
-
-        AppsService.registerInstallHandlerFactory({
-            type: 'serve',
-            createFromUrl: createFromUrl, // returns a promise.
-            createFromJson: createFromJson // does not return a promise.
-        });
-    }]);
-})();

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/c3939e03/www/cdvah_js/ServeInstaller.js
----------------------------------------------------------------------
diff --git a/www/cdvah_js/ServeInstaller.js b/www/cdvah_js/ServeInstaller.js
new file mode 100644
index 0000000..4cbb7f9
--- /dev/null
+++ b/www/cdvah_js/ServeInstaller.js
@@ -0,0 +1,87 @@
+(function(){
+    "use strict";
+    /* global myApp */
+    myApp.run(["Installer", "AppsService", "ResourcesLoader", function(Installer, AppsService, ResourcesLoader) {
+        var platformId = cordova.platformId;
+
+        function ServeInstaller(url, appId) {
+            Installer.call(this, url, appId);
+            this._cachedProjectJson = null;
+            this._cachedConfigXml = null;
+        }
+        ServeInstaller.prototype = Object.create(Installer.prototype);
+
+        ServeInstaller.prototype.type = 'serve';
+
+        ServeInstaller.prototype._updateAppMeta = function() {
+            var self = this;
+            return ResourcesLoader.xhrGet(this.url + '/' + platformId + '/project.json')
+            .then(function(xhr) {
+                self._cachedProjectJson = JSON.parse(xhr.responseText);
+                return ResourcesLoader.xhrGet(self.url + self._cachedProjectJson['configPath']);
+            })
+            .then(function(xhr) {
+                self._cachedConfigXml = xhr.responseText;
+                var configXml = new DOMParser().parseFromString(self._cachedConfigXml, 'text/xml');
+                self.appId = configXml.firstChild.getAttribute('id');
+            });
+        };
+
+        // TODO: update should be more atomic. Maybe download to a new directory?
+        ServeInstaller.prototype.updateApp = function(installPath) {
+            var self = this;
+            return this._updateAppMeta()
+            .then(function() {
+                var wwwPath = self._cachedProjectJson['wwwPath'];
+                var files = self._cachedProjectJson['wwwFileList'];
+                var i = 0;
+                function downloadNext() {
+                    // Don't download cordova.js. We want to use the version bundled with the harness.
+                    if (/\/cordova(?:_plugins)?.js$/.exec(files[i])) {
+                        ++i;
+                    }
+                    if (!files[i]) {
+                        Installer.prototype.updateApp.call(self, installPath);
+                        return;
+                    }
+                    console.log('now downloading ' + i + ' of ' + files.length);
+                    var sourceUrl = self.url + wwwPath + files[i];
+                    var destPath = installPath + '/www' + files[i];
+                    console.log(destPath);
+                    i += 1;
+                    return ResourcesLoader.downloadFromUrl(sourceUrl, destPath).then(downloadNext);
+                }
+                return ResourcesLoader.ensureDirectoryExists(installPath + '/config.xml')
+                .then(function() {
+                    return ResourcesLoader.writeFileContents(installPath + '/config.xml', self._cachedConfigXml)
+                })
+                .then(downloadNext);
+            });
+        };
+
+        function createFromUrl(url) {
+            // Strip platform and trailing slash if they exist.
+            url = url.replace(/\/$/, '').replace(new RegExp(platformId + '$'), '').replace(/\/$/, '');
+            if (!/^http:/.test(url)) {
+                url = 'http://' + url;
+            }
+            if (!/:(\d)/.test(url)) {
+                url = url.replace(/(.*?\/\/[^\/]*)/, '$1:8000');
+            }
+            // Fetch config.xml.
+            var ret = new ServeInstaller(url);
+
+            return ret._updateAppMeta().then(function() { return ret; });
+        }
+
+        function createFromJson(url, appId, installPath) {
+            return new ServeInstaller(url, appId);
+        }
+
+        AppsService.registerInstallerFactory({
+            type: 'serve',
+            createFromUrl: createFromUrl, // returns a promise.
+            createFromJson: createFromJson // does not return a promise.
+        });
+    }]);
+})();

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/c3939e03/www/cdvah_js/app.js
----------------------------------------------------------------------
diff --git a/www/cdvah_js/app.js b/www/cdvah_js/app.js
index c40bda7..9aa5429 100644
--- a/www/cdvah_js/app.js
+++ b/www/cdvah_js/app.js
@@ -1,7 +1,7 @@
 
 Q.longStackSupport = true;
 
-var myApp = angular.module("CordovaAppHarness", []);
+var myApp = angular.module("CordovaAppHarness", ['ngRoute']);
 
 
 myApp.config(["$routeProvider", function($routeProvider){
@@ -21,7 +21,6 @@ document.addEventListener('deviceready', function() {
         var path = dirEntry.fullPath;
         myApp.value("INSTALL_DIRECTORY", path + "/apps");
         myApp.value("APPS_JSON", path + "/apps.json");
-        alert('booting strap');
         angular.bootstrap(document, ['CordovaAppHarness']);
     });
 }, false);

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/c3939e03/www/cdvah_js/libs/angular-route.js
----------------------------------------------------------------------
diff --git a/www/cdvah_js/libs/angular-route.js b/www/cdvah_js/libs/angular-route.js
new file mode 100644
index 0000000..d0c4cd5
--- /dev/null
+++ b/www/cdvah_js/libs/angular-route.js
@@ -0,0 +1,860 @@
+/**
+ * @license AngularJS v1.2.0rc1
+ * (c) 2010-2012 Google, Inc. http://angularjs.org
+ * License: MIT
+ */
+(function(window, angular, undefined) {'use strict';
+
+var copy = angular.copy,
+    equals = angular.equals,
+    extend = angular.extend,
+    forEach = angular.forEach,
+    isDefined = angular.isDefined,
+    isFunction = angular.isFunction,
+    isString = angular.isString,
+    jqLite = angular.element,
+    noop = angular.noop,
+    toJson = angular.toJson;
+
+
+function inherit(parent, extra) {
+  return extend(new (extend(function() {}, {prototype:parent}))(), extra);
+}
+
+/**
+ * @ngdoc overview
+ * @name ngRoute
+ * @description
+ *
+ * Module that provides routing and deeplinking services and directives for angular apps.
+ */
+
+var ngRouteModule = angular.module('ngRoute', ['ng']).
+                        provider('$route', $RouteProvider);
+
+/**
+ * @ngdoc object
+ * @name ngRoute.$routeProvider
+ * @function
+ *
+ * @description
+ *
+ * Used for configuring routes. See {@link ngRoute.$route $route} for an example.
+ */
+function $RouteProvider(){
+  var routes = {};
+
+  /**
+   * @ngdoc method
+   * @name ngRoute.$routeProvider#when
+   * @methodOf ngRoute.$routeProvider
+   *
+   * @param {string} path Route path (matched against `$location.path`). If `$location.path`
+   *    contains redundant trailing slash or is missing one, the route will still match and the
+   *    `$location.path` will be updated to add or drop the trailing slash to exactly match the
+   *    route definition.
+   *
+   *      * `path` can contain named groups starting with a colon (`:name`). All characters up
+   *        to the next slash are matched and stored in `$routeParams` under the given `name`
+   *        when the route matches.
+   *      * `path` can contain named groups starting with a colon and ending with a star (`:name*`). 
+   *        All characters are eagerly stored in `$routeParams` under the given `name` 
+   *        when the route matches.
+   *      * `path` can contain optional named groups with a question mark (`:name?`).
+   *
+   *    For example, routes like `/color/:color/largecode/:largecode*\/edit` will match
+   *    `/color/brown/largecode/code/with/slashs/edit` and extract:
+   *
+   *      * `color: brown`
+   *      * `largecode: code/with/slashs`.
+   *
+   *
+   * @param {Object} route Mapping information to be assigned to `$route.current` on route
+   *    match.
+   *
+   *    Object properties:
+   *
+   *    - `controller` – `{(string|function()=}` – Controller fn that should be associated with newly
+   *      created scope or the name of a {@link angular.Module#controller registered controller}
+   *      if passed as a string.
+   *    - `controllerAs` – `{string=}` – A controller alias name. If present the controller will be
+   *      published to scope under the `controllerAs` name.
+   *    - `template` – `{string=|function()=}` – html template as a string or a function that
+   *      returns an html template as a string which should be used by {@link
+   *      ngRoute.directive:ngView ngView} or {@link ng.directive:ngInclude ngInclude} directives.
+   *      This property takes precedence over `templateUrl`.
+   *
+   *      If `template` is a function, it will be called with the following parameters:
+   *
+   *      - `{Array.<Object>}` - route parameters extracted from the current
+   *        `$location.path()` by applying the current route
+   *
+   *    - `templateUrl` – `{string=|function()=}` – path or function that returns a path to an html
+   *      template that should be used by {@link ngRoute.directive:ngView ngView}.
+   *
+   *      If `templateUrl` is a function, it will be called with the following parameters:
+   *
+   *      - `{Array.<Object>}` - route parameters extracted from the current
+   *        `$location.path()` by applying the current route
+   *
+   *    - `resolve` - `{Object.<string, function>=}` - An optional map of dependencies which should
+   *      be injected into the controller. If any of these dependencies are promises, they will be
+   *      resolved and converted to a value before the controller is instantiated and the
+   *      `$routeChangeSuccess` event is fired. The map object is:
+   *
+   *      - `key` – `{string}`: a name of a dependency to be injected into the controller.
+   *      - `factory` - `{string|function}`: If `string` then it is an alias for a service.
+   *        Otherwise if function, then it is {@link api/AUTO.$injector#invoke injected}
+   *        and the return value is treated as the dependency. If the result is a promise, it is resolved
+   *        before its value is injected into the controller. Be aware that `ngRoute.$routeParams` will
+   *        still refer to the previous route within these resolve functions.  Use `$route.current.params`
+   *        to access the new route parameters, instead.
+   *
+   *    - `redirectTo` – {(string|function())=} – value to update
+   *      {@link ng.$location $location} path with and trigger route redirection.
+   *
+   *      If `redirectTo` is a function, it will be called with the following parameters:
+   *
+   *      - `{Object.<string>}` - route parameters extracted from the current
+   *        `$location.path()` by applying the current route templateUrl.
+   *      - `{string}` - current `$location.path()`
+   *      - `{Object}` - current `$location.search()`
+   *
+   *      The custom `redirectTo` function is expected to return a string which will be used
+   *      to update `$location.path()` and `$location.search()`.
+   *
+   *    - `[reloadOnSearch=true]` - {boolean=} - reload route when only $location.search()
+   *    changes.
+   *
+   *      If the option is set to `false` and url in the browser changes, then
+   *      `$routeUpdate` event is broadcasted on the root scope.
+   *
+   *    - `[caseInsensitiveMatch=false]` - {boolean=} - match routes without being case sensitive
+   *
+   *      If the option is set to `true`, then the particular route can be matched without being
+   *      case sensitive
+   *
+   * @returns {Object} self
+   *
+   * @description
+   * Adds a new route definition to the `$route` service.
+   */
+  this.when = function(path, route) {
+    routes[path] = extend(
+      {reloadOnSearch: true},
+      route,
+      path && pathRegExp(path, route)
+    );
+
+    // create redirection for trailing slashes
+    if (path) {
+      var redirectPath = (path[path.length-1] == '/')
+          ? path.substr(0, path.length-1)
+          : path +'/';
+
+      routes[redirectPath] = extend(
+        {redirectTo: path},
+        pathRegExp(redirectPath, route)
+      );
+    }
+
+    return this;
+  };
+
+   /**
+    * @param path {string} path
+    * @param opts {Object} options
+    * @return {?Object}
+    *
+    * @description
+    * Normalizes the given path, returning a regular expression
+    * and the original path.
+    *
+    * Inspired by pathRexp in visionmedia/express/lib/utils.js.
+    */
+  function pathRegExp(path, opts) {
+    var insensitive = opts.caseInsensitiveMatch,
+        ret = {
+          originalPath: path,
+          regexp: path
+        },
+        keys = ret.keys = [];
+
+    path = path
+      .replace(/([().])/g, '\\$1')
+      .replace(/(\/)?:(\w+)([\?|\*])?/g, function(_, slash, key, option){
+        var optional = option === '?' ? option : null;
+        var star = option === '*' ? option : null;
+        keys.push({ name: key, optional: !!optional });
+        slash = slash || '';
+        return ''
+          + (optional ? '' : slash)
+          + '(?:'
+          + (optional ? slash : '')
+          + (star && '(.+)?' || '([^/]+)?') + ')'
+          + (optional || '');
+      })
+      .replace(/([\/$\*])/g, '\\$1');
+
+    ret.regexp = new RegExp('^' + path + '$', insensitive ? 'i' : '');
+    return ret;
+  }
+
+  /**
+   * @ngdoc method
+   * @name ngRoute.$routeProvider#otherwise
+   * @methodOf ngRoute.$routeProvider
+   *
+   * @description
+   * Sets route definition that will be used on route change when no other route definition
+   * is matched.
+   *
+   * @param {Object} params Mapping information to be assigned to `$route.current`.
+   * @returns {Object} self
+   */
+  this.otherwise = function(params) {
+    this.when(null, params);
+    return this;
+  };
+
+
+  this.$get = ['$rootScope', '$location', '$routeParams', '$q', '$injector', '$http', '$templateCache', '$sce',
+      function( $rootScope,   $location,   $routeParams,   $q,   $injector,   $http,   $templateCache,   $sce) {
+
+    /**
+     * @ngdoc object
+     * @name ngRoute.$route
+     * @requires $location
+     * @requires $routeParams
+     *
+     * @property {Object} current Reference to the current route definition.
+     * The route definition contains:
+     *
+     *   - `controller`: The controller constructor as define in route definition.
+     *   - `locals`: A map of locals which is used by {@link ng.$controller $controller} service for
+     *     controller instantiation. The `locals` contain
+     *     the resolved values of the `resolve` map. Additionally the `locals` also contain:
+     *
+     *     - `$scope` - The current route scope.
+     *     - `$template` - The current route template HTML.
+     *
+     * @property {Array.<Object>} routes Array of all configured routes.
+     *
+     * @description
+     * Is used for deep-linking URLs to controllers and views (HTML partials).
+     * It watches `$location.url()` and tries to map the path to an existing route definition.
+     *
+     * You can define routes through {@link ngRoute.$routeProvider $routeProvider}'s API.
+     *
+     * The `$route` service is typically used in conjunction with {@link ngRoute.directive:ngView ngView}
+     * directive and the {@link ngRoute.$routeParams $routeParams} service.
+     *
+     * @example
+       This example shows how changing the URL hash causes the `$route` to match a route against the
+       URL, and the `ngView` pulls in the partial.
+
+       Note that this example is using {@link ng.directive:script inlined templates}
+       to get it working on jsfiddle as well.
+
+     <example module="ngView" deps="angular-route.js">
+       <file name="index.html">
+         <div ng-controller="MainCntl">
+           Choose:
+           <a href="Book/Moby">Moby</a> |
+           <a href="Book/Moby/ch/1">Moby: Ch1</a> |
+           <a href="Book/Gatsby">Gatsby</a> |
+           <a href="Book/Gatsby/ch/4?key=value">Gatsby: Ch4</a> |
+           <a href="Book/Scarlet">Scarlet Letter</a><br/>
+
+           <div ng-view></div>
+           <hr />
+
+           <pre>$location.path() = {{$location.path()}}</pre>
+           <pre>$route.current.templateUrl = {{$route.current.templateUrl}}</pre>
+           <pre>$route.current.params = {{$route.current.params}}</pre>
+           <pre>$route.current.scope.name = {{$route.current.scope.name}}</pre>
+           <pre>$routeParams = {{$routeParams}}</pre>
+         </div>
+       </file>
+
+       <file name="book.html">
+         controller: {{name}}<br />
+         Book Id: {{params.bookId}}<br />
+       </file>
+
+       <file name="chapter.html">
+         controller: {{name}}<br />
+         Book Id: {{params.bookId}}<br />
+         Chapter Id: {{params.chapterId}}
+       </file>
+
+       <file name="script.js">
+         angular.module('ngView', ['ngRoute']).config(function($routeProvider, $locationProvider) {
+           $routeProvider.when('/Book/:bookId', {
+             templateUrl: 'book.html',
+             controller: BookCntl,
+             resolve: {
+               // I will cause a 1 second delay
+               delay: function($q, $timeout) {
+                 var delay = $q.defer();
+                 $timeout(delay.resolve, 1000);
+                 return delay.promise;
+               }
+             }
+           });
+           $routeProvider.when('/Book/:bookId/ch/:chapterId', {
+             templateUrl: 'chapter.html',
+             controller: ChapterCntl
+           });
+
+           // configure html5 to get links working on jsfiddle
+           $locationProvider.html5Mode(true);
+         });
+
+         function MainCntl($scope, $route, $routeParams, $location) {
+           $scope.$route = $route;
+           $scope.$location = $location;
+           $scope.$routeParams = $routeParams;
+         }
+
+         function BookCntl($scope, $routeParams) {
+           $scope.name = "BookCntl";
+           $scope.params = $routeParams;
+         }
+
+         function ChapterCntl($scope, $routeParams) {
+           $scope.name = "ChapterCntl";
+           $scope.params = $routeParams;
+         }
+       </file>
+
+       <file name="scenario.js">
+         it('should load and compile correct template', function() {
+           element('a:contains("Moby: Ch1")').click();
+           var content = element('.doc-example-live [ng-view]').text();
+           expect(content).toMatch(/controller\: ChapterCntl/);
+           expect(content).toMatch(/Book Id\: Moby/);
+           expect(content).toMatch(/Chapter Id\: 1/);
+
+           element('a:contains("Scarlet")').click();
+           sleep(2); // promises are not part of scenario waiting
+           content = element('.doc-example-live [ng-view]').text();
+           expect(content).toMatch(/controller\: BookCntl/);
+           expect(content).toMatch(/Book Id\: Scarlet/);
+         });
+       </file>
+     </example>
+     */
+
+    /**
+     * @ngdoc event
+     * @name ngRoute.$route#$routeChangeStart
+     * @eventOf ngRoute.$route
+     * @eventType broadcast on root scope
+     * @description
+     * Broadcasted before a route change. At this  point the route services starts
+     * resolving all of the dependencies needed for the route change to occurs.
+     * Typically this involves fetching the view template as well as any dependencies
+     * defined in `resolve` route property. Once  all of the dependencies are resolved
+     * `$routeChangeSuccess` is fired.
+     *
+     * @param {Route} next Future route information.
+     * @param {Route} current Current route information.
+     */
+
+    /**
+     * @ngdoc event
+     * @name ngRoute.$route#$routeChangeSuccess
+     * @eventOf ngRoute.$route
+     * @eventType broadcast on root scope
+     * @description
+     * Broadcasted after a route dependencies are resolved.
+     * {@link ngRoute.directive:ngView ngView} listens for the directive
+     * to instantiate the controller and render the view.
+     *
+     * @param {Object} angularEvent Synthetic event object.
+     * @param {Route} current Current route information.
+     * @param {Route|Undefined} previous Previous route information, or undefined if current is first route entered.
+     */
+
+    /**
+     * @ngdoc event
+     * @name ngRoute.$route#$routeChangeError
+     * @eventOf ngRoute.$route
+     * @eventType broadcast on root scope
+     * @description
+     * Broadcasted if any of the resolve promises are rejected.
+     *
+     * @param {Route} current Current route information.
+     * @param {Route} previous Previous route information.
+     * @param {Route} rejection Rejection of the promise. Usually the error of the failed promise.
+     */
+
+    /**
+     * @ngdoc event
+     * @name ngRoute.$route#$routeUpdate
+     * @eventOf ngRoute.$route
+     * @eventType broadcast on root scope
+     * @description
+     *
+     * The `reloadOnSearch` property has been set to false, and we are reusing the same
+     * instance of the Controller.
+     */
+
+    var forceReload = false,
+        $route = {
+          routes: routes,
+
+          /**
+           * @ngdoc method
+           * @name ngRoute.$route#reload
+           * @methodOf ngRoute.$route
+           *
+           * @description
+           * Causes `$route` service to reload the current route even if
+           * {@link ng.$location $location} hasn't changed.
+           *
+           * As a result of that, {@link ngRoute.directive:ngView ngView}
+           * creates new scope, reinstantiates the controller.
+           */
+          reload: function() {
+            forceReload = true;
+            $rootScope.$evalAsync(updateRoute);
+          }
+        };
+
+    $rootScope.$on('$locationChangeSuccess', updateRoute);
+
+    return $route;
+
+    /////////////////////////////////////////////////////
+
+    /**
+     * @param on {string} current url
+     * @param route {Object} route regexp to match the url against
+     * @return {?Object}
+     *
+     * @description
+     * Check if the route matches the current url.
+     *
+     * Inspired by match in
+     * visionmedia/express/lib/router/router.js.
+     */
+    function switchRouteMatcher(on, route) {
+      var keys = route.keys,
+          params = {};
+
+      if (!route.regexp) return null;
+
+      var m = route.regexp.exec(on);
+      if (!m) return null;
+
+      var N = 0;
+      for (var i = 1, len = m.length; i < len; ++i) {
+        var key = keys[i - 1];
+
+        var val = 'string' == typeof m[i]
+          ? decodeURIComponent(m[i])
+          : m[i];
+
+        if (key && val) {
+          params[key.name] = val;
+        }
+      }
+      return params;
+    }
+
+    function updateRoute() {
+      var next = parseRoute(),
+          last = $route.current;
+
+      if (next && last && next.$$route === last.$$route
+          && equals(next.pathParams, last.pathParams) && !next.reloadOnSearch && !forceReload) {
+        last.params = next.params;
+        copy(last.params, $routeParams);
+        $rootScope.$broadcast('$routeUpdate', last);
+      } else if (next || last) {
+        forceReload = false;
+        $rootScope.$broadcast('$routeChangeStart', next, last);
+        $route.current = next;
+        if (next) {
+          if (next.redirectTo) {
+            if (isString(next.redirectTo)) {
+              $location.path(interpolate(next.redirectTo, next.params)).search(next.params)
+                       .replace();
+            } else {
+              $location.url(next.redirectTo(next.pathParams, $location.path(), $location.search()))
+                       .replace();
+            }
+          }
+        }
+
+        $q.when(next).
+          then(function() {
+            if (next) {
+              var locals = extend({}, next.resolve),
+                  template, templateUrl;
+
+              forEach(locals, function(value, key) {
+                locals[key] = isString(value) ? $injector.get(value) : $injector.invoke(value);
+              });
+
+              if (isDefined(template = next.template)) {
+                if (isFunction(template)) {
+                  template = template(next.params);
+                }
+              } else if (isDefined(templateUrl = next.templateUrl)) {
+                if (isFunction(templateUrl)) {
+                  templateUrl = templateUrl(next.params);
+                }
+                templateUrl = $sce.getTrustedResourceUrl(templateUrl);
+                if (isDefined(templateUrl)) {
+                  next.loadedTemplateUrl = templateUrl;
+                  template = $http.get(templateUrl, {cache: $templateCache}).
+                      then(function(response) { return response.data; });
+                }
+              }
+              if (isDefined(template)) {
+                locals['$template'] = template;
+              }
+              return $q.all(locals);
+            }
+          }).
+          // after route change
+          then(function(locals) {
+            if (next == $route.current) {
+              if (next) {
+                next.locals = locals;
+                copy(next.params, $routeParams);
+              }
+              $rootScope.$broadcast('$routeChangeSuccess', next, last);
+            }
+          }, function(error) {
+            if (next == $route.current) {
+              $rootScope.$broadcast('$routeChangeError', next, last, error);
+            }
+          });
+      }
+    }
+
+
+    /**
+     * @returns the current active route, by matching it against the URL
+     */
+    function parseRoute() {
+      // Match a route
+      var params, match;
+      forEach(routes, function(route, path) {
+        if (!match && (params = switchRouteMatcher($location.path(), route))) {
+          match = inherit(route, {
+            params: extend({}, $location.search(), params),
+            pathParams: params});
+          match.$$route = route;
+        }
+      });
+      // No route matched; fallback to "otherwise" route
+      return match || routes[null] && inherit(routes[null], {params: {}, pathParams:{}});
+    }
+
+    /**
+     * @returns interpolation of the redirect path with the parameters
+     */
+    function interpolate(string, params) {
+      var result = [];
+      forEach((string||'').split(':'), function(segment, i) {
+        if (i == 0) {
+          result.push(segment);
+        } else {
+          var segmentMatch = segment.match(/(\w+)(.*)/);
+          var key = segmentMatch[1];
+          result.push(params[key]);
+          result.push(segmentMatch[2] || '');
+          delete params[key];
+        }
+      });
+      return result.join('');
+    }
+  }];
+}
+
+ngRouteModule.provider('$routeParams', $RouteParamsProvider);
+
+
+/**
+ * @ngdoc object
+ * @name ngRoute.$routeParams
+ * @requires $route
+ *
+ * @description
+ * Current set of route parameters. The route parameters are a combination of the
+ * {@link ng.$location $location} `search()`, and `path()`. The `path` parameters
+ * are extracted when the {@link ngRoute.$route $route} path is matched.
+ *
+ * In case of parameter name collision, `path` params take precedence over `search` params.
+ *
+ * The service guarantees that the identity of the `$routeParams` object will remain unchanged
+ * (but its properties will likely change) even when a route change occurs.
+ *
+ * Note that the `$routeParams` are only updated *after* a route change completes successfully.
+ * This means that you cannot rely on `$routeParams` being correct in route resolve functions.
+ * Instead you can use `$route.current.params` to access the new route's parameters.
+ *
+ * @example
+ * <pre>
+ *  // Given:
+ *  // URL: http://server.com/index.html#/Chapter/1/Section/2?search=moby
+ *  // Route: /Chapter/:chapterId/Section/:sectionId
+ *  //
+ *  // Then
+ *  $routeParams ==> {chapterId:1, sectionId:2, search:'moby'}
+ * </pre>
+ */
+function $RouteParamsProvider() {
+  this.$get = function() { return {}; };
+}
+
+/**
+ * @ngdoc directive
+ * @name ngRoute.directive:ngView
+ * @restrict ECA
+ *
+ * @description
+ * # Overview
+ * `ngView` is a directive that complements the {@link ngRoute.$route $route} service by
+ * including the rendered template of the current route into the main layout (`index.html`) file.
+ * Every time the current route changes, the included view changes with it according to the
+ * configuration of the `$route` service.
+ *
+ * @animations
+ * enter - animation is used to bring new content into the browser.
+ * leave - animation is used to animate existing content away.
+ *
+ * The enter and leave animation occur concurrently.
+ *
+ * @scope
+ * @example
+    <example module="ngViewExample" deps="angular-route.js" animations="true">
+      <file name="index.html">
+        <div ng-controller="MainCntl as main">
+          Choose:
+          <a href="Book/Moby">Moby</a> |
+          <a href="Book/Moby/ch/1">Moby: Ch1</a> |
+          <a href="Book/Gatsby">Gatsby</a> |
+          <a href="Book/Gatsby/ch/4?key=value">Gatsby: Ch4</a> |
+          <a href="Book/Scarlet">Scarlet Letter</a><br/>
+
+          <div class="example-animate-container">
+            <div ng-view class="view-example"></div>
+          </div>
+          <hr />
+
+          <pre>$location.path() = {{main.$location.path()}}</pre>
+          <pre>$route.current.templateUrl = {{main.$route.current.templateUrl}}</pre>
+          <pre>$route.current.params = {{main.$route.current.params}}</pre>
+          <pre>$route.current.scope.name = {{main.$route.current.scope.name}}</pre>
+          <pre>$routeParams = {{main.$routeParams}}</pre>
+        </div>
+      </file>
+
+      <file name="book.html">
+        <div>
+          controller: {{book.name}}<br />
+          Book Id: {{book.params.bookId}}<br />
+        </div>
+      </file>
+
+      <file name="chapter.html">
+        <div>
+          controller: {{chapter.name}}<br />
+          Book Id: {{chapter.params.bookId}}<br />
+          Chapter Id: {{chapter.params.chapterId}}
+        </div>
+      </file>
+
+      <file name="animations.css">
+        .example-animate-container {
+          position:relative;
+          background:white;
+          border:1px solid black;
+          height:40px;
+          overflow:hidden;
+        }
+
+        .example-animate-container > div {
+          padding:10px;
+        }
+
+        .view-example.ng-enter, .view-example.ng-leave {
+          -webkit-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 1.5s;
+          -moz-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 1.5s;
+          -o-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 1.5s;
+          transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 1.5s;
+
+          display:block;
+          width:100%;
+          border-left:1px solid black;
+
+          position:absolute;
+          top:0;
+          left:0;
+          right:0;
+          bottom:0;
+          padding:10px;
+        }
+
+        .example-animate-container {
+          position:relative;
+          height:100px;
+        }
+
+        .view-example.ng-enter {
+          left:100%;
+        }
+        .view-example.ng-enter.ng-enter-active {
+          left:0;
+        }
+
+        .view-example.ng-leave { }
+        .view-example.ng-leave.ng-leave-active {
+          left:-100%;
+        }
+      </file>
+
+      <file name="script.js">
+        angular.module('ngViewExample', ['ngRoute', 'ngAnimate'], function($routeProvider, $locationProvider) {
+          $routeProvider.when('/Book/:bookId', {
+            templateUrl: 'book.html',
+            controller: BookCntl,
+            controllerAs: 'book'
+          });
+          $routeProvider.when('/Book/:bookId/ch/:chapterId', {
+            templateUrl: 'chapter.html',
+            controller: ChapterCntl,
+            controllerAs: 'chapter'
+          });
+
+          // configure html5 to get links working on jsfiddle
+          $locationProvider.html5Mode(true);
+        });
+
+        function MainCntl($route, $routeParams, $location) {
+          this.$route = $route;
+          this.$location = $location;
+          this.$routeParams = $routeParams;
+        }
+
+        function BookCntl($routeParams) {
+          this.name = "BookCntl";
+          this.params = $routeParams;
+        }
+
+        function ChapterCntl($routeParams) {
+          this.name = "ChapterCntl";
+          this.params = $routeParams;
+        }
+      </file>
+
+      <file name="scenario.js">
+        it('should load and compile correct template', function() {
+          element('a:contains("Moby: Ch1")').click();
+          var content = element('.doc-example-live [ng-view]').text();
+          expect(content).toMatch(/controller\: ChapterCntl/);
+          expect(content).toMatch(/Book Id\: Moby/);
+          expect(content).toMatch(/Chapter Id\: 1/);
+
+          element('a:contains("Scarlet")').click();
+          content = element('.doc-example-live [ng-view]').text();
+          expect(content).toMatch(/controller\: BookCntl/);
+          expect(content).toMatch(/Book Id\: Scarlet/);
+        });
+      </file>
+    </example>
+ */
+
+
+/**
+ * @ngdoc event
+ * @name ngRoute.directive:ngView#$viewContentLoaded
+ * @eventOf ngRoute.directive:ngView
+ * @eventType emit on the current ngView scope
+ * @description
+ * Emitted every time the ngView content is reloaded.
+ */
+var NG_VIEW_PRIORITY = 500;
+var ngViewDirective = ['$route', '$anchorScroll', '$compile', '$controller', '$animate', 
+               function($route,   $anchorScroll,   $compile,   $controller,   $animate) {
+  return {
+    restrict: 'ECA',
+    terminal: true,
+    priority: NG_VIEW_PRIORITY,
+    compile: function(element, attr) {
+      var onloadExp = attr.onload || '';
+
+      element.html('');
+      var anchor = jqLite(document.createComment(' ngView '));
+      element.replaceWith(anchor);
+
+      return function(scope) {
+        var currentScope, currentElement;
+
+        scope.$on('$routeChangeSuccess', update);
+        update();
+
+        function cleanupLastView() {
+          if (currentScope) {
+            currentScope.$destroy();
+            currentScope = null;
+          }
+          if(currentElement) {
+            $animate.leave(currentElement);
+            currentElement = null;
+          }
+        }
+
+        function update() {
+          var locals = $route.current && $route.current.locals,
+              template = locals && locals.$template;
+
+          if (template) {
+            cleanupLastView();
+
+            currentScope = scope.$new();
+            currentElement = element.clone();
+            currentElement.html(template);
+            $animate.enter(currentElement, null, anchor);
+
+            var link = $compile(currentElement, false, NG_VIEW_PRIORITY - 1),
+                current = $route.current;
+
+            if (current.controller) {
+              locals.$scope = currentScope;
+              var controller = $controller(current.controller, locals);
+              if (current.controllerAs) {
+                currentScope[current.controllerAs] = controller;
+              }
+              currentElement.data('$ngControllerController', controller);
+              currentElement.children().data('$ngControllerController', controller);
+            }
+
+            current.scope = currentScope;
+
+            link(currentScope);
+
+            currentScope.$emit('$viewContentLoaded');
+            currentScope.$eval(onloadExp);
+
+            // $anchorScroll might listen on event...
+            $anchorScroll();
+          } else {
+            cleanupLastView();
+          }
+        }
+      }
+    }
+  };
+}];
+
+ngRouteModule.directive('ngView', ngViewDirective);
+
+
+})(window, window.angular);


Mime
View raw message