diff --git a/blocks/navigation/navigation.js b/blocks/navigation/navigation.js
index 725c3bc6d8f..df21f0cf18c 100644
--- a/blocks/navigation/navigation.js
+++ b/blocks/navigation/navigation.js
@@ -162,7 +162,7 @@ M.block_navigation.classes.tree.prototype.init_load_ajax = function(e, branch) {
M.block_navigation.classes.tree.prototype.load_ajax = function(tid, outcome, args) {
try {
var object = this.Y.JSON.parse(outcome.responseText);
- if (this.add_branch(object, args.target.ancestor('LI') ,1)) {
+ if (this.add_branch(object, args.target.ancestor('li') ,1)) {
if (this.candock) {
M.core_dock.resize();
}
@@ -298,8 +298,10 @@ M.block_navigation.classes.branch.prototype.construct_from_json = function(obj)
*/
M.block_navigation.classes.branch.prototype.inject_into_dom = function(element) {
+ var Y = this.tree.Y;
+
var isbranch = ((this.expandable !== null || this.haschildren) && this.expansionceiling===null);
- var branchli = this.tree.Y.Node.create('
');
+ var branchli = Y.Node.create('');
var branchp = this.tree.Y.Node.create('');
if (isbranch) {
@@ -322,7 +324,8 @@ M.block_navigation.classes.branch.prototype.inject_into_dom = function(element)
// Prepare the icon, should be an object representing a pix_icon
var branchicon = false;
if (this.icon != null && !isbranch) {
- branchicon = this.tree.Y.Node.create('
');
+ branchicon = Y.Node.create('
');
+ branchicon.setAttribute('src', M.util.image_url(this.icon.pix, this.icon.component));
branchli.addClass('item_with_icon');
if (this.icon.alt) {
branchicon.setAttribute('alt', this.icon.alt);
@@ -343,7 +346,7 @@ M.block_navigation.classes.branch.prototype.inject_into_dom = function(element)
}
branchp.append(this.name.replace(/\n/g, '
'));
} else {
- var branchlink = this.tree.Y.Node.create('');
+ var branchlink = Y.Node.create('');
if (branchicon) {
branchlink.appendChild(branchicon);
}
@@ -356,7 +359,7 @@ M.block_navigation.classes.branch.prototype.inject_into_dom = function(element)
branchli.appendChild(branchp);
if (this.haschildren) {
- var childrenul = this.tree.Y.Node.create('');
+ var childrenul = Y.Node.create('');
branchli.appendChild(childrenul);
element.appendChild(branchli);
return childrenul
diff --git a/lib/ajax/getnavbranch.php b/lib/ajax/getnavbranch.php
index 7c288c96c3e..24e32bfd3d7 100644
--- a/lib/ajax/getnavbranch.php
+++ b/lib/ajax/getnavbranch.php
@@ -43,7 +43,7 @@ try {
$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
// Create a global nav object
- $navigation = new global_navigation_for_ajax($PAGE);
+ $navigation = new global_navigation_for_ajax($PAGE, $branchtype, $branchid);
if ($instanceid!==null) {
// Get the db record for the block instance
@@ -68,8 +68,6 @@ try {
}
// Create a navigation object to use, we can't guarantee PAGE will be complete
-
- $expandable = $navigation->initialise($branchtype, $branchid);
if (!isloggedin() || isguestuser()) {
$navigation->set_expansion_limit(navigation_node::TYPE_COURSE);
} else {
@@ -102,7 +100,7 @@ if (empty($branch) || $branch->nodetype !== navigation_node::NODETYPE_BRANCH) {
}
// Prepare an XML converter for the branch
-$converter->set_expandable($expandable);
+$converter->set_expandable($navigation->get_expandable());
// Set XML headers
header('Content-type: text/plain');
// Convert and output the branch as XML
diff --git a/lib/navigationlib.php b/lib/navigationlib.php
index 0282a447769..b618315366f 100644
--- a/lib/navigationlib.php
+++ b/lib/navigationlib.php
@@ -1878,12 +1878,16 @@ class global_navigation extends navigation_node {
}
public function get($key, $type = null) {
- $this->initialise();
+ if (!$this->initialised) {
+ $this->initialise();
+ }
return parent::get($key, $type);
}
public function find($key, $type) {
- $this->initialise();
+ if (!$this->initialised) {
+ $this->initialise();
+ }
return parent::find($key, $type);
}
}
@@ -1912,14 +1916,11 @@ class global_navigation_for_ajax extends global_navigation {
/**
* Constructs the navigation for use in AJAX request
*/
- public function __construct($page) {
- global $SITE;
+ public function __construct($page, $branchtype, $id) {
$this->page = $page;
$this->cache = new navigation_cache(NAVIGATION_CACHE_NAME);
$this->children = new navigation_node_collection();
- $this->rootnodes = array();
- $this->rootnodes['site'] = $this->add_course($SITE);
- $this->rootnodes['courses'] = $this->add(get_string('courses'), null, self::TYPE_ROOTNODE, null, 'courses');
+ $this->initialise($branchtype, $id);
}
/**
* Initialise the navigation given the type and id for the branch to expand.
@@ -1929,11 +1930,16 @@ class global_navigation_for_ajax extends global_navigation {
* @return array The expandable nodes
*/
public function initialise($branchtype, $id) {
- global $CFG, $DB, $PAGE;
+ global $CFG, $DB, $PAGE, $SITE;
if ($this->initialised || during_initial_install()) {
return $this->expandable;
}
+ $this->initialised = true;
+
+ $this->rootnodes = array();
+ $this->rootnodes['site'] = $this->add_course($SITE);
+ $this->rootnodes['courses'] = $this->add(get_string('courses'), null, self::TYPE_ROOTNODE, null, 'courses');
// Branchtype will be one of navigation_node::TYPE_*
switch ($branchtype) {
@@ -2001,6 +2007,10 @@ class global_navigation_for_ajax extends global_navigation {
$this->find_expandable($this->expandable);
return $this->expandable;
}
+
+ public function get_expandable() {
+ return $this->expandable;
+ }
}
/**