PageRenderTime 56ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 0ms

/ajax/libs/angular.js/1.3.6/angular-loader.js

https://gitlab.com/alidz1982/cdnjs
JavaScript | 405 lines | 94 code | 42 blank | 269 comment | 13 complexity | f4374b1dc789b32ce2cc8c48c750d9e0 MD5 | raw file
  1. /**
  2. * @license AngularJS v1.3.6
  3. * (c) 2010-2014 Google, Inc. http://angularjs.org
  4. * License: MIT
  5. */
  6. (function() {'use strict';
  7. /**
  8. * @description
  9. *
  10. * This object provides a utility for producing rich Error messages within
  11. * Angular. It can be called as follows:
  12. *
  13. * var exampleMinErr = minErr('example');
  14. * throw exampleMinErr('one', 'This {0} is {1}', foo, bar);
  15. *
  16. * The above creates an instance of minErr in the example namespace. The
  17. * resulting error will have a namespaced error code of example.one. The
  18. * resulting error will replace {0} with the value of foo, and {1} with the
  19. * value of bar. The object is not restricted in the number of arguments it can
  20. * take.
  21. *
  22. * If fewer arguments are specified than necessary for interpolation, the extra
  23. * interpolation markers will be preserved in the final string.
  24. *
  25. * Since data will be parsed statically during a build step, some restrictions
  26. * are applied with respect to how minErr instances are created and called.
  27. * Instances should have names of the form namespaceMinErr for a minErr created
  28. * using minErr('namespace') . Error codes, namespaces and template strings
  29. * should all be static strings, not variables or general expressions.
  30. *
  31. * @param {string} module The namespace to use for the new minErr instance.
  32. * @param {function} ErrorConstructor Custom error constructor to be instantiated when returning
  33. * error from returned function, for cases when a particular type of error is useful.
  34. * @returns {function(code:string, template:string, ...templateArgs): Error} minErr instance
  35. */
  36. function minErr(module, ErrorConstructor) {
  37. ErrorConstructor = ErrorConstructor || Error;
  38. return function() {
  39. var code = arguments[0],
  40. prefix = '[' + (module ? module + ':' : '') + code + '] ',
  41. template = arguments[1],
  42. templateArgs = arguments,
  43. message, i;
  44. message = prefix + template.replace(/\{\d+\}/g, function(match) {
  45. var index = +match.slice(1, -1), arg;
  46. if (index + 2 < templateArgs.length) {
  47. return toDebugString(templateArgs[index + 2]);
  48. }
  49. return match;
  50. });
  51. message = message + '\nhttp://errors.angularjs.org/1.3.6/' +
  52. (module ? module + '/' : '') + code;
  53. for (i = 2; i < arguments.length; i++) {
  54. message = message + (i == 2 ? '?' : '&') + 'p' + (i - 2) + '=' +
  55. encodeURIComponent(toDebugString(arguments[i]));
  56. }
  57. return new ErrorConstructor(message);
  58. };
  59. }
  60. /**
  61. * @ngdoc type
  62. * @name angular.Module
  63. * @module ng
  64. * @description
  65. *
  66. * Interface for configuring angular {@link angular.module modules}.
  67. */
  68. function setupModuleLoader(window) {
  69. var $injectorMinErr = minErr('$injector');
  70. var ngMinErr = minErr('ng');
  71. function ensure(obj, name, factory) {
  72. return obj[name] || (obj[name] = factory());
  73. }
  74. var angular = ensure(window, 'angular', Object);
  75. // We need to expose `angular.$$minErr` to modules such as `ngResource` that reference it during bootstrap
  76. angular.$$minErr = angular.$$minErr || minErr;
  77. return ensure(angular, 'module', function() {
  78. /** @type {Object.<string, angular.Module>} */
  79. var modules = {};
  80. /**
  81. * @ngdoc function
  82. * @name angular.module
  83. * @module ng
  84. * @description
  85. *
  86. * The `angular.module` is a global place for creating, registering and retrieving Angular
  87. * modules.
  88. * All modules (angular core or 3rd party) that should be available to an application must be
  89. * registered using this mechanism.
  90. *
  91. * When passed two or more arguments, a new module is created. If passed only one argument, an
  92. * existing module (the name passed as the first argument to `module`) is retrieved.
  93. *
  94. *
  95. * # Module
  96. *
  97. * A module is a collection of services, directives, controllers, filters, and configuration information.
  98. * `angular.module` is used to configure the {@link auto.$injector $injector}.
  99. *
  100. * ```js
  101. * // Create a new module
  102. * var myModule = angular.module('myModule', []);
  103. *
  104. * // register a new service
  105. * myModule.value('appName', 'MyCoolApp');
  106. *
  107. * // configure existing services inside initialization blocks.
  108. * myModule.config(['$locationProvider', function($locationProvider) {
  109. * // Configure existing providers
  110. * $locationProvider.hashPrefix('!');
  111. * }]);
  112. * ```
  113. *
  114. * Then you can create an injector and load your modules like this:
  115. *
  116. * ```js
  117. * var injector = angular.injector(['ng', 'myModule'])
  118. * ```
  119. *
  120. * However it's more likely that you'll just use
  121. * {@link ng.directive:ngApp ngApp} or
  122. * {@link angular.bootstrap} to simplify this process for you.
  123. *
  124. * @param {!string} name The name of the module to create or retrieve.
  125. * @param {!Array.<string>=} requires If specified then new module is being created. If
  126. * unspecified then the module is being retrieved for further configuration.
  127. * @param {Function=} configFn Optional configuration function for the module. Same as
  128. * {@link angular.Module#config Module#config()}.
  129. * @returns {module} new module with the {@link angular.Module} api.
  130. */
  131. return function module(name, requires, configFn) {
  132. var assertNotHasOwnProperty = function(name, context) {
  133. if (name === 'hasOwnProperty') {
  134. throw ngMinErr('badname', 'hasOwnProperty is not a valid {0} name', context);
  135. }
  136. };
  137. assertNotHasOwnProperty(name, 'module');
  138. if (requires && modules.hasOwnProperty(name)) {
  139. modules[name] = null;
  140. }
  141. return ensure(modules, name, function() {
  142. if (!requires) {
  143. throw $injectorMinErr('nomod', "Module '{0}' is not available! You either misspelled " +
  144. "the module name or forgot to load it. If registering a module ensure that you " +
  145. "specify the dependencies as the second argument.", name);
  146. }
  147. /** @type {!Array.<Array.<*>>} */
  148. var invokeQueue = [];
  149. /** @type {!Array.<Function>} */
  150. var configBlocks = [];
  151. /** @type {!Array.<Function>} */
  152. var runBlocks = [];
  153. var config = invokeLater('$injector', 'invoke', 'push', configBlocks);
  154. /** @type {angular.Module} */
  155. var moduleInstance = {
  156. // Private state
  157. _invokeQueue: invokeQueue,
  158. _configBlocks: configBlocks,
  159. _runBlocks: runBlocks,
  160. /**
  161. * @ngdoc property
  162. * @name angular.Module#requires
  163. * @module ng
  164. *
  165. * @description
  166. * Holds the list of modules which the injector will load before the current module is
  167. * loaded.
  168. */
  169. requires: requires,
  170. /**
  171. * @ngdoc property
  172. * @name angular.Module#name
  173. * @module ng
  174. *
  175. * @description
  176. * Name of the module.
  177. */
  178. name: name,
  179. /**
  180. * @ngdoc method
  181. * @name angular.Module#provider
  182. * @module ng
  183. * @param {string} name service name
  184. * @param {Function} providerType Construction function for creating new instance of the
  185. * service.
  186. * @description
  187. * See {@link auto.$provide#provider $provide.provider()}.
  188. */
  189. provider: invokeLater('$provide', 'provider'),
  190. /**
  191. * @ngdoc method
  192. * @name angular.Module#factory
  193. * @module ng
  194. * @param {string} name service name
  195. * @param {Function} providerFunction Function for creating new instance of the service.
  196. * @description
  197. * See {@link auto.$provide#factory $provide.factory()}.
  198. */
  199. factory: invokeLater('$provide', 'factory'),
  200. /**
  201. * @ngdoc method
  202. * @name angular.Module#service
  203. * @module ng
  204. * @param {string} name service name
  205. * @param {Function} constructor A constructor function that will be instantiated.
  206. * @description
  207. * See {@link auto.$provide#service $provide.service()}.
  208. */
  209. service: invokeLater('$provide', 'service'),
  210. /**
  211. * @ngdoc method
  212. * @name angular.Module#value
  213. * @module ng
  214. * @param {string} name service name
  215. * @param {*} object Service instance object.
  216. * @description
  217. * See {@link auto.$provide#value $provide.value()}.
  218. */
  219. value: invokeLater('$provide', 'value'),
  220. /**
  221. * @ngdoc method
  222. * @name angular.Module#constant
  223. * @module ng
  224. * @param {string} name constant name
  225. * @param {*} object Constant value.
  226. * @description
  227. * Because the constant are fixed, they get applied before other provide methods.
  228. * See {@link auto.$provide#constant $provide.constant()}.
  229. */
  230. constant: invokeLater('$provide', 'constant', 'unshift'),
  231. /**
  232. * @ngdoc method
  233. * @name angular.Module#animation
  234. * @module ng
  235. * @param {string} name animation name
  236. * @param {Function} animationFactory Factory function for creating new instance of an
  237. * animation.
  238. * @description
  239. *
  240. * **NOTE**: animations take effect only if the **ngAnimate** module is loaded.
  241. *
  242. *
  243. * Defines an animation hook that can be later used with
  244. * {@link ngAnimate.$animate $animate} service and directives that use this service.
  245. *
  246. * ```js
  247. * module.animation('.animation-name', function($inject1, $inject2) {
  248. * return {
  249. * eventName : function(element, done) {
  250. * //code to run the animation
  251. * //once complete, then run done()
  252. * return function cancellationFunction(element) {
  253. * //code to cancel the animation
  254. * }
  255. * }
  256. * }
  257. * })
  258. * ```
  259. *
  260. * See {@link ng.$animateProvider#register $animateProvider.register()} and
  261. * {@link ngAnimate ngAnimate module} for more information.
  262. */
  263. animation: invokeLater('$animateProvider', 'register'),
  264. /**
  265. * @ngdoc method
  266. * @name angular.Module#filter
  267. * @module ng
  268. * @param {string} name Filter name.
  269. * @param {Function} filterFactory Factory function for creating new instance of filter.
  270. * @description
  271. * See {@link ng.$filterProvider#register $filterProvider.register()}.
  272. */
  273. filter: invokeLater('$filterProvider', 'register'),
  274. /**
  275. * @ngdoc method
  276. * @name angular.Module#controller
  277. * @module ng
  278. * @param {string|Object} name Controller name, or an object map of controllers where the
  279. * keys are the names and the values are the constructors.
  280. * @param {Function} constructor Controller constructor function.
  281. * @description
  282. * See {@link ng.$controllerProvider#register $controllerProvider.register()}.
  283. */
  284. controller: invokeLater('$controllerProvider', 'register'),
  285. /**
  286. * @ngdoc method
  287. * @name angular.Module#directive
  288. * @module ng
  289. * @param {string|Object} name Directive name, or an object map of directives where the
  290. * keys are the names and the values are the factories.
  291. * @param {Function} directiveFactory Factory function for creating new instance of
  292. * directives.
  293. * @description
  294. * See {@link ng.$compileProvider#directive $compileProvider.directive()}.
  295. */
  296. directive: invokeLater('$compileProvider', 'directive'),
  297. /**
  298. * @ngdoc method
  299. * @name angular.Module#config
  300. * @module ng
  301. * @param {Function} configFn Execute this function on module load. Useful for service
  302. * configuration.
  303. * @description
  304. * Use this method to register work which needs to be performed on module loading.
  305. * For more about how to configure services, see
  306. * {@link providers#provider-recipe Provider Recipe}.
  307. */
  308. config: config,
  309. /**
  310. * @ngdoc method
  311. * @name angular.Module#run
  312. * @module ng
  313. * @param {Function} initializationFn Execute this function after injector creation.
  314. * Useful for application initialization.
  315. * @description
  316. * Use this method to register work which should be performed when the injector is done
  317. * loading all modules.
  318. */
  319. run: function(block) {
  320. runBlocks.push(block);
  321. return this;
  322. }
  323. };
  324. if (configFn) {
  325. config(configFn);
  326. }
  327. return moduleInstance;
  328. /**
  329. * @param {string} provider
  330. * @param {string} method
  331. * @param {String=} insertMethod
  332. * @returns {angular.Module}
  333. */
  334. function invokeLater(provider, method, insertMethod, queue) {
  335. if (!queue) queue = invokeQueue;
  336. return function() {
  337. queue[insertMethod || 'push']([provider, method, arguments]);
  338. return moduleInstance;
  339. };
  340. }
  341. });
  342. };
  343. });
  344. }
  345. setupModuleLoader(window);
  346. })(window);
  347. /**
  348. * Closure compiler type information
  349. *
  350. * @typedef { {
  351. * requires: !Array.<string>,
  352. * invokeQueue: !Array.<Array.<*>>,
  353. *
  354. * service: function(string, Function):angular.Module,
  355. * factory: function(string, Function):angular.Module,
  356. * value: function(string, *):angular.Module,
  357. *
  358. * filter: function(string, Function):angular.Module,
  359. *
  360. * init: function(Function):angular.Module
  361. * } }
  362. */
  363. angular.Module;