expected note title feature added
This commit is contained in:
@@ -3,7 +3,28 @@ var iosDetected = navigator.userAgent.match("(iPad|iPod|iPhone)");
|
||||
var timer = null;
|
||||
var timerDelay = iosDetected ? 800 : 400;
|
||||
var show = function(elem) { elem.style.display = "block" }
|
||||
var $note, $action, $preview, $plain_password, $input_elems, $dashed_line, updatePreview;
|
||||
var $note, $action, $preview, $plain_password, $input_elems, $dashed_line, $proposed_title, updatePreview;
|
||||
var firstLines_;
|
||||
var backendTimer;
|
||||
|
||||
function updateProposedTitle() {
|
||||
clearTimeout(backendTimer);
|
||||
backendTimer = setTimeout(function () {
|
||||
var http = new XMLHttpRequest();
|
||||
var url = "/propose-title";
|
||||
http.open("POST", url, true);
|
||||
http.onreadystatechange = function() {
|
||||
if(http.readyState == 4 && http.status == 200) {
|
||||
var now = new Date();
|
||||
$proposed_title.innerHTML =
|
||||
"Expected URL: https://www.notehub.org/" +
|
||||
now.getFullYear() + "/" + (now.getMonth()+1) + "/" + now.getDate() + "/" +
|
||||
http.responseText;
|
||||
}
|
||||
}
|
||||
http.send($note.value);
|
||||
}, 500);
|
||||
}
|
||||
|
||||
function md2html(input){
|
||||
return marked(input);
|
||||
@@ -14,6 +35,7 @@ function onLoad () {
|
||||
$action = $("action");
|
||||
$preview = $("preview");
|
||||
$plain_password = $("plain-password");
|
||||
$proposed_title = $("proposed-title");
|
||||
$input_elems = $("input-elems");
|
||||
$dashed_line = $("dashed-line");
|
||||
updatePreview = function(){
|
||||
@@ -24,6 +46,11 @@ function onLoad () {
|
||||
show($dashed_line);
|
||||
show($input_elems);
|
||||
$preview.innerHTML = md2html(content);
|
||||
var firstLines = content.split("\n", 2);
|
||||
if(firstLines_ != firstLines) {
|
||||
firstLines_ = firstLines;
|
||||
updateProposedTitle();
|
||||
}
|
||||
}, delay);
|
||||
};
|
||||
if($action){
|
||||
|
||||
Reference in New Issue
Block a user