-
Notifications
You must be signed in to change notification settings - Fork 2
/
engross.js
95 lines (78 loc) · 2.42 KB
/
engross.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
(function() {
var $ = document.querySelector.bind(document);
var fs = (function() {
var body = document.documentElement,
rfs = body.requestFullscreen || body.webkitRequestFullscreen,
efs = document.exitFullscreen || document.webkitExitFullscreen;
this.toggle = function() {
if (!(document.fullscreenElement || document.webkitFullscreenElement)) {
if (rfs) {
rfs.call(body, [Element.ALLOW_KEYBOARD_INPUT]);
}
else if (body.mozRequestFullScreen) {
alert('Sorry, Firefox is too lame to support keyboard input in fullsceen.');
}
else {
alert('Sorry, your browser is too lame to support fullscreen');
}
}
else {
if (efs) {
efs.apply(document);
}
}
}.bind(this);
return this;
})();
var c = $('#content'),
t = $('#title');
var lastItem = localStorage.getItem('lastItem'),
items = JSON.parse(localStorage.getItem('items')),
currentItem = null;
function clearPlaceholder(e) {
e.target.innerHTML = '';
var range = document.createRange(),
selection = window.getSelection();
range.selectNodeContents(e.target);
selection.removeAllRanges();
selection.addRange(range);
e.target.removeEventListener('focus', clearPlaceholder);
}
if (lastItem && (currentItem = items[lastItem])) {
t.innerHTML = currentItem.title;
c.innerHTML = currentItem.content;
c.focus();
var range = document.createRange(),
selection = window.getSelection();
range.selectNodeContents(c);
range.collapse(false);
selection.removeAllRanges();
selection.addRange(range);
}
else {
t.innerHTML = 'This is where you write the title';
c.innerHTML = 'This is where you write whatever you want to write.<br><br>WARNING: THIS IS A WORK IN PROGRESS. DON\'T USE THIS FOR ANYTHING SERIOUS';
t.addEventListener('focus', clearPlaceholder);
c.addEventListener('focus', clearPlaceholder);
items = [];
currentItem = {
title: '',
content: ''
};
items.push(currentItem);
localStorage.setItem('lastItem', 0);
}
$('button[fs]').addEventListener('click', function() {
fs.toggle();
})
document.addEventListener('DOMContentLoaded', function() {
});
document.documentElement.addEventListener('keyup', function(e) {
currentItem.title = t.innerHTML;
currentItem.content = c.innerHTML;
localStorage.setItem('items', JSON.stringify(items));
});
$('button[light]').addEventListener('click', function() {
document.documentElement.classList.toggle('dark');
});
}());