This repository has been archived by the owner on May 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.js
95 lines (82 loc) · 3.03 KB
/
action.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
'use strict';
let originData;
let browserError;
window.onload = function() {
if (!(navigator.userAgent.indexOf('AppleWebKit') != -1)) {
browserError = true;
alertCloseBtn.classList.add('hidden');
browserAlertMessage.classList.remove('hidden');
alertScreen.classList.remove('hidden');
} else if (/mobile/i.test(navigator.userAgent)) {
mobileAlertMessage.classList.remove('hidden');
alertScreen.classList.remove('hidden');
}
if (localStorage.getItem('state-of-sw-size') == 'true') document.getElementById('sw-size').checked = true;
if (localStorage.getItem('state-of-sw-font') == 'true') document.getElementById('sw-font').checked = true;
if (localStorage.getItem('state-of-sw-auto') == 'true') document.getElementById('sw-auto').checked = true;
};
function pressedSwitch(theSwitch) {
let state = document.getElementById(theSwitch).checked;
localStorage.setItem('state-of-' + theSwitch, state);
if (theSwitch !== 'sw-auto' && CKEDITOR.instances.editor.mode === 'source') processHtml(originData);
}
/* Work with the result panel above the CKEditor */
resultScreen.addEventListener('click', function() {
if (isHover(copyButton) === true) {
copyStringToClipboard(CKEDITOR.instances.editor.getData());
} else {
originData = '';
CKEDITOR.instances.editor.setData('');
/* It is this strange because of a strange bug with focus */
CKEDITOR.instances.editor.setMode('wysiwyg', function() {
CKEDITOR.instances.editor.focus();
});
resultScreen.style.display = 'none';
}
});
function isHover(element) {
return element.parentElement.querySelector(':hover') === element;
}
// From StackOverflow
function copyStringToClipboard(str) {
/* Create new element */
let el = document.createElement('textarea');
/* Set value (string to be copied) */
el.value = str;
/* Set non-editable to avoid focus and move outside of view */
el.setAttribute('readonly', '');
el.style = { position: 'absolute', left: '-9999px' };
document.body.appendChild(el);
/* Select text inside element */
el.select();
/* Copy text to clipboard */
document.execCommand('copy');
/* Remove temporary element */
document.body.removeChild(el);
}
function performPasting(evtData) {
originData = getFixedData(evtData);
evtData = '';
CKEDITOR.instances.editor.setMode('source');
resultScreen.style.display = 'block';
processHtml(originData);
}
/* Work with alert screen */
let arrayOfAlertMessages = document.getElementsByClassName('alert__message');
alertScreen.addEventListener('click', function() {
if (isHover(alertContent) == false && browserError == false) {
alertScreen.classList.add('hidden');
hideArrayItems(arrayOfAlertMessages);
}
});
alertCloseBtn.addEventListener('click', function() {
alertScreen.classList.add('hidden');
hideArrayItems(arrayOfAlertMessages);
});
function hideArrayItems(classElements) {
for (let element of classElements) element.classList.add('hidden');
}
function pressedInfo() {
infoAlertMessage.classList.remove('hidden');
alertScreen.classList.remove('hidden');
}