function moodle_initialise_body() {
document.body.className += ' jsenabled';
-}
\ No newline at end of file
+}
+
+/**
+ * Oject to handle a collapsible region, see print_collapsible_region in weblib.php
+ * @constructor
+ * @param String id the HTML id for the div.
+ * @param String userpref the user preference that records the state of this box. false if none.
+ * @param Boolean startcollapsed whether the box should start collapsed.
+ */
+function collapsible_region(id, userpref, strtooltip) {
+ // Record the pref name
+ this.userpref = userpref;
+
+ // Find the divs in the document.
+ this.div = document.getElementById(id);
+ this.innerdiv = document.getElementById(id + '_inner');
+ this.caption = document.getElementById(id + '_caption');
+ this.caption.title = strtooltip;
+
+ // Put the contents of caption in an <a> to make it focussable.
+ var a = document.createElement('a');
+ while (e = this.caption.firstChild) {
+ a.appendChild(e);
+ }
+ a.href = '#';
+ this.caption.appendChild(a);
+
+ // Create the animation.
+ this.animation = new YAHOO.util.Anim(this.div, {}, 0.3, YAHOO.util.Easing.easeBoth);
+
+ // Get to the right initial state.
+ if (this.div.className.match(/\bcollapsed\b/)) {
+ this.collapsed = true;
+ var region = YAHOO.util.Region.getRegion(this.caption);
+ this.div.style.height = (region.bottom - region.top) + 'px';
+ }
+
+ // Add the appropriate image.
+ this.icon = document.createElement('img');
+ this.icon.id = id + '_icon';
+ this.icon.alt = '';
+ if (this.collapsed) {
+ this.icon.src = moodle_cfg.pixpath + '/t/collapsed.png';
+ } else {
+ this.icon.src = moodle_cfg.pixpath + '/t/expanded.png';
+ }
+ this.caption.appendChild(this.icon);
+
+ // Hook up the event handler.
+ self = this;
+ YAHOO.util.Event.addListener(this.caption, 'click', function(e) {self.handle_click(e);});
+ YAHOO.util.Event.addListener(a, 'click', function(e) {self.handle_click(e);});
+}
+
+/**
+ * The user preference that stores the state of this box.
+ * @property userpref, innerdiv, captiondiv
+ * @type String
+ */
+collapsible_region.prototype.userpref = null;
+
+/**
+ * The key divs that make up this
+ * @property div, innerdiv, captiondiv
+ * @type HTMLDivElement
+ */
+collapsible_region.prototype.div = null;
+collapsible_region.prototype.innerdiv = null;
+collapsible_region.prototype.captiondiv = null;
+
+/**
+ * The key divs that make up this
+ * @property icon
+ * @type HTMLImageElement
+ */
+collapsible_region.prototype.icon = null;
+
+/**
+ * Whether the region is currently collapsed.
+ * @property collapsed
+ * @type Boolean
+ */
+collapsible_region.prototype.collapsed = false;
+
+/**
+ * @property animation
+ * @type YAHOO.util.Anim
+ */
+collapsible_region.prototype.animation = null;
+
+collapsible_region.prototype.handle_click = function(e) {
+ // Toggle the state.
+ this.collapsed = !this.collapsed;
+
+ // Stop the click following the link.
+ YAHOO.util.Event.stopEvent(e);
+
+ // Animate to the appropriate size.
+ if (this.animation.isAnimated()) {
+ this.animation.stop();
+ }
+ if (this.collapsed) {
+ var targetel = this.caption;
+ this.div.className += ' collapsed';
+ } else {
+ var targetel = this.innerdiv;
+ this.div.className = this.div.className.replace(/\s*\bcollapsed\b\s*/, ' ');
+ }
+ var region = YAHOO.util.Region.getRegion(targetel);
+ this.animation.attributes.height = { to: region.bottom - region.top, unit: 'px' };
+ this.animation.animate();
+
+ // Set the appropriate icon.
+ if (this.collapsed) {
+ this.icon.src = moodle_cfg.pixpath + '/t/collapsed.png';
+ } else {
+ this.icon.src = moodle_cfg.pixpath + '/t/expanded.png';
+ }
+
+ // Update the user preference.
+ if (this.userpref) {
+ set_user_preference(this.userpref, this.collapsed);
+ }
+}
return print_container_end($return);
}
+function print_collapsible_region($contents, $classes, $id, $caption, $userpref = '', $default = false, $return = false) {
+ $output = print_collapsible_region_start($classes, $id, $caption, $userpref, true);
+ $output .= $contents;
+ $output .= print_collapsible_region_end(true);
+
+ if ($return) {
+ return $output;
+ } else {
+ echo $output;
+ }
+}
+
+function print_collapsible_region_start($classes, $id, $caption, $userpref = false, $default = false, $return = false) {
+ global $CFG;
+
+ // Include required JavaScript libraries.
+ require_js(array('yui_yahoo', 'yui_dom-event', 'yui_event', 'yui_animation'));
+
+ // Work out the initial state.
+ if (is_string($userpref)) {
+ user_preference_allow_ajax_update($userpref, PARAM_BOOL);
+ $collapsed = get_user_preferences($userpref, $default);
+ } else {
+ $collapsed = $default;
+ $userpref = false;
+ }
+
+ $output = '';
+ $output .= '<div id="' . $id . '" class="collapsibleregion ' . $classes . '">';
+ $output .= '<div id="' . $id . '_inner" class="collapsibleregioninner">';
+ $output .= '<div id="' . $id . '_caption" class="collapsibleregioncaption">';
+ $output .= $caption . ' ';
+ $output .= "</div>\n";
+ $output .= print_js_call('new collapsible_region', array($id, $userpref, get_string('clicktohideshow')), true);
+
+ if ($return) {
+ return $output;
+ } else {
+ echo $output;
+ }
+}
+
+function print_collapsible_region_end($return = false) {
+ $output = '</div></div>';
+
+ if ($return) {
+ return $output;
+ } else {
+ echo $output;
+ }
+}
+
/**
* Print a message in a standard themed container.
*
function print_container($message, $clearfix=false, $classes='', $idbase='', $return=false) {
$output = print_container_start($clearfix, $classes, $idbase, true);
+ $output .= $message;
$output .= print_container_end(true);
if ($return) {