-
Notifications
You must be signed in to change notification settings - Fork 0
/
render.js
72 lines (66 loc) · 3.58 KB
/
render.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
var addItemToCanvas = function(item) {
var canvasItem = document.createElement("div");
canvasItem.classList.add('item');
canvasItem.innerText = item.text;
canvasItem.style.fontWeight = item.bold ? 'bold' : 'normal';
canvasItem.style.fontStyle = item.italic ? 'italic' : 'normal';
canvasItem.style.textDecoration = item.underline ? 'underline' : '';
canvasItem.style.fontSize = item.size;
document.getElementById('canvas').appendChild(canvasItem);
};
var addItemToEditor = function(item, index) {
var editorItem = document.createElement("div");
editorItem.classList.add('item-editor');
editorItem.classList.add('mdl-card');
editorItem.classList.add('mdl-shadow--2dp');
editorItem.innerHTML =
'<div class="text-container">' +
'<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">' +
'<input class="mdl-textfield__input" type="text" id="item-editor-' + index + '-text" value="' + item.text + '">' +
'<label class="mdl-textfield__label" for="item-editor-' + index + '-text">Text...</label>' +
'</div>' +
'<button class="mdl-button mdl-js-button mdl-button--icon delete-item" id="item-editor-' + index + '-delete">' +
'<i class="material-icons">close</i>' +
'</button>' +
'</div>' +
'<div class="text-ctas">' +
'<label class="mdl-icon-toggle mdl-js-icon-toggle mdl-js-ripple-effect" for="item-editor-' + index + '-bold">' +
'<input type="checkbox" id="item-editor-' + index + '-bold" class="mdl-icon-toggle__input"' + (item.bold ? "checked":"") + '>' +
'<i class="mdl-icon-toggle__label material-icons">format_bold</i>' +
'</label>' +
'<label class="mdl-icon-toggle mdl-js-icon-toggle mdl-js-ripple-effect" for="item-editor-' + index + '-italic">' +
'<input type="checkbox" id="item-editor-' + index + '-italic" class="mdl-icon-toggle__input"' + (item.italic ? "checked":"") + '>' +
'<i class="mdl-icon-toggle__label material-icons">format_italic</i>' +
'</label>' +
'<label class="mdl-icon-toggle mdl-js-icon-toggle mdl-js-ripple-effect" for="item-editor-' + index + '-underline">' +
'<input type="checkbox" id="item-editor-' + index + '-underline" class="mdl-icon-toggle__input"' + (item.underline ? "checked":"") + '>' +
'<i class="mdl-icon-toggle__label material-icons">format_underline</i>' +
'</label>' +
'<div class="mdl-layout-spacer"></div>' +
'<button class="mdl-button mdl-js-button mdl-button--icon" id="item-editor-' + index + '-size-up">' +
'<i class="material-icons">format_size</i>' +
'</button>' +
'<button class="mdl-button mdl-js-button mdl-button--icon" id="item-editor-' + index + '-size-down">' +
'<i class="material-icons">text_fields</i>' +
'</button>'
'</div>';
document.getElementById('item-editors').appendChild(editorItem);
};
renderCanvas = function(items){
// clear document
document.getElementById('canvas').innerHTML = '';
// Add all the items
items.forEach((item, index) => {
addItemToCanvas(item);
});
}
renderEditor = function(items) {
// clear document
document.getElementById('item-editors').innerHTML = '<span class="mdl-layout-title">Items</span>';
// Add all the items
items.forEach((item, index) => {
addItemToEditor(item, index);
});
// This is for mdl
componentHandler.upgradeDom();
}