diff --git a/blocks/admin_tree/admintree.js b/blocks/admin_tree/admintree.js new file mode 100644 index 00000000000..bbf92a4d489 --- /dev/null +++ b/blocks/admin_tree/admintree.js @@ -0,0 +1,75 @@ +admin_tree = { + numdivs: null, + hiddennodes: null, + closedimg: null, + openimg: null, + closedalt: null, + openalt: null, + + init: function(numdivs, expandnodes, pixpath, openalt, closedalt) { + // Store the information we were passed in. + admin_tree.closedimg = pixpath + '/i/closed.gif'; + admin_tree.openimg = pixpath + '/i/open.gif'; + admin_tree.closedalt = closedalt; + admin_tree.openalt = openalt; + admin_tree.numdivs = numdivs; + + // Initialise the hiddennodes array. + admin_tree.hiddennodes = new Array(); + for (var i = 1; i <= admin_tree.numdivs; i++) { + admin_tree.hiddennodes[i] = null; + } + + // Collapse everything while adding the event handlers. + for (var i = admin_tree.numdivs; i > 0; i--) { + admin_tree.collapse(i); + var togglelink = document.getElementById("vh_div" + i + "indicator").parentNode; + togglelink.href = '#'; + YAHOO.util.Event.addListener(togglelink, 'click', admin_tree.toggle, i); + } + + // Re-expand the bits we want expanded. + for (var i = 0; i < expandnodes.length; i++) { + admin_tree.expand(expandnodes[i]); + } + }, + + toggle: function(e, i) { + if (admin_tree.hiddennodes[i] === null) { + admin_tree.collapse(i); + } else { + admin_tree.expand(i); + } + YAHOO.util.Event. preventDefault(e); + }, + + collapse: function(i) { + if (admin_tree.hiddennodes[i] !== null) { + return; + } + var obj = document.getElementById("vh_div" + i); + if (obj === null) { + return; + } + var nothing = document.createElement("span"); + nothing.setAttribute("id", "vh_div" + i); + admin_tree.hiddennodes[i] = obj; + obj.parentNode.replaceChild(nothing, obj); + var icon = document.getElementById("vh_div" + i + "indicator"); + icon.src = admin_tree.closedimg; + icon.alt = admin_tree.closedalt; + }, + + expand: function(i) { + if (admin_tree.hiddennodes[i] === null) { + return; + } + var nothing = document.getElementById("vh_div" + i); + var obj = admin_tree.hiddennodes[i]; + admin_tree.hiddennodes[i] = null; + nothing.parentNode.replaceChild(obj, nothing); + var icon = document.getElementById("vh_div" + i + "indicator"); + icon.src = admin_tree.openimg; + icon.alt = admin_tree.openalt; + } +}; diff --git a/blocks/admin_tree/block_admin_tree.php b/blocks/admin_tree/block_admin_tree.php index 14cd47ee5c2..d7ac10ecf42 100644 --- a/blocks/admin_tree/block_admin_tree.php +++ b/blocks/admin_tree/block_admin_tree.php @@ -18,7 +18,7 @@ class block_admin_tree extends block_base { $this->tempcontent = ''; $this->section = (isset($PAGE->section) ? $PAGE->section : ''); $this->pathtosection = array(); - $this->expandjavascript = ''; + $this->expandnodes = array(); } function applicable_formats() { @@ -37,8 +37,8 @@ class block_admin_tree extends block_base { global $CFG; $strfolderopened = s(get_string('folderopened')); - $this->tempcontent .= '