-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
291 lines (247 loc) · 9.11 KB
/
script.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
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
/*******************************************
JavaScript by zeankun.dev (c)
Protected with Apache Licence v2.0 and the
GNU General Public License
*******************************************/
const editor = document.getElementById('editor')
var btnBold = document.getElementById("btnBold");
var btnItalic = document.getElementById("btnItalic");
var btnUnderline = document.getElementById("btnUnderline");
var btnStrike = document.getElementById("btnStrike");
var btnSubscript = document.getElementById("btnSubscript");
var str1 = 'New Document 1';
var pageClone = editor.cloneNode(true);
var spaceLeftScrub = document.getElementById("space-left-range");
var spaceRightScrub = document.getElementById("space-right-range");
var btnRemoveFormat = document.getElementById("btnRemoveFormat");
var btnSuperscript = document.getElementById("btnSuperscript");
var btnSubscript = document.getElementById("btnSubscript");
var btnAddPage = document.getElementById("btnAddPage");
var btnSpacing = document.getElementById("btnSpacing");
var spacingModal = document.getElementById("adjust");
var btnclose = document.getElementsByClassName("close")[0];
var btnCenter = document.getElementById("btnCenter");
var btnRight = document.getElementById("btnRight");
var btnLeft = document.getElementById("btnLeft");
var btnUndo = document.getElementById("btnUndo");
var btnRedo = document.getElementById("btnRedo")
var btnSave = document.getElementById("btnSave")
var btnDelete = document.getElementById("btnDelete")
var btnCopy = document.getElementById("btnCopy")
var btnPaste = document.getElementById("btnPaste")
var Bold = document.getElementById("Bold");
var Italic = document.getElementById("Italic");
var Underline = document.getElementById("Underline");
var Strike = document.getElementById("Strike");
// all ordinary text formatting
function cut(){
document.execCommand("cut");
event.preventDefault()
}
btnStrike.addEventListener("mousedown", function(event){
document.execCommand("strikethrough");
console.log("Strikethrough successful from right click");
event.preventDefault();
});
Bold.addEventListener("mousedown", function(event){
document.execCommand("bold");
console.log("Bold formatted successful from right click");
event.preventDefault();
});
Italic.addEventListener("mousedown", function(event){
document.execCommand("italic");
console.log("Italic formatted successful from right click");
event.preventDefault();
});
Underline.addEventListener("mousedown", function(event){
document.execCommand("underline");
console.log("Underline formatted successful from right click");
event.preventDefault();
});
btnCopy.addEventListener("mousedown", function(event){
document.execCommand("copy");
event.preventDefault()
})
btnPaste.addEventListener("mousedown", function(event){
document.execCommand("paste");
event.preventDefault()
})
btnDelete.addEventListener("mousedown", function(event){
document.execCommand("delete");
console.log("Delete successful");
event.preventDefault();
});
btnRedo.addEventListener("mousedown", function(event){
document.execCommand("redo");
console.log("Redo successful");
event.preventDefault();
});
btnUndo.addEventListener("mousedown", function(event){
document.execCommand("undo");
console.log("Undo successful");
event.preventDefault();
});
btnLeft.addEventListener("mousedown", function(event){
document.execCommand("justifyLeft");
console.log("Justify to the left successful");
event.preventDefault();
});
btnRight.addEventListener("mousedown", function(event){
document.execCommand("justifyRight");
console.log("Justify to the right successful");
event.preventDefault();
});
btnCenter.addEventListener('mousedown', function(event){
document.execCommand("justifyCenter");
console.log("Justify to the center successful");
event.preventDefault();
});
btnSubscript.addEventListener("mousedown", function(event){
document.execCommand("subscript");
console.log("Subscript successful");
event.preventDefault();
});
btnSuperscript.addEventListener("mousedown", function(event){
document.execCommand("superscript");
console.log("Superscript successful");
event.preventDefault();
});
btnRemoveFormat.addEventListener("mousedown", function(event){
document.execCommand("removeFormat");
console.log("Format remove successful");
event.preventDefault();
});
btnStrike.addEventListener("mousedown", function(event){
document.execCommand("strikethrough");
console.log("Strikethrough successful");
event.preventDefault();
});
btnBold.addEventListener("mousedown", function(event){
document.execCommand("bold");
console.log("Bold formatted successful");
event.preventDefault();
});
btnItalic.addEventListener("mousedown", function(event){
document.execCommand("italic");
console.log("Italic formatted successful");
event.preventDefault();
});
btnUnderline.addEventListener("mousedown", function(event){
document.execCommand("underline");
console.log("Underline formatted successful");
event.preventDefault();
});
btnAddPage.addEventListener("mousedown", function(event) {
document.getElementById("page").appendChild(pageClone);
getComputedStyle(editor, pageClone);
});
// some functions
function openForm() {
document.getElementById("myForm").style.display = "block";
}
function closeForm() {
document.getElementById("myForm").style.display = "none";
}
spaceLeftScrub.oninput = function() {
editor.style.paddingLeft = spaceLeftScrub.value + 'px';
document.getElementById('spacing-left').innerHTML = 'Spacing left: ' + editor.style.paddingLeft;
console.log('editor left: ' + spaceLeftScrub.value + 'px')
}
spaceRightScrub.oninput = function() {
editor.style.paddingRight = spaceRightScrub.value + 'px';
document.getElementById('spacing-right').innerHTML = 'Spacing left: ' + editor.style.paddingRight;
console.log('editor right: ' + spaceRightScrub.value + 'px')
}
function myFunction() {
str1 = document.getElementById("title").value;
var str2 = " - Kasius Type";
if (str1 !='') {
var res = str1.concat(str2);
}
else {
str1 = 'Untitled';
var res = str1.concat(str2);
}
document.getElementById("pageTitle").innerHTML = res;
}
btnSpacing.onclick = function() {
spacingModal.style.display = "block";
}
btnclose.onclick = function() {
spacingModal.style.display = "none";
}
window.onlick = function(event) {
if (event.target == spacingModal) {
spacingModal.style.display = "none";
}
}
function saveDoc() {
var a = document.body.appendChild(
document.createElement('a')
);
a.download = str1 + '.html';
a.href = 'data:text/html,' + editor.innerHTML;
a.click();
}
function color() {
console.log("Changed color")
let color = document.getElementById("colorInput").value
document.getElementById("editor").style.color = document.getElementById("colorInput").value;
}
function font() {
console.log("Font changed")
let font = document.getElementById("fontInput").value;
document.execCommand('fontName', false, font);
document.getElementById("fontInput").style.fontFamily = document.getElementById("fontInput").value
}
function size() {
console.log("Font size changed");
let fontSize = document.getElementById("fontsizeInput");
document.getElementById("editor").style.fontSize = document.getElementById("fontsizeInput").value+"px"
};
// Warning before leaving the page (back button, or outgoinglink)
window.onbeforeunload = function() {
return "Do you really want to leave our brilliant application?";
//if we return nothing here (just calling return;) then there will be no pop-up question at all
//return;
};
const menu = document.getElementById('menu')
const outClick = document.getElementById('out-click')
editor.addEventListener('contextmenu', e => {
e.preventDefault()
menu.style.top = `${e.clientY}px`
menu.style.left = `${e.clientX}px`
menu.classList.add('show')
outClick.style.display = "block"
})
outClick.addEventListener('click', () => {
menu.classList.remove('show')
outClick.style.display = "none"
})
function speichern() {
var str1 = document.getElementById("title").value;
if (str1.value = "") {
str1.value = "Neues Dokument 1"
}
var str2 = " - Kasius Type";
var res = str1.concat(str2);
doc.save(document.getElementById("pageTitle").innerHTML = res + ".pdf");
}
/* When the user clicks on the button,
toggle between hiding and showing the dropdown content */
function showAccess() {
document.getElementById("allAccess").classList.toggle("show");
}
// Close the dropdown menu if the user clicks outside of it
window.onclick = function(event) {
if (!event.target.matches('.accessbtn')) {
var dropdowns = document.getElementsByClassName("access");
var i;
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
}