-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
165 lines (152 loc) · 5.99 KB
/
index.html
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<html>
<head>
<title>Lazy Web Devs</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<style>
* {
font-family: sans-serif;
margin: 0px;
}
.container, .sidebar, .content {
height: 99vh;
}
.container {
width: 100%;
}
.sidebar {
width: 20%;
padding-top: 40px;
background-color: #eee;
}
.content {
width: 79%;
}
td {
vertical-align: top;
}
</style>
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha256-/SIrNqv8h6QGKDuNoLGA4iret+kyesCkHGzVUUV0shc=" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script src="/js/bstrapSnippet.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script>
'use strict';
let protocol = 'https',
host = window.location.host,
url = `${protocol}://${host}`;
console.log(url);
let socket = io.connect(url);
function createElement(data){
let element = $(`<${data.element}>`);
element.attr('id', (data.id));
switch (data.element) {
case 'ol':
case 'ul': {
element.addClass('list-group');
break;
}
case 'li': {
element.addClass('list-group-item');
break;
}
}
element.css({
'width': data.width,
'height': data.height,
'background-color': data.bg
});
return element;
}
function getChildSelectors(parent){
/*
[
{id : 123},
{
id : 234,
children : [
{id : 111},
{id : 222}
]
}
]
*/
return $.map($(parent).children(), (elem) => {
let item = { selector: (elem.getAttribute('id') || elem.getAttribute('class')) };
if($(elem).children().length){
item.children = getChildSelectors(elem);
}
return item;
});
}
function generateSelectorList(arr){
let ul = $('<ul>'),
li = () => $('<li>');
let listItem;
arr.forEach((item) => {
listItem = li();
listItem.text(item.selector);
if(item.children){
listItem.append(generateSelectorList(item.children));
}
ul.append(listItem);
});
return ul;
}
// Selector of the Destination container that will have all the added elements
const DEST = '.content';
socket.on('message', (data) => {
console.log(data);
switch(data.action){
case 'create': {
if(data.parent && data.children){
let parent = createElement(data.parent),
child;
$(DEST).append(parent);
//parent.text(data.parent.content || new Date().getTime());
data.children.ID.forEach((id) => {
child = createElement(data.children.child);
child.attr('id', id);
parent.append(child);
child.text(data.children.child.content || id);
});
}
else {
let element = createElement(data);
$(DEST).append(element);
element.text(data.content);
}
break;
}
case 'edit': {
let element = $(`#${data.id}`);
element.css({
'height': data.height || element.height(),
'width': data.width || element.width(),
'background-color': data.bg || element.css('background-color')
});
break;
}
case 'delete': {
$(`#${data.id}`).remove();
break;
}
case 'bootstrap': {
$(DEST).append($(SNIPPET[data.component]));
break;
}
}
let arrID = getChildSelectors('.content');
$('.sidebar').empty();
$('.sidebar').append(generateSelectorList(arrID));
});
</script>
</head>
<body>
<table class="container">
<tr>
<td class="sidebar"></td>
<td class="content"></td>
</tr>
</table>
</body>
</html>