This repository has been archived by the owner on Feb 28, 2019. It is now read-only.
forked from Jasonette/Jasonette-Web
-
Notifications
You must be signed in to change notification settings - Fork 5
/
layers.js
52 lines (51 loc) · 1.63 KB
/
layers.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
var Layers = {
_items: [],
class: "layers hidden",
_update: function(body) {
if (body.layers) {
this.classList.remove("hidden");
this._items = body.layers;
}
},
$update: function() {
this.$components = this._items.map(Layers.tpl)
},
tpl: function(item) {
var component = {};
if (item.type === 'image') {
component.$type = 'img';
if (item.url) {
component.src = item.url;
}
} else if (item.type === 'label') {
component.$type = 'span';
if (item.text) {
component.$text = item.text;
}
}
if (item.class) {
component.class = item.class;
}
if (item.style) {
/// common styling
for (var key in item.style) {
if (/^[0-9]+$/.test(item.style[key])) {
item.style[key] = item.style[key] + "px";
} else if (/.*%[ ]*[+-][ ]*[0-9]+[ ]*/.test(item.style[key])) {
// "width": "50%-10px"
item.style[key] = ("calc(" + item.style[key] + "px)").split("+").join(" + ").split("-").join(" - ");
} else {
item.style[key] = item.style[key];
}
}
component.style = Style.transform(item.style)
// layer specific styling - top,left,right,bottom
if (item.style.top != undefined) { component.style.top = item.style.top; }
if (item.style.left != undefined) { component.style.left = item.style.left; }
if (item.style.right != undefined) { component.style.right = item.style.right; }
if (item.style.bottom != undefined) { component.style.bottom = item.style.bottom; }
component.style.position = "absolute";
}
return component;
}
}