1
|
import { classify, createEvent, isString, mergeOptions, toNode } from '../util/index';
|
2
|
|
3
|
export default function (UIkit) {
|
4
|
|
5
|
const DATA = UIkit.data;
|
6
|
|
7
|
UIkit.use = function (plugin) {
|
8
|
|
9
|
if (plugin.installed) {
|
10
|
return;
|
11
|
}
|
12
|
|
13
|
plugin.call(null, this);
|
14
|
plugin.installed = true;
|
15
|
|
16
|
return this;
|
17
|
};
|
18
|
|
19
|
UIkit.mixin = function (mixin, component) {
|
20
|
component = (isString(component) ? UIkit.components[component] : component) || this;
|
21
|
mixin = mergeOptions({}, mixin);
|
22
|
mixin.mixins = component.options.mixins;
|
23
|
delete component.options.mixins;
|
24
|
component.options = mergeOptions(mixin, component.options);
|
25
|
};
|
26
|
|
27
|
UIkit.extend = function (options) {
|
28
|
|
29
|
options = options || {};
|
30
|
|
31
|
var Super = this, name = options.name || Super.options.name;
|
32
|
var Sub = createClass(name || 'UIkitComponent');
|
33
|
|
34
|
Sub.prototype = Object.create(Super.prototype);
|
35
|
Sub.prototype.constructor = Sub;
|
36
|
Sub.options = mergeOptions(Super.options, options);
|
37
|
|
38
|
Sub['super'] = Super;
|
39
|
Sub.extend = Super.extend;
|
40
|
|
41
|
return Sub;
|
42
|
};
|
43
|
|
44
|
UIkit.update = function (e, element, parents = false) {
|
45
|
|
46
|
e = createEvent(e || 'update');
|
47
|
|
48
|
if (!element) {
|
49
|
|
50
|
update(UIkit.instances, e);
|
51
|
return;
|
52
|
|
53
|
}
|
54
|
|
55
|
element = toNode(element);
|
56
|
|
57
|
if (parents) {
|
58
|
|
59
|
do {
|
60
|
|
61
|
update(element[DATA], e);
|
62
|
element = element.parentNode;
|
63
|
|
64
|
} while (element)
|
65
|
|
66
|
} else {
|
67
|
|
68
|
apply(element, element => update(element[DATA], e));
|
69
|
|
70
|
}
|
71
|
|
72
|
};
|
73
|
|
74
|
var container;
|
75
|
Object.defineProperty(UIkit, 'container', {
|
76
|
|
77
|
get() {
|
78
|
return container || document.body;
|
79
|
},
|
80
|
|
81
|
set(element) {
|
82
|
container = element;
|
83
|
}
|
84
|
|
85
|
});
|
86
|
|
87
|
}
|
88
|
|
89
|
function createClass(name) {
|
90
|
return new Function(`return function ${classify(name)} (options) { this._init(options); }`)();
|
91
|
}
|
92
|
|
93
|
function apply(node, fn) {
|
94
|
|
95
|
if (node.nodeType !== Node.ELEMENT_NODE) {
|
96
|
return;
|
97
|
}
|
98
|
|
99
|
fn(node);
|
100
|
node = node.firstChild;
|
101
|
while (node) {
|
102
|
apply(node, fn);
|
103
|
node = node.nextSibling;
|
104
|
}
|
105
|
}
|
106
|
|
107
|
function update(data, e) {
|
108
|
|
109
|
if (!data) {
|
110
|
return;
|
111
|
}
|
112
|
|
113
|
for (var name in data) {
|
114
|
if (data[name]._isReady) {
|
115
|
data[name]._callUpdate(e);
|
116
|
}
|
117
|
}
|
118
|
|
119
|
}
|