to make it focussable.
- var a = document.createElement('a');
- while (e = context.caption.firstChild) {
- a.appendChild(e);
- }
- a.href = '#';
- context.caption.appendChild(a);
-
- // Create the animation.
- context.animation = new Y.Anim({
- node: context.div,
- duration: 0.3,
- easing: Y.Easing.easeBoth
- });
-
- // Get to the right initial state.
- if (context.div.className.match(/\bcollapsed\b/)) {
- context.collapsed = true;
- var region = Y.one(context.caption).get('region');
- context.div.style.height = (region.bottom - region.top + 3) + 'px';
- }
-
- // Add the appropriate image.
- context.icon = document.createElement('img');
- context.icon.id = id + '_icon';
- context.icon.alt = '';
- if (context.collapsed) {
- context.icon.src = context.collapsedicon;
- } else {
- context.icon.src = context.expandedicon;
- }
- a.appendChild(context.icon);
-
- // Hook up the event handler.
- Y.on('click', context.handle_click, a, context);
-
- // Handler for the animation finishing.
- context.animation.on('end', function() {
- if (this.collapsed) {
- this.div.className += ' collapsed';
- }
- }, context);
- });
-}
-
-/**
- * The user preference that stores the state of this box.
- * @property userpref
- * @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 Y.Anim
- */
-collapsible_region.prototype.animation = null;
-
-/** When clicked, toggle the collapsed state, and trigger the animation. */
-collapsible_region.prototype.handle_click = function(e) {
- var context = this;
-
- YUI(M.yui.loader).use('anim', function(Y) {
- // Toggle the state.
- context.collapsed = !context.collapsed;
-
- // Stop the click following the link.
- e.preventDefault();
-
- // Animate to the appropriate size.
- if (context.animation.get('running')) {
- context.animation.stop();
- }
- if (context.collapsed) {
- var region = Y.one(context.caption).get('region');
- var targetheight = region.bottom - region.top + 3;
- } else {
- var region = Y.one(context.innerdiv).get('region');
- var targetheight = region.bottom - region.top + 2;
- context.div.className = context.div.className.replace(/\s*\bcollapsed\b\s*/, ' ');
- }
- context.animation.set('to', { height: targetheight });
- context.animation.run();
-
- // Set the appropriate icon.
- if (context.collapsed) {
- context.icon.src =context.collapsedicon;
- } else {
- context.icon.src = context.expandedicon;
- }
-
- // Update the user preference.
- if (context.userpref) {
- set_user_preference(context.userpref, context.collapsed);
- }
- });
-}
/**
* Oject to handle expanding and collapsing blocks when an icon is clicked on.
diff --git a/lib/weblib.php b/lib/weblib.php
index e00db532d22..601a477c963 100644
--- a/lib/weblib.php
+++ b/lib/weblib.php
@@ -2125,9 +2125,7 @@ function print_collapsible_region_start($classes, $id, $caption, $userpref = fal
$output .= '';
$output .= $caption . ' ';
$output .= '
';
- $PAGE->requires->js_function_call('new collapsible_region',
- array($id, $userpref, get_string('clicktohideshow'),
- $OUTPUT->pix_url('t/collapsed')->out(false), $OUTPUT->pix_url('t/expanded')->out(false)));
+ $PAGE->requires->js_init_call('M.util.init_collapsible_region', array($id, $userpref, get_string('clicktohideshow')));
if ($return) {
return $output;