templates/layout.tmpl
changeset 129 67a30d680f60
parent 119 df859bfdd3be
child 131 67f5d2fdca1d
--- a/templates/layout.tmpl	Sat Feb 14 20:13:26 2009 +0200
+++ b/templates/layout.tmpl	Sun Feb 15 23:50:24 2009 +0200
@@ -25,6 +25,37 @@
     <head>
         <title>irclogs.qmsk.net${(' :: ' + channel.title) if channel else ''}</title>
         <link rel="Stylesheet" type="text/css" href="${req.site_root}/static/irclogs.css" />
+    ## timezone-autodetect
+    % if prefs and prefs.is_default('timezone') :
+        <script language="Javascript" type="text/javascript">
+/*
+ * Set a preference cookie
+ */
+function set_pref (name, value) {
+    // XXX: expire?
+    document.cookie = (name + "=" + value + "; path=/");
+}
+
+/*
+ * Set the timezone_offset cookie to the current Date's timezone offset
+ */
+function autodetect_tz_offset () {
+    // current datetime
+    var now = new Date();
+
+    // timezone offset from UTC in minutes
+    var timezone_offset = -now.getTimezoneOffset()
+    
+    // store cookie with offset in minutes
+    set_pref('timezone_offset', timezone_offset);
+}
+
+/*
+ * Autodetect at load
+ */
+window.onload = autodetect_tz_offset;
+        </script>
+    % endif
     </head>
     <body>
         <div id="menu">