-
Notifications
You must be signed in to change notification settings - Fork 40
/
index-dev.html
209 lines (178 loc) · 5.81 KB
/
index-dev.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
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
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Relax...</title>
<meta name="HandheldFriendly" content="True">
<meta name="viewport" content="initial-scale = 1.0">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="stylesheet" href="vendor/css/grid.css" type-"text/css">
<link rel="stylesheet" href="vendor/css/meteo/stylesheet.css" type="text/css">
<link rel="stylesheet" href="vendor/css/fontello/fontello.css" type="text/css">
<link rel="stylesheet" href="vendor/css/glyphicons.css" type="text/css">
<link rel="stylesheet" href="vendor/css/editor.css" />
<link rel="stylesheet" href="static/css/fitgrd.pack.css" type="text/css">
<link rel="stylesheet" href="static/css/style.css" type="text/css">
<link rel="stylesheet" href="static/css/preview.css" type="text/css">
</head>
<body>
<div class="wrapper">
<header>
<div class="center">
<div class="row">
<div class="fg12 title-container">
<h1>Relax...</h1>
</div>
</div>
</div>
</header>
<section>
<div class="center">
<div class="row">
<div class="fg10">
<div class="editor-wrapper">
<form action="" id="editor">
<textarea placeholder="Please relax and type away..."></textarea>
</form>
</div>
</div>
<div class="fg2 sidebar">
<div id="soundlinks"></div>
<hr>
<div class="toolbar">
<p id="btn-save-wrapper"><a id="btn-save" href="#"><i class="glyphicon glyphicon-save"></i> Save as...</a></p>
<hr>
<p><i class="glyphicon glyphicon-open"></i> Open</p>
<p id="document-list"></p>
</div>
<hr>
<small class="notes">made with love by <a href="https://jehaisleprintemps.net">Bruno Bord</a> - © 2014. Grab <a href="https://github.com/brunobord/relax">the source on Github</a>, inspired by the fantastic concept of <a href="https://noisli.com">Noisli.com</a></small>
</div>
</div>
</div>
</section>
</div> <!-- /wrapper -->
<script type="text/javascript" src="vendor/js/jquery.min.js"></script>
<script type="text/javascript" src="vendor/js/jquery.jplayer.min.js"></script>
<script type="text/javascript" src="vendor/js/marked.js"></script>
<script type="text/javascript" src="vendor/js/codemirror.js"></script>
<script type="text/javascript" src="vendor/js/intro.js"></script>
<script type="text/javascript" src="vendor/js/editor.js"></script>
<script src="static/js/load.js"></script>
<script type="text/javascript">
if (!String.prototype.startsWith) {
Object.defineProperty(String.prototype, 'startsWith', {
enumerable: false,
configurable: false,
writable: false,
value: function (searchString, position) {
position = position || 0;
return this.indexOf(searchString, position) === position;
}
});
}
var myEditor;
$(document).ready(function() {
var prefix = 'relax';
// Load localStorage
var content = '';
if (localStorage[prefix]) {
content = localStorage[prefix];
}
myEditor = new Editor();
myEditor.render();
myEditor.codemirror.setValue(content);
var intervalID = window.setInterval(function() {
myEditor.element.value = myEditor.codemirror.getValue();
localStorage[prefix] = myEditor.element.value;
}, 500);
function loadDocuments() {
// clear the list
$('#document-list').html('');
// load from localStorage
for (var k in localStorage) {
if (k.startsWith(prefix+':')) {
var link = $('<a/>').attr({
'href': '#',
'class': 'load',
'data-document': k,
});
link.html(" " + k.replace(prefix+':', ''));
$('#document-list').append(link);
var link = $('<a/>').attr({
'href': '#',
'class': 'delete',
'data-document': k,
});
link.html('<i class="glyphicon glyphicon-trash"></i>');
$('#document-list').append(' ').append(link);
var link = $('<a/>').attr({
'href': '#',
'class': 'download',
'data-document': k,
});
link.html('<i class="glyphicon glyphicon-download"></i>');
$('#document-list').append(' ').append(link);
$('#document-list').append('<br/>');
}
};
$('.load').on('click', function() {
var name = $(this).data('document');
myEditor.codemirror.setValue(localStorage[name]);
});
$('.delete').on('click', function() {
var name = $(this).data('document');
localStorage.removeItem(name);
loadDocuments();
});
$('.download').on('click', function() {
var name = $(this).data('document');
var data = localStorage[name];
var filename = name.replace(prefix+':', '')+'.md';
saveTextAsFile(data, filename);
})
}
loadDocuments();
$('#btn-save').on('click', function() {
ok = false;
while (!ok) {
var name = prompt("File name?");
if (name === null) break;
if (localStorage[prefix+':'+name] === undefined) {
ok = true;
} else {
if (confirm('Are you sure you want to overwrite `'+name+'`?')) {
ok = true;
}
}
}
localStorage[prefix+':'+name] = localStorage[prefix];
loadDocuments();
});
function destroyClickedElement(event) {
document.body.removeChild(event.target);
}
function saveTextAsFile(text, filename) {
var textFileAsBlob = new Blob([text], {type:'text/plain'});
var downloadLink = document.createElement("a");
downloadLink.download = filename;
downloadLink.innerHTML = "Download File";
if (window.webkitURL != null) {
// Chrome allows the link to be clicked
// without actually adding it to the DOM.
downloadLink.href = window.webkitURL.createObjectURL(textFileAsBlob);
} else {
// Firefox requires the link to be added to the DOM
// before it can be clicked.
downloadLink.href = window.URL.createObjectURL(textFileAsBlob);
downloadLink.onclick = destroyClickedElement;
downloadLink.style.display = "none";
document.body.appendChild(downloadLink);
}
downloadLink.click();
}
});
</script>
</body>
</html>