-
Notifications
You must be signed in to change notification settings - Fork 17
/
angular.ng-modules.js
65 lines (55 loc) · 2.44 KB
/
angular.ng-modules.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
// By Luis Perez
// From blog post: http://www.simplygoodcode.com/2014/04/angularjs-getting-around-ngapp-limitations-with-ngmodule/
(function() {
function initNgModules(element) {
var elements = [element],
moduleElements = [],
modules = [],
names = ['ng:module', 'ng-module', 'x-ng-module', 'data-ng-module', 'ng:modules', 'ng-modules', 'x-ng-modules', 'data-ng-modules'],
NG_MODULE_CLASS_REGEXP = /\sng[:\-]module[s](:\s*([\w\d_]+);?)?\s/;
function append(element) {
element && elements.push(element);
}
for(var i = 0; i < names.length; i++) {
var name = names[i];
append(document.getElementById(name));
name = name.replace(':', '\\:');
if (element.querySelectorAll) {
var elements2;
elements2 = element.querySelectorAll('.' + name);
for(var j = 0; j < elements2.length; j++) append(elements2[j]);
elements2 = element.querySelectorAll('.' + name + '\\:');
for(var j = 0; j < elements2.length; j++) append(elements2[j]);
elements2 = element.querySelectorAll('[' + name + ']');
for(var j = 0; j < elements2.length; j++) append(elements2[j]);
}
}
for(var i = 0; i < elements.length; i++) {
var element = elements[i];
var className = ' ' + element.className + ' ';
var match = NG_MODULE_CLASS_REGEXP.exec(className);
if (match) {
moduleElements.push(element);
modules.push((match[2] || '').replace(/\s+/g, ','));
} else {
if(element.attributes) {
for(var j = 0; j < element.attributes.length; j++) {
var attr = element.attributes[j];
if (names.indexOf(attr.name) != -1) {
moduleElements.push(element);
modules.push(attr.value);
}
}
}
}
}
for(var i = 0; i < moduleElements.length; i++) {
var moduleElement = moduleElements[i];
var module = modules[i].replace(/ /g,'').split(",");
angular.bootstrap(moduleElement, module);
}
}
angular.element(document).ready(function() {
initNgModules(document);
});
})();