From 46389aeae7027ad9f91ee3cb8deb25580546e178 Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Fri, 9 Oct 2015 19:17:44 +0200 Subject: [PATCH 1/2] added option multiselectFiltersGroup --- lib/timeline/component/ItemSet.js | 46 ++++++++++++++++++++----------- lib/timeline/optionsTimeline.js | 2 ++ 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/lib/timeline/component/ItemSet.js b/lib/timeline/component/ItemSet.js index 094dbc6a..03455be7 100644 --- a/lib/timeline/component/ItemSet.js +++ b/lib/timeline/component/ItemSet.js @@ -307,7 +307,7 @@ ItemSet.prototype._create = function(){ ItemSet.prototype.setOptions = function(options) { if (options) { // copy all options that we know - var fields = ['type', 'align', 'order', 'stack', 'selectable', 'multiselect', 'groupOrder', 'dataAttributes', 'template', 'groupTemplate', 'hide', 'snap', 'groupOrderSwap']; + var fields = ['type', 'align', 'order', 'stack', 'selectable', 'multiselect', 'multiselectFiltersGroup', 'groupOrder', 'dataAttributes', 'template', 'groupTemplate', 'hide', 'snap', 'groupOrderSwap']; util.selectiveExtend(fields, this.options, options); if ('orientation' in options) { @@ -1759,23 +1759,37 @@ ItemSet.prototype._onMultiSelectItem = function (event) { if (shiftKey && this.options.multiselect) { // select all items between the old selection and the tapped item - + var itemGroup = this.itemsData.get(item.id).group; + + // when filtering get the group of the last selected item + var lastSelectedGroup = undefined; + if (this.options.multiselectFiltersGroup) { + if (selection.length > 0) { + lastSelectedGroup = this.itemsData.get(selection[0]).group; + } + } + // determine the selection range - selection.push(item.id); + if (!this.options.multiselectFiltersGroup || lastSelectedGroup == undefined || lastSelectedGroup == itemGroup) { + selection.push(item.id); + } var range = ItemSet._getItemRange(this.itemsData.get(selection, this.itemOptions)); - - // select all items within the selection range - selection = []; - for (var id in this.items) { - if (this.items.hasOwnProperty(id)) { - var _item = this.items[id]; - var start = _item.data.start; - var end = (_item.data.end !== undefined) ? _item.data.end : start; - - if (start >= range.min && - end <= range.max && - !(_item instanceof BackgroundItem)) { - selection.push(_item.id); // do not use id but item.id, id itself is stringified + + if (!this.options.multiselectFiltersGroup || lastSelectedGroup == itemGroup) { + // select all items within the selection range + selection = []; + for (var id in this.items) { + if (this.items.hasOwnProperty(id)) { + var _item = this.items[id]; + var start = _item.data.start; + var end = (_item.data.end !== undefined) ? _item.data.end : start; + + if (start >= range.min && + end <= range.max && + (!this.options.multiselectFiltersGroup || lastSelectedGroup == this.itemsData.get(_item.id).group) && + !(_item instanceof BackgroundItem)) { + selection.push(_item.id); // do not use id but item.id, id itself is stringified + } } } } diff --git a/lib/timeline/optionsTimeline.js b/lib/timeline/optionsTimeline.js index 5d0ad3c1..2d6750db 100644 --- a/lib/timeline/optionsTimeline.js +++ b/lib/timeline/optionsTimeline.js @@ -98,6 +98,7 @@ let allOptions = { minHeight: {number, string}, moveable: {boolean}, multiselect: {boolean}, + multiselectFiltersGroup: {boolean}, onAdd: {'function': 'function'}, onUpdate: {'function': 'function'}, onMove: {'function': 'function'}, @@ -191,6 +192,7 @@ let configureOptions = { minHeight: '', moveable: false, multiselect: false, + multiselectFiltersGroup: false, //onAdd: {'function': 'function'}, //onUpdate: {'function': 'function'}, //onMove: {'function': 'function'}, From 4b414646fabb95c5e667f5906c51283f986aa61f Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Mon, 12 Oct 2015 11:54:56 +0200 Subject: [PATCH 2/2] renamed option from multiselectFiltersGroup to multiselectPerGroup, added docs --- docs/timeline/index.html | 10 ++++++++++ lib/timeline/component/ItemSet.js | 10 +++++----- lib/timeline/optionsTimeline.js | 4 ++-- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/docs/timeline/index.html b/docs/timeline/index.html index 92823b52..8987c78b 100644 --- a/docs/timeline/index.html +++ b/docs/timeline/index.html @@ -769,6 +769,16 @@ function (option, path) { Only applicable when option selectable is true. + + + multiselectPerGroup + boolean + false + + If true, selecting multiple items using shift+click will only select items residing in the same group as the first selected item. + Only applicable when option selectable and multiselect are true. + + onAdd diff --git a/lib/timeline/component/ItemSet.js b/lib/timeline/component/ItemSet.js index 03455be7..e688bf11 100644 --- a/lib/timeline/component/ItemSet.js +++ b/lib/timeline/component/ItemSet.js @@ -307,7 +307,7 @@ ItemSet.prototype._create = function(){ ItemSet.prototype.setOptions = function(options) { if (options) { // copy all options that we know - var fields = ['type', 'align', 'order', 'stack', 'selectable', 'multiselect', 'multiselectFiltersGroup', 'groupOrder', 'dataAttributes', 'template', 'groupTemplate', 'hide', 'snap', 'groupOrderSwap']; + var fields = ['type', 'align', 'order', 'stack', 'selectable', 'multiselect', 'multiselectPerGroup', 'groupOrder', 'dataAttributes', 'template', 'groupTemplate', 'hide', 'snap', 'groupOrderSwap']; util.selectiveExtend(fields, this.options, options); if ('orientation' in options) { @@ -1763,19 +1763,19 @@ ItemSet.prototype._onMultiSelectItem = function (event) { // when filtering get the group of the last selected item var lastSelectedGroup = undefined; - if (this.options.multiselectFiltersGroup) { + if (this.options.multiselectPerGroup) { if (selection.length > 0) { lastSelectedGroup = this.itemsData.get(selection[0]).group; } } // determine the selection range - if (!this.options.multiselectFiltersGroup || lastSelectedGroup == undefined || lastSelectedGroup == itemGroup) { + if (!this.options.multiselectPerGroup || lastSelectedGroup == undefined || lastSelectedGroup == itemGroup) { selection.push(item.id); } var range = ItemSet._getItemRange(this.itemsData.get(selection, this.itemOptions)); - if (!this.options.multiselectFiltersGroup || lastSelectedGroup == itemGroup) { + if (!this.options.multiselectPerGroup || lastSelectedGroup == itemGroup) { // select all items within the selection range selection = []; for (var id in this.items) { @@ -1786,7 +1786,7 @@ ItemSet.prototype._onMultiSelectItem = function (event) { if (start >= range.min && end <= range.max && - (!this.options.multiselectFiltersGroup || lastSelectedGroup == this.itemsData.get(_item.id).group) && + (!this.options.multiselectPerGroup || lastSelectedGroup == this.itemsData.get(_item.id).group) && !(_item instanceof BackgroundItem)) { selection.push(_item.id); // do not use id but item.id, id itself is stringified } diff --git a/lib/timeline/optionsTimeline.js b/lib/timeline/optionsTimeline.js index 2d6750db..e3e9c3f3 100644 --- a/lib/timeline/optionsTimeline.js +++ b/lib/timeline/optionsTimeline.js @@ -98,7 +98,7 @@ let allOptions = { minHeight: {number, string}, moveable: {boolean}, multiselect: {boolean}, - multiselectFiltersGroup: {boolean}, + multiselectPerGroup: {boolean}, onAdd: {'function': 'function'}, onUpdate: {'function': 'function'}, onMove: {'function': 'function'}, @@ -192,7 +192,7 @@ let configureOptions = { minHeight: '', moveable: false, multiselect: false, - multiselectFiltersGroup: false, + multiselectPerGroup: false, //onAdd: {'function': 'function'}, //onUpdate: {'function': 'function'}, //onMove: {'function': 'function'},