upgrade to 0.10.6 final
[angular-drzb] / app / lib / angular / angular-loader.js
1 /**
2  * @license AngularJS v0.10.6
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 {@link angular.directive.ng:app ng:app} or
63      * {@link angular.bootstrap} to simplify this process for you.
64      *
65      * @param {!string} name The name of the module to create or retrieve.
66      * @param {Array.<string>=} requires If specified then new module is being created. If unspecified then the
67      *        the module is being retrieved for further configuration.
68      * @param {Function} configFn Option configuration function for the module. Same as
69      *        {@link angular.Module#config Module#config()}.
70      * @returns {module} new module with the {@link angular.Module} api.
71      */
72     return function module(name, requires, configFn) {
73       if (requires && modules.hasOwnProperty(name)) {
74         modules[name] = null;
75       }
76       return ensure(modules, name, function() {
77         if (!requires) {
78           throw Error('No module: ' + name);
79         }
80
81         /** @type {!Array.<Array.<*>>} */
82         var invokeQueue = [];
83
84         /** @type {!Array.<Function>} */
85         var runBlocks = [];
86
87         var config = invokeLater('$injector', 'invoke');
88
89         /** @type {angular.Module} */
90         var moduleInstance = {
91           // Private state
92           _invokeQueue: invokeQueue,
93           _runBlocks: runBlocks,
94
95           /**
96            * @ngdoc property
97            * @name angular.Module#requires
98            * @propertyOf angular.Module
99            * @returns {Array.<string>} List of module names which must be loaded before this module.
100            * @description
101            * Holds the list of modules which the injector will load before the current module is loaded.
102            */
103           requires: requires,
104
105           /**
106            * @ngdoc property
107            * @name angular.Module#name
108            * @propertyOf angular.Module
109            * @returns {string} Name of the module.
110            * @description
111            */
112           name: name,
113
114
115           /**
116            * @ngdoc method
117            * @name angular.Module#service
118            * @methodOf angular.Module
119            * @param {string} name service name
120            * @param {Function} providerType Construction function for creating new instance of the service.
121            * @description
122            * See {@link angular.module.AUTO.$provide#service $provide.service()}.
123            */
124           service: invokeLater('$provide', 'service'),
125
126           /**
127            * @ngdoc method
128            * @name angular.Module#factory
129            * @methodOf angular.Module
130            * @param {string} name service name
131            * @param {Function} providerFunction Function for creating new instance of the service.
132            * @description
133            * See {@link angular.module.AUTO.$provide#service $provide.factory()}.
134            */
135           factory: invokeLater('$provide', 'factory'),
136
137           /**
138            * @ngdoc method
139            * @name angular.Module#value
140            * @methodOf angular.Module
141            * @param {string} name service name
142            * @param {*} object Service instance object.
143            * @description
144            * See {@link angular.module.AUTO.$provide#value $provide.value()}.
145            */
146           value: invokeLater('$provide', 'value'),
147
148           /**
149            * @ngdoc method
150            * @name angular.Module#filter
151            * @methodOf angular.Module
152            * @param {string} name filterr name
153            * @param {Function} filterFactory Factory function for creating new instance of filter.
154            * @description
155            * See {@link angular.module.ng.$filterProvider#register $filterProvider.register()}.
156            */
157           filter: invokeLater('$filterProvider', 'register'),
158
159           /**
160            * @ngdoc method
161            * @name angular.Module#config
162            * @methodOf angular.Module
163            * @param {Function} configFn Execute this function on module load. Useful for service
164            *    configuration.
165            * @description
166            * Use this method to register work which needs to be performed on module loading.
167            */
168           config: config,
169
170           /**
171            * @ngdoc method
172            * @name angular.Module#run
173            * @methodOf angular.Module
174            * @param {Function} initializationFn Execute this function after injector creation.
175            *    Useful for application initialization.
176            * @description
177            * Use this method to register work which needs to be performed when the injector with
178            * with the current module is finished loading.
179            */
180           run: function(block) {
181             runBlocks.push(block);
182             return this;
183           }
184         };
185
186         if (configFn) {
187           config(configFn);
188         }
189
190         return  moduleInstance;
191
192         /**
193          * @param {string} provider
194          * @param {string} method
195          * @returns {angular.Module}
196          */
197         function invokeLater(provider, method) {
198           return function() {
199             invokeQueue.push([provider, method, arguments]);
200             return moduleInstance;
201           }
202         }
203       });
204     };
205   });
206
207 }
208 )(window);
209
210 /**
211  * Closure compiler type information
212  *
213  * @typedef { {
214  *   requires: !Array.<string>,
215  *   invokeQueue: !Array.<Array.<*>>,
216  *
217  *   service: function(string, Function):angular.Module,
218  *   factory: function(string, Function):angular.Module,
219  *   value: function(string, *):angular.Module,
220  *
221  *   filter: function(string, Function):angular.Module,
222  *
223  *   init: function(Function):angular.Module
224  * } }
225  */
226 angular.Module;
227