From: defacer Date: Wed, 9 Feb 2005 01:23:06 +0000 (+0000) Subject: Redoing the hide/show thingy for blocks purely through CSS. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=d4f7a8152dba6d33edf91f2a75b9431c79ecbf83;p=moodle.git Redoing the hide/show thingy for blocks purely through CSS. Instance id's next time, Urs! ;-) --- diff --git a/lib/container.js b/lib/container.js index 436c1a3876..f320ff8e89 100644 --- a/lib/container.js +++ b/lib/container.js @@ -1,22 +1,69 @@ -function containerDisplaySwitching(id) -{ - var id_cont = id + "_cont"; - var x = new getObj(id_cont); - var what = (x.style.display == 'inline' || x.style.display == '') ? 'none' : 'inline'; - x.style.display = what; - new cookie(id, what, 356, '/').set(); +/* + findParentNode (start, elementName, elementClass, elementID) + + Travels up the DOM hierarchy to find a parent element with the + specified tag name, class, and id. All conditions must be met, + but any can be ommitted. Returns the BODY element if no match + found. +*/ +function findParentNode(el, elName, elClass, elId) { + while(el.nodeName != 'BODY') { + if( + (!elName || el.nodeName == elName) && + (!elClass || el.className.indexOf(elClass) != -1) && + (!elId || el.id == elId)) + { + break; + } + el = el.parentNode; + } + return el; } -function containerDisplaySet(id) -{ - var id_cont = id + "_cont"; - var x = new getObj(id_cont); - var what = new cookie(id).read(); - if (what != null) { - x.style.display = what; +/* + elementToggleHide (element, elementFinder) + + If elementFinder is not provided, toggles the "hidden" class for the specified element. + If elementFinder is provided, then the "hidden" class will be toggled for the object + returned by the function call elementFinder(element). + + If persistent == true, also sets a cookie for this. +*/ +function elementToggleHide(el, persistent, elementFinder) { + if(!elementFinder) { + var obj = el; + } + else { + var obj = elementFinder(el); + } + if(obj.className.indexOf('hidden') == -1) { + obj.className += ' hidden'; + var shown = 0; + } + else { + obj.className = obj.className.replace(new RegExp(' ?hidden'), '') + var shown = 1; + } + + if(persistent == true) { + new cookie('hide:' + obj.id, 1, (shown ? -1 : 356), '/').set(); + } +} + + +function elementCookieHide(id) { + var obj = document.getElementById(id); + var cook = new cookie('hide:' + id).read(); + if(cook != null) { + elementToggleHide(obj, false); } } +/* + +Is there some specific reason for this function? I think pretty +much every browser worth considering supports getElementById() [Jon] + function getObj(id) { if (document.getElementById) @@ -35,3 +82,4 @@ function getObj(id) this.style = document.layers[id]; } } +*/ diff --git a/lib/weblib.php b/lib/weblib.php index 7014470c19..b581d9befa 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -3544,47 +3544,43 @@ function print_side_block_start($heading='', $attributes = array()) { else if(!strpos($attributes['class'], 'sideblock')) { $attributes['class'] .= ' sideblock'; } + // OK, the class is surely there and in addition to anything // else, it's tagged as a sideblock + /* + + // IE misery: if I do it this way, blocks which start hidden cannot be "unhidden" + + // If there is a cookie to hide this thing, start it hidden + if(!empty($attributes['id']) && isset($_COOKIE['hide:'.$attributes['id']])) { + $attributes['class'] = 'hidden '.$attributes['class']; + } + */ + $attrtext = ''; foreach($attributes as $attr => $val) { $attrtext .= ' '.$attr.'="'.$val.'"'; } - echo ''; + echo ''; if ($heading) { - // orig echo ''; echo ''; } - // orig echo '
'.$heading.'
'.$heading; - if(isset($attributes['id'])) { - echo ''; - } + echo '
'; echo '
'; - if(isset($attributes['id'])) { - echo '
'; - } - else { - echo '
'; - } + + echo '
'; } /** * Print table ending tags for a side block box. */ -function print_side_block_end($attributes = array()) { - echo '
'; - // js call to set block display state which is saved in cookie. - if(isset($attributes['id'])) { - echo "\n "; - echo "\n"; - } +function print_side_block_end($attributes) { + echo ''; + // IE workaround: if I do it THIS way, it works! WTF? + echo ''; } diff --git a/theme/standard/styles_layout.css b/theme/standard/styles_layout.css index 5880aa4c5b..8985bd0569 100644 --- a/theme/standard/styles_layout.css +++ b/theme/standard/styles_layout.css @@ -456,6 +456,17 @@ td.cal_event_description { border-top:1px solid; } +.sideblock .sideblockheading .hide-show img { + background: url('../../pix/t/switch.gif') no-repeat bottom; +} + +.sideblock.hidden .sideblockheading .hide-show img { + background: url('../../pix/t/down.gif') no-repeat bottom; +} + +.sideblock.hidden .sideblockmain { + display: none; +} /* sideblock weblib.php */ #block_course_summary .sideblockmain { diff --git a/theme/standard/styles_moz.css b/theme/standard/styles_moz.css index 8dba94fe9e..e9d53f2146 100644 --- a/theme/standard/styles_moz.css +++ b/theme/standard/styles_moz.css @@ -16,6 +16,10 @@ -moz-border-radius-bottomright:20px; } +#left-column .hidden, #right-column .hidden { + -moz-border-radius: 0px; +} + .generalbox { -moz-border-radius-topleft:3px; -moz-border-radius-topright:3px;