@ -10,7 +10,7 @@
<meta name="google" value="notranslate">
<meta name="google" value="notranslate">
</head>
</head>
<body id="pad" class="light">
<body id="pad" class="light classic ">
<div id="overlay"></div>
<div id="overlay"></div>
@ -19,6 +19,7 @@
<!-- Markdown <input type=radio name=inputformat value=markdown checked> </label> -->
<!-- Markdown <input type=radio name=inputformat value=markdown checked> </label> -->
<!-- <label> <input type=radio name=inputformat value=prosemirror> WYSIWYM</label> -->
<!-- <label> <input type=radio name=inputformat value=prosemirror> WYSIWYM</label> -->
<!-- </div> -->
<!-- </div> -->
<input type="text" id="title" name="title" placeholder="Title..." {{if .Post.Title}}value="{{.Post.Title}}"{{end}} autofocus />
<div id="editor" style="margin-bottom: 0"></div>
<div id="editor" style="margin-bottom: 0"></div>
<div style="display: none"><textarea id="content"{{if .Post.Content }} value={{.Post.Content}}>{{.Post.Content}}{{else}}>{{end}}</textarea></div>
<div style="display: none"><textarea id="content"{{if .Post.Content }} value={{.Post.Content}}>{{.Post.Content}}{{else}}>{{end}}</textarea></div>
@ -93,6 +94,7 @@
if (H.get('padTheme', 'light') != 'light') {
if (H.get('padTheme', 'light') != 'light') {
toggleTheme();
toggleTheme();
}
}
var $ title = H.getEl('title');
var $ writer = H.getQEl('div.ProseMirror');
var $ writer = H.getQEl('div.ProseMirror');
var $ content = H.getEl('content');
var $ content = H.getEl('content');
var $ btnPublish = H.getEl('publish');
var $ btnPublish = H.getEl('publish');
@ -103,6 +105,10 @@
if (val != '') {
if (val != '') {
words = $ content . el . value . trim ().replace(/\s+/gi, ' ').split(' ').length;
words = $ content . el . value . trim ().replace(/\s+/gi, ' ').split(' ').length;
}
}
val = $ title . el . value . trim ();
if (val != '') {
words += $ title . el . value . trim ().replace(/\s+/gi, ' ').split(' ').length;
}
$ wc . el . innerText = words + " word" + (words != 1 ? "s" : "");
$ wc . el . innerText = words + " word" + (words != 1 ? "s" : "");
};
};
var setButtonStates = function() {
var setButtonStates = function() {
@ -118,7 +124,7 @@
};
};
{{if .Post.Id}}var draftDoc = 'draft{{.Post.Id}}';
{{if .Post.Id}}var draftDoc = 'draft{{.Post.Id}}';
var origDoc = '{{.Post.Content}}';{{else}}var draftDoc = 'lastDoc';{{end}}
var origDoc = '{{.Post.Content}}';{{else}}var draftDoc = 'lastDoc';{{end}}
H.load( $ content , draftDoc, true);
H.loadClassic( $ title , $ writer , draftDoc, true);
updateWordCount();
updateWordCount();
var typingTimer;
var typingTimer;
@ -140,7 +146,7 @@
var publishing = false;
var publishing = false;
var justPublished = false;
var justPublished = false;
var silenced = {{.Silenced}};
var silenced = {{.Silenced}};
var publish = function(content, font) {
var publish = function(title, content, font) {
if (silenced === true) {
if (silenced === true) {
alert("Your account is silenced, so you can't publish or update posts.");
alert("Your account is silenced, so you can't publish or update posts.");
return;
return;
@ -165,7 +171,7 @@
var params = {
var params = {
body: post.content,
body: post.content,
title: post. title,
title: title,
font: font,
font: font,
lang: lang
lang: lang
};
};
@ -248,6 +254,21 @@
};
};
setButtonStates();
setButtonStates();
$ title . on ('keyup input', function() {
setButtonStates();
clearTimeout(typingTimer);
typingTimer = setTimeout(doneTyping, doneTypingInterval);
}, false);
$ title . on ('keydown', function(e) {
if (e.keyCode == 13) {
if (e.metaKey || e.ctrlKey) {
$ btnPublish . el . click ();
} else {
e.preventDefault();
$ writer . el . focus ();
}
}
});
$ writer . on ('keyup input', function() {
$ writer . on ('keyup input', function() {
setButtonStates();
setButtonStates();
clearTimeout(typingTimer);
clearTimeout(typingTimer);
@ -262,8 +283,9 @@
$ btnPublish . on ('click', function(e) {
$ btnPublish . on ('click', function(e) {
e.preventDefault();
e.preventDefault();
if (!publishing && $ content . el . value ) {
if (!publishing && $ content . el . value ) {
var title = $ title . el . value ;
var content = $ content . el . value ;
var content = $ content . el . value ;
publish(content, selectedFont);
publish(title, content, selectedFont);
}
}
});
});
@ -329,6 +351,7 @@
e.preventDefault();
e.preventDefault();
selectedFont = this.href.substring(this.href.indexOf(' #')+1);
selectedFont = this.href.substring(this.href.indexOf(' #')+1);
// TODO: don't change classes on the editor window
// TODO: don't change classes on the editor window
// $ title . el . className = selectedFont;
// $ writer . el . className = selectedFont;
// $ writer . el . className = selectedFont;
document.querySelector('nav #font - picker li . selected ' ).classList.remove( ' selected ' );
document.querySelector('nav #font - picker li . selected ' ).classList.remove( ' selected ' );
this.parentElement.classList.add('selected');
this.parentElement.classList.add('selected');
@ -346,7 +369,7 @@
var doneTyping = function() {
var doneTyping = function() {
if (draftDoc == 'lastDoc' || $ content . el . value != origDoc) {
if (draftDoc == 'lastDoc' || $ content . el . value != origDoc) {
H.save( $ content , draftDoc);
H.saveClassic ( $ title , $ content , draftDoc);
updateWordCount();
updateWordCount();
}
}
};
};