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
/
header.js
111 lines (106 loc) · 2.59 KB
/
header.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
var Header = {
$type: "nav",
class: "header nav nav-justified",
_title: null,
_menu: null,
_style: null,
_update: function(body) {
if (body.header) {
// title
if (body.header.title) {
if (typeof body.header.title === 'string') {
this._title = { type: "label", text: body.header.title };
} else {
this._title = body.header.title;
}
}
// menu
if (body.header.menu) {
this._menu = body.header.menu;
}
// style
if (body.header.style) {
this._style = body.header.style;
}
}
},
$update: function() {
// style
Style.node(this);
// menu drawing
var menuItem;
if (this._menu) {
if (this._menu.image) {
menuItem = {
class: "nav-item",
$components: [{ $type: "img", src: this._menu.image, class: "icon float-right" } ]
}
} else if (this._menu && this._menu.text) {
menuItem = {
class: "nav-item",
$components: [{ $type: "span", $text: this._menu.text, class: "icon nav-item float-right" }]
}
}
if (this._menu.style) menuItem.style = Style.transform(this._menu.style);
} else {
menuItem = {
class: "nav-item",
$components: [{ $type: "span", $text: "", class: "icon float-right" }]
}
}
// Build title
/*
label type
{
"type": "label",
"text": "this isa title",
"style": {
"font": "..",
"size": "..",
"color": ".."
}
}
image type
{
"type": "image",
"url": "..",
"style": {
"width": "..",
"height": ".."
}
}
*/
var titleItem;
if (this._title) {
var t = this._title;
if (t.type) {
var newStyle = {};
if (t.style) {
var style = Style.transform(t.style);
for (var key in style) {
newStyle[key] = Utils.units(style[key]);
}
}
if (t.type === 'label') {
titleItem = { $type: "h5", $text: t.text, class: "nav-item" };
if (newStyle) titleItem.style = newStyle;
} else if (t.type === 'image') {
titleItem = {
class: "nav-item",
$components: [{
$type: "img", src: t.url
}]
}
if (newStyle) titleItem.$components[0].style = newStyle;
}
}
} else {
titleItem = { $type: "h5", $text: "", class: "nav-item" };
}
this.$components = [
{ $type: "span", $text: "", class: "nav-item" },
titleItem,
menuItem
]
}
}