aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorthe little girl <yui@blekksprut.net>2014-02-28 14:35:39 +0100
committerthe little girl <yui@blekksprut.net>2014-02-28 14:35:39 +0100
commitc9f565d621357397a8e561a0699e653ea306b449 (patch)
tree23f98489435c683aa57d952d5f4ca9d519fef954
parentbc199a9c3100b48d8109a010006655bf8ea1895b (diff)
downloadukulele-c9f565d621357397a8e561a0699e653ea306b449.tar.xz
wiki.js
-rw-r--r--wiki.js110
1 files changed, 110 insertions, 0 deletions
diff --git a/wiki.js b/wiki.js
new file mode 100644
index 0000000..4c6cab4
--- /dev/null
+++ b/wiki.js
@@ -0,0 +1,110 @@
+function insert(text) {
+ var t = document.getElementsByName('t')[0];
+ if(!t) return;
+ if(t.selectionStart || t.selectionStart == '0') {
+ var pos = t.selectionStart;
+ var end = t.selectionEnd;
+ t.value = t.value.substring(0, pos) + text + t.value.substring(end, t.value.length);
+ } else {
+ t.value += s;
+ }
+}
+
+function wrap(prefix, postfix) {
+ var t = document.getElementsByName('t')[0];
+ if(!t) return;
+ if(t.selectionStart || t.selectionStart == '0') {
+ var pos = t.selectionStart;
+ var end = t.selectionEnd;
+ var n = t.value.indexOf("\n", pos);
+ if(n > 0 && n < end) end = n;
+ t.value = t.value.substring(0, pos) + prefix + t.value.substring(pos, end) + postfix + t.value.substring(end, t.value.length);
+ }
+ t.focus();
+ var cpos = t.selectionEnd + prefix.length + postfix.length;
+ t.setSelectionRange(cpos, cpos);
+}
+
+function marxup_bold(e) {
+ wrap("*", "*");
+}
+
+function marxup_header(e) {
+ wrap("= ", "");
+}
+
+function marxup_italics(e) {
+ wrap("_", "_");
+}
+
+function marxup_link(e) {
+ wrap("[", "]");
+}
+
+function marxup_quote(e) {
+ var t = document.getElementsByName('t')[0];
+ if(!t) return;
+ if(t.selectionStart || t.selectionStart == '0') {
+ var pos = t.selectionStart;
+ var end = t.selectionEnd;
+ for(;pos < end; pos++) {
+ if(t.value.charAt(pos) != "\n") break;
+ }
+ var quote = "";
+ var lines = t.value.substring(pos, end).split("\n");
+ var cpos = end;
+ for(var i=0; i < lines.length; i++) {
+ if(lines[i].length > 0) {
+ quote += "\n> " + lines[i];
+ cpos += 2;
+ }
+ }
+ if(t.value.substring(pos - 1, pos) == "\n")
+ quote = quote.trim() + "\n";
+ t.value = t.value.substring(0, pos) + quote + t.value.substring(end, t.value.length);
+ }
+ t.focus();
+ t.setSelectionRange(cpos, cpos);
+}
+
+function button(node, html, fun) {
+ var a = document.createElement("a");
+ a.innerHTML = html;
+ a.href = "#";
+ a.onclick = fun;
+ node.parentNode.insertBefore(a, node.nextSibling);
+}
+
+function pick(src) {
+ insert("\n@" + src.replace(".t.jpg", "") + "\n");
+}
+
+document.addEventListener("DOMContentLoaded", function(e) {
+ var title = document.getElementsByTagName('h1')[0];
+ var headers = document.getElementsByTagName("h2");
+ if(headers.length > 0) {
+ var menu = document.createElement("div"); menu.className = 'magisk meny';
+ for(var i = 0; i < headers.length; i++) {
+ var a = document.createElement("a");
+ var id = "h-" + i; headers[i].id = id; a.href = "#" + id;
+ a.textContent = headers[i].textContent;
+ menu.appendChild(a);
+ menu.appendChild(document.createElement("br"));
+ }
+ title.parentNode.insertBefore(menu, title.nextSibling);
+ }
+
+ var orz = document.getElementById('orz');
+ if(orz) {
+ orz.onclick = function(e) {
+ window.open("/orz");
+ return false;
+ }
+ button(orz, "> sitat", marxup_quote);
+ button(orz, "[lenke]", marxup_link);
+ button(orz, "<i>_kursiv_</i>", marxup_italics);
+ button(orz, "<b>*fet*</b>", marxup_bold);
+ button(orz, "= overskrift", marxup_header);
+ }
+});
+