Browse Source

Fixed removing items

css_transitions
jos 10 years ago
parent
commit
463aee0ce9
3 changed files with 23 additions and 9 deletions
  1. +8
    -0
      src/timeline/component/Group.js
  2. +13
    -6
      src/timeline/component/ItemSet.js
  3. +2
    -3
      src/timeline/component/item/Item.js

+ 8
- 0
src/timeline/component/Group.js View File

@ -248,6 +248,14 @@ Group.prototype.remove = function remove(item) {
// TODO: also remove from ordered items? // 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 * Order the items
* @private * @private

+ 13
- 6
src/timeline/component/ItemSet.js View File

@ -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.stackDirty = true; // force re-stacking of all items next repaint
this.emit('change'); 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 * Handle updated groups
* @param {Number[]} ids * @param {Number[]} ids

+ 2
- 3
src/timeline/component/item/Item.js View File

@ -112,8 +112,7 @@ Item.prototype.repositionY = function repositionY() {
Item.prototype._repaintDeleteButton = function (anchor) { Item.prototype._repaintDeleteButton = function (anchor) {
if (this.selected && this.options.editable && !this.dom.deleteButton) { if (this.selected && this.options.editable && !this.dom.deleteButton) {
// create and show button // create and show button
var parent = this.parent;
var id = this.id;
var me = this;
var deleteButton = document.createElement('div'); var deleteButton = document.createElement('div');
deleteButton.className = 'delete'; deleteButton.className = 'delete';
@ -122,7 +121,7 @@ Item.prototype._repaintDeleteButton = function (anchor) {
Hammer(deleteButton, { Hammer(deleteButton, {
preventDefault: true preventDefault: true
}).on('tap', function (event) { }).on('tap', function (event) {
parent.removeItem(id);
me.parent.removeFromDataSet(me);
event.stopPropagation(); event.stopPropagation();
}); });

Loading…
Cancel
Save