PageRenderTime 55ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

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

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