-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate.html
More file actions
305 lines (276 loc) · 13.6 KB
/
Copy pathcreate.html
File metadata and controls
305 lines (276 loc) · 13.6 KB
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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset='utf-8'>
<meta name="viewport" content="width=device-width, initial-scale=1,user-scalable=no">
<title>Create Note | Notable</title>
<!-- notable-css -->
<link rel="stylesheet" href="style.css">
<link rel="icon"href="app data/ico@max.png">
<!-- bs link -->
<link rel="stylesheet" href="res/bs.css">
<!-- mt de ic cdn -->
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<!-- github@sndresorhus's css for github markdown -->
<link rel="stylesheet" href="res/ghmdsindre.css">
<!-- meta -->
<meta name="description" content="this is Bosted's note editing app.">
<meta name="theme-color" content="#6610f2">
<script>
if(localStorage.mode==="dark"){var styleFordark = document.createElement("style"); styleFordark.innerHTML=`body{background:#181614;} .form-control,.form-control[readonly],.form-control:focus{background: transparent;color:#efefef !important;}textarea:focus{color:#efefef;}textarea,div.fullscreen-div{ color:#efefef;}.material-icons{ color:#efefef !important;}.markdown-body pre{background:#0d1e1f;}.markdown-body table th,.markdown-body td{background:#101025;}`;document.head.append(styleFordark);}
getParam=(p,str)=>{
var url = new URL(str);
var c = url.searchParams.get(p);
console.log(c);return c}
window.addEventListener("load", function (){
if(sessionStorage.i!=null&&getParam("edit",window.location.href)!=null){
$("input[data-id-of-note]").value=sessionStorage.i.replaceAll("#","");
$("input[data-id-of-note]").readOnly=true;
$("input[data-id-of-note]").addEventListener('click',function(){
swalt("you can not change id in editing session <br> sorry",{
title:'You can not change id',mode:localStorage.mode
})
})
}
if(sessionStorage.cnt!=null&&getParam("edit",window.location.href)!=null){
$("textarea[data-type=input-for-note]").value=sessionStorage.cnt;
}
});
</script>
</head>
<body class="page-create">
<div class="fullscreen-div markdown-body"data-type="preview-for-note">
</div>
<textarea class="fullscreen-div"style="outline:none; background: transparent;"data-type="input-for-note" placeholder="> start Note here"></textarea>
<div data-type="toolbar-op" >
<button data-href="index.html" data-type="back from-for-note" class="btn mt-ico-nt cc"><i class="material-icons" style="margin:auto;">arrow_back</i></button>
<button data-type="done-for-note" class="btn mt-ico-nt cc" data-saver><i class="material-icons" style="margin:auto;" >save</i></button>
<button data-type="back from-for-note" class="btn mt-ico-nt cc"><i class="material-icons" style="margin:auto;" onclick="guide()">help</i></button>
</div>
<div data-type="toolbar-op">
<button data-type="preview-for-note" class="btn mt-ico-nt cc"><i class="material-icons" style="margin:auto;">play_circle</i></button>
<input type="text" class="form-control cc" placeholder="Enter title" data-title-of-note><input type="text" class="form-control cc" placeholder="Enter id" oninput="this.value=this.value.replaceAll('#','').replaceAll(' ','').replaceAll('<','');" data-id-of-note >
</div>
<notable-post-cdns>
<script src="res/sd.js"></script>
<!-- bs script -->
<script src="res/bs.js"></script>
<!-- github@codeninja02's alerts cdn -->
<script src="res/swalt@codeninja02.js"></script>
</notable-post-cdns>
<script>
var encodeInfos ={
"base":{
ret:atob,
pus:btoa
},
"ascii":{
ret:unescape,
pus:escape
},
"none":{
ret:simpleText,
pus:simpleText
}
}
showdown.setFlavor('github');
showdown.setOption('ghMentions', 'true');
showdown.setOption('ghMentionsLink', '#{u}');
showdown.setOption('underline', 'true');
$ = (str) =>{
return document.querySelector(str);
}
$all = (str) =>{
return document.querySelectorAll(str)
}
var previewIsOn=false;
$("button[data-type=preview-for-note]").addEventListener('click', function (){
if(previewIsOn!=true){
previewIsOn=true;
$("button[data-saver]").disabled=true;
var converter = new showdown.Converter();
this.style.border="1px solid #6610f2";
var text = $("textarea[data-type=input-for-note]").value;
html = converter.makeHtml(text);
html = html.replaceAll("&gt","<");
$("textarea[data-type=input-for-note]").placeholder="";
$("div[data-type=preview-for-note]").innerHTML = html;
$("textarea[data-type=input-for-note]").value="";
$("textarea[data-type=input-for-note]").style.display="none";
this.innerHTML=`<i class="material-icons" style="margin:auto;">play_disabled</i>`;
$all("a").forEach(function (e){
e.dataset.href=e.href;
e.href="#"
console.log(e.href);
e.addEventListener('click', function (e){
swalt(`
${this.dataset.href} will be loaded after click .
You can't leave now because the note will not be saved.
<br>
still if you want to go then
<a href="${this.dataset.href}">click here</a>
`,{
title:"you can't leave session",
btnValue:"I understood",
});
});
});
this.addEventListener('dblclick', function (){
$("button[data-saver]").disabled=false;
this.innerHTML=`<i class="material-icons" style="margin:auto;">play_circle</i>`;
previewIsOn=false;
this.style.border="1px solid transparent"
$("textarea[data-type=input-for-note]").placeholder="> start Note here";
$("div[data-type=preview-for-note]").innerHTML="";
$("textarea[data-type=input-for-note]").focus();
$("textarea[data-type=input-for-note]").style.display="block";
$("textarea[data-type=input-for-note]").value=text;
});
}
});
function guide (){
swalt(`
<div style="text-align:left; overflow:scroll" class="markdown-body">
<h3>Info</h3><br>
This is markdown editor for notes
for getting started with id code in the input area.<br>
<hr />
<h3>Preview</h3><br>
By clicking (button in ui)<br>
<i class="material-icons">play_circle</i><br>
You will get preview of your md note
<br>
To continue writing back from preview you should click on(same button)<br>
<i class="material-icons">play_disabled</i><br>
double times.
<hr>
<h3>Type tools</h3>
<i class="material-icons">format_italic</i><br>
<i>italic </i> : this is used to convert your md note template's particular word/sentence/paragraph into italic format.
<br>After clicking on it it'll provide you 2 stars like <kbd>**</kbd>.
You have to type your matter between two stars but you have no need to do it your cursor/caret will already present there(between two stars).If it won't you have to do at your self.
<br><kbd>*italic*</kbd> => <i>italic</i><br>
<i class="material-icons">format_bold</i>
<br>
<b>bold </b> : This is type of bold text. It works similarly as italic but in bold there are 4 stars like <kbd>****</kbd><br>
keep cursor between them if it's not automatically .<br>
<kbd>**bold**</kbd> => <b>bold</b><br>
<i class="material-icons">link</i><br>
<a href="#">link </a> : This will help to make text formatted links means not showing url links.after clicking you will get alert and you have to fill infos about link it's simple.
<kbd>[title](link) </kbd> => <a href="#" class="btn-link">title</a><br>
<i class="material-icons">strikethrough_s</i><i class="material-icons">format_underlined</i>
strike through and underline<br>
Both works similarly but underline have <kbd> ____ </kbd> four underscores amd strike through have <kbd> ~~~~ </kbd> four this type of symbols.you have to keep cursor in between it if it doesn't automatically.<br>
<kbd> __under__ </kbd> => <u>under</u><br>
<kbd> ~~strike~~ </kbd> => <del>strike</del><br>
<i class="material-icons">unfold_less</i>
This is just to remove toolbar when you are getting hard to see your md note template.
<hr>
</div>
`,{
title:"<h5>Guide for md notable editor</h5>",
btnValue:"Got it !",
mode: localStorage.mode || "light",
});
}
/*buttons as link*/
$all("button").forEach(function (e){if(e.dataset.href){e.addEventListener('click',()=>{window.location.assign(e.dataset.href)});}});
/*creating toolbar*/
var textToolbarElement = [ { icon:"format_italic",fun: function (e,t,ta){var pos = ta.selectionStart;ta.value=ta.value.substring(0,pos) + "**"+ta.value.substring(pos,ta.value.length);setCursor(ta,pos+1);}},{icon:"format_bold",fun: function (e,t,ta){var pos = ta.selectionStart;ta.value=ta.value.substring(0,pos) + "****"+ta.value.substring(pos,ta.value.length);setCursor(ta,pos+2);}},{icon:"format_underlined",fun: function (e,t,ta){var pos = ta.selectionStart;ta.value=ta.value.substring(0,pos) + " ____ "+ta.value.substring(pos,ta.value.length);setCursor(ta,pos+3);}},{icon:"strikethrough_s",fun:function (e,t,ta){var pos = ta.selectionStart; ta.value=ta.value.substring(0,pos) + "~~~~"+ta.value.substring(pos,ta.value.length);setCursor(ta,pos+2);}},{icon:"link",fun: function (e,t,ta){ var al = document.createElement("div");var inAl = document.createElement("div");inAl.style.paddingTop=15+"px"; al.classList.add('alert-super-container',`alert-${localStorage.mode}`); document.body.append(al);al.append(inAl); inAl.classList.add('alert-container'); inAl.style.paddingBottom="0";inAl.innerHTML=`<p class="para">Enter information about url</p><div style="padding:15px;" ><input style="margin-bottom:5px;"class="alert-input" placeholder="Enter title for url" data-input-link-0><input placeholder="Enter url" class="alert-input" data-input-link-1 ></div><div style="display:flex;width:100%;"><button class='alert-btn'style='border-radius:0;border-left:0;border-right:0;border-bottom:0' data-close-btn-alert-of-link>Close</button><button class='alert-btn' style="border-radius:0;border-left:0;border-right:0;border-bottom:0;" data-add-alert-link>Add</button> </div>`;$("button[data-close-btn-alert-of-link]").addEventListener('click', function (){al.remove();});t.remove();$("textarea[data-type=input-for-note]").style.height="calc(100vh - 100px)";$("div[data-type=preview-for-note]").style.height="calc(100vh - 100px)";$("button[data-add-alert-link]").addEventListener('click', function(){link = $("input[data-input-link-1]").value;tit = $("input[data-input-link-0]").value;var pos = ta.selectionStart; ta.value=ta.value.substring(0,pos) +` [${tit}](${link}) `+ta.value.substring(pos,ta.value.length); setCursor(ta,pos+tit.length+link.length+6);al.remove(); }); }},{ icon:"unfold_less", fun:(e,t,ta)=>{t.remove();$("textarea[data-type=input-for-note]").style.height="calc(100vh - 100px)";$("div[data-type=preview-for-note]").style.height="calc(100vh - 100px)";}}]
$("textarea[data-type=input-for-note]").addEventListener('focus', function (e){
if(!$(".toolbar-on-focus")){
var toolbar = document.createElement('div');
toolbar.classList.add('toolbar-on-focus');
document.body.append(toolbar);
$("textarea[data-type=input-for-note]").style.height="calc(100vh - 150px)";
$("div[data-type=preview-for-note]").style.height="calc(100vh - 150px)";
for(tool of textToolbarElement){
var tl = document.createElement('button');
tl.classList.add('btn','mt-ico-nt')
tl.innerHTML=`<i class="material-icons">${tool.icon}</i>`
toolbar.append(tl);
tl.dataset.num=textToolbarElement.indexOf(tool);
tl.addEventListener('click', function (e){
textToolbarElement[this.dataset.num].fun(e,toolbar,$("textarea[data-type=input-for-note]"));
});
}
}
});
function setCursor(elemId, caretPos) {
var elem = elemId;
if(elem != null) {
if(elem.createTextRange) {
var range = elem.createTextRange();
range.move('character', caretPos);
range.select();
}
else {
if(elem.selectionStart) {
elem.focus();
elem.setSelectionRange(caretPos, caretPos);
}
else
elem.focus();
}
}
}
function simpleText(s) {
return s;
}
if(!sessionStorage.encodeType){
sessionStorage.encodeType="none";
}
$("button[data-saver]").addEventListener('click', function (){
var title_of_note = $("input[data-title-of-note]").value;
var id_of_note =$("input[data-id-of-note]").value.replaceAll('<','');
if(id_of_note!=""&&title_of_note!=""&&id_of_note!=" "*id_of_note&&title_of_note!=" "*title_of_note){
var isEdit = getParam("edit",window.location.href||location.href);
console.log(localStorage.noteStores)
var allNotes = JSON.parse(localStorage.noteStores);
if(Object.keys(allNotes).includes(id_of_note)&&isEdit!="true"){
swalt(`Id is already in use try something another ..`,{
title:"ID is already taken try any another",
btnValue:'okay',mode:localStorage.mode||"light",
});
}else{
if(allNotes[id_of_note]){
if(allNotes[id_of_note]){
allNotes[id_of_note]={
title:title_of_note,
id:id_of_note,
generatedId:Object.keys(allNotes).length,
content:$("textarea[data-type=input-for-note]").value,
cat:allNotes[id_of_note].cat
}
}else{
allNotes[id_of_note]={
title:title_of_note,
id:id_of_note,
generatedId:Object.keys(allNotes).length,
content:$("textarea[data-type=input-for-note]").value,
}
}
}else{
allNotes[id_of_note]={
title:title_of_note,
id:id_of_note,
generatedId:Object.keys(allNotes).length,
content:$("textarea[data-type=input-for-note]").value,}
}
localStorage.noteStores=JSON.stringify(allNotes);
swalt(`NOTE is saved successfully <br>with id ${id_of_note} <br>`,{
title:"SAVED",
btnValue:'okay',mode:localStorage.mode||"light",
});
}
}else{
swalt("Please make sure that you entered title and id for note and 0 is not allowed at first position of title or id.",{
title:"Something went wrong",
mode:localStorage.mode||"light",
btnValue:"okay"
});
}
});
</script>
</body>
</html>