// Get the expandable items so we can pass them to JS
$expandable = array();
$navigation->find_expandable($expandable);
+ if ($expansionlimit) {
+ foreach ($expandable as $key=>$node) {
+ if ($node['type'] > $expansionlimit && !($expansionlimit == navigation_node::TYPE_COURSE && $node['type'] == $expansionlimit && $node['branchid'] == SITEID)) {
+ unset($expandable[$key]);
+ }
+ }
+ }
// Initialise the JS tree object
$module = array('name'=>'block_navigation', 'fullpath'=>'/blocks/navigation/navigation.js', 'requires'=>array('core_dock', 'io', 'node', 'dom', 'event-custom', 'json-parse'), 'strings'=>array(array('viewallcourses','moodle')));
// Attach event to toggle expansion
node.all('.tree_item.branch').on('click', this.toggleexpansion , this);
- // Attache events to expand by AJAX
+ // Attach events to expand by AJAX
+ //var expandablenode;
for (var i in this.expansions) {
- this.Y.one('#'+this.expansions[i].id).on('ajaxload|click', this.init_load_ajax, this, this.expansions[i]);
- M.block_navigation.expandablebranchcount++;
+ var expandablenode = Y.one('#'+this.expansions[i].id);
+ if (expandablenode) {
+ expandablenode.on('ajaxload|click', this.init_load_ajax, this, this.expansions[i]);
+ M.block_navigation.expandablebranchcount++;
+ } else if (M.cfg.debug) {
+ Y.one(document.body).append(Y.Node.create('<div class="notification" style="font-size:6pt;">Expandable node within navigation was missing [#'+this.expansions[i].id+']</div>'));
+ } else {
+ // Failing over silently
+ }
}
if (node.hasClass('block_js_expansion')) {
if (e.target.get('nodeName').toUpperCase() != 'P') {
return true;
}
- var cfginstance = '';
+ var cfginstance = '', Y = this.Y;
if (this.instance != null) {
cfginstance = '&instance='+this.instance
}
- this.Y.io(M.cfg.wwwroot+'/lib/ajax/getnavbranch.php', {
+ Y.io(M.cfg.wwwroot+'/lib/ajax/getnavbranch.php', {
method:'POST',
data:'elementid='+branch.id+'&id='+branch.branchid+'&type='+branch.type+'&sesskey='+M.cfg.sesskey+cfginstance,
on: {
complete:this.load_ajax,
- success:function() {this.Y.detach('click', this.init_load_ajax, e.target);}
+ success:function() {Y.detach('click', this.init_load_ajax, e.target);}
},
context:this,
arguments:{
// Make the new branch into an object
var branch = new M.block_navigation.classes.branch(this, branchobj);
- var childrenul = false;
+ var childrenul = false, Y = this.Y;
if (depth === 1) {
if (!branch.children) {
return false;
}
- childrenul = this.Y.Node.create('<ul></ul>');
+ childrenul = Y.Node.create('<ul></ul>');
target.appendChild(childrenul);
} else {
childrenul = branch.inject_into_dom(target);
var isbranch = ((this.expandable !== null || this.haschildren) && this.expansionceiling===null);
var branchli = Y.Node.create('<li></li>');
- var branchp = this.tree.Y.Node.create('<p class="tree_item"></p>');
+ var branchp = Y.Node.create('<p class="tree_item"></p>');
if (isbranch) {
branchli.addClass('collapsed');
public function set_expansion_limit($type) {
$nodes = $this->find_all_of_type($type);
foreach ($nodes as &$node) {
+ // We need to generate the full site node
+ if ($type == self::TYPE_COURSE && $node->key == SITEID) {
+ continue;
+ }
foreach ($node->children as &$child) {
+ // We still want to show course reports and participants containers
+ // or there will be navigation missing.
+ if ($type == self::TYPE_COURSE && $child->type === self::TYPE_CONTAINER) {
+ continue;
+ }
$child->display = false;
}
}