-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwings.js
86 lines (68 loc) · 1.75 KB
/
wings.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
define(
function () {
return function (modules/*[, targets][, callback]*/) {
var targets = {};
var callback = null;
var modulez = [];
var counter = 0;
var resolve = function () {
if (++counter === modulez.length && typeof callback === 'function') {
callback();
}
};
if (typeof modules !== 'object') throw new TypeError('modules must be an Object');
if (typeof arguments[1] === 'object') targets = arguments[1];
if (typeof arguments[1] === 'function') callback = arguments[1];
if (typeof arguments[2] === 'function') callback = arguments[2];
Object.keys(targets).forEach(function (alias) {
targets[alias] = matchMedia(targets[alias]).matches;
});
Object.keys(modules).forEach(function (module) {
[].concat(modules[module]).forEach(function (config) {
if (!config) {
config = {
enabled: false
};
}
config = jQuery.extend(
true,
{
domReady: false,
enabled: true,
options: {},
selector: document,
targets: {}
},
config
);
Object.keys(config.targets || {}).forEach(function (alias) {
var target = config.targets[alias];
if (!targets[alias]) return false;
if (!target) target = { enabled: false };
config = jQuery.extend(
true,
config,
target
);
});
modulez.push({
config: config,
name: module
});
});
});
modulez.forEach(function (module) {
var config = module.config;
var name = module.name;
if (config.enabled) {
require([name], function (component) {
component.attachTo(config.selector, config.options, config.domReady, resolve);
});
}
else {
resolve();
}
});
};
}
);