Browse Source

Fixed repeatedly fired select event when clicking in an empty space in the Timeline

css_transitions
jos 10 years ago
parent
commit
edec21743e
3 changed files with 29 additions and 35 deletions
  1. +10
    -4
      src/timeline/Timeline.js
  2. +2
    -31
      src/timeline/component/GroupSet.js
  3. +17
    -0
      src/util.js

+ 10
- 4
src/timeline/Timeline.js View File

@ -536,14 +536,20 @@ Timeline.prototype._onSelectItem = function (event) {
return;
}
var item = ItemSet.itemFromTarget(event);
var oldSelection = this.getSelection();
var item = ItemSet.itemFromTarget(event);
var selection = item ? [item.id] : [];
this.setSelection(selection);
this.emit('select', {
items: this.getSelection()
});
var newSelection = this.getSelection();
// if selection is changed, emit a select event
if (!util.equalArray(oldSelection, newSelection)) {
this.emit('select', {
items: this.getSelection()
});
}
event.stopPropagation();
};

+ 2
- 31
src/timeline/component/GroupSet.js View File

@ -473,16 +473,9 @@ GroupSet.groupSetFromTarget = function groupSetFromTarget (event) {
*/
GroupSet.groupFromTarget = function groupFromTarget (event) {
// find the groupSet
var groupSet = null;
var target = event.target;
while (target && !groupSet) {
if (target.hasOwnProperty('timeline-groupset')) {
groupSet = target['timeline-groupset'];
}
target = target.parentNode;
}
var groupSet = GroupSet.groupSetFromTarget(event);
// find the itemset
// find the ItemSet
var itemSet = ItemSet.itemSetFromTarget(event);
// find the right group
@ -497,27 +490,5 @@ GroupSet.groupFromTarget = function groupFromTarget (event) {
}
}
/* TODO: cleanup
while (target) {
if (target.hasOwnProperty('timeline-groupset')) {
groupset = target['timeline-groupset'];
break;
}
target = target.parentNode;
}
if (groupset) {
for (var groupId in groupset.groups) {
if (groupset.groups.hasOwnProperty(groupId)) {
var group = groupset.groups[groupId];
if (group.itemset && ItemSet.itemSetFromTarget(event) == group.itemset) {
return group;
}
}
}
}
*/
return null;
};

+ 17
- 0
src/util.js View File

@ -97,6 +97,23 @@ util.extend = function (a, b) {
return a;
};
/**
* Test whether all elements in two arrays are equal.
* @param {Array} a
* @param {Array} b
* @return {boolean} Returns true if both arrays have the same length and same
* elements.
*/
util.equalArray = function (a, b) {
if (a.length != b.length) return false;
for (var i = 1, len = a.length; i < len; i++) {
if (a[i] != b[i]) return false;
}
return true;
};
/**
* Convert an object to another type
* @param {Boolean | Number | String | Date | Moment | Null | undefined} object

Loading…
Cancel
Save