Move Guru Meditation javascript code outside
authorBernie Innocenti <bernie@codewiz.org>
Wed, 8 Apr 2009 16:21:21 +0000 (18:21 +0200)
committerBernie Innocenti <bernie@codewiz.org>
Wed, 8 Apr 2009 16:21:21 +0000 (18:21 +0200)
geekigeeki.py
gurumeditation.js [new file with mode: 0644]

index 774225ba4ae53f125fb5ff0bc39f9a36766eba97..9f4400fef4a2a4c30d24d5840817d7024a7d9ccb 100755 (executable)
@@ -81,6 +81,13 @@ def permalink(s):
 def emit_header(mime_type="text/html"):
     print "Content-type: " + mime_type + "; charset=utf-8\n"
 
+def sendfile(dest_file, src_file):
+    """Efficiently copy file data between file descriptors"""
+    while 1:
+        data = src_file.read(65536)
+        if not data: break
+        dest_file.write(data)
+
 def send_guru(msg_text, msg_type):
     if not msg_text: return
     print '<pre id="guru" onclick="this.style.display = \'none\'" class="' + msg_type + '">'
@@ -90,28 +97,10 @@ def send_guru(msg_text, msg_type):
     if msg_type == 'error':
         print '\n      Guru Meditation #DEADBEEF.ABADC0DE'
     print '</pre>'
-    # FIXME: This little JS snippet is harder to pass than ACID 3.0 
-    print """
-    <script language="JavaScript" type="text/javascript">
-        var guru = document.getElementById('guru');
-        // Firefox 2.0 doesn't take border-color, but returns border-top-color fine
-        var color = document.defaultView.getComputedStyle(guru,null).getPropertyValue('border-top-color');
-
-        function guruOn() {
-            guru.style.setProperty('border-color', color, '');
-            setTimeout('guruOff()', 1000);
-        }
-        function guruOff() {
-            guru.style.setProperty('border-color', '#000000', '');
-            setTimeout('guruOn()', 1000);
-        }
-        // Safari 2.0 returns this rgba crap
-        // Konqueror 3.5.6 doesn't seem to support computed properties
-        if (color && color != 'rgba(0, 0, 0, 0)') {
-            //window.alert("enabled! color='" + color + "'");
-            guruOn();
-        }
-    </script>"""
+    try:
+        sendfile(sys.stdout, open('gurumeditation.js', 'rb'))
+    except IOError, err:
+        pass
 
 def send_title(name, text="Limbo", msg_text=None, msg_type='error', writable=False):
     global title_done
diff --git a/gurumeditation.js b/gurumeditation.js
new file mode 100644 (file)
index 0000000..0f783a9
--- /dev/null
@@ -0,0 +1,25 @@
+<script language="JavaScript" type="text/javascript">
+// Copyright 2008, 2009 Bernie Innocenti <bernie@codewiz.org>
+//
+// FIXME: The following JS snippet is harder to pass than ACID 3
+
+var guru = document.getElementById('guru');
+
+// Firefox 2.0 doesn't take border-color, but returns border-top-color fine
+var color = document.defaultView.getComputedStyle(guru,null).getPropertyValue('border-top-color');
+
+function guruOn() {
+       guru.style.setProperty('border-color', color, '');
+       setTimeout('guruOff()', 1000);
+}
+function guruOff() {
+       guru.style.setProperty('border-color', '#000000', '');
+       setTimeout('guruOn()', 1000);
+}
+// Safari 2.0 returns this rgba crap
+// Konqueror 3.5.6 doesn't seem to support computed properties
+if (color && color != 'rgba(0, 0, 0, 0)') {
+       //window.alert("enabled! color='" + color + "'");
+       guruOn();
+}
+</script>