upgrade seed to 1.0.0rc2 silence-absorption
[angular-drzb] / app / lib / angular / angular-loader.js
1 /**
2  * @license AngularJS v1.0.0rc2
3  * (c) 2010-2012 AngularJS http://angularjs.org
4  * License: MIT
5  */
6
7 (
8
9 /**
10  * @ngdoc interface
11  * @name angular.Module
12  * @description
13  *
14  * Interface for configuring angular {@link angular.module modules}.
15  */
16
17 function setupModuleLoader(window) {
18
19   function ensure(obj, name, factory) {
20     return obj[name] || (obj[name] = factory());
21   }
22
23   return ensure(ensure(window, 'angular', Object), 'module', function() {
24     /** @type {Object.<string, angular.Module>} */
25     var modules = {};
26
27     /**
28      * @ngdoc function
29      * @name angular.module
30      * @description
31      *
32      * The `angular.module` is a global place for creating and registering Angular modules. All
33      * modules (angular core or 3rd party) that should be available to an application must be
34      * registered using this mechanism.
35      *
36      *
37      * # Module
38      *
39      * A module is a collocation of services, directives, filters, and configure information. Module
40      * is used to configure the {@link angular.module.AUTO.$injector $injector}.
41      *
42      * <pre>
43      * // Create a new module
44      * var myModule = angular.module('myModule', []);
45      *
46      * // register a new service
47      * myModule.value('appName', 'MyCoolApp');
48      *
49      * // configure existing services inside initialization blocks.
50      * myModule.config(function($locationProvider) {
51      *   // Configure existing providers
52      *   $locationProvider.hashPrefix('!');
53      * });
54      * </pre>
55      *
56      * Then you can create an injector and load your modules like this:
57      *
58      * <pre>
59      * var injector = angular.injector(['ng', 'MyModule'])
60      * </pre>
61      *
62      * However it's more likely that you'll just use
63      * {@link angular.module.ng.$compileProvider.directive.ng-app ng-app} or
64      * {@link angular.bootstrap} to simplify this process for you.
65      *
66      * @param {!string} name The name of the module to create or retrieve.
67      * @param {Array.<string>=} requires If specified then new module is being created. If unspecified then the
68      *        the module is being retrieved for further configuration.
69      * @param {Function} configFn Option configuration function for the module. Same as
70      *        {@link angular.Module#config Module#config()}.
71      * @returns {module} new module with the {@link angular.Module} api.
72      */
73     return function module(name, requires, configFn) {
74       if (requires && modules.hasOwnProperty(name)) {
75         modules[name] = null;
76       }
77       return ensure(modules, name, function() {
78         if (!requires) {
79           throw Error('No module: ' + name);
80         }
81
82         /** @type {!Array.<Array.<*>>} */
83         var invokeQueue = [];
84
85         /** @type {!Array.<Function>} */
86         var runBlocks = [];
87
88         var config = invokeLater('$injector', 'invoke');
89
90         /** @type {angular.Module} */
91         var moduleInstance = {
92           // Private state
93           _invokeQueue: invokeQueue,
94           _runBlocks: runBlocks,
95
96           /**
97            * @ngdoc property
98            * @name angular.Module#requires
99            * @propertyOf angular.Module
100            * @returns {Array.<string>} List of module names which must be loaded before this module.
101            * @description
102            * Holds the list of modules which the injector will load before the current module is loaded.
103            */
104           requires: requires,
105
106           /**
107            * @ngdoc property
108            * @name angular.Module#name
109            * @propertyOf angular.Module
110            * @returns {string} Name of the module.
111            * @description
112            */
113           name: name,
114
115
116           /**
117            * @ngdoc method
118            * @name angular.Module#provider
119            * @methodOf angular.Module
120            * @param {string} name service name
121            * @param {Function} providerType Construction function for creating new instance of the service.
122            * @description
123            * See {@link angular.module.AUTO.$provide#provider $provide.provider()}.
124            */
125           provider: invokeLater('$provide', 'provider'),
126
127           /**
128            * @ngdoc method
129            * @name angular.Module#factory
130            * @methodOf angular.Module
131            * @param {string} name service name
132            * @param {Function} providerFunction Function for creating new instance of the service.
133            * @description
134            * See {@link angular.module.AUTO.$provide#factory $provide.factory()}.
135            */
136           factory: invokeLater('$provide', 'factory'),
137
138           /**
139            * @ngdoc method
140            * @name angular.Module#service
141            * @methodOf angular.Module
142            * @param {string} name service name
143            * @param {Function} constructor A constructor function that will be instantiated.
144            * @description
145            * See {@link angular.module.AUTO.$provide#service $provide.service()}.
146            */
147           service: invokeLater('$provide', 'service'),
148
149           /**
150            * @ngdoc method
151            * @name angular.Module#value
152            * @methodOf angular.Module
153            * @param {string} name service name
154            * @param {*} object Service instance object.
155            * @description
156            * See {@link angular.module.AUTO.$provide#value $provide.value()}.
157            */
158           value: invokeLater('$provide', 'value'),
159
160           /**
161            * @ngdoc method
162            * @name angular.Module#constant
163            * @methodOf angular.Module
164            * @param {string} name constant name
165            * @param {*} object Constant value.
166            * @description
167            * Because the constant are fixed, they get applied before other provide methods.
168            * See {@link angular.module.AUTO.$provide#constant $provide.constant()}.
169            */
170           constant: invokeLater('$provide', 'constant', 'unshift'),
171
172           /**
173            * @ngdoc method
174            * @name angular.Module#filter
175            * @methodOf angular.Module
176            * @param {string} name filter name
177            * @param {Function} filterFactory Factory function for creating new instance of filter.
178            * @description
179            * See {@link angular.module.ng.$filterProvider#register $filterProvider.register()}.
180            */
181           filter: invokeLater('$filterProvider', 'register'),
182
183           /**
184            * @ngdoc method
185            * @name angular.Module#directive
186            * @methodOf angular.Module
187            * @param {string} name directive name
188            * @param {Function} directiveFactory Factory function for creating new instance of
189            * directives.
190            * @description
191            * See {@link angular.module.ng.$compileProvider.directive $compileProvider.directive()}.
192            */
193           directive: invokeLater('$compileProvider', 'directive'),
194
195           /**
196            * @ngdoc method
197            * @name angular.Module#config
198            * @methodOf angular.Module
199            * @param {Function} configFn Execute this function on module load. Useful for service
200            *    configuration.
201            * @description
202            * Use this method to register work which needs to be performed on module loading.
203            */
204           config: config,
205
206           /**
207            * @ngdoc method
208            * @name angular.Module#run
209            * @methodOf angular.Module
210            * @param {Function} initializationFn Execute this function after injector creation.
211            *    Useful for application initialization.
212            * @description
213            * Use this method to register work which needs to be performed when the injector with
214            * with the current module is finished loading.
215            */
216           run: function(block) {
217             runBlocks.push(block);
218             return this;
219           }
220         };
221
222         if (configFn) {
223           config(configFn);
224         }
225
226         return  moduleInstance;
227
228         /**
229          * @param {string} provider
230          * @param {string} method
231          * @param {String=} insertMethod
232          * @returns {angular.Module}
233          */
234         function invokeLater(provider, method, insertMethod) {
235           return function() {
236             invokeQueue[insertMethod || 'push']([provider, method, arguments]);
237             return moduleInstance;
238           }
239         }
240       });
241     };
242   });
243
244 }
245 )(window);
246
247 /**
248  * Closure compiler type information
249  *
250  * @typedef { {
251  *   requires: !Array.<string>,
252  *   invokeQueue: !Array.<Array.<*>>,
253  *
254  *   service: function(string, Function):angular.Module,
255  *   factory: function(string, Function):angular.Module,
256  *   value: function(string, *):angular.Module,
257  *
258  *   filter: function(string, Function):angular.Module,
259  *
260  *   init: function(Function):angular.Module
261  * } }
262  */
263 angular.Module;
264