Skip to content

Commit

Permalink
MDL-35590 block_navigation: fix remaining issues
Browse files Browse the repository at this point in the history
  • Loading branch information
lameze committed Jan 22, 2016
1 parent 10ac8ba commit 6759dc3
Show file tree
Hide file tree
Showing 15 changed files with 101 additions and 75 deletions.
1 change: 1 addition & 0 deletions blocks/navigation/amd/build/ajax_response_renderer.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions blocks/navigation/amd/build/nav_loader.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions blocks/navigation/amd/build/navblock.min.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
define(["jquery","core/tree"],function(a,b){return{init:function(){new b(".block_navigation .block_tree")}}});
1 change: 1 addition & 0 deletions blocks/navigation/amd/build/site_admin_loader.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 22 additions & 15 deletions blocks/navigation/amd/src/ajax_response_renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,42 @@ define(['jquery'], function($) {
// Mappings for the different types of nodes coming from the navigation.
// Copied from lib/navigationlib.php navigation_node constants.
var NODETYPE = {
// @type int Root node = 0
// @type int Root node = 0.
ROOTNODE : 0,
// @type int System context = 1
// @type int System context = 1.
SYSTEM : 1,
// @type int Course category = 10
// @type int Course category = 10.
CATEGORY : 10,
// @type int MYCATEGORY = 11
// @type int MYCATEGORY = 11.
MYCATEGORY : 11,
// @type int Course = 20
// @type int Course = 20.
COURSE : 20,
// @type int Course section = 30
// @type int Course section = 30.
SECTION : 30,
// @type int Activity (course module) = 40
// @type int Activity (course module) = 40.
ACTIVITY : 40,
// @type int Resource (course module = 50
// @type int Resource (course module = 50.
RESOURCE : 50,
// @type int Custom node (could be anything) = 60
// @type int Custom node (could be anything) = 60.
CUSTOM : 60,
// @type int Setting = 70
// @type int Setting = 70.
SETTING : 70,
// @type int site administration = 71
// @type int site administration = 71.
SITEADMIN : 71,
// @type int User context = 80
// @type int User context = 80.
USER : 80,
// @type int Container = 90
// @type int Container = 90.
CONTAINER : 90
};

/**
* Build DOM.
*
* @method buildDOM
* @param {Object} rootElement the root element of DOM.
* @param {object} nodes jquery object representing the nodes to be build.
* @return
*/
function buildDOM(rootElement, nodes) {
var ul = $('<ul></ul>');
ul.attr('role', 'group');
Expand Down Expand Up @@ -149,8 +157,7 @@ define(['jquery'], function($) {

return {
render: function(element, nodes) {
// The first element of the response is the existing node
// so we start with processing the children.
// The first element of the response is the existing node so we start with processing the children.
if (nodes.children && nodes.children.length) {
buildDOM(element, nodes.children);
} else {
Expand Down
18 changes: 12 additions & 6 deletions blocks/navigation/amd/src/nav_loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,19 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define(['jquery', 'core/ajax', 'core/config', 'block_navigation/ajax_response_renderer'],
function($, ajax, config, renderer) {
function($, ajax, config, renderer) {
var URL = config.wwwroot + '/lib/ajax/getnavbranch.php';

var URL = config.wwwroot + '/lib/ajax/getnavbranch.php';

function getBlockInstanceId(element) {
return element.closest('[data-block]').attr('data-instanceid');
}
/**
* Get the block instance id.
*
* @function getBlockInstanceId
* @param element
* @returns {*}
*/
function getBlockInstanceId(element) {
return element.closest('[data-block]').attr('data-instanceid');
}

return {
load: function(element) {
Expand Down
2 changes: 1 addition & 1 deletion blocks/navigation/amd/src/navblock.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Load the navtree javscript
* Load the navigation tree javascript.
*
* @module block_navigation/navblock
* @package core
Expand Down
2 changes: 1 addition & 1 deletion blocks/navigation/amd/src/site_admin_loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ define(['jquery', 'core/ajax', 'core/config', 'block_navigation/ajax_response_re
var promise = $.Deferred();
var data = {
type: SITE_ADMIN_NODE_TYPE,
sesskey: config.sesskey,
sesskey: config.sesskey
};
var settings = {
type: 'POST',
Expand Down
2 changes: 1 addition & 1 deletion blocks/navigation/block_navigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ function instance_can_be_docked() {
* Gets Javascript that may be required for navigation
*/
function get_required_javascript() {
global $CFG;
parent::get_required_javascript();
$this->page->requires->string_for_js('viewallcourses', 'moodle');
$this->page->requires->js_call_amd('block_navigation/navblock', 'init', array());
Expand All @@ -119,6 +118,7 @@ function get_required_javascript() {
* @return object $this->content
*/
function get_content() {
global $CFG;
// First check if we have already generated, don't waste cycles
if ($this->contentgenerated === true) {
return $this->content;
Expand Down
3 changes: 2 additions & 1 deletion blocks/navigation/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ protected function navigation_node($items, $attrs=array(), $expansionlimit=null,
// Create the structure.
$content = html_writer::tag('p', $content, $divattr);
if ($isexpandable) {
$content .= $this->navigation_node($item->children, array('role' => 'group'), $expansionlimit, $options, $depth+1);
$content .= $this->navigation_node($item->children, array('role' => 'group'), $expansionlimit,
$options, $depth + 1);
}
if (!empty($item->preceedwithhr) && $item->preceedwithhr===true) {
$content = html_writer::empty_tag('hr') . $content;
Expand Down
1 change: 1 addition & 0 deletions blocks/settings/amd/build/settingsblock.min.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
define(["jquery","core/tree"],function(a,b){return{init:function(){new b(".block_settings .block_tree")}}});
15 changes: 12 additions & 3 deletions blocks/settings/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ public function settings_tree(settings_navigation $navigation) {
return $content;
}

/**
* Build the navigation node.
*
* @param navigation_node $node the navigation node object.
* @param array $attrs list of attributes.
* @param int $depth the depth, default to 1.
* @return string the navigation node code.
*/
protected function navigation_node(navigation_node $node, $attrs=array(), $depth = 1) {
$items = $node->children;

Expand Down Expand Up @@ -73,7 +81,8 @@ protected function navigation_node(navigation_node $node, $attrs=array(), $depth
$liexpandable = array();
if ($isbranch) {
$liclasses[] = 'contains_branch';
if (!$item->forceopen || (!$item->forceopen && $item->collapse) || ($item->children->count()==0 && $item->nodetype==navigation_node::NODETYPE_BRANCH)) {
if (!$item->forceopen || (!$item->forceopen && $item->collapse) || ($item->children->count() == 0
&& $item->nodetype == navigation_node::NODETYPE_BRANCH)) {
$liexpandable = array('aria-expanded' => 'false');
} else {
$liexpandable = array('aria-expanded' => 'true');
Expand All @@ -90,7 +99,7 @@ protected function navigation_node(navigation_node $node, $attrs=array(), $depth
$liclasses[] = 'current_branch';
}
$nodetextid = 'label_' . $depth . '_' . $number;
$liattr = array('class' => join(' ',$liclasses), 'tabindex' => '-1', 'role' => 'treeitem') + $liexpandable;
$liattr = array('class' => join(' ', $liclasses), 'tabindex' => '-1', 'role' => 'treeitem') + $liexpandable;
// class attribute on the div item which only contains the item content
$divclasses = array('tree_item');
if ($isbranch) {
Expand All @@ -105,7 +114,7 @@ protected function navigation_node(navigation_node $node, $attrs=array(), $depth
if (!empty($item->id)) {
$divattr['id'] = $item->id;
}
$content = html_writer::tag('p', $content, $divattr) . $this->navigation_node($item, array(), $depth+1);
$content = html_writer::tag('p', $content, $divattr) . $this->navigation_node($item, array(), $depth + 1);
if (!empty($item->preceedwithhr) && $item->preceedwithhr===true) {
$content = html_writer::empty_tag('hr') . $content;
}
Expand Down
6 changes: 6 additions & 0 deletions blocks/upgrade.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
This files describes API changes in /blocks/* - activity modules,
information provided here is intended especially for developers.

=== 3.1 ===

* The collapsed class was removed from the navigation block to make it compatible with aria.
* New aria attributes were added on the navigation block [aria-expanded="false"].
* The tree JS handling were moved from YUI to AMD module (Jquery).

=== 2.9 ===

* The obsolete method preferred_width() was removed (it was not doing anything)
Expand Down
1 change: 1 addition & 0 deletions lib/amd/build/tree.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6759dc3

Please sign in to comment.