js stuff
authorMart Lubbers <mart@martlubbers.net>
Tue, 6 May 2014 20:01:53 +0000 (22:01 +0200)
committerMart Lubbers <mart@martlubbers.net>
Tue, 6 May 2014 20:01:53 +0000 (22:01 +0200)
program/hypfront/hyper.py
program/hypfront/sel.js [new file with mode: 0644]

index e773f86..bcf521e 100644 (file)
@@ -1,11 +1,11 @@
 #!/bin/env python
 # -*- coding: utf-8 -*-
 
+from mod_python import apache
 import feedparser
-import urllib
 import pprint
 import re
-from mod_python import apache
+import urllib
 
 
 def req_pre(req):
@@ -16,8 +16,13 @@ def req_pre(req):
 <html>
     <head>
         <title>HyperFrontend RSS feed input</title>
+        <script src="sel.js"></script>
     </head>
     <body>
+    Selecteer iets en klik de link<br />
+    <button onclick="javascript:f_wie()">Wie</button>
+    <button onclick="javascript:f_wat()">Wat</button>
+    <button onclick="javascript:f_wan()">Wanneer</button>
 """)
 
 
@@ -34,13 +39,15 @@ def feed2html(req, url, name):
     req.write('\tLoading "{}" as "{}"<br />\n'.format(url, name))
     feed = feedparser.parse(url)
     channel = feed.feed
-    req.write('\t<table border="1">\n')
-    req.write('\t\t<tr><th>Title</th><th>...</th></tr>\n')
+    req.write('\t<table border="1" id="htab">\n')
+    req.write('\t\t<tr><th>Title</th><th>Summary</th><th>...</th></tr>\n')
     for i in feed.entries:
-        req.write('\t\t<tr><td>{}</td><td>...</td></tr>\n'.
-                  format(i['title'].encode('ascii', 'xmlcharrefreplace')))
-
-    req.write('\t</table>\n')
+        req.write('\t\t<tr><td>{}</td><td>{}</td><td>...</td></tr>\n'.
+                  format(i['title'].encode('ascii', 'xmlcharrefreplace'),
+                         i['summary'].encode('ascii', 'xmlcharrefreplace')))
+    req.write('\t</table>\n<br />')
+    for k, v in feed.entries[0].iteritems():
+        req.write('{}: {}<br />\n'.format(k, v))
 
 
 def handler(req):
diff --git a/program/hypfront/sel.js b/program/hypfront/sel.js
new file mode 100644 (file)
index 0000000..1cd90a7
--- /dev/null
@@ -0,0 +1,58 @@
+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;
+               }
+       }
+       return html;
+}
+
+function stylizeHighlightedString() 
+{
+    var range               = window.getSelection().getRangeAt(0);
+    var selectionContents   = range.extractContents();
+    var span                = document.createElement("span");
+    span.appendChild(selectionContents);
+    span.setAttribute("class","uiWebviewHighlight");
+
+    span.style.backgroundColor  = "red";
+    span.style.color            = "white";
+
+    range.insertNode(span);
+}
+
+function f_wan() {
+       console.log("wanneer")
+       console.log(getSelectionHtml());
+       stylizeHighlightedString()
+}
+
+function f_wie() {
+       console.log("wie")
+       console.log(getSelectionHtml());
+}
+
+function f_wat() {
+       console.log("wat")
+       console.log(getSelectionHtml());
+}
+
+
+window.onload = function() {
+       var box = document.getElementById('htab');
+       box.addEventListener('contextmenu', function(e) {
+               console.log(getSelectionHtml());
+       });
+}
+
+