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.
*
* @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;
+ }
};
/**
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);
}