A pastebin for markdown pages.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.6 KiB

var $ = function(id){ return document.getElementById(id); }
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;
12 years ago
var md5 = function (input) {
12 years ago
return hex_md5(input.replace(/[\n\r]/g, ""));
12 years ago
}
function md2html(input){
12 years ago
return marked(input);
}
function onLoad() {
12 years ago
$note = $("note");
$action = $("action");
$preview = $("preview");
$plain_password = $("plain-password");
$input_elems = $("input-elems");
$dashed_line = $("dashed-line");
updatePreview = function(){
clearTimeout(timer);
var content = $note.value;
var delay = Math.min(timerDelay, timerDelay * (content.length / 400));
timer = setTimeout(function(){
show($dashed_line);
show($input_elems);
$preview.innerHTML = md2html(content);
}, delay);
};
if($action){
if($action.value == "update") updatePreview(); else $note.value = "";
$note.onkeyup = updatePreview;
$("publish-button").onclick = function(e) {
if($plain_password.value != "") $("password").value = md5($plain_password.value);
$plain_password.value = null;
$("signature").value = md5($("session").value + $note.value);
}
12 years ago
if(iosDetected) $note.className += " ui-border"; else $note.focus();
}
12 years ago
var mdDocs = document.getElementsByClassName("markdown");
for(var i = 0; i < mdDocs.length; i++){
var elem = mdDocs[i];
var child = elem.childNodes[0];
elem.innerHTML = md2html(child.value);
show(elem);
12 years ago
}
}