|
| 1 | +/** |
| 2 | + * @license AngularJS v1.0.8 |
| 3 | + * (c) 2010-2012 Google, Inc. 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 collection of services, directives, filters, and configuration information. |
| 40 | + * `angular.module` is used to configure the {@link 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 | +'use strict'; |
| 52 | + * // Configure existing providers |
| 53 | + * $locationProvider.hashPrefix('!'); |
| 54 | + * }); |
| 55 | + * </pre> |
| 56 | + * |
| 57 | + * Then you can create an injector and load your modules like this: |
| 58 | + * |
| 59 | + * <pre> |
| 60 | + * var injector = angular.injector(['ng', 'MyModule']) |
| 61 | + * </pre> |
| 62 | + * |
| 63 | + * However it's more likely that you'll just use |
| 64 | + * {@link ng.directive:ngApp ngApp} or |
| 65 | + * {@link angular.bootstrap} to simplify this process for you. |
| 66 | + * |
| 67 | + * @param {!string} name The name of the module to create or retrieve. |
| 68 | + * @param {Array.<string>=} requires If specified then new module is being created. If unspecified then the |
| 69 | + * the module is being retrieved for further configuration. |
| 70 | + * @param {Function} configFn Optional configuration function for the module. Same as |
| 71 | + * {@link angular.Module#config Module#config()}. |
| 72 | + * @returns {module} new module with the {@link angular.Module} api. |
| 73 | + */ |
| 74 | + return function module(name, requires, configFn) { |
| 75 | + if (requires && modules.hasOwnProperty(name)) { |
| 76 | + modules[name] = null; |
| 77 | + } |
| 78 | + return ensure(modules, name, function() { |
| 79 | + if (!requires) { |
| 80 | + throw Error('No module: ' + name); |
| 81 | + } |
| 82 | + |
| 83 | + /** @type {!Array.<Array.<*>>} */ |
| 84 | + var invokeQueue = []; |
| 85 | + |
| 86 | + /** @type {!Array.<Function>} */ |
| 87 | + var runBlocks = []; |
| 88 | + |
| 89 | + var config = invokeLater('$injector', 'invoke'); |
| 90 | + |
| 91 | + /** @type {angular.Module} */ |
| 92 | + var moduleInstance = { |
| 93 | + // Private state |
| 94 | + _invokeQueue: invokeQueue, |
| 95 | + _runBlocks: runBlocks, |
| 96 | + |
| 97 | + /** |
| 98 | + * @ngdoc property |
| 99 | + * @name angular.Module#requires |
| 100 | + * @propertyOf angular.Module |
| 101 | + * @returns {Array.<string>} List of module names which must be loaded before this module. |
| 102 | + * @description |
| 103 | + * Holds the list of modules which the injector will load before the current module is loaded. |
| 104 | + */ |
| 105 | + requires: requires, |
| 106 | + |
| 107 | + /** |
| 108 | + * @ngdoc property |
| 109 | + * @name angular.Module#name |
| 110 | + * @propertyOf angular.Module |
| 111 | + * @returns {string} Name of the module. |
| 112 | + * @description |
| 113 | + */ |
| 114 | + name: name, |
| 115 | + |
| 116 | + |
| 117 | + /** |
| 118 | + * @ngdoc method |
| 119 | + * @name angular.Module#provider |
| 120 | + * @methodOf angular.Module |
| 121 | + * @param {string} name service name |
| 122 | + * @param {Function} providerType Construction function for creating new instance of the service. |
| 123 | + * @description |
| 124 | + * See {@link AUTO.$provide#provider $provide.provider()}. |
| 125 | + */ |
| 126 | + provider: invokeLater('$provide', 'provider'), |
| 127 | + |
| 128 | + /** |
| 129 | + * @ngdoc method |
| 130 | + * @name angular.Module#factory |
| 131 | + * @methodOf angular.Module |
| 132 | + * @param {string} name service name |
| 133 | + * @param {Function} providerFunction Function for creating new instance of the service. |
| 134 | + * @description |
| 135 | + * See {@link AUTO.$provide#factory $provide.factory()}. |
| 136 | + */ |
| 137 | + factory: invokeLater('$provide', 'factory'), |
| 138 | + |
| 139 | + /** |
| 140 | + * @ngdoc method |
| 141 | + * @name angular.Module#service |
| 142 | + * @methodOf angular.Module |
| 143 | + * @param {string} name service name |
| 144 | + * @param {Function} constructor A constructor function that will be instantiated. |
| 145 | + * @description |
| 146 | + * See {@link AUTO.$provide#service $provide.service()}. |
| 147 | + */ |
| 148 | + service: invokeLater('$provide', 'service'), |
| 149 | + |
| 150 | + /** |
| 151 | + * @ngdoc method |
| 152 | + * @name angular.Module#value |
| 153 | + * @methodOf angular.Module |
| 154 | + * @param {string} name service name |
| 155 | + * @param {*} object Service instance object. |
| 156 | + * @description |
| 157 | + * See {@link AUTO.$provide#value $provide.value()}. |
| 158 | + */ |
| 159 | + value: invokeLater('$provide', 'value'), |
| 160 | + |
| 161 | + /** |
| 162 | + * @ngdoc method |
| 163 | + * @name angular.Module#constant |
| 164 | + * @methodOf angular.Module |
| 165 | + * @param {string} name constant name |
| 166 | + * @param {*} object Constant value. |
| 167 | + * @description |
| 168 | + * Because the constant are fixed, they get applied before other provide methods. |
| 169 | + * See {@link AUTO.$provide#constant $provide.constant()}. |
| 170 | + */ |
| 171 | + constant: invokeLater('$provide', 'constant', 'unshift'), |
| 172 | + |
| 173 | + /** |
| 174 | + * @ngdoc method |
| 175 | + * @name angular.Module#filter |
| 176 | + * @methodOf angular.Module |
| 177 | + * @param {string} name Filter name. |
| 178 | + * @param {Function} filterFactory Factory function for creating new instance of filter. |
| 179 | + * @description |
| 180 | + * See {@link ng.$filterProvider#register $filterProvider.register()}. |
| 181 | + */ |
| 182 | + filter: invokeLater('$filterProvider', 'register'), |
| 183 | + |
| 184 | + /** |
| 185 | + * @ngdoc method |
| 186 | + * @name angular.Module#controller |
| 187 | + * @methodOf angular.Module |
| 188 | + * @param {string} name Controller name. |
| 189 | + * @param {Function} constructor Controller constructor function. |
| 190 | + * @description |
| 191 | + * See {@link ng.$controllerProvider#register $controllerProvider.register()}. |
| 192 | + */ |
| 193 | + controller: invokeLater('$controllerProvider', 'register'), |
| 194 | + |
| 195 | + /** |
| 196 | + * @ngdoc method |
| 197 | + * @name angular.Module#directive |
| 198 | + * @methodOf angular.Module |
| 199 | + * @param {string} name directive name |
| 200 | + * @param {Function} directiveFactory Factory function for creating new instance of |
| 201 | + * directives. |
| 202 | + * @description |
| 203 | + * See {@link ng.$compileProvider#directive $compileProvider.directive()}. |
| 204 | + */ |
| 205 | + directive: invokeLater('$compileProvider', 'directive'), |
| 206 | + |
| 207 | + /** |
| 208 | + * @ngdoc method |
| 209 | + * @name angular.Module#config |
| 210 | + * @methodOf angular.Module |
| 211 | + * @param {Function} configFn Execute this function on module load. Useful for service |
| 212 | + * configuration. |
| 213 | + * @description |
| 214 | + * Use this method to register work which needs to be performed on module loading. |
| 215 | + */ |
| 216 | + config: config, |
| 217 | + |
| 218 | + /** |
| 219 | + * @ngdoc method |
| 220 | + * @name angular.Module#run |
| 221 | + * @methodOf angular.Module |
| 222 | + * @param {Function} initializationFn Execute this function after injector creation. |
| 223 | + * Useful for application initialization. |
| 224 | + * @description |
| 225 | + * Use this method to register work which should be performed when the injector is done |
| 226 | + * loading all modules. |
| 227 | + */ |
| 228 | + run: function(block) { |
| 229 | + runBlocks.push(block); |
| 230 | + return this; |
| 231 | + } |
| 232 | + }; |
| 233 | + |
| 234 | + if (configFn) { |
| 235 | + config(configFn); |
| 236 | + } |
| 237 | + |
| 238 | + return moduleInstance; |
| 239 | + |
| 240 | + /** |
| 241 | + * @param {string} provider |
| 242 | + * @param {string} method |
| 243 | + * @param {String=} insertMethod |
| 244 | + * @returns {angular.Module} |
| 245 | + */ |
| 246 | + function invokeLater(provider, method, insertMethod) { |
| 247 | + return function() { |
| 248 | + invokeQueue[insertMethod || 'push']([provider, method, arguments]); |
| 249 | + return moduleInstance; |
| 250 | + } |
| 251 | + } |
| 252 | + }); |
| 253 | + }; |
| 254 | + }); |
| 255 | + |
| 256 | +} |
| 257 | + |
| 258 | +)(window); |
| 259 | + |
| 260 | +/** |
| 261 | + * Closure compiler type information |
| 262 | + * |
| 263 | + * @typedef { { |
| 264 | + * requires: !Array.<string>, |
| 265 | + * invokeQueue: !Array.<Array.<*>>, |
| 266 | + * |
| 267 | + * service: function(string, Function):angular.Module, |
| 268 | + * factory: function(string, Function):angular.Module, |
| 269 | + * value: function(string, *):angular.Module, |
| 270 | + * |
| 271 | + * filter: function(string, Function):angular.Module, |
| 272 | + * |
| 273 | + * init: function(Function):angular.Module |
| 274 | + * } } |
| 275 | + */ |
| 276 | +angular.Module; |
| 277 | + |
0 commit comments