-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeneral.js
139 lines (114 loc) · 2.73 KB
/
general.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
addNavBar = function() {
var navbar = document.createElement('nav-bar');
navbar.id = 'navbar';
document.getElementById('body').appendChild(navbar);
};
getNavBar = function() {
return document.getElementById('navbar');
}
addNavBarTab = function(text, src, float) {
if (text === undefined) {
console.log('You need at least 1 parameter as the tab\'s text');
return;
}
if (getNavBar() === null) {
addNavBar();
}
if (float === undefined) {
console.log('float undefined');
float = 'left';
}
var tab = document.createElement('nav-bar-tab');
tab.innerHTML = text;
if (getNavBar().childNodes.length === 0) {
tab.setAttribute(':active', true);
} else {
tab.setAttribute(':active', false);
}
tab.setAttribute('linked', String(text).toLowerCase().trim());
tab.setAttribute('float', float);
if (src !== undefined && src !== '') {
tab.setAttribute('src', src);
}
document.getElementById('navbar').appendChild(tab);
}
setActiveTab = function(id) {
var tabs = getNavBar().childNodes;
for (var i = 0; i < tabs.length; i++) {
tabs[i].setAttribute(':active', false);
}
tabs[id].setAttribute(':active', true);
}
getContent = function() {
return document.getElementById('content');
}
var xhttp = new XMLHttpRequest();
var json;
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
json = JSON.parse(this.responseText);
getContent().innerHTML = '<h3>' + json.title + '</h2><hr><p>' + json.body + "</p>";
}
};
xhttp.open("GET", "/posts/test.json", true);
xhttp.send();
addNavBarTab('Home');
addNavBarTab('About');
addNavBarTab('Test', 'test.html', 'right');
setActiveTab(0);
Vue.component('nav-bar', {
template: '<ul class="nav-bar"><slot/></ul>'
})
var NavBarTab = Vue.component('nav-bar-tab', {
template: '<li class="nav-bar-tab" :class="{active: active}" :style=styleObj @mouseover="mouseover"><a :href="src" @click="clicked"><slot/></a></li>',
props: {
src: {
type: String
},
float: {
type: String,
default: "left"
},
active: Boolean,
linked: null
},
data: function() {
return {
styleObj: {
float: this.float
},
selectedTab: 'home'
}
},
methods: {
mouseover: function() {
console.log(this.src);
this.$emit('hover');
},
clicked: function(e) {
console.log("clicked", e);
//TODO
}
}
});
//needs to be after component registration
new Vue({
el: '#body'
})
new Vue({
el: '#content'
})
/*var content = new Vue({
el: '#content',
data: {
selectedTab: 'home'
},
components: {
home: {
template: '<my-element>abc</my-element>'
},
about: {
template: '<my-element>def</my-element>'
}
}
})*/