much better interaction on levels keys with tabs

This commit is contained in:
Peter Cottle 2013-10-26 12:46:19 -07:00
parent 12e921a781
commit c522722513
4 changed files with 56 additions and 2 deletions

View file

@ -89,6 +89,10 @@ var LevelDropdownView = ContainedBase.extend({
if (id === this.JSON.selectedTab) {
return;
}
this.updateTabTo(id);
},
updateTabTo: function(id) {
this.JSON.selectedTab = id;
this.render();
if (this.selectedID) {
@ -119,7 +123,24 @@ var LevelDropdownView = ContainedBase.extend({
leftOrRight: function(delta) {
this.deselectIconByID(this.selectedID);
this.selectedIndex = this.wrapIndex(this.selectedIndex + delta, this.getCurrentSequence());
var index = this.selectedIndex + delta;
var sequence = this.getCurrentSequence();
var tabs = this.JSON.tabs;
// switch tabs now if needed / possible
if (index >= sequence.length &&
this.getTabIndex() + 1 < tabs.length) {
this.switchToTabIndex(this.getTabIndex() + 1);
this.selectedIndex = 0;
} else if (index < 0 &&
this.getTabIndex() - 1 >= 0) {
this.switchToTabIndex(this.getTabIndex() - 1);
this.selectedIndex = 0;
} else {
this.selectedIndex = this.wrapIndex(
this.selectedIndex + delta, this.getCurrentSequence()
);
}
this.updateSelectedIcon();
},
@ -168,6 +189,18 @@ var LevelDropdownView = ContainedBase.extend({
this.selectedSequence = undefined;
},
getTabIndex: function() {
var ids = _.map(this.JSON.tabs, function(tab) {
return tab.id;
});
return ids.indexOf(this.JSON.selectedTab);
},
switchToTabIndex: function(index) {
var tabID = this.JSON.tabs[index].id;
this.updateTabTo(tabID);
},
wrapIndex: function(index, arr) {
index = (index >= arr.length) ? 0 : index;
index = (index < 0) ? arr.length - 1 : index;