This repository was archived by the owner on Oct 10, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathngDefine.js
112 lines (82 loc) · 2.75 KB
/
ngDefine.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/**
* ngDefine - a friendly integration of AngularJS into RequireJS powered applications
*
* See https://github.com/Nikku/requirejs-angular-define for details.
*
* @version 1.1.0
* @author Nico Rehwaldt <http://github.com/Nikku>
*
* @license (c) 2013 Nico Rehwaldt, MIT
*/
(function(window) {
define([ 'angular', 'ngParse' ], function(angular, ngParse) {
//////// utilities /////////
function toArray(arrayLike) {
return Array.prototype.slice.call(arrayLike, 0);
}
///////// main /////////
function internalModule(angular, name, dependencies, body) {
if (!body) {
body = dependencies;
dependencies = null;
}
var definition = ngParse.parseNgModule(name, dependencies || []);
var module, exists;
var moduleDependencies = definition.moduleDependencies,
fileDependencies = definition.fileDependencies;
try {
angular.module(name);
exists = true;
} catch (e) {
exists = false;
}
if (moduleDependencies.length && exists) {
throw new Error(
"Cannot re-define angular module " + name + " with new dependencies [" + moduleDependencies + "]. " +
"Make sure the module is not defined else where or define a sub-module with additional angular module dependencies instead.");
}
if (moduleDependencies.length || !exists) {
module = angular.module(name, moduleDependencies);
debugLog(name, "defined with dependencies", moduleDependencies);
} else {
module = angular.module(name);
debugLog(name, "looked up");
}
define(fileDependencies, function() {
var results = toArray(arguments);
results.unshift(module);
body.apply(window, results);
debugLog(name, "loaded");
return module;
});
}
//////// module exports /////////
var exports = function(name, dependencies, body) {
if (!dependencies) {
throw new Error("wrong number of arguments, expected name[, dependencies], body");
}
internalModule(angular, name, dependencies, body);
};
if (typeof window !== undefined && !window.ngDefine) {
window.ngDefine = exports;
}
///////// logging /////////
var debugLog = (function() {
var log;
// IE 9 logging #!?.
if (Function.prototype.bind && window.console && window.console.log) {
log = Function.prototype.bind.call(window.console.log, window.console);
}
return function() {
if (!exports.debug || !log) {
return;
}
var args = toArray(arguments);
args.unshift("[ngDefine]");
log.apply(log, args);
};
})();
///////// export //////////
return exports;
});
})(window);