]> git.mjollnir.org Git - moodle.git/commitdiff
I added all code to handle the cookies and the sideblock content, the icon and the...
authorurs_hunkler <urs_hunkler>
Sat, 5 Feb 2005 21:37:53 +0000 (21:37 +0000)
committerurs_hunkler <urs_hunkler>
Sat, 5 Feb 2005 21:37:53 +0000 (21:37 +0000)
How it works:
_ within the "sideblockheading" a DIV with class="hide-show" holds a link calling the JS containerDisplaySwitching(). To the user it's represented by the icon "switch.gif" (a plus in a square) at the right end side of the header.
_ all content of the sideblock is surounded by a new <div class="blockcontent" id="'.$attributes['id']."_cont\">"
_ a call of the JS containerDisplaySwitching() changes the state of the appropriate DIV with the content to "display:none/inline" and writes this state into a cookie.
_ at the end of every block I added a call to the JS "containerDisplaySet()". This reads the block's state and hides the content or leaves it visible with every page load.
_ in the stylesheet I added the positioning of the icon:
.sideblockheading .hide-show {
    float:right;
}
.sideblockheading a img.hide-show-image {
    padding-top:0.25em;
}

lib/container.js [new file with mode: 0644]
lib/cookies.js [new file with mode: 0644]
lib/javascript.php
lib/weblib.php
pix/t/switch.gif [new file with mode: 0644]
theme/orangewhite/styles_layout.css
theme/standard/styles_layout.css

diff --git a/lib/container.js b/lib/container.js
new file mode 100644 (file)
index 0000000..436c1a3
--- /dev/null
@@ -0,0 +1,37 @@
+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();
+}
+
+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;
+    }
+}
+
+function getObj(id)
+{
+  if (document.getElementById)
+  {
+       this.obj = document.getElementById(id);
+       this.style = document.getElementById(id).style;
+  }
+  else if (document.all)
+  {
+       this.obj = document.all[id];
+       this.style = document.all[id].style;
+  }
+  else if (document.layers)
+  {
+       this.obj = document.layers[id];
+       this.style = document.layers[id];
+  }
+}
diff --git a/lib/cookies.js b/lib/cookies.js
new file mode 100644 (file)
index 0000000..966b7c2
--- /dev/null
@@ -0,0 +1,84 @@
+/*******************************************************
+COOKIE FUNCTIONALITY
+Based on "Night of the Living Cookie" by Bill Dortch
+(c) 2003, Ryan Parman
+http://www.skyzyx.com
+Distributed according to SkyGPL 2.1, http://www.skyzyx.com/license/
+*******************************************************/
+function cookie(name, value, expires, path, domain, secure)
+{
+       // Passed Values
+       this.name=name;
+       this.value=value;
+       this.expires=expires;
+       this.path=path;
+       this.domain=domain;
+       this.secure=secure;
+
+       // Read cookie
+       this.read=function()
+       {
+               // To allow for faster parsing
+               var ck=document.cookie;
+
+               var arg = this.name + "=";
+               var alen = arg.length;
+               var clen = ck.length;
+               var i = 0;
+
+               while (i < clen)
+               {
+                       var j = i + alen;
+                       if (ck.substring(i, j) == arg)
+                       {
+                               var endstr = ck.indexOf (";", j);
+                               if (endstr == -1) endstr = ck.length;
+                               return unescape(ck.substring(j, endstr));
+                       }
+                       i = ck.indexOf(" ", i) + 1;
+                       if (i == 0) break;
+               }
+               return null;
+       }
+
+       // Set cookie
+       this.set=function()
+       {
+               // Store initial value of "this.expires" for re-initialization.
+               expStore=this.expires;
+
+               // Set time to absolute zero.
+               exp = new Date();
+               base = new Date(0);
+               skew = base.getTime();
+               if (skew > 0)  exp.setTime (exp.getTime() - skew);
+               exp.setTime(exp.getTime() + (this.expires*24*60*60*1000));
+               this.expires=exp;
+
+               document.cookie = this.name + "=" + escape (this.value) +
+                               ((this.expires) ? "; expires=" + this.expires.toGMTString() : "") +
+                               ((this.path) ? "; path=" + this.path : "") +
+                               ((this.domain) ? "; domain=" + this.domain : "") +
+                               ((this.secure) ? "; secure" : "");
+
+               // Re-initialize
+               this.expires=expStore;
+       }
+
+       // Kill cookie
+       this.kill=function()
+       {
+               document.cookie = this.name + "=" +
+                               ((this.path) ? "; path=" + this.path : "") +
+                               ((this.domain) ? "; domain=" + this.domain : "") +
+                               "; expires=Thu, 01-Jan-70 00:00:01 GMT";
+       }
+
+       // Change cookie settings.
+       this.changeName=function(chName) { this.kill(); this.name=chName; this.set(); }
+       this.changeVal=function(chVal) { this.kill(); this.value=chVal; this.set(); }
+       this.changeExp=function(chExp) { this.kill(); this.expires=chExp; this.set(); }
+       this.changePath=function(chPath) { this.kill(); this.path=chPath; this.set(); }
+       this.changeDomain=function(chDom) { this.kill(); this.domain=chDom; this.set(); }
+       this.changeSecurity=function(chSec) { this.kill(); this.secure=chSec; this.set(); }
+}
index d4dd36c6fc91f027b8aeda321b792b224cfbf164..d871c780b885f105f7d3e4a8a77143e8060605d8 100644 (file)
@@ -11,6 +11,9 @@
 ?>
 <script language="JavaScript" type="text/javascript" src="<?php echo $CFG->wwwroot ?>/lib/overlib.js"></script>
 <script language="JavaScript" type="text/javascript" src="<?php echo $CFG->wwwroot ?>/lib/javascript-static.js"></script>
