From 5e1169eb88d0192ca9ce45469e6937d7defa1d7e Mon Sep 17 00:00:00 2001 From: Liuqing Chen Date: Fri, 23 Oct 2015 16:56:11 -0700 Subject: [PATCH 1/2] add allDraggable option for timeline to support dragging unselected item --- lib/timeline/component/ItemSet.js | 9 ++++++--- lib/timeline/optionsTimeline.js | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/timeline/component/ItemSet.js b/lib/timeline/component/ItemSet.js index e688bf11..3cc5fbc8 100644 --- a/lib/timeline/component/ItemSet.js +++ b/lib/timeline/component/ItemSet.js @@ -43,6 +43,7 @@ function ItemSet(body, options) { selectable: true, multiselect: false, + allDraggable: false, editable: { updateTime: false, @@ -307,7 +308,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', 'multiselectPerGroup', 'groupOrder', 'dataAttributes', 'template', 'groupTemplate', 'hide', 'snap', 'groupOrderSwap']; + var fields = ['type', 'align', 'order', 'stack', 'selectable', 'multiselect', 'allDraggable', 'multiselectPerGroup', 'groupOrder', 'dataAttributes', 'template', 'groupTemplate', 'hide', 'snap', 'groupOrderSwap']; util.selectiveExtend(fields, this.options, options); if ('orientation' in options) { @@ -1172,7 +1173,7 @@ ItemSet.prototype._onDragStart = function (event) { var me = this; var props; - if (item && item.selected) { + if (item && (item.selected || this.options.allDraggable)) { if (!this.options.editable.updateTime && !this.options.editable.updateGroup && @@ -1213,7 +1214,9 @@ ItemSet.prototype._onDragStart = function (event) { var baseGroupIndex = this._getGroupIndex(item.data.group); - this.touchParams.itemProps = this.getSelection().map(function (id) { + var itemsToDrag = (this.options.allDraggable && !item.selected) ? [item.id] : this.getSelection(); + + this.touchParams.itemProps = itemsToDrag.map(function (id) { var item = me.items[id]; var groupIndex = me._getGroupIndex(item.data.group); return { diff --git a/lib/timeline/optionsTimeline.js b/lib/timeline/optionsTimeline.js index e3e9c3f3..fecafff6 100644 --- a/lib/timeline/optionsTimeline.js +++ b/lib/timeline/optionsTimeline.js @@ -26,6 +26,7 @@ let allOptions = { //globals : align: {string}, + allDraggable: { boolean: boolean }, autoResize: {boolean}, throttleRedraw: {number}, clickToUse: {boolean}, From 5009adca927c307104f1dd05b3f952d768d5894d Mon Sep 17 00:00:00 2001 From: Liuqing Chen Date: Sun, 8 Nov 2015 17:11:01 -0800 Subject: [PATCH 2/2] Rename timeline option 'allDraggable' to 'itemsAlwaysDraggable' and update documentation --- docs/timeline/index.html | 8 ++++++++ lib/timeline/component/ItemSet.js | 8 ++++---- lib/timeline/optionsTimeline.js | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/docs/timeline/index.html b/docs/timeline/index.html index 8987c78b..f7a28fa6 100644 --- a/docs/timeline/index.html +++ b/docs/timeline/index.html @@ -666,6 +666,14 @@ function (option, path) { and set repeat to weekly. + + + itemsAlwaysDraggable + boolean + false + If true, all items in the Timeline are draggable without being selected. If false, only the selected item(s) are draggable. + + locale String diff --git a/lib/timeline/component/ItemSet.js b/lib/timeline/component/ItemSet.js index 3cc5fbc8..4ec39bfb 100644 --- a/lib/timeline/component/ItemSet.js +++ b/lib/timeline/component/ItemSet.js @@ -43,7 +43,7 @@ function ItemSet(body, options) { selectable: true, multiselect: false, - allDraggable: false, + itemsAlwaysDraggable: false, editable: { updateTime: false, @@ -308,7 +308,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', 'allDraggable', 'multiselectPerGroup', 'groupOrder', 'dataAttributes', 'template', 'groupTemplate', 'hide', 'snap', 'groupOrderSwap']; + var fields = ['type', 'align', 'order', 'stack', 'selectable', 'multiselect', 'itemsAlwaysDraggable', 'multiselectPerGroup', 'groupOrder', 'dataAttributes', 'template', 'groupTemplate', 'hide', 'snap', 'groupOrderSwap']; util.selectiveExtend(fields, this.options, options); if ('orientation' in options) { @@ -1173,7 +1173,7 @@ ItemSet.prototype._onDragStart = function (event) { var me = this; var props; - if (item && (item.selected || this.options.allDraggable)) { + if (item && (item.selected || this.options.itemsAlwaysDraggable)) { if (!this.options.editable.updateTime && !this.options.editable.updateGroup && @@ -1214,7 +1214,7 @@ ItemSet.prototype._onDragStart = function (event) { var baseGroupIndex = this._getGroupIndex(item.data.group); - var itemsToDrag = (this.options.allDraggable && !item.selected) ? [item.id] : this.getSelection(); + var itemsToDrag = (this.options.itemsAlwaysDraggable && !item.selected) ? [item.id] : this.getSelection(); this.touchParams.itemProps = itemsToDrag.map(function (id) { var item = me.items[id]; diff --git a/lib/timeline/optionsTimeline.js b/lib/timeline/optionsTimeline.js index fecafff6..5218a64e 100644 --- a/lib/timeline/optionsTimeline.js +++ b/lib/timeline/optionsTimeline.js @@ -26,7 +26,6 @@ let allOptions = { //globals : align: {string}, - allDraggable: { boolean: boolean }, autoResize: {boolean}, throttleRedraw: {number}, clickToUse: {boolean}, @@ -80,6 +79,7 @@ let allOptions = { repeat: {string}, __type__: {object, array} }, + itemsAlwaysDraggable: { boolean: boolean }, locale:{string}, locales:{ __type__: {object}