PageSourceSearch

https://toptilt.virtualhost2.workers.dev/angular-route.js

js toptilt.virtualhost2.workers.dev collected 2026-10-03 08:11:49 UTC 11,102 bytes, 425 lines download raw bytes

1(function(window, angular)
2{
3'use strict';
4function shallowCopy(src, dst) {
5if (isArray(src)) {
6dst = dst || [];
7for (var i = 0, ii = src.length; i < ii; i++) {
8dst[i] = src[i];
9}
10} else if (isObject(src)) {
11dst = dst || {};
12for (var key in src) {
13if (!(key.charAt(0) === '$' && key.charAt(1) === '$')) {
14dst[key] = src[key];
15}
16}
17}
18return dst || src;
19}
20var isArray;
21var isObject;
22var isDefined;
23var noop;
24var ngRouteModule = angular.
25module('ngRoute', []).
26info({ angularVersion: '1.6.7' }).
27provider('$route', $RouteProvider).
28run(instantiateRoute);
29var $routeMinErr = angular.$$minErr('ngRoute');
30var isEagerInstantiationEnabled;
31function $RouteProvider() {
32isArray = angular.isArray;
33isObject = angular.isObject;
34isDefined = angular.isDefined;
35noop = angular.noop;
36function inherit(parent, extra) {
37return angular.extend(Object.create(parent), extra);
38}
39var routes = {};
40this.when = function(path, route) {
41var routeCopy = shallowCopy(route);
42if (angular.isUndefined(routeCopy.reloadOnSearch)) {
43routeCopy.reloadOnSearch = true;
44}
45if (angular.isUndefined(routeCopy.caseInsensitiveMatch)) {
46routeCopy.caseInsensitiveMatch = this.caseInsensitiveMatch;
47}
48routes[path] = angular.extend(
49routeCopy,
50path && pathRegExp(path, routeCopy)
51);
52if (path) {
53var redirectPath = (path[path.length - 1] === '/')
54? path.substr(0, path.length - 1)
55: path + '/';
56routes[redirectPath] = angular.extend(
57{redirectTo: path},
58pathRegExp(redirectPath, routeCopy)
59);
60}
61return this;
62};
63this.caseInsensitiveMatch = false;
64function pathRegExp(path, opts) {
65var insensitive = opts.caseInsensitiveMatch,
66ret = {
67originalPath: path,
68regexp: path
69},
70keys = ret.keys = [];
71path = path
72.replace(/([().])/g, '\\$1')
73.replace(/(\/)?:(\w+)(\*\?|[?*])?/g, function(_, slash, key, option) {
74var optional = (option === '?' || option === '*?') ? '?' : null;
75var star = (option === '*' || option === '*?') ? '*' : null;
76keys.push({ name: key, optional: !!optional });
77slash = slash || '';
78return ''
79+ (optional ? '' : slash)
80+ '(?:'
81+ (optional ? slash : '')
82+ (star && '(.+?)' || '([^/]+)')
83+ (optional || '')
84+ ')'
85+ (optional || '');
86})
87.replace(/([/$*])/g, '\\$1');
88ret.regexp = new RegExp('^' + path + '$', insensitive ? 'i' : '');
89return ret;
90}
91this.otherwise = function(params) {
92if (typeof params === 'string') {
93params = {redirectTo: params};
94}
95this.when(null, params);
96return this;
97};
98isEagerInstantiationEnabled = true;
99this.eagerInstantiationEnabled = function eagerInstantiationEnabled(enabled) {
100if (isDefined(enabled)) {
101isEagerInstantiationEnabled = enabled;
102return this;
103}
104return isEagerInstantiationEnabled;
105};
106this.$get = ['$rootScope',
107'$location',
108'$routeParams',
109'$q',
110'$injector',
111'$templateRequest',
112'$sce',
113'$browser',
114function($rootScope, $location, $routeParams, $q, $injector, $templateRequest, $sce, $browser) {
115var forceReload = false,
116preparedRoute,
117preparedRouteIsUpdateOnly,
118$route = {
119routes: routes,
120reload: function() {
121forceReload = true;
122var fakeLocationEvent = {
123defaultPrevented: false,
124preventDefault: function fakePreventDefault() {
125this.defaultPrevented = true;
126forceReload = false;
127}
128};
129$rootScope.$evalAsync(function() {
130prepareRoute(fakeLocationEvent);
131if (!fakeLocationEvent.defaultPrevented) commitRoute();
132});
133},
134updateParams: function(newParams) {
135if (this.current && this.current.$$route) {
136newParams = angular.extend({}, this.current.params, newParams);
137$location.path(interpolate(this.current.$$route.originalPath, newParams));
138$location.search(newParams);
139} else {
140throw $routeMinErr('norout', 'Tried updating route when with no current route');
141}
142}
143};
144$rootScope.$on('$locationChangeStart', prepareRoute);
145$rootScope.$on('$locationChangeSuccess', commitRoute);
146return $route;
147function switchRouteMatcher(on, route) {
148var keys = route.keys,
149params = {};
150if (!route.regexp) return null;
151var m = route.regexp.exec(on);
152if (!m) return null;
153for (var i = 1, len = m.length; i < len; ++i) {
154var key = keys[i - 1];
155var val = m[i];
156if (key && val) {
157params[key.name] = val;
158}
159}
160return params;
161}
162function prepareRoute($locationEvent) {
163var lastRoute = $route.current;
164preparedRoute = parseRoute();
165preparedRouteIsUpdateOnly = preparedRoute && lastRoute && preparedRoute.$$route === lastRoute.$$route
166&& angular.equals(preparedRoute.pathParams, lastRoute.pathParams)
167&& !preparedRoute.reloadOnSearch && !forceReload;
168if (!preparedRouteIsUpdateOnly && (lastRoute || preparedRoute)) {
169if ($rootScope.$broadcast('$routeChangeStart', preparedRoute, lastRoute).defaultPrevented) {
170if ($locationEvent) {
171$locationEvent.preventDefault();
172}
173}
174}
175}
176function commitRoute() {
177var lastRoute = $route.current;
178var nextRoute = preparedRoute;
179if (preparedRouteIsUpdateOnly) {
180lastRoute.params = nextRoute.params;
vendor: 6,399 bytes, lines 181-425
181angular.copy(lastRoute.params, $routeParams);
182$rootScope.$broadcast('$routeUpdate', lastRoute);
183} else if (nextRoute || lastRoute) {
184forceReload = false;
185$route.current = nextRoute;
186var nextRoutePromise = $q.resolve(nextRoute);
187$browser.$$incOutstandingRequestCount();
188nextRoutePromise.
189then(getRedirectionData).
190then(handlePossibleRedirection).
191then(function(keepProcessingRoute) {
192return keepProcessingRoute && nextRoutePromise.
193then(resolveLocals).
194then(function(locals) {
195if (nextRoute === $route.current) {
196if (nextRoute) {
197nextRoute.locals = locals;
198angular.copy(nextRoute.params, $routeParams);
199}
200$rootScope.$broadcast('$routeChangeSuccess', nextRoute, lastRoute);
201}
202});
203}).catch(function(error) {
204if (nextRoute === $route.current) {
205$rootScope.$broadcast('$routeChangeError', nextRoute, lastRoute, error);
206}
207}).finally(function() {
208$browser.$$completeOutstandingRequest(noop);
209});
210}
211}
212function getRedirectionData(route) {
213var data = {
214route: route,
215hasRedirection: false
216};
217if (route) {
218if (route.redirectTo) {
219if (angular.isString(route.redirectTo)) {
220data.path = interpolate(route.redirectTo, route.params);
221data.search = route.params;
222data.hasRedirection = true;
223} else {
224var oldPath = $location.path();
225var oldSearch = $location.search();
226var newUrl = route.redirectTo(route.pathParams, oldPath, oldSearch);
227if (angular.isDefined(newUrl)) {
228data.url = newUrl;
229data.hasRedirection = true;
230}
231}
232} else if (route.resolveRedirectTo) {
233return $q.
234resolve($injector.invoke(route.resolveRedirectTo)).
235then(function(newUrl) {
236if (angular.isDefined(newUrl)) {
237data.url = newUrl;
238data.hasRedirection = true;
239}
240return data;
241});
242}
243}
244return data;
245}
246function handlePossibleRedirection(data) {
247var keepProcessingRoute = true;
248if (data.route !== $route.current) {
249keepProcessingRoute = false;
250} else if (data.hasRedirection) {
251var oldUrl = $location.url();
252var newUrl = data.url;
253if (newUrl) {
254$location.
255url(newUrl).
256replace();
257} else {
258newUrl = $location.
259path(data.path).
260search(data.search).
261replace().
262url();
263}
264if (newUrl !== oldUrl) {
265keepProcessingRoute = false;
266}
267}
268return keepProcessingRoute;
269}
270function resolveLocals(route) {
271if (route) {
272var locals = angular.extend({}, route.resolve);
273angular.forEach(locals, function(value, key) {
274locals[key] = angular.isString(value) ?
275$injector.get(value) :
276$injector.invoke(value, null, null, key);
277});
278var template = getTemplateFor(route);
279if (angular.isDefined(template)) {
280locals['$template'] = template;
281}
282return $q.all(locals);
283}
284}
285function getTemplateFor(route) {
286var template, templateUrl;
287if (angular.isDefined(template = route.template)) {
288if (angular.isFunction(template)) {
289template = template(route.params);
290}
291} else if (angular.isDefined(templateUrl = route.templateUrl)) {
292if (angular.isFunction(templateUrl)) {
293templateUrl = templateUrl(route.params);
294}
295if (angular.isDefined(templateUrl)) {
296route.loadedTemplateUrl = $sce.valueOf(templateUrl);
297template = $templateRequest(templateUrl);
298}
299}
300return template;
301}
302function parseRoute() {
303var params, match;
304angular.forEach(routes, function(route, path) {
305if (!match && (params = switchRouteMatcher($location.path(), route))) {
306match = inherit(route, {
307params: angular.extend({}, $location.search(), params),
308pathParams: params});
309match.$$route = route;
310}
311});
312return match || routes[null] && inherit(routes[null], {params: {}, pathParams:{}});
313}
314function interpolate(string, params) {
315var result = [];
316angular.forEach((string || '').split(':'), function(segment, i) {
317if (i === 0) {
318result.push(segment);
319} else {
320var segmentMatch = segment.match(/(\w+)(?:[?*])?(.*)/);
321var key = segmentMatch[1];
322result.push(params[key]);
323result.push(segmentMatch[2] || '');
324delete params[key];
325}
326});
327return result.join('');
328}
329}];
330}
331instantiateRoute.$inject = ['$injector'];
332function instantiateRoute($injector) {
333if (isEagerInstantiationEnabled) {
334$injector.get('$route');
335}
336}
337ngRouteModule.provider('$routeParams', $RouteParamsProvider);
338function $RouteParamsProvider() {
339this.$get = function() { return {}; };
340}
341ngRouteModule.directive('ngView', ngViewFactory);
342ngRouteModule.directive('ngView', ngViewFillContentFactory);
343ngViewFactory.$inject = ['$route', '$anchorScroll', '$animate'];
344function ngViewFactory($route, $anchorScroll, $animate) {
345return {
346restrict: 'ECA',
347terminal: true,
348priority: 400,
349transclude: 'element',
350link: function(scope, $element, attr, ctrl, $transclude) {
351var currentScope,
352currentElement,
353previousLeaveAnimation,
354autoScrollExp = attr.autoscroll,
355onloadExp = attr.onload || '';
356scope.$on('$routeChangeSuccess', update);
357update();
358function cleanupLastView() {
359if (previousLeaveAnimation) {
360$animate.cancel(previousLeaveAnimation);
361previousLeaveAnimation = null;
362}
363if (currentScope) {
364currentScope.$destroy();
365currentScope = null;
366}
367if (currentElement) {
368previousLeaveAnimation = $animate.leave(currentElement);
369previousLeaveAnimation.done(function(response) {
370if (response !== false) previousLeaveAnimation = null;
371});
372currentElement = null;
373}
374}
375function update() {
376var locals = $route.current && $route.current.locals,
377template = locals && locals.$template;
378if (angular.isDefined(template)) {
379var newScope = scope.$new();
380var current = $route.current;
381var clone = $transclude(newScope, function(clone) {
382$animate.enter(clone, null, currentElement || $element).done(function onNgViewEnter(response) {
383if (response !== false && angular.isDefined(autoScrollExp)
384&& (!autoScrollExp || scope.$eval(autoScrollExp))) {
385$anchorScroll();
386}
387});
388cleanupLastView();
389});
390currentElement = clone;
391currentScope = current.scope = newScope;
392currentScope.$emit('$viewContentLoaded');
393currentScope.$eval(onloadExp);
394} else {
395cleanupLastView();
396}
397}
398}
399};
400}
401ngViewFillContentFactory.$inject = ['$compile', '$controller', '$route'];
402function ngViewFillContentFactory($compile, $controller, $route) {
403return {
404restrict: 'ECA',
405priority: -400,
406link: function(scope, $element) {
407var current = $route.current,
408locals = current.locals;
409$element.html(locals.$template);
410var link = $compile($element.contents());
411if (current.controller) {
412locals.$scope = scope;
413var controller = $controller(current.controller, locals);
414if (current.controllerAs) {
415scope[current.controllerAs] = controller;
416}
417$element.data('$ngControllerController', controller);
418$element.children().data('$ngControllerController', controller);
419}
420scope[current.resolveAs || '$resolve'] = locals;
421link(scope);
422}
423};
424}
425})(window, window.angular);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.