From: Mart Lubbers Date: Wed, 14 May 2014 14:36:02 +0000 (+0200) Subject: stuff X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=7e1254b690cd23df9746fcbd2b1c23cadeaa8aa7;p=bsc-thesis1415.git stuff --- diff --git a/program/hypfront/contextmenu_o.js b/program/hypfront/contextmenu_o.js index 568cce4..468cfc6 100644 --- a/program/hypfront/contextmenu_o.js +++ b/program/hypfront/contextmenu_o.js @@ -1,3 +1,4 @@ +var selection; var mouse_x = 0; var mouse_y = 0; var mouse_left = false; @@ -20,13 +21,15 @@ function RightMouseDown() { } function init(a, w) { + console.log(a) var b = document.createElement("DIV"); b.id = "contextmenu"; if (!w) var w = 120; b.style.width = w + "px"; - var c = '
'; + var c = '
'; c += a; c += '
'; + console.log(c) b.innerHTML = c; b.style.position = "absolute"; b.style.left = "0px"; @@ -41,7 +44,10 @@ function init(a, w) { } function mouseUp(e) { - selection = getSelectionHtml() + var curselection = window.getSelection().getRangeAt(0); + if (curselection.endOffset - curselection.startOffset > 0) + selection = curselection; + console.log(selection) if (e.which == 1) document.getElementById("contextmenu").style.visibility = "hidden"; else if (e.which == 3) mouse_right = false } @@ -52,25 +58,45 @@ function mouseDown(e) { document.getElementById("contextmenu").style.left = mouse_x + "px"; document.getElementById("contextmenu").style.top = mouse_y + "px"; document.getElementById("contextmenu").style.visibility = "visible" - console.log(selection) } } -function getSelectionHtml() { - var html = ""; - if (typeof window.getSelection != "undefined") { - var sel = window.getSelection(); - if (sel.rangeCount) { - var container = document.createElement("div"); - for (var i = 0, len = sel.rangeCount; i < len; ++i) { - container.appendChild(sel.getRangeAt(i).cloneContents()); - } - html = container.innerHTML; - } - } else if (typeof document.selection != "undefined") { - if (document.selection.type == "Text") { - html = document.selection.createRange().htmlText; + +function stylizeHighlightedString(range, col) +{ + var selectionContents = range.extractContents(); + var span = document.createElement("span"); + span.appendChild(selectionContents); + span.setAttribute("class","uiWebviewHighlight"); + span.style.backgroundColor = col; + span.style.color = "white"; + range.insertNode(span); +} + +function f_wanneer() { + stylizeHighlightedString(selection, "red") +} + +function f_wat() { + stylizeHighlightedString(selection, "green") +} + +function f_waar() { + stylizeHighlightedString(selection, "blue") +} + +function post_all() { + var xmlhttp = new XMLHttpRequest(); + xmlhttp.onreadystatechange=function() + { + if (xmlhttp.readyState==4) + { + document.write(xmlhttp.responseText); } } - return html; + var params = "content="+encodeURIComponent(document.getElementsByTagName("table")[0].innerHTML); + xmlhttp.open("POST", "hyper.py", true); + xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); + xmlhttp.setRequestHeader("Content-length", params.length); + xmlhttp.send(params); } diff --git a/program/hypfront/hyper.py b/program/hypfront/hyper.py index edf4786..7640394 100644 --- a/program/hypfront/hyper.py +++ b/program/hypfront/hyper.py @@ -16,7 +16,7 @@ def req_pre(req): HyperFrontend RSS feed input - +