[Rt-commit] r3426 - in rt/branches/3.5-TESTING: . html/Elements html/NoAuth/js html/Widgets

trs at bestpractical.com trs at bestpractical.com
Fri Jul 8 00:40:28 EDT 2005


Author: trs
Date: Fri Jul  8 00:40:27 2005
New Revision: 3426

Added:
   rt/branches/3.5-TESTING/html/NoAuth/js/titlebox-state.js
Modified:
   rt/branches/3.5-TESTING/   (props changed)
   rt/branches/3.5-TESTING/html/Elements/Header
   rt/branches/3.5-TESTING/html/NoAuth/js/util.js
   rt/branches/3.5-TESTING/html/Widgets/TitleBoxStart
Log:
 r4858 at wintermute:  tom | 2005-07-08 00:14:27 -0400
 Stateful titleboxes using JS and cookies.  The generated titlebox IDs should
 be unique.


Modified: rt/branches/3.5-TESTING/html/Elements/Header
==============================================================================
--- rt/branches/3.5-TESTING/html/Elements/Header	(original)
+++ rt/branches/3.5-TESTING/html/Elements/Header	Fri Jul  8 00:40:27 2005
@@ -59,9 +59,10 @@
     <link rel="alternate" href="<%$RSSAutoDiscovery%>" type="application/rss+xml" title="RSS RT Search" />
 % }
     <script type="text/javascript" src="<%$RT::WebPath%>/NoAuth/js/util.js"></script>
+    <script type="text/javascript" src="<%$RT::WebPath%>/NoAuth/js/titlebox-state.js"></script>
 <& /Elements/Callback, _CallbackName => 'Head', %ARGS &>
   </head>
-  <body onload="<% $onload |n %><% $Focus && qq[ setFocus('$Focus');] |n %>">
+  <body onload="<% "$onload;" |n %><% $Focus && qq[ setFocus('$Focus');] |n %>loadTitleBoxStates();">
 
 % if ($ShowBar) {
 <div id="quickbar">

Added: rt/branches/3.5-TESTING/html/NoAuth/js/titlebox-state.js
==============================================================================
--- (empty file)
+++ rt/branches/3.5-TESTING/html/NoAuth/js/titlebox-state.js	Fri Jul  8 00:40:27 2005
@@ -0,0 +1,34 @@
+function createCookie(name,value,days) {
+    var path = "<%$RT::WebPath%>" ? "<%$RT::WebPath%>" : "/";
+
+    if (days) {
+        var date = new Date();
+        date.setTime(date.getTime()+(days*24*60*60*1000));
+        var expires = "; expires="+date.toGMTString();
+    }
+    else
+        expires = "";
+    
+    document.cookie = name+"="+value+expires+"; path="+path;
+}
+
+function loadTitleBoxStates() {
+    var cookies = document.cookie.split(/;\s*/);
+    var len     = cookies.length;
+
+    for (var i = 0; i < len; i++) {
+        var c = cookies[i].split('=');
+        
+        if (c[0].match(/^TitleBox--/)) {
+            var e    = document.getElementById(c[0]);
+            var link = document.getElementById(c[0]+"-link");
+
+            if (c[1] != 0) {
+                set_rollup_state(e,link,'shown');
+            }
+            else {
+                set_rollup_state(e,link,'hidden');
+            }
+        }
+    }
+}

Modified: rt/branches/3.5-TESTING/html/NoAuth/js/util.js
==============================================================================
--- rt/branches/3.5-TESTING/html/NoAuth/js/util.js	(original)
+++ rt/branches/3.5-TESTING/html/NoAuth/js/util.js	Fri Jul  8 00:40:27 2005
@@ -1,23 +1,36 @@
 % $r->content_type('application/x-javascript');
 
-function rollup(link, id) {
-    var e = document.getElementById(id);
+function rollup(id) {
+    var e    = document.getElementById(id);
+    var link = document.getElementById(id+"-link");
     
     if (e.className.match(/\bhidden\b/)) {
-        show(e);
-        link.className = link.className.replace(/\s?\brolled-up\b/, '');
+        set_rollup_state(e,link,'shown');
+        createCookie(id,1,365);
     }
     else {
-        hide(e);
-        if (link.className)
-            link.className += ' rolled-up';
-        else
-            link.className = 'rolled-up';
+        set_rollup_state(e,link,'hidden');
+        createCookie(id,0,365);
     }
-    link.focus(0);
     return false;
 }
 
+function set_rollup_state(e,link,state) {
+    if (e && link) {
+        if (state == 'shown') {
+            show(e);
+            link.className = link.className.replace(/\s?\brolled-up\b/, '');
+        }
+        else if (state == 'hidden') {
+            hide(e);
+            if (link.className)
+                link.className += ' rolled-up';
+            else
+                link.className = 'rolled-up';
+        }
+    }
+}
+
 function hideshow(id) {
     var e = document.getElementById(id);
     

Modified: rt/branches/3.5-TESTING/html/Widgets/TitleBoxStart
==============================================================================
--- rt/branches/3.5-TESTING/html/Widgets/TitleBoxStart	(original)
+++ rt/branches/3.5-TESTING/html/Widgets/TitleBoxStart	Fri Jul  8 00:40:27 2005
@@ -45,10 +45,10 @@
 %# END BPS TAGGED BLOCK }}}
 <div class="titlebox<% $class && " $class" %>"<% $id && qq[ id="$id"] |n %>>
   <div class="title<% $title_class && " $title_class" %>">
-    <span><a href="#" onclick="return rollup(this, 'element-<%$rid%>');" onfocus="this.blur(); return false;">^</a></span>
+    <span><a href="#" id="<%$tid%>-link" onclick="return rollup('<%$tid%>');" onfocus="this.blur(); return false;">^</a></span>
     <% $title_href && qq[<a href="$title_href">] | n %><% $title |n %><% $title_href && "</a>" |n%>
   </div>
-  <div class="content<% $bodyclass && " $bodyclass" %>" id="element-<%$rid%>">
+  <div class="content<% $bodyclass && " $bodyclass" %>" id="<%$tid%>">
 
 <%ARGS>
 $width => undef
@@ -63,7 +63,19 @@
 $color => "#336699"
 $id => undef
 </%ARGS>
-
+<%once>
+my $cache;
+</%once>
 <%init>
-my $rid = rand(2000);
+#
+# This should be pretty bulletproof
+#
+my $page = $m->request_comp->path;
+my $tid  = "TitleBox--$page--" .
+            join '--', ($class, $bodyclass, $title, $id);
+
+my $i = 0;
+$i++ while $cache->{"$tid-$i"};
+$cache->{"$tid-$i"}++;
+$tid = "$tid-$i";
 </%init>


More information about the Rt-commit mailing list