Skip to content

Commit

Permalink
navigation MDL-20297 Fixed bug whereby ajax events wern't be detached…
Browse files Browse the repository at this point in the history
… leading to over population of the tree
  • Loading branch information
samhemelryk committed Sep 18, 2009
1 parent 4b51168 commit 2a8a4ac
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/javascript-navigation.js
Expand Up @@ -66,6 +66,7 @@ function navigation_tree (treename, key) {
this.cachedcontent = null;
this.cachedfooter = null;
this.position = 'block';
this.skipsetposition = false;
this.togglesidetabdisplay = '[[togglesidetabdisplay]]';
this.toggleblockdisplay = '[[toggleblockdisplay]]';
this.sideblockwidth = null;
Expand Down Expand Up @@ -105,6 +106,7 @@ navigation_tree.prototype.initialise = function() {
}
for (i = 0; i<this.expansions.length; i++) {
try {
this.expansions[i].element = document.getElementById(this.expansions[i].id);
YAHOO.util.Event.addListener(this.expansions[i].id, 'click', this.init_load_ajax, this.expansions[i], this);
} catch (err) {
this.errorlog += "attaching ajax load events: \t"+err+"\n";
Expand Down Expand Up @@ -132,6 +134,7 @@ navigation_tree.prototype.initialise = function() {

if (YAHOO.util.Dom.hasClass(e, 'sideblock_js_sidebarpopout')) {
YAHOO.util.Dom.removeClass(e, 'sideblock_js_sidebarpopout');
this.skipsetposition = true;
this.toggle_block_display(e, this);
} else if (YAHOO.util.Dom.hasClass(e, 'sideblock_js_expansion')) {
YAHOO.util.Event.addListener(e, 'mouseover', this.togglesize, e, this);
Expand Down Expand Up @@ -219,7 +222,7 @@ navigation_tree.prototype.load_ajax = function(outcome) {
var branch = outcome.responseXML.documentElement;
if (branch!=null && this.add_branch(branch,outcome.argument.target ,1)) {
// If we get here everything worked perfectly
YAHOO.util.Event.removeListener(outcome.argument.branch.id, 'click', this.init_load_ajax);
YAHOO.util.Event.removeListener(outcome.argument.branch.element, 'click', navigation_tree.prototype.init_load_ajax);
if (this.position === 'sidebar') {
YAHOO.moodle.navigation.tabpanel.resize_tab();
}
Expand Down Expand Up @@ -351,7 +354,11 @@ navigation_tree.prototype.move_to_sidebar_popout = function(e) {
YAHOO.moodle.navigation.tabpanel = new navigation_tab_panel();
}
YAHOO.moodle.navigation.tabpanel.add_to_tab_panel(this.name, tabtitle, tabcontent, tabcommands);
set_user_preference('nav_in_tab_panel_'+this.name, 1);
if (!this.skipsetposition) {
set_user_preference('nav_in_tab_panel_'+this.name, 1);
} else {
this.skipsetposition = false;
}
return true;
}
/**
Expand Down Expand Up @@ -744,7 +751,7 @@ navigation_tree_branch.prototype.inject_into_dom = function (element, gntinstanc
YAHOO.util.Dom.addClass(branchli, 'collapsed');
YAHOO.util.Event.addListener(branchp, 'click', gntinstance.toggleexpansion, this, gntinstance);
if (this.myexpandable) {
YAHOO.util.Event.addListener(branchp, 'click', gntinstance.init_load_ajax, {branchid:this.mykey,id:this.myid,type:this.mytype}, gntinstance);
YAHOO.util.Event.addListener(branchp, 'click', gntinstance.init_load_ajax, {branchid:this.mykey,id:this.myid,type:this.mytype,element:branchp}, gntinstance);
}
}
if (this.myclass != null) {
Expand Down

0 comments on commit 2a8a4ac

Please sign in to comment.