diff --git a/src/timeline/Timeline.js b/src/timeline/Timeline.js index 0c4b7b76..c4e79e6c 100644 --- a/src/timeline/Timeline.js +++ b/src/timeline/Timeline.js @@ -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(); }; diff --git a/src/timeline/component/GroupSet.js b/src/timeline/component/GroupSet.js index 053e1c10..cc439c94 100644 --- a/src/timeline/component/GroupSet.js +++ b/src/timeline/component/GroupSet.js @@ -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; }; diff --git a/src/util.js b/src/util.js index 788cea5e..789de735 100644 --- a/src/util.js +++ b/src/util.js @@ -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