From 463aee0ce902a7785903642088ae179bc5000f21 Mon Sep 17 00:00:00 2001 From: jos Date: Thu, 1 May 2014 12:01:04 +0200 Subject: [PATCH] Fixed removing items --- src/timeline/component/Group.js | 8 ++++++++ src/timeline/component/ItemSet.js | 19 +++++++++++++------ src/timeline/component/item/Item.js | 5 ++--- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/timeline/component/Group.js b/src/timeline/component/Group.js index c22ce385..757d36b3 100644 --- a/src/timeline/component/Group.js +++ b/src/timeline/component/Group.js @@ -248,6 +248,14 @@ Group.prototype.remove = function remove(item) { // TODO: also remove from ordered items? }; +/** + * Remove an item from the corresponding DataSet + * @param {Item} item + */ +Group.prototype.removeFromDataSet = function removeFromDataSet(item) { + this.itemSet.removeItem(item.id); +}; + /** * Order the items * @private diff --git a/src/timeline/component/ItemSet.js b/src/timeline/component/ItemSet.js index a92fff7d..ca137272 100644 --- a/src/timeline/component/ItemSet.js +++ b/src/timeline/component/ItemSet.js @@ -572,12 +572,7 @@ ItemSet.prototype._onUpdate = function _onUpdate(ids) { } }); - // reorder the items in all groups - // TODO: optimization: only reorder groups affected by the changed items - util.forEach(this.groups, function (group) { - group._order(); - }); - + this._order(); this.stackDirty = true; // force re-stacking of all items next repaint this.emit('change'); }; @@ -613,6 +608,18 @@ ItemSet.prototype._onRemove = function _onRemove(ids) { } }; +/** + * Update the order of item in all groups + * @private + */ +ItemSet.prototype._order = function _order() { + // reorder the items in all groups + // TODO: optimization: only reorder groups affected by the changed items + util.forEach(this.groups, function (group) { + group._order(); + }); +}; + /** * Handle updated groups * @param {Number[]} ids diff --git a/src/timeline/component/item/Item.js b/src/timeline/component/item/Item.js index 64cb5577..470b7569 100644 --- a/src/timeline/component/item/Item.js +++ b/src/timeline/component/item/Item.js @@ -112,8 +112,7 @@ Item.prototype.repositionY = function repositionY() { Item.prototype._repaintDeleteButton = function (anchor) { if (this.selected && this.options.editable && !this.dom.deleteButton) { // create and show button - var parent = this.parent; - var id = this.id; + var me = this; var deleteButton = document.createElement('div'); deleteButton.className = 'delete'; @@ -122,7 +121,7 @@ Item.prototype._repaintDeleteButton = function (anchor) { Hammer(deleteButton, { preventDefault: true }).on('tap', function (event) { - parent.removeItem(id); + me.parent.removeFromDataSet(me); event.stopPropagation(); });