MDL-62491 navigation: Update to tree.js to allow callbacks.

This commit is contained in:
Adrian Greeve
2018-10-09 09:40:06 +08:00
parent 375eb5e975
commit bb76ffff21
2 changed files with 18 additions and 3 deletions
+1 -1
View File
File diff suppressed because one or more lines are too long
+17 -2
View File
@@ -70,6 +70,10 @@ define(['jquery'], function($) {
this.bindEventHandlers();
};
Tree.prototype.registerEnterCallback = function(callback) {
this.enterCallback = callback;
};
/**
* Find all visible tree items and save a cache of them on the tree object.
*
@@ -136,7 +140,13 @@ define(['jquery'], function($) {
* @returns {bool}
*/
Tree.prototype.getGroupFromItem = function(item) {
return this.treeRoot.find('#' + item.attr('aria-owns')) || item.children('[role=group]');
var ariaowns = this.treeRoot.find('#' + item.attr('aria-owns'));
var plain = item.children('[role=group]');
if (ariaowns.length > plain.length) {
return ariaowns;
} else {
return plain;
}
};
/**
@@ -371,7 +381,12 @@ define(['jquery'], function($) {
case this.keys.enter: {
var links = item.children('a').length ? item.children('a') : item.children().not(SELECTORS.GROUP).find('a');
if (links.length) {
window.location.href = links.first().attr('href');
// See if we have a callback.
if (typeof this.enterCallback === 'function') {
this.enterCallback(item);
} else {
window.location.href = links.first().attr('href');
}
} else if (this.isGroupItem(item)) {
this.toggleGroup(item, true);
}