migrated to API internally

This commit is contained in:
Christian Mueller
2014-01-15 19:47:44 +01:00
parent 5cca39b41b
commit a245dd8bcf
11 changed files with 115 additions and 182 deletions
+8 -20
View File
@@ -1,36 +1,24 @@
var hash = function (input) {
var shortMod = function(i) { return i % 32767 };
var charCodes = input.split("")
.filter(function(c){ return c != "\n" && c != "\r" })
.map(function(c){ return c.charCodeAt(0) });
var h = 0;
for(var i in charCodes)
h = shortMod(h + shortMod(charCodes[i] * (h % 2 != 0 ? 16381 ^ i : 16381 & i)));
return h;
}
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 $draft, $action, $preview, $password, $plain_password, $input_elems, $dashed_line, updatePreview;
var $note, $action, $preview, $plain_password, $input_elems, $dashed_line, updatePreview;
function md2html(input){
return marked(input);
}
function loadPage() {
$draft = $("draft");
$note = $("note");
$action = $("action");
$preview = $("preview");
$password = $("password");
$plain_password = $("plain-password");
$input_elems = $("input-elems");
$dashed_line = $("dashed-line");
updatePreview = function(){
clearTimeout(timer);
var content = $draft.value;
var content = $note.value;
var delay = Math.min(timerDelay, timerDelay * (content.length / 400));
timer = setTimeout(function(){
show($dashed_line);
@@ -39,14 +27,14 @@ function loadPage() {
}, delay);
};
if($action){
if($action.value == "update") updatePreview(); else $draft.value = "";
$draft.onkeyup = updatePreview;
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);
if($plain_password.value != "") $("password").value = md5($plain_password.value);
$plain_password.value = null;
$("session-value").value = hash($draft.value + $("session-key").value);
$("signature").value = md5($("session").value + $note.value);
}
if(iosDetected) $draft.className += " ui-border"; else $draft.focus();
if(iosDetected) $note.className += " ui-border"; else $note.focus();
}
var mdDocs = document.getElementsByClassName("markdown");