PageRenderTime 44ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

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

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