Commit 7aab2e48 authored by Thomas Sibley's avatar Thomas Sibley
Browse files

Stateful titleboxes using JS and cookies. The generated titlebox IDs should

be unique.

git-svn-id: svn+ssh://svn.bestpractical.com/svn/bps-public/rt/branches/3.5-TESTING@3426 e417ac7c-1bcc-0310-8ffa-8f5827389a85
parent 206f9303
......@@ -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">
......
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');
}
}
}
}
% $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);
......
......@@ -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 @@ $contentbg => "#dddddd"
$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>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment