Skip to content
This repository has been archived by the owner on Jul 29, 2019. It is now read-only.

Fix #2285 #2304

Merged
merged 1 commit into from
Nov 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions lib/timeline/component/ItemSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -1789,22 +1789,19 @@ ItemSet.prototype._onMouseOut = function (event) {
});
};


/**
* Handle creation and updates of an item on double tap
* Handle updates of an item on double tap
* @param event
* @private
*/
ItemSet.prototype._onAddItem = function (event) {
ItemSet.prototype._onUpdateItem = function (item) {
if (!this.options.selectable) return;
if (!this.options.editable.add) return;

var me = this;
var snap = this.options.snap || null;
var item = this.itemFromTarget(event);


if (item) {
// update item

// execute async handler to update the item (or cancel it)
var itemData = me.itemsData.get(item.id); // get a clone of the data from the dataset
this.options.onUpdate(itemData, function (itemData) {
Expand All @@ -1813,7 +1810,22 @@ ItemSet.prototype._onAddItem = function (event) {
}
});
}
else {
}

/**
* Handle creation of an item on double tap
* @param event
* @private
*/
ItemSet.prototype._onAddItem = function (event) {
if (!this.options.selectable) return;
if (!this.options.editable.add) return;

var me = this;
var snap = this.options.snap || null;
var item = this.itemFromTarget(event);

if (!item) {
// add item
if (this.options.rtl) {
var xAbs = util.getAbsoluteRight(this.dom.frame);
Expand Down
65 changes: 36 additions & 29 deletions lib/timeline/component/item/Item.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,42 @@ Item.prototype.repositionY = function() {
// should be implemented by the item
};

/**
* Repaint a drag area on the center of the item when the item is selected
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you mode the function in the file? Its confusing... :-)

* @protected
*/
Item.prototype._repaintDragCenter = function () {
if (this.selected && this.options.editable.updateTime && !this.dom.dragCenter) {
var me = this;

// create and show drag area
var dragCenter = document.createElement('div');
dragCenter.className = 'vis-drag-center';
dragCenter.dragCenterItem = this;

new Hammer(dragCenter).on('doubletap', function (event) {
event.stopPropagation();
me.parent.itemSet._onUpdateItem(me);
});

if (this.dom.box) {
this.dom.box.appendChild(dragCenter);
}
else if (this.dom.point) {
this.dom.point.appendChild(dragCenter);
}

this.dom.dragCenter = dragCenter;
}
else if (!this.selected && this.dom.dragCenter) {
// delete drag area
if (this.dom.dragCenter.parentNode) {
this.dom.dragCenter.parentNode.removeChild(this.dom.dragCenter);
}
this.dom.dragCenter = null;
}
};

/**
* Repaint a delete button on the top right of the item when the item is selected
* @param {HTMLElement} anchor
Expand Down Expand Up @@ -401,33 +437,4 @@ Item.prototype.getWidthRight = function () {
return 0;
};

/**
* Repaint a drag area on the center of the item when the item is selected
* @protected
*/
Item.prototype._repaintDragCenter = function () {
if (this.selected && this.options.editable.updateTime && !this.dom.dragCenter) {
// create and show drag area
var dragCenter = document.createElement('div');
dragCenter.className = 'vis-drag-center';
dragCenter.dragCenterItem = this;

if (this.dom.box) {
this.dom.box.appendChild(dragCenter);
}
else if (this.dom.point) {
this.dom.point.appendChild(dragCenter);
}

this.dom.dragCenter = dragCenter;
}
else if (!this.selected && this.dom.dragCenter) {
// delete drag area
if (this.dom.dragCenter.parentNode) {
this.dom.dragCenter.parentNode.removeChild(this.dom.dragCenter);
}
this.dom.dragCenter = null;
}
};

module.exports = Item;