diff --git a/course_menu/Install.txt b/Install.txt similarity index 100% rename from course_menu/Install.txt rename to Install.txt diff --git a/course_menu/README.txt b/README.txt similarity index 100% rename from course_menu/README.txt rename to README.txt diff --git a/course_menu/ajax.php b/ajax.php similarity index 100% rename from course_menu/ajax.php rename to ajax.php diff --git a/course_menu/block_course_menu.php b/block_course_menu.php similarity index 100% rename from course_menu/block_course_menu.php rename to block_course_menu.php diff --git a/course_menu/config/chapters.php b/config/chapters.php similarity index 100% rename from course_menu/config/chapters.php rename to config/chapters.php diff --git a/course_menu/config/elements.php b/config/elements.php similarity index 100% rename from course_menu/config/elements.php rename to config/elements.php diff --git a/course_menu/config/global.php b/config/global.php similarity index 100% rename from course_menu/config/global.php rename to config/global.php diff --git a/course_menu/config/links.php b/config/links.php similarity index 100% rename from course_menu/config/links.php rename to config/links.php diff --git a/course_menu/course_menu.js b/course_menu.js similarity index 97% rename from course_menu/course_menu.js rename to course_menu.js index 70438cc..0d00345 100644 --- a/course_menu/course_menu.js +++ b/course_menu.js @@ -1,457 +1,457 @@ -/* - * --------------------------------------------------------------------------------------------------------------------- - * - * This file is part of the Course Menu block for Moodle - * - * The Course Menu block for Moodle software package is Copyright � 2008 onwards NetSapiensis AB and is provided under - * the terms of the GNU GENERAL PUBLIC LICENSE Version 3 (GPL). This program is free software: you can redistribute it - * and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, - * either version 3 of the License, or (at your option) any later version. - * - * This program is free software: you can redistribute it and/or modify it under the terms of the GNU - * General Public License as published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. This program is distributed in the hope that - * it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A - * PARTICULAR PURPOSE. - * - * See the GNU General Public License for more details. You should have received a copy of the GNU General Public - * License along with this program. - * If not, see . - * --------------------------------------------------------------------------------------------------------------------- - */ - -M.block_course_menu = M.block_course_menu || { - /** The number of expandable branches in existence */ - expandablebranchcount:0, - /** An array of initialised trees */ - treecollection:[], - initDone: false, - /** - * Will contain all of the classes for the navigation blocks - * @namespace - */ - classes:{}, - courselimit : 20, - /** - * This function gets called when the module is first loaded as required by - * the YUI.add statement at the bottom of the page. - * - * NOTE: This will only be executed ONCE - * @function - */ - init:function(Y) { - - M.core_dock.init(Y); - if (M.core_dock.genericblock) { - // Give the tree class the dock block properties - Y.augment(M.block_course_menu.classes.tree, M.core_dock.genericblock); - //adjust the title to fit the content ? - - } - }, - /** - * Add new instance of navigation tree to tree collection - */ - init_add_tree:function(Y, id, properties) { - this.bg_color = properties.bg_color; - if (properties.courselimit) { - this.courselimit = properties.courselimit; - } - M.block_course_menu.treecollection[id] = new M.block_course_menu.classes.tree(Y, id, properties); - } -}; - -/** - * @class tree - * @constructor - * @base M.core_dock.genericblock - * @param {YUI} Y A yui instance to use with the navigation - * @param {string} id The name of the tree - * @param {object} properties Object containing tree properties - */ -M.block_course_menu.classes.tree = function(Y, id, properties) { - this.Y = Y; - this.id = id; - this.key = id; - this.errorlog = []; - this.ajaxbranches = 0; - this.expansions = []; - this.instance = id; - this.cachedcontentnode = null; - this.cachedfooter = null; - this.position = 'block'; - this.skipsetposition = false; - this.candock = false; - this.docked = properties.docked - - var _bg = properties.bg_color; - M.core_dock.on('dock:itemadded', function () { - var _items = this.items; - for (var i = 0; i < _items.length; i++) { - if (_items[i] && typeof _items[i] == "object" && _items[i].blockclass == 'block_course_menu') { - var _current = _items[i]; - var ttl = _current.nodes.docktitle; - ttl.setStyle("background", "none").setStyle("backgroundColor", _bg); - } - } - }); - - if (properties.expansions) { - this.expansions = properties.expansions; - } - if (properties.instance) { - this.instance = properties.instance; - } - if (properties.candock) { - this.candock = true; - } - - var node = this.Y.one('#inst'+this.id); - - // Can't find the block instance within the page - if (node === null) { - return; - } - - - // Attach event to toggle expansion - node.all('.tree_item.branch').on('click', this.toggleexpansion , this); - var uri = location.href; - var section = ''; - var sectionLinks = Y.all("a.section_link"); - - section = uri.split("#")[1]; - sectionLinks.each (function (v) { - if(v.getAttribute("href") == "#" + section) { - v.get('parentNode').addClass("active_tree_node"); - v.get('parentNode').get('parentNode').addClass("current_branch"); - Y.one("#showonlysection_nr").set('text', section.split("-")[1]); - var newHref = ""; - var pp = Y.one("#showallsections").getAttribute('href').split("="); - pp.pop(); - for (var x in pp) { - newHref += pp[x] + "="; - } - newHref += section.split("-")[1]; - Y.one("#showallsections").setAttribute('href', newHref); - } - }); - sectionLinks.on('click', function (e) { - var v = e.currentTarget; - if (v.getAttribute("href").indexOf("#") != -1) { - section = v.getAttribute("href"); - Y.all(".active_tree_node").each (function (v) { - v.removeClass("active_tree_node"); - v.get('parentNode').removeClass("current_branch"); - }); - v.get('parentNode').addClass("active_tree_node"); - v.get('parentNode').get('parentNode').addClass("current_branch"); - Y.one("#showonlysection_nr").set('text', section.split("-")[1]); - var newHref = ""; - var pp = Y.one("#showallsections").getAttribute('href').split("="); - pp.pop(); - for (var x in pp) { - newHref += pp[x] + "="; - } - newHref += section.split("-")[1]; - Y.one("#showallsections").setAttribute('href', newHref); - } - }); - // Attach events to expand by AJAX - //var expandablenode; - for (var i in this.expansions) { - var expandablenode = Y.one('#'+this.expansions[i].id); - if (expandablenode) { - expandablenode.on('ajaxload|click', this.init_load_ajax, this, this.expansions[i]); - M.block_course_menu.expandablebranchcount++; - } else if (M.cfg.debug) { - Y.one(document.body).append(Y.Node.create('
Expandable node within navigation was missing [#'+this.expansions[i].id+']
')); - } else { - // Failing over silently - } - } - - if (node.hasClass('block_js_expansion')) { - node.on('mouseover', function(e){this.toggleClass('mouseover');}, node); - node.on('mouseout', function(e){this.toggleClass('mouseover');}, node); - } -}; - -/** - * Loads a branch via AJAX - * - * @param {event} e The event object - * @param {object} branch A branch to load via ajax - */ -M.block_course_menu.classes.tree.prototype.init_load_ajax = function(e, branch) { - e.stopPropagation(); - var target = e.target; - if (target.test('span')) { - target = target.ancestor('p'); - } - if (!target || !target.test('p')) { - return true; - } - var cfginstance = '', Y = this.Y; - if (this.instance != null) { - cfginstance = '&instance='+this.instance - } - 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() {Y.detach('click', this.init_load_ajax, target);} - }, - context:this, - arguments:{ - target:target - } - }); - return true; -}; - -/** - * Takes an branch provided through ajax and loads it into the tree - * @param {int} tid The transaction id - * @param {object} outcome - * @param {mixed} args - * @return bool - */ -M.block_course_menu.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.candock) { - M.core_dock.resize(); - } - return true; - } - } catch (e) { - // If we got here then there was an error parsing the result - } - // The branch is empty so class it accordingly - args.target.replaceClass('branch', 'emptybranch'); - return true; -}; - -/** - * Adds a branch into the tree provided with some XML - * @param {object} branchobj - * @param {Y.Node} target - * @param {int} depth - * @return bool - */ -M.block_course_menu.classes.tree.prototype.add_branch = function(branchobj, target, depth) { - - // Make the new branch into an object - var branch = new M.block_course_menu.classes.branch(this, branchobj); - var childrenul = false, Y = this.Y; - if (depth === 1) { - if (!branch.children) { - return false; - } - childrenul = Y.Node.create(''); - target.appendChild(childrenul); - } else { - childrenul = branch.inject_into_dom(target); - } - if (childrenul) { - var count = 0; - for (var i in branch.children) { - // Add each branch to the tree - if (branch.children[i].type == 20) { - count++; - } - if (typeof(branch.children[i])=='object') { - this.add_branch(branch.children[i], childrenul, depth+1); - } - } - if (branch.type == 10 && count >= M.block_course_menu.courselimit) { - var properties = Array(); - properties['name'] = M.str.moodle.viewallcourses; - properties['title'] = M.str.moodle.viewallcourses; - properties['link'] = M.cfg.wwwroot+'/course/category.php?id='+branch.key; - properties['haschildren'] = false; - properties['icon'] = {'pix':"i/navigationitem",'component':'moodle'}; - this.add_branch(properties, childrenul, depth+1); - } - } - return true; -}; -/** - * Toggle a branch as expanded or collapsed - * @param {Event} e - */ -M.block_course_menu.classes.tree.prototype.toggleexpansion = function(e) { - // First check if they managed to click on the li iteslf, then find the closest - // LI ancestor and use that - - if (e.target.get('nodeName').toUpperCase() == 'A') { - // A link has been clicked don't fire any more events just do the default. - e.stopPropagation(); - return; - } - - var target = e.target; - if (!target.test('li')) { - target = target.ancestor('li') - } - - if (target && !target.hasClass('depth_1')) { - target.toggleClass('collapsed'); - } - - if (this.candock) { - M.core_dock.resize(); - } - - var act = "add"; - if (target.hasClass('collapsed')) { - act = "remove"; - } - var elName = target.one('.item_name').get('innerHTML'); - var Y = this.Y; - var instId = this.id; - Y.io(M.cfg.wwwroot + '/blocks/course_menu/ajax.php', { - method:'POST', - data:'element_name='+elName+'&action='+act+'&instance='+instId, - on: { - success:function() { } - }, - context:this - }); - -}; - -/** - * This class represents a branch for a tree - * @class branch - * @constructor - * @param {M.block_course_menu.classes.tree} tree - * @param {object|null} obj - */ -M.block_course_menu.classes.branch = function(tree, obj) { - this.tree = tree; - this.name = null; - this.title = null; - this.classname = null; - this.id = null; - this.key = null; - this.type = null; - this.link = null; - this.icon = null; - this.expandable = null; - this.expansionceiling = null; - this.hidden = false; - this.haschildren = false; - this.children = false; - if (obj !== null) { - // Construct from the provided xml - this.construct_from_json(obj); - } -}; -/** - * Populates this branch from a JSON object - * @param {object} obj - */ -M.block_course_menu.classes.branch.prototype.construct_from_json = function(obj) { - for (var i in obj) { - this[i] = obj[i]; - } - if (this.children && this.children.length > 0) { - this.haschildren = true; - } else { - this.children = []; - } - if (this.id && this.id.match(/^expandable_branch_\d+$/)) { - // Assign a new unique id for this new expandable branch - M.block_course_menu.expandablebranchcount++; - this.id = 'expandable_branch_'+M.block_course_menu.expandablebranchcount; - } -}; -/** - * Injects a branch into the tree at the given location - * @param {element} element - */ -M.block_course_menu.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 = Y.Node.create('
  • '); - var branchp = Y.Node.create('

    '); - - if (isbranch) { - branchli.addClass('collapsed'); - branchli.addClass('contains_branch'); - branchp.addClass('branch'); - branchp.on('click', this.tree.toggleexpansion, this.tree); - if (this.expandable) { - branchp.on('ajaxload|click', this.tree.init_load_ajax, this.tree, {branchid:this.key,id:this.id,type:this.type}); - } - } - - if (this.myclass !== null) { - branchp.addClass(this.myclass); - } - if (this.id !== null) { - branchp.setAttribute('id', this.id); - } - - // Prepare the icon, should be an object representing a pix_icon - var branchicon = false; - if (this.icon != null && (!isbranch || this.type == 40)) { - 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); - } - if (this.icon.title) { - branchicon.setAttribute('alt', this.icon.title); - } - if (this.icon.classes) { - for (var i in this.icon.classes) { - branchicon.addClass(this.icon.classes[i]); - } - } - } - - if (this.link === null) { - if (branchicon) { - branchp.appendChild(branchicon); - } - branchp.append(this.name.replace(/\n/g, '
    ')); - } else { - var branchlink = Y.Node.create(''); - if (branchicon) { - branchlink.appendChild(branchicon); - } - branchlink.append(this.name.replace(/\n/g, '
    ')); - if (this.hidden) { - branchlink.addClass('dimmed'); - } - branchp.appendChild(branchlink); - } - - branchli.appendChild(branchp); - if (this.haschildren) { - var childrenul = Y.Node.create(''); - branchli.appendChild(childrenul); - element.appendChild(branchli); - return childrenul - } else { - element.appendChild(branchli); - return false; - } -}; - -/** - * Causes the course menu block module to initalise the first time the module - * is used! - * - * NOTE: Never convert the second argument to a function reference... - * doing so causes scoping issues - */ +/* + * --------------------------------------------------------------------------------------------------------------------- + * + * This file is part of the Course Menu block for Moodle + * + * The Course Menu block for Moodle software package is Copyright � 2008 onwards NetSapiensis AB and is provided under + * the terms of the GNU GENERAL PUBLIC LICENSE Version 3 (GPL). This program is free software: you can redistribute it + * and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, + * either version 3 of the License, or (at your option) any later version. + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU + * General Public License as published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. This program is distributed in the hope that + * it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. + * + * See the GNU General Public License for more details. You should have received a copy of the GNU General Public + * License along with this program. + * If not, see . + * --------------------------------------------------------------------------------------------------------------------- + */ + +M.block_course_menu = M.block_course_menu || { + /** The number of expandable branches in existence */ + expandablebranchcount:0, + /** An array of initialised trees */ + treecollection:[], + initDone: false, + /** + * Will contain all of the classes for the navigation blocks + * @namespace + */ + classes:{}, + courselimit : 20, + /** + * This function gets called when the module is first loaded as required by + * the YUI.add statement at the bottom of the page. + * + * NOTE: This will only be executed ONCE + * @function + */ + init:function(Y) { + + M.core_dock.init(Y); + if (M.core_dock.genericblock) { + // Give the tree class the dock block properties + Y.augment(M.block_course_menu.classes.tree, M.core_dock.genericblock); + //adjust the title to fit the content ? + + } + }, + /** + * Add new instance of navigation tree to tree collection + */ + init_add_tree:function(Y, id, properties) { + this.bg_color = properties.bg_color; + if (properties.courselimit) { + this.courselimit = properties.courselimit; + } + M.block_course_menu.treecollection[id] = new M.block_course_menu.classes.tree(Y, id, properties); + } +}; + +/** + * @class tree + * @constructor + * @base M.core_dock.genericblock + * @param {YUI} Y A yui instance to use with the navigation + * @param {string} id The name of the tree + * @param {object} properties Object containing tree properties + */ +M.block_course_menu.classes.tree = function(Y, id, properties) { + this.Y = Y; + this.id = id; + this.key = id; + this.errorlog = []; + this.ajaxbranches = 0; + this.expansions = []; + this.instance = id; + this.cachedcontentnode = null; + this.cachedfooter = null; + this.position = 'block'; + this.skipsetposition = false; + this.candock = false; + this.docked = properties.docked + + var _bg = properties.bg_color; + M.core_dock.on('dock:itemadded', function () { + var _items = this.items; + for (var i = 0; i < _items.length; i++) { + if (_items[i] && typeof _items[i] == "object" && _items[i].blockclass == 'block_course_menu') { + var _current = _items[i]; + var ttl = _current.nodes.docktitle; + ttl.setStyle("background", "none").setStyle("backgroundColor", _bg); + } + } + }); + + if (properties.expansions) { + this.expansions = properties.expansions; + } + if (properties.instance) { + this.instance = properties.instance; + } + if (properties.candock) { + this.candock = true; + } + + var node = this.Y.one('#inst'+this.id); + + // Can't find the block instance within the page + if (node === null) { + return; + } + + + // Attach event to toggle expansion + node.all('.tree_item.branch').on('click', this.toggleexpansion , this); + var uri = location.href; + var section = ''; + var sectionLinks = Y.all("a.section_link"); + + section = uri.split("#")[1]; + sectionLinks.each (function (v) { + if(v.getAttribute("href") == "#" + section) { + v.get('parentNode').addClass("active_tree_node"); + v.get('parentNode').get('parentNode').addClass("current_branch"); + Y.one("#showonlysection_nr").set('text', section.split("-")[1]); + var newHref = ""; + var pp = Y.one("#showallsections").getAttribute('href').split("="); + pp.pop(); + for (var x in pp) { + newHref += pp[x] + "="; + } + newHref += section.split("-")[1]; + Y.one("#showallsections").setAttribute('href', newHref); + } + }); + sectionLinks.on('click', function (e) { + var v = e.currentTarget; + if (v.getAttribute("href").indexOf("#") != -1) { + section = v.getAttribute("href"); + Y.all(".active_tree_node").each (function (v) { + v.removeClass("active_tree_node"); + v.get('parentNode').removeClass("current_branch"); + }); + v.get('parentNode').addClass("active_tree_node"); + v.get('parentNode').get('parentNode').addClass("current_branch"); + Y.one("#showonlysection_nr").set('text', section.split("-")[1]); + var newHref = ""; + var pp = Y.one("#showallsections").getAttribute('href').split("="); + pp.pop(); + for (var x in pp) { + newHref += pp[x] + "="; + } + newHref += section.split("-")[1]; + Y.one("#showallsections").setAttribute('href', newHref); + } + }); + // Attach events to expand by AJAX + //var expandablenode; + for (var i in this.expansions) { + var expandablenode = Y.one('#'+this.expansions[i].id); + if (expandablenode) { + expandablenode.on('ajaxload|click', this.init_load_ajax, this, this.expansions[i]); + M.block_course_menu.expandablebranchcount++; + } else if (M.cfg.debug) { + Y.one(document.body).append(Y.Node.create('
    Expandable node within navigation was missing [#'+this.expansions[i].id+']
    ')); + } else { + // Failing over silently + } + } + + if (node.hasClass('block_js_expansion')) { + node.on('mouseover', function(e){this.toggleClass('mouseover');}, node); + node.on('mouseout', function(e){this.toggleClass('mouseover');}, node); + } +}; + +/** + * Loads a branch via AJAX + * + * @param {event} e The event object + * @param {object} branch A branch to load via ajax + */ +M.block_course_menu.classes.tree.prototype.init_load_ajax = function(e, branch) { + e.stopPropagation(); + var target = e.target; + if (target.test('span')) { + target = target.ancestor('p'); + } + if (!target || !target.test('p')) { + return true; + } + var cfginstance = '', Y = this.Y; + if (this.instance != null) { + cfginstance = '&instance='+this.instance + } + 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() {Y.detach('click', this.init_load_ajax, target);} + }, + context:this, + arguments:{ + target:target + } + }); + return true; +}; + +/** + * Takes an branch provided through ajax and loads it into the tree + * @param {int} tid The transaction id + * @param {object} outcome + * @param {mixed} args + * @return bool + */ +M.block_course_menu.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.candock) { + M.core_dock.resize(); + } + return true; + } + } catch (e) { + // If we got here then there was an error parsing the result + } + // The branch is empty so class it accordingly + args.target.replaceClass('branch', 'emptybranch'); + return true; +}; + +/** + * Adds a branch into the tree provided with some XML + * @param {object} branchobj + * @param {Y.Node} target + * @param {int} depth + * @return bool + */ +M.block_course_menu.classes.tree.prototype.add_branch = function(branchobj, target, depth) { + + // Make the new branch into an object + var branch = new M.block_course_menu.classes.branch(this, branchobj); + var childrenul = false, Y = this.Y; + if (depth === 1) { + if (!branch.children) { + return false; + } + childrenul = Y.Node.create(''); + target.appendChild(childrenul); + } else { + childrenul = branch.inject_into_dom(target); + } + if (childrenul) { + var count = 0; + for (var i in branch.children) { + // Add each branch to the tree + if (branch.children[i].type == 20) { + count++; + } + if (typeof(branch.children[i])=='object') { + this.add_branch(branch.children[i], childrenul, depth+1); + } + } + if (branch.type == 10 && count >= M.block_course_menu.courselimit) { + var properties = Array(); + properties['name'] = M.str.moodle.viewallcourses; + properties['title'] = M.str.moodle.viewallcourses; + properties['link'] = M.cfg.wwwroot+'/course/category.php?id='+branch.key; + properties['haschildren'] = false; + properties['icon'] = {'pix':"i/navigationitem",'component':'moodle'}; + this.add_branch(properties, childrenul, depth+1); + } + } + return true; +}; +/** + * Toggle a branch as expanded or collapsed + * @param {Event} e + */ +M.block_course_menu.classes.tree.prototype.toggleexpansion = function(e) { + // First check if they managed to click on the li iteslf, then find the closest + // LI ancestor and use that + + if (e.target.get('nodeName').toUpperCase() == 'A') { + // A link has been clicked don't fire any more events just do the default. + e.stopPropagation(); + return; + } + + var target = e.target; + if (!target.test('li')) { + target = target.ancestor('li') + } + + if (target && !target.hasClass('depth_1')) { + target.toggleClass('collapsed'); + } + + if (this.candock) { + M.core_dock.resize(); + } + + var act = "add"; + if (target.hasClass('collapsed')) { + act = "remove"; + } + var elName = target.one('.item_name').get('innerHTML'); + var Y = this.Y; + var instId = this.id; + Y.io(M.cfg.wwwroot + '/blocks/course_menu/ajax.php', { + method:'POST', + data:'element_name='+elName+'&action='+act+'&instance='+instId, + on: { + success:function() { } + }, + context:this + }); + +}; + +/** + * This class represents a branch for a tree + * @class branch + * @constructor + * @param {M.block_course_menu.classes.tree} tree + * @param {object|null} obj + */ +M.block_course_menu.classes.branch = function(tree, obj) { + this.tree = tree; + this.name = null; + this.title = null; + this.classname = null; + this.id = null; + this.key = null; + this.type = null; + this.link = null; + this.icon = null; + this.expandable = null; + this.expansionceiling = null; + this.hidden = false; + this.haschildren = false; + this.children = false; + if (obj !== null) { + // Construct from the provided xml + this.construct_from_json(obj); + } +}; +/** + * Populates this branch from a JSON object + * @param {object} obj + */ +M.block_course_menu.classes.branch.prototype.construct_from_json = function(obj) { + for (var i in obj) { + this[i] = obj[i]; + } + if (this.children && this.children.length > 0) { + this.haschildren = true; + } else { + this.children = []; + } + if (this.id && this.id.match(/^expandable_branch_\d+$/)) { + // Assign a new unique id for this new expandable branch + M.block_course_menu.expandablebranchcount++; + this.id = 'expandable_branch_'+M.block_course_menu.expandablebranchcount; + } +}; +/** + * Injects a branch into the tree at the given location + * @param {element} element + */ +M.block_course_menu.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 = Y.Node.create('
  • '); + var branchp = Y.Node.create('

    '); + + if (isbranch) { + branchli.addClass('collapsed'); + branchli.addClass('contains_branch'); + branchp.addClass('branch'); + branchp.on('click', this.tree.toggleexpansion, this.tree); + if (this.expandable) { + branchp.on('ajaxload|click', this.tree.init_load_ajax, this.tree, {branchid:this.key,id:this.id,type:this.type}); + } + } + + if (this.myclass !== null) { + branchp.addClass(this.myclass); + } + if (this.id !== null) { + branchp.setAttribute('id', this.id); + } + + // Prepare the icon, should be an object representing a pix_icon + var branchicon = false; + if (this.icon != null && (!isbranch || this.type == 40)) { + 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); + } + if (this.icon.title) { + branchicon.setAttribute('alt', this.icon.title); + } + if (this.icon.classes) { + for (var i in this.icon.classes) { + branchicon.addClass(this.icon.classes[i]); + } + } + } + + if (this.link === null) { + if (branchicon) { + branchp.appendChild(branchicon); + } + branchp.append(this.name.replace(/\n/g, '
    ')); + } else { + var branchlink = Y.Node.create(''); + if (branchicon) { + branchlink.appendChild(branchicon); + } + branchlink.append(this.name.replace(/\n/g, '
    ')); + if (this.hidden) { + branchlink.addClass('dimmed'); + } + branchp.appendChild(branchlink); + } + + branchli.appendChild(branchp); + if (this.haschildren) { + var childrenul = Y.Node.create(''); + branchli.appendChild(childrenul); + element.appendChild(branchli); + return childrenul + } else { + element.appendChild(branchli); + return false; + } +}; + +/** + * Causes the course menu block module to initalise the first time the module + * is used! + * + * NOTE: Never convert the second argument to a function reference... + * doing so causes scoping issues + */ YUI.add('block_course_menu', function(Y){M.block_course_menu.init(Y);}, '0.0.0.1', M.yui.loader.modules.block_course_menu.requires); \ No newline at end of file diff --git a/course_menu/css/styles.php b/css/styles.php similarity index 100% rename from course_menu/css/styles.php rename to css/styles.php diff --git a/course_menu/db/access.php b/db/access.php similarity index 100% rename from course_menu/db/access.php rename to db/access.php diff --git a/course_menu/db/upgrade.php b/db/upgrade.php similarity index 100% rename from course_menu/db/upgrade.php rename to db/upgrade.php diff --git a/course_menu/edit_form.php b/edit_form.php similarity index 100% rename from course_menu/edit_form.php rename to edit_form.php diff --git a/course_menu/icons/blog.gif b/icons/blog.gif similarity index 100% rename from course_menu/icons/blog.gif rename to icons/blog.gif diff --git a/course_menu/icons/bug.gif b/icons/bug.gif similarity index 100% rename from course_menu/icons/bug.gif rename to icons/bug.gif diff --git a/course_menu/icons/cal.gif b/icons/cal.gif similarity index 100% rename from course_menu/icons/cal.gif rename to icons/cal.gif diff --git a/course_menu/icons/configure.gif b/icons/configure.gif similarity index 100% rename from course_menu/icons/configure.gif rename to icons/configure.gif diff --git a/course_menu/icons/directory.gif b/icons/directory.gif similarity index 100% rename from course_menu/icons/directory.gif rename to icons/directory.gif diff --git a/course_menu/icons/file.gif b/icons/file.gif similarity index 100% rename from course_menu/icons/file.gif rename to icons/file.gif diff --git a/course_menu/icons/folder.gif b/icons/folder.gif similarity index 100% rename from course_menu/icons/folder.gif rename to icons/folder.gif diff --git a/course_menu/icons/group.gif b/icons/group.gif similarity index 100% rename from course_menu/icons/group.gif rename to icons/group.gif diff --git a/course_menu/icons/i.gif b/icons/i.gif similarity index 100% rename from course_menu/icons/i.gif rename to icons/i.gif diff --git a/course_menu/icons/kuser1.gif b/icons/kuser1.gif similarity index 100% rename from course_menu/icons/kuser1.gif rename to icons/kuser1.gif diff --git a/course_menu/icons/l.gif b/icons/l.gif similarity index 100% rename from course_menu/icons/l.gif rename to icons/l.gif diff --git a/course_menu/icons/link.gif b/icons/link.gif similarity index 100% rename from course_menu/icons/link.gif rename to icons/link.gif diff --git a/course_menu/icons/lminus.gif b/icons/lminus.gif similarity index 100% rename from course_menu/icons/lminus.gif rename to icons/lminus.gif diff --git a/course_menu/icons/lplus.gif b/icons/lplus.gif similarity index 100% rename from course_menu/icons/lplus.gif rename to icons/lplus.gif diff --git a/course_menu/icons/messages.gif b/icons/messages.gif similarity index 100% rename from course_menu/icons/messages.gif rename to icons/messages.gif diff --git a/course_menu/icons/openfolder.gif b/icons/openfolder.gif similarity index 100% rename from course_menu/icons/openfolder.gif rename to icons/openfolder.gif diff --git a/course_menu/icons/scale.gif b/icons/scale.gif similarity index 100% rename from course_menu/icons/scale.gif rename to icons/scale.gif diff --git a/course_menu/icons/scontrols.gif b/icons/scontrols.gif similarity index 100% rename from course_menu/icons/scontrols.gif rename to icons/scontrols.gif diff --git a/course_menu/icons/smanual.gif b/icons/smanual.gif similarity index 100% rename from course_menu/icons/smanual.gif rename to icons/smanual.gif diff --git a/course_menu/icons/t.gif b/icons/t.gif similarity index 100% rename from course_menu/icons/t.gif rename to icons/t.gif diff --git a/course_menu/icons/tforum.gif b/icons/tforum.gif similarity index 100% rename from course_menu/icons/tforum.gif rename to icons/tforum.gif diff --git a/course_menu/icons/tforum2.gif b/icons/tforum2.gif similarity index 100% rename from course_menu/icons/tforum2.gif rename to icons/tforum2.gif diff --git a/course_menu/icons/tmanual.gif b/icons/tmanual.gif similarity index 100% rename from course_menu/icons/tmanual.gif rename to icons/tmanual.gif diff --git a/course_menu/icons/tminus.gif b/icons/tminus.gif similarity index 100% rename from course_menu/icons/tminus.gif rename to icons/tminus.gif diff --git a/course_menu/icons/tplus.gif b/icons/tplus.gif similarity index 100% rename from course_menu/icons/tplus.gif rename to icons/tplus.gif diff --git a/course_menu/icons/trans.gif b/icons/trans.gif similarity index 100% rename from course_menu/icons/trans.gif rename to icons/trans.gif diff --git a/course_menu/icons/tree/lm.gif b/icons/tree/lm.gif similarity index 100% rename from course_menu/icons/tree/lm.gif rename to icons/tree/lm.gif diff --git a/course_menu/icons/tree/lmh.gif b/icons/tree/lmh.gif similarity index 100% rename from course_menu/icons/tree/lmh.gif rename to icons/tree/lmh.gif diff --git a/course_menu/icons/tree/ln.gif b/icons/tree/ln.gif similarity index 100% rename from course_menu/icons/tree/ln.gif rename to icons/tree/ln.gif diff --git a/course_menu/icons/tree/loading.gif b/icons/tree/loading.gif similarity index 100% rename from course_menu/icons/tree/loading.gif rename to icons/tree/loading.gif diff --git a/course_menu/icons/tree/lp.gif b/icons/tree/lp.gif similarity index 100% rename from course_menu/icons/tree/lp.gif rename to icons/tree/lp.gif diff --git a/course_menu/icons/tree/lph.gif b/icons/tree/lph.gif similarity index 100% rename from course_menu/icons/tree/lph.gif rename to icons/tree/lph.gif diff --git a/course_menu/icons/tree/tm.gif b/icons/tree/tm.gif similarity index 100% rename from course_menu/icons/tree/tm.gif rename to icons/tree/tm.gif diff --git a/course_menu/icons/tree/tmh.gif b/icons/tree/tmh.gif similarity index 100% rename from course_menu/icons/tree/tmh.gif rename to icons/tree/tmh.gif diff --git a/course_menu/icons/tree/tn.gif b/icons/tree/tn.gif similarity index 100% rename from course_menu/icons/tree/tn.gif rename to icons/tree/tn.gif diff --git a/course_menu/icons/tree/tp.gif b/icons/tree/tp.gif similarity index 100% rename from course_menu/icons/tree/tp.gif rename to icons/tree/tp.gif diff --git a/course_menu/icons/tree/tph.gif b/icons/tree/tph.gif similarity index 100% rename from course_menu/icons/tree/tph.gif rename to icons/tree/tph.gif diff --git a/course_menu/icons/tree/vline.gif b/icons/tree/vline.gif similarity index 100% rename from course_menu/icons/tree/vline.gif rename to icons/tree/vline.gif diff --git a/course_menu/icons/up.gif b/icons/up.gif similarity index 100% rename from course_menu/icons/up.gif rename to icons/up.gif diff --git a/course_menu/icons/userpwd.gif b/icons/userpwd.gif similarity index 100% rename from course_menu/icons/userpwd.gif rename to icons/userpwd.gif diff --git a/course_menu/icons/viewall.gif b/icons/viewall.gif similarity index 100% rename from course_menu/icons/viewall.gif rename to icons/viewall.gif diff --git a/course_menu/js/course_menu.js.php b/js/course_menu.js.php similarity index 98% rename from course_menu/js/course_menu.js.php rename to js/course_menu.js.php index ebf1e66..c3a88e6 100644 --- a/course_menu/js/course_menu.js.php +++ b/js/course_menu.js.php @@ -1,140 +1,140 @@ - \ No newline at end of file diff --git a/course_menu/lang/en/block_course_menu.php b/lang/en/block_course_menu.php similarity index 96% rename from course_menu/lang/en/block_course_menu.php rename to lang/en/block_course_menu.php index 8022caa..6a0a14c 100644 --- a/course_menu/lang/en/block_course_menu.php +++ b/lang/en/block_course_menu.php @@ -35,6 +35,8 @@ $string['correcturlmsg'] = '*The URL must be entered as an absolute url, containing the protocol, too. (eg correct urls: http://www.moodle.org, ftp://ftp.moodle.org; eg wrong urls: www.moodle.org, moodle.org)'; $string['courseadministration'] = "Course administration"; $string['coursemainpage'] = 'Course main page'; +$string['course_menu:addinstance'] = 'Add a new Course Menu block to a course page'; +$string['course_menu:myaddinstance'] = 'Add a new Course Menu block to the /my page'; $string['customlink'] = 'Custom Link'; $string['defaultelements'] = 'Default elements'; $string['defaultgrouping'] = 'Default grouping'; @@ -105,4 +107,4 @@ $string['weeks'] = 'Weeks'; $string['window'] = 'Window'; $string['wrongnumber'] = 'Number of chapters must be a correct number (only digits), greater than 1, less than the number of subchapters and less then the number of visible topics / weeks !'; -$string['wrongsubchapnumber'] = 'Number of sub-chapters must be a correct number (only digits), greater than the number of chapters and less then the number of visible topics / weeks !'; \ No newline at end of file +$string['wrongsubchapnumber'] = 'Number of sub-chapters must be a correct number (only digits), greater than the number of chapters and less then the number of visible topics / weeks !'; diff --git a/course_menu/lib/settingslib.php b/lib/settingslib.php similarity index 100% rename from course_menu/lib/settingslib.php rename to lib/settingslib.php diff --git a/course_menu/link_with_navigation.php b/link_with_navigation.php similarity index 100% rename from course_menu/link_with_navigation.php rename to link_with_navigation.php diff --git a/course_menu/renderer.php b/renderer.php similarity index 100% rename from course_menu/renderer.php rename to renderer.php diff --git a/course_menu/settings.php b/settings.php similarity index 100% rename from course_menu/settings.php rename to settings.php diff --git a/course_menu/styles.css b/styles.css similarity index 100% rename from course_menu/styles.css rename to styles.css diff --git a/course_menu/version.php b/version.php similarity index 100% rename from course_menu/version.php rename to version.php diff --git a/course_menu/yui/navigation/navigation.js b/yui/navigation/navigation.js similarity index 100% rename from course_menu/yui/navigation/navigation.js rename to yui/navigation/navigation.js diff --git a/course_menu/yui/settings/settings.js b/yui/settings/settings.js similarity index 100% rename from course_menu/yui/settings/settings.js rename to yui/settings/settings.js