(function (window, angular, undefined){ 'use strict'; var ngRouteModule = angular.module('ngRoute', ['ng'] ).provider('$route', $RouteProvider); function $RouteProvider(){ function inherit(parent, extra){ return angular.extend(new (angular.extend(function (){ } , { prototype: parent} ))(), extra); } var routes = { } ; this.when = function (path, route){ routes[path] = angular.extend({ reloadOnSearch: true } , route, path && pathRegExp(path, route)); if (path) { var redirectPath = (path[_AN_Read_length('length', path) - 1] == '/')? path.substr(0, _AN_Read_length('length', path) - 1): path + '/'; routes[redirectPath] = angular.extend({ redirectTo: path} , pathRegExp(redirectPath, route)); } return this; } ; function pathRegExp(path, opts){ var insensitive = opts.caseInsensitiveMatch, ret = { originalPath: path, regexp: path} , keys = ret.keys = [] ; path = _AN_Call_replace('replace', _AN_Call_replace('replace', _AN_Call_replace('replace', path, /([().])/g, '\\$1'), /(\/)?:(\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 || '') + ')' + (optional || ''); } ), /([\/$\*])/g, '\\$1'); ret.regexp = new RegExp('^' + path + '$', insensitive? 'i': ''); return ret; } 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){ var forceReload = false , $route = { routes: routes, reload: function (){ forceReload = true ; $rootScope.$evalAsync(updateRoute); } } ; $rootScope.$on('$locationChangeSuccess', updateRoute); return $route; function switchRouteMatcher(on, route){ var keys = route.keys, params = { } ; if (!route.regexp) return null ; var m = route.regexp.exec(on); if (!m) return null ; for (var i = 1, len = _AN_Read_length('length', m); 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 && angular.equals(next.pathParams, last.pathParams) && !next.reloadOnSearch && !forceReload) { last.params = next.params; angular.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 (angular.isString(next.redirectTo)) { _AN_Call_replace('replace', $location.path(interpolate(next.redirectTo, next.params)).search(next.params)); } else { _AN_Call_replace('replace', $location.url(next.redirectTo(next.pathParams, $location.path(), $location.search()))); } } } $q.when(next).then(function (){ if (next) { var locals = angular.extend({ } , next.resolve), template, templateUrl; angular.forEach(locals, function (value, key){ locals[key] = angular.isString(value)? $injector.get(value): $injector.invoke(value); } ); if (angular.isDefined(template = next.template)) { if (angular.isFunction(template)) { template = template(next.params); } } else if (angular.isDefined(templateUrl = next.templateUrl)) { if (angular.isFunction(templateUrl)) { templateUrl = templateUrl(next.params); } templateUrl = $sce.getTrustedResourceUrl(templateUrl); if (angular.isDefined(templateUrl)) { next.loadedTemplateUrl = templateUrl; template = $http.get(templateUrl, { cache: $templateCache} ).then(function (response){ return response.data; } ); } } if (angular.isDefined(template)) { locals.$template = template; } return $q.all(locals); } } ).then(function (locals){ if (next == $route.current) { if (next) { next.locals = locals; angular.copy(next.params, $routeParams); } $rootScope.$broadcast('$routeChangeSuccess', next, last); } } , function (error){ if (next == $route.current) { $rootScope.$broadcast('$routeChangeError', next, last, error); } } ); } } function parseRoute(){ var params, match; angular.forEach(routes, function (route, path){ if (!match && (params = switchRouteMatcher($location.path(), route))) { match = inherit(route, { params: angular.extend({ } , $location.search(), params), pathParams: params} ); match.$$route = route; } } ); return match || routes[null ] && inherit(routes[null ], { params: { } , pathParams: { } } ); } function interpolate(string, params){ var result = [] ; angular.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); function $RouteParamsProvider(){ this.$get = function (){ return { } ; } ; } ngRouteModule.directive('ngView', ngViewFactory); ngRouteModule.directive('ngView', ngViewFillContentFactory); ngViewFactory.$inject = ['$route', '$anchorScroll', '$animate'] ; function ngViewFactory($route, $anchorScroll, $animate){ return { restrict: 'ECA', terminal: true , priority: 400, transclude: 'element', link: function (scope, $element, attr, ctrl, $transclude){ var currentScope, currentElement, autoScrollExp = attr.autoscroll, onloadExp = attr.onload || ''; 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 (angular.isDefined(template)) { var newScope = scope.$new(); var current = $route.current; var clone = $transclude(newScope, function (clone){ $animate.enter(clone, null , currentElement || $element, function onNgViewEnter(){ if (angular.isDefined(autoScrollExp) && (!autoScrollExp || scope.$eval(autoScrollExp))) { $anchorScroll(); } } ); cleanupLastView(); } ); currentElement = clone; currentScope = current.scope = newScope; currentScope.$emit('$viewContentLoaded'); currentScope.$eval(onloadExp); } else { cleanupLastView(); } } } } ; } ngViewFillContentFactory.$inject = ['$compile', '$controller', '$route'] ; function ngViewFillContentFactory($compile, $controller, $route){ return { restrict: 'ECA', priority: -400, link: function (scope, $element){ var current = $route.current, locals = current.locals; $element.html(locals.$template); var link = $compile($element.contents()); if (current.controller) { locals.$scope = scope; var controller = $controller(current.controller, locals); if (current.controllerAs) { scope[current.controllerAs] = controller; } $element.data('$ngControllerController', controller); $element.children().data('$ngControllerController', controller); } link(scope); } } ; } } )(window, window.angular);