angular-loader.js 27 KB

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