MDL-62491 navigation: Update to tree.js to allow callbacks.
This commit is contained in:
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+17
-2
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user