1 | /** |
||
2 | * @license AngularJS v1.5.0 |
||
3 | * (c) 2010-2016 Google, Inc. http://angularjs.org |
||
4 | * License: MIT |
||
5 | */ |
||
6 | |||
7 | (function() {'use strict'; |
||
8 | function isFunction(value) {return typeof value === 'function';}; |
||
9 | |||
10 | /* global: toDebugString: true */ |
||
11 | |||
12 | function serializeObject(obj) { |
||
13 | var seen = []; |
||
14 | |||
15 | return JSON.stringify(obj, function(key, val) { |
||
16 | val = toJsonReplacer(key, val); |
||
17 | if (isObject(val)) { |
||
18 | |||
19 | if (seen.indexOf(val) >= 0) return '...'; |
||
20 | |||
21 | seen.push(val); |
||
22 | } |
||
23 | return val; |
||
24 | }); |
||
25 | } |
||
26 | |||
27 | function toDebugString(obj) { |
||
28 | if (typeof obj === 'function') { |
||
29 | return obj.toString().replace(/ \{[\s\S]*$/, ''); |
||
30 | } else if (isUndefined(obj)) { |
||
31 | return 'undefined'; |
||
32 | } else if (typeof obj !== 'string') { |
||
33 | return serializeObject(obj); |
||
34 | } |
||
35 | return obj; |
||
36 | } |
||
37 | |||
38 | /** |
||
39 | * @description |
||
40 | * |
||
41 | * This object provides a utility for producing rich Error messages within |
||
42 | * Angular. It can be called as follows: |
||
43 | * |
||
44 | * var exampleMinErr = minErr('example'); |
||
45 | * throw exampleMinErr('one', 'This {0} is {1}', foo, bar); |
||
46 | * |
||
47 | * The above creates an instance of minErr in the example namespace. The |
||
48 | * resulting error will have a namespaced error code of example.one. The |
||
49 | * resulting error will replace {0} with the value of foo, and {1} with the |
||
50 | * value of bar. The object is not restricted in the number of arguments it can |
||
51 | * take. |
||
52 | * |
||
53 | * If fewer arguments are specified than necessary for interpolation, the extra |
||
54 | * interpolation markers will be preserved in the final string. |
||
55 | * |
||
56 | * Since data will be parsed statically during a build step, some restrictions |
||
57 | * are applied with respect to how minErr instances are created and called. |
||
58 | * Instances should have names of the form namespaceMinErr for a minErr created |
||
59 | * using minErr('namespace') . Error codes, namespaces and template strings |
||
60 | * should all be static strings, not variables or general expressions. |
||
61 | * |
||
62 | * @param {string} module The namespace to use for the new minErr instance. |
||
63 | * @param {function} ErrorConstructor Custom error constructor to be instantiated when returning |
||
64 | * error from returned function, for cases when a particular type of error is useful. |
||
65 | * @returns {function(code:string, template:string, ...templateArgs): Error} minErr instance |
||
66 | */ |
||
67 | |||
68 | function minErr(module, ErrorConstructor) { |
||
69 | ErrorConstructor = ErrorConstructor || Error; |
||
70 | return function() { |
||
71 | var SKIP_INDEXES = 2; |
||
72 | |||
73 | var templateArgs = arguments, |
||
74 | code = templateArgs[0], |
||
75 | message = '[' + (module ? module + ':' : '') + code + '] ', |
||
76 | template = templateArgs[1], |
||
77 | paramPrefix, i; |
||
78 | |||
79 | message += template.replace(/\{\d+\}/g, function(match) { |
||
80 | var index = +match.slice(1, -1), |
||
81 | shiftedIndex = index + SKIP_INDEXES; |
||
82 | |||
83 | if (shiftedIndex < templateArgs.length) { |
||
84 | return toDebugString(templateArgs[shiftedIndex]); |
||
85 | } |
||
86 | |||
87 | return match; |
||
88 | }); |
||
89 | |||
90 | message += '\nhttp://errors.angularjs.org/1.5.0/' + |
||
91 | (module ? module + '/' : '') + code; |
||
92 | |||
93 | for (i = SKIP_INDEXES, paramPrefix = '?'; i < templateArgs.length; i++, paramPrefix = '&') { |
||
94 | message += paramPrefix + 'p' + (i - SKIP_INDEXES) + '=' + |
||
95 | encodeURIComponent(toDebugString(templateArgs[i])); |
||
96 | } |
||
97 | |||
98 | return new ErrorConstructor(message); |
||
99 | }; |
||
100 | } |
||
101 | |||
102 | /** |
||
103 | * @ngdoc type |
||
104 | * @name angular.Module |
||
105 | * @module ng |
||
106 | * @description |
||
107 | * |
||
108 | * Interface for configuring angular {@link angular.module modules}. |
||
109 | */ |
||
110 | |||
111 | View Code Duplication | function setupModuleLoader(window) { |
|
112 | |||
113 | var $injectorMinErr = minErr('$injector'); |
||
114 | var ngMinErr = minErr('ng'); |
||
115 | |||
116 | function ensure(obj, name, factory) { |
||
117 | return obj[name] || (obj[name] = factory()); |
||
118 | } |
||
119 | |||
120 | var angular = ensure(window, 'angular', Object); |
||
121 | |||
122 | // We need to expose `angular.$$minErr` to modules such as `ngResource` that reference it during bootstrap |
||
123 | angular.$$minErr = angular.$$minErr || minErr; |
||
124 | |||
125 | return ensure(angular, 'module', function() { |
||
126 | /** @type {Object.<string, angular.Module>} */ |
||
127 | var modules = {}; |
||
128 | |||
129 | /** |
||
130 | * @ngdoc function |
||
131 | * @name angular.module |
||
132 | * @module ng |
||
133 | * @description |
||
134 | * |
||
135 | * The `angular.module` is a global place for creating, registering and retrieving Angular |
||
136 | * modules. |
||
137 | * All modules (angular core or 3rd party) that should be available to an application must be |
||
138 | * registered using this mechanism. |
||
139 | * |
||
140 | * Passing one argument retrieves an existing {@link angular.Module}, |
||
141 | * whereas passing more than one argument creates a new {@link angular.Module} |
||
142 | * |
||
143 | * |
||
144 | * # Module |
||
145 | * |
||
146 | * A module is a collection of services, directives, controllers, filters, and configuration information. |
||
147 | * `angular.module` is used to configure the {@link auto.$injector $injector}. |
||
148 | * |
||
149 | * ```js |
||
150 | * // Create a new module |
||
151 | * var myModule = angular.module('myModule', []); |
||
152 | * |
||
153 | * // register a new service |
||
154 | * myModule.value('appName', 'MyCoolApp'); |
||
155 | * |
||
156 | * // configure existing services inside initialization blocks. |
||
157 | * myModule.config(['$locationProvider', function($locationProvider) { |
||
158 | * // Configure existing providers |
||
159 | * $locationProvider.hashPrefix('!'); |
||
160 | * }]); |
||
161 | * ``` |
||
162 | * |
||
163 | * Then you can create an injector and load your modules like this: |
||
164 | * |
||
165 | * ```js |
||
166 | * var injector = angular.injector(['ng', 'myModule']) |
||
167 | * ``` |
||
168 | * |
||
169 | * However it's more likely that you'll just use |
||
170 | * {@link ng.directive:ngApp ngApp} or |
||
171 | * {@link angular.bootstrap} to simplify this process for you. |
||
172 | * |
||
173 | * @param {!string} name The name of the module to create or retrieve. |
||
174 | * @param {!Array.<string>=} requires If specified then new module is being created. If |
||
175 | * unspecified then the module is being retrieved for further configuration. |
||
176 | * @param {Function=} configFn Optional configuration function for the module. Same as |
||
177 | * {@link angular.Module#config Module#config()}. |
||
178 | * @returns {angular.Module} new module with the {@link angular.Module} api. |
||
179 | */ |
||
180 | return function module(name, requires, configFn) { |
||
181 | var assertNotHasOwnProperty = function(name, context) { |
||
182 | if (name === 'hasOwnProperty') { |
||
183 | throw ngMinErr('badname', 'hasOwnProperty is not a valid {0} name', context); |
||
184 | } |
||
185 | }; |
||
186 | |||
187 | assertNotHasOwnProperty(name, 'module'); |
||
188 | if (requires && modules.hasOwnProperty(name)) { |
||
189 | modules[name] = null; |
||
190 | } |
||
191 | return ensure(modules, name, function() { |
||
192 | if (!requires) { |
||
193 | throw $injectorMinErr('nomod', "Module '{0}' is not available! You either misspelled " + |
||
194 | "the module name or forgot to load it. If registering a module ensure that you " + |
||
195 | "specify the dependencies as the second argument.", name); |
||
196 | } |
||
197 | |||
198 | /** @type {!Array.<Array.<*>>} */ |
||
199 | var invokeQueue = []; |
||
200 | |||
201 | /** @type {!Array.<Function>} */ |
||
202 | var configBlocks = []; |
||
203 | |||
204 | /** @type {!Array.<Function>} */ |
||
205 | var runBlocks = []; |
||
206 | |||
207 | var config = invokeLater('$injector', 'invoke', 'push', configBlocks); |
||
208 | |||
209 | /** @type {angular.Module} */ |
||
210 | var moduleInstance = { |
||
211 | // Private state |
||
212 | _invokeQueue: invokeQueue, |
||
213 | _configBlocks: configBlocks, |
||
214 | _runBlocks: runBlocks, |
||
215 | |||
216 | /** |
||
217 | * @ngdoc property |
||
218 | * @name angular.Module#requires |
||
219 | * @module ng |
||
220 | * |
||
221 | * @description |
||
222 | * Holds the list of modules which the injector will load before the current module is |
||
223 | * loaded. |
||
224 | */ |
||
225 | requires: requires, |
||
226 | |||
227 | /** |
||
228 | * @ngdoc property |
||
229 | * @name angular.Module#name |
||
230 | * @module ng |
||
231 | * |
||
232 | * @description |
||
233 | * Name of the module. |
||
234 | */ |
||
235 | name: name, |
||
236 | |||
237 | |||
238 | /** |
||
239 | * @ngdoc method |
||
240 | * @name angular.Module#provider |
||
241 | * @module ng |
||
242 | * @param {string} name service name |
||
243 | * @param {Function} providerType Construction function for creating new instance of the |
||
244 | * service. |
||
245 | * @description |
||
246 | * See {@link auto.$provide#provider $provide.provider()}. |
||
247 | */ |
||
248 | provider: invokeLaterAndSetModuleName('$provide', 'provider'), |
||
249 | |||
250 | /** |
||
251 | * @ngdoc method |
||
252 | * @name angular.Module#factory |
||
253 | * @module ng |
||
254 | * @param {string} name service name |
||
255 | * @param {Function} providerFunction Function for creating new instance of the service. |
||
256 | * @description |
||
257 | * See {@link auto.$provide#factory $provide.factory()}. |
||
258 | */ |
||
259 | factory: invokeLaterAndSetModuleName('$provide', 'factory'), |
||
260 | |||
261 | /** |
||
262 | * @ngdoc method |
||
263 | * @name angular.Module#service |
||
264 | * @module ng |
||
265 | * @param {string} name service name |
||
266 | * @param {Function} constructor A constructor function that will be instantiated. |
||
267 | * @description |
||
268 | * See {@link auto.$provide#service $provide.service()}. |
||
269 | */ |
||
270 | service: invokeLaterAndSetModuleName('$provide', 'service'), |
||
271 | |||
272 | /** |
||
273 | * @ngdoc method |
||
274 | * @name angular.Module#value |
||
275 | * @module ng |
||
276 | * @param {string} name service name |
||
277 | * @param {*} object Service instance object. |
||
278 | * @description |
||
279 | * See {@link auto.$provide#value $provide.value()}. |
||
280 | */ |
||
281 | value: invokeLater('$provide', 'value'), |
||
282 | |||
283 | /** |
||
284 | * @ngdoc method |
||
285 | * @name angular.Module#constant |
||
286 | * @module ng |
||
287 | * @param {string} name constant name |
||
288 | * @param {*} object Constant value. |
||
289 | * @description |
||
290 | * Because the constants are fixed, they get applied before other provide methods. |
||
291 | * See {@link auto.$provide#constant $provide.constant()}. |
||
292 | */ |
||
293 | constant: invokeLater('$provide', 'constant', 'unshift'), |
||
294 | |||
295 | /** |
||
296 | * @ngdoc method |
||
297 | * @name angular.Module#decorator |
||
298 | * @module ng |
||
299 | * @param {string} The name of the service to decorate. |
||
300 | * @param {Function} This function will be invoked when the service needs to be |
||
301 | * instantiated and should return the decorated service instance. |
||
302 | * @description |
||
303 | * See {@link auto.$provide#decorator $provide.decorator()}. |
||
304 | */ |
||
305 | decorator: invokeLaterAndSetModuleName('$provide', 'decorator'), |
||
306 | |||
307 | /** |
||
308 | * @ngdoc method |
||
309 | * @name angular.Module#animation |
||
310 | * @module ng |
||
311 | * @param {string} name animation name |
||
312 | * @param {Function} animationFactory Factory function for creating new instance of an |
||
313 | * animation. |
||
314 | * @description |
||
315 | * |
||
316 | * **NOTE**: animations take effect only if the **ngAnimate** module is loaded. |
||
317 | * |
||
318 | * |
||
319 | * Defines an animation hook that can be later used with |
||
320 | * {@link $animate $animate} service and directives that use this service. |
||
321 | * |
||
322 | * ```js |
||
323 | * module.animation('.animation-name', function($inject1, $inject2) { |
||
324 | * return { |
||
325 | * eventName : function(element, done) { |
||
326 | * //code to run the animation |
||
327 | * //once complete, then run done() |
||
328 | * return function cancellationFunction(element) { |
||
329 | * //code to cancel the animation |
||
330 | * } |
||
331 | * } |
||
332 | * } |
||
333 | * }) |
||
334 | * ``` |
||
335 | * |
||
336 | * See {@link ng.$animateProvider#register $animateProvider.register()} and |
||
337 | * {@link ngAnimate ngAnimate module} for more information. |
||
338 | */ |
||
339 | animation: invokeLaterAndSetModuleName('$animateProvider', 'register'), |
||
340 | |||
341 | /** |
||
342 | * @ngdoc method |
||
343 | * @name angular.Module#filter |
||
344 | * @module ng |
||
345 | * @param {string} name Filter name - this must be a valid angular expression identifier |
||
346 | * @param {Function} filterFactory Factory function for creating new instance of filter. |
||
347 | * @description |
||
348 | * See {@link ng.$filterProvider#register $filterProvider.register()}. |
||
349 | * |
||
350 | * <div class="alert alert-warning"> |
||
351 | * **Note:** Filter names must be valid angular {@link expression} identifiers, such as `uppercase` or `orderBy`. |
||
352 | * Names with special characters, such as hyphens and dots, are not allowed. If you wish to namespace |
||
353 | * your filters, then you can use capitalization (`myappSubsectionFilterx`) or underscores |
||
354 | * (`myapp_subsection_filterx`). |
||
355 | * </div> |
||
356 | */ |
||
357 | filter: invokeLaterAndSetModuleName('$filterProvider', 'register'), |
||
358 | |||
359 | /** |
||
360 | * @ngdoc method |
||
361 | * @name angular.Module#controller |
||
362 | * @module ng |
||
363 | * @param {string|Object} name Controller name, or an object map of controllers where the |
||
364 | * keys are the names and the values are the constructors. |
||
365 | * @param {Function} constructor Controller constructor function. |
||
366 | * @description |
||
367 | * See {@link ng.$controllerProvider#register $controllerProvider.register()}. |
||
368 | */ |
||
369 | controller: invokeLaterAndSetModuleName('$controllerProvider', 'register'), |
||
370 | |||
371 | /** |
||
372 | * @ngdoc method |
||
373 | * @name angular.Module#directive |
||
374 | * @module ng |
||
375 | * @param {string|Object} name Directive name, or an object map of directives where the |
||
376 | * keys are the names and the values are the factories. |
||
377 | * @param {Function} directiveFactory Factory function for creating new instance of |
||
378 | * directives. |
||
379 | * @description |
||
380 | * See {@link ng.$compileProvider#directive $compileProvider.directive()}. |
||
381 | */ |
||
382 | directive: invokeLaterAndSetModuleName('$compileProvider', 'directive'), |
||
383 | |||
384 | /** |
||
385 | * @ngdoc method |
||
386 | * @name angular.Module#component |
||
387 | * @module ng |
||
388 | * @param {string} name Name of the component in camel-case (i.e. myComp which will match as my-comp) |
||
389 | * @param {Object} options Component definition object (a simplified |
||
390 | * {@link ng.$compile#directive-definition-object directive definition object}) |
||
391 | * |
||
392 | * @description |
||
393 | * See {@link ng.$compileProvider#component $compileProvider.component()}. |
||
394 | */ |
||
395 | component: invokeLaterAndSetModuleName('$compileProvider', 'component'), |
||
396 | |||
397 | /** |
||
398 | * @ngdoc method |
||
399 | * @name angular.Module#config |
||
400 | * @module ng |
||
401 | * @param {Function} configFn Execute this function on module load. Useful for service |
||
402 | * configuration. |
||
403 | * @description |
||
404 | * Use this method to register work which needs to be performed on module loading. |
||
405 | * For more about how to configure services, see |
||
406 | * {@link providers#provider-recipe Provider Recipe}. |
||
407 | */ |
||
408 | config: config, |
||
409 | |||
410 | /** |
||
411 | * @ngdoc method |
||
412 | * @name angular.Module#run |
||
413 | * @module ng |
||
414 | * @param {Function} initializationFn Execute this function after injector creation. |
||
415 | * Useful for application initialization. |
||
416 | * @description |
||
417 | * Use this method to register work which should be performed when the injector is done |
||
418 | * loading all modules. |
||
419 | */ |
||
420 | run: function(block) { |
||
421 | runBlocks.push(block); |
||
422 | return this; |
||
423 | } |
||
424 | }; |
||
425 | |||
426 | if (configFn) { |
||
427 | config(configFn); |
||
428 | } |
||
429 | |||
430 | return moduleInstance; |
||
431 | |||
432 | /** |
||
433 | * @param {string} provider |
||
434 | * @param {string} method |
||
435 | * @param {String=} insertMethod |
||
436 | * @returns {angular.Module} |
||
437 | */ |
||
438 | function invokeLater(provider, method, insertMethod, queue) { |
||
439 | if (!queue) queue = invokeQueue; |
||
440 | return function() { |
||
441 | queue[insertMethod || 'push']([provider, method, arguments]); |
||
442 | return moduleInstance; |
||
443 | }; |
||
444 | } |
||
445 | |||
446 | /** |
||
447 | * @param {string} provider |
||
448 | * @param {string} method |
||
449 | * @returns {angular.Module} |
||
450 | */ |
||
451 | function invokeLaterAndSetModuleName(provider, method) { |
||
452 | return function(recipeName, factoryFunction) { |
||
453 | if (factoryFunction && isFunction(factoryFunction)) factoryFunction.$$moduleName = name; |
||
454 | invokeQueue.push([provider, method, arguments]); |
||
455 | return moduleInstance; |
||
456 | }; |
||
457 | } |
||
458 | }); |
||
459 | }; |
||
460 | }); |
||
461 | |||
462 | } |
||
463 | |||
464 | setupModuleLoader(window); |
||
465 | })(window); |
||
466 | |||
467 | /** |
||
468 | * Closure compiler type information |
||
469 | * |
||
470 | * @typedef { { |
||
471 | * requires: !Array.<string>, |
||
472 | * invokeQueue: !Array.<Array.<*>>, |
||
473 | * |
||
474 | * service: function(string, Function):angular.Module, |
||
475 | * factory: function(string, Function):angular.Module, |
||
476 | * value: function(string, *):angular.Module, |
||
477 | * |
||
478 | * filter: function(string, Function):angular.Module, |
||
479 | * |
||
480 | * init: function(Function):angular.Module |
||
481 | * } } |
||
482 | */ |
||
483 | angular.Module; |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
484 | |||
485 |