diff --git a/source/Ox.UI/js/List/CustomList.js b/source/Ox.UI/js/List/CustomList.js index f121697f..c15a16dc 100644 --- a/source/Ox.UI/js/List/CustomList.js +++ b/source/Ox.UI/js/List/CustomList.js @@ -134,6 +134,11 @@ Ox.CustomList = function(options, self) { return that; }; + that.selectSelected = function(offset) { + that.$list.selectSelected(offset); + return that; + }; + /*@ size size @*/ diff --git a/source/Ox.UI/js/List/IconList.js b/source/Ox.UI/js/List/IconList.js index 9b1a25fe..4cb571bd 100644 --- a/source/Ox.UI/js/List/IconList.js +++ b/source/Ox.UI/js/List/IconList.js @@ -220,6 +220,16 @@ Ox.IconList = function(options, self) { return that; }; + that.selectPosition = function(pos) { + that.$element.selectPosition(pos); + return that; + }; + + that.selectSelected = function(offset) { + that.$element.selectSelected(offset); + return that; + }; + /*@ size get size of list () -> size diff --git a/source/Ox.UI/js/List/InfoList.js b/source/Ox.UI/js/List/InfoList.js index 2b614775..540963d0 100644 --- a/source/Ox.UI/js/List/InfoList.js +++ b/source/Ox.UI/js/List/InfoList.js @@ -239,6 +239,16 @@ Ox.InfoList = function(options, self) { return that; }; + that.selectPosition = function(pos) { + that.$element.selectPosition(pos); + return that; + }; + + that.selectSelected = function(offset) { + that.$element.selectSelected(offset); + return that; + }; + /*@ size size @*/ diff --git a/source/Ox.UI/js/List/List.js b/source/Ox.UI/js/List/List.js index 762ba829..b338e5d2 100644 --- a/source/Ox.UI/js/List/List.js +++ b/source/Ox.UI/js/List/List.js @@ -355,21 +355,19 @@ Ox.List = function(options, self) { } function addToSelection(pos) { - var triggerEvent = false; - Ox.makeArray(pos).forEach(function(pos) { + Ox.makeArray(pos).reverse().forEach(function(pos) { if (!isSelected(pos)) { - self.selected.push(pos); + self.selected.unshift(pos); if (!Ox.isUndefined(self.$items[pos])) { self.$items[pos].addClass('OxSelected'); } - triggerEvent = true; } else { - // allow for 'cursor navigation' if orientation == 'both' + // allow for 'cursor navigation' if orientation is 'both' self.selected.splice(self.selected.indexOf(pos), 1); - self.selected.push(pos); + self.selected.unshift(pos); } }); - triggerEvent && triggerSelectEvent(); + triggerSelectEvent(); } function clear() { @@ -573,7 +571,7 @@ Ox.List = function(options, self) { function getAbove() { var pos = -1; if (self.selected.length) { - pos = self.selected[self.selected.length - 1] - self.rowLength; + pos = self.selected[0] - self.rowLength; if (pos < 0) { pos = -1; } @@ -584,7 +582,7 @@ Ox.List = function(options, self) { function getBelow() { var pos = -1; if (self.selected.length) { - pos = self.selected[self.selected.length - 1] + self.rowLength; + pos = self.selected[0] + self.rowLength; if (pos >= self.$items.length) { pos = -1; } @@ -609,9 +607,11 @@ Ox.List = function(options, self) { function getNext() { var pos = -1; if (self.selected.length) { - pos = (self.options.orientation == 'both' - ? self.selected[self.selected.length - 1] - : Ox.max(self.selected)) + 1; + pos = ( + self.options.orientation == 'both' + ? self.selected[0] + : Ox.max(self.selected) + ) + 1; if (pos == self.$items.length) { pos = -1; } @@ -721,9 +721,11 @@ Ox.List = function(options, self) { function getPrevious() { var pos = -1; if (self.selected.length) { - pos = (self.options.orientation == 'both' - ? self.selected[self.selected.length - 1] - : Ox.min(self.selected)) - 1; + pos = ( + self.options.orientation == 'both' + ? self.selected[0] + : Ox.min(self.selected) + ) - 1; } return pos; } @@ -1316,7 +1318,7 @@ Ox.List = function(options, self) { } var triggerSelectEvent = Ox.debounce(function() { - // throttle in case shift+cursor is pressed + // throttle in case shift+arrow is pressed getSelectedIds(function(ids, rest) { self.options.selected = ids; that.triggerEvent('select', Ox.extend({ @@ -1721,6 +1723,24 @@ Ox.List = function(options, self) { return that; }; + /*@ + selectSelected Change the first selected item within the selection + (offset) -> List Object + offset Offset (`-1` for previous, `1` for next) + @*/ + that.selectSelected = function(offset) { + var pos, positions; + if (self.selected.length > 1) { + positions = Ox.sort(Ox.clone(self.selected)); + pos = positions[ + Ox.mod(positions.indexOf(self.selected[0]) + offset, positions.length) + ]; + addToSelection(pos); + scrollToPosition(pos); + } + return that; + }; + /*@ size fixme: not a good function name () -> List Object diff --git a/source/Ox.UI/js/List/TableList.js b/source/Ox.UI/js/List/TableList.js index 7d19f816..af2cf664 100644 --- a/source/Ox.UI/js/List/TableList.js +++ b/source/Ox.UI/js/List/TableList.js @@ -1133,6 +1133,11 @@ Ox.TableList = function(options, self) { return that; }; + that.selectSelected = function(offset) { + that.$body.selectSelected(offset); + return that; + }; + that.setColumnTitle = function(id, title) { var index = getColumnIndexById(id); self.options.columns[index].title = title;