+<script language="JavaScript" type="text/javascript"
+src="<?php echo "$CFG->wwwroot/lib/container.js" ?>"></script><script language="JavaScript" type="text/javascript"
+src="<?php echo "$CFG->wwwroot/lib/cookies.js" ?>"></script>
 <script language="JavaScript" type="text/javascript">
 
 <!-- // Non-Static Javascript functions
index 0ab26b2fdd466a22b7220a61df03060131a73f7e..8bd9a29e534caa094749eb5a33416ccdc8c32cb6 100644 (file)
@@ -3504,7 +3504,7 @@ function print_side_block($heading='', $content='', $list=NULL, $icons=NULL, $fo
         echo '</table>';
     }
 
-    print_side_block_end();
+    print_side_block_end($attributes);
 }
 
 /**
@@ -3516,6 +3516,7 @@ function print_side_block($heading='', $content='', $list=NULL, $icons=NULL, $fo
  */
 function print_side_block_start($heading='', $attributes = array()) {
 
+    global $CFG;
     // If there are no special attributes, give a default CSS class
     if(empty($attributes) || !is_array($attributes)) {
         $attributes = array('class' => 'sideblock');
@@ -3536,17 +3537,32 @@ function print_side_block_start($heading='', $attributes = array()) {
 
     echo '<table class="sideblock" cellspacing="0" cellpadding="5"'.$attrtext.'>';
     if ($heading) {
-        echo '<thead><tr><td class="sideblockheading">'.$heading.'</td></tr></thead>';
+        // orig echo '<thead><tr><td class="sideblockheading">'.$heading.'</td></tr></thead>';
+        echo '<thead>
+        <tr>
+            <td class="sideblockheading">'
+            .$heading.
+            '<div class="hide-show">
+                <a href="javascript:containerDisplaySwitching('."'".$attributes['id']."'".');"\ >'."<img src=\"$CFG->pixpath/t/switch.gif\" alt=\"\" height=\"11\" width=\"11\" class=\"hide-show-image\" />".'</a>
+            </div>
+            </td>
+        </tr>
+        </thead>';
     }
-    echo '<tbody><tr><td class="sideblockmain">';
+    // orig echo '<tbody><tr><td class="sideblockmain">';
+    echo '<tbody><tr><td class="sideblockmain"><div class="blockcontent" id="'.$attributes['id']."_cont\">";
 }
 
 
 /**
  * Print table ending tags for a side block box.
  */
-function print_side_block_end() {
-    echo '</td></tr></tbody></table>';
+function print_side_block_end($attributes = array()) {
+    echo '</div></td></tr></tbody></table>';
+    // js call to set block display state which is saved in cookie.
+    echo "\n <script language=\"JavaScript\"> <!-- //hide ";
+    echo "\n containerDisplaySet(\"".$attributes['id']."\");";
+    echo "\n // done hiding --> </script>";
     echo "\n";
 }
 
diff --git a/pix/t/switch.gif b/pix/t/switch.gif
new file mode 100644 (file)
index 0000000..84ac353
Binary files /dev/null and b/pix/t/switch.gif differ
index 2c6d3e5835417b1865dd86a3e997726ed6f519bf..48ede844c3a9fbea5bcc0e6b1645470e264b7793 100644 (file)
@@ -676,6 +676,14 @@ TD.cal_event_description {
     padding-top:0.5em;
 }
 
+.sideblockheading .hide-show {
+    float:right;
+}
+
+.sideblockheading a img.hide-show-image {
+    padding-top:0.35em;
+}
+
 .sideblockmain HR {
        height:1px;
        border:none;
index 8b96433e1c594861ae1c995c8df0c64cab2249e9..4fcaaa79950f363142b6cf635af0a86b6606f7c4 100644 (file)
@@ -436,6 +436,14 @@ td.cal_event_description {
     background-repeat:repeat-x;
 }
 
+.sideblockheading .hide-show {
+    float:right;
+}
+
+.sideblockheading a img.hide-show-image {
+    padding-top:0.25em;
+}
+
 .sideblockmain hr {
     height:1px;
     margin-top:4px;