vendor/assets/vis/timeline/component/GroupSet.js in vis-rails-0.0.4 vs vendor/assets/vis/timeline/component/GroupSet.js in vis-rails-0.0.5

- old
+ new

@@ -130,11 +130,11 @@ if (this.groupsData) { // subscribe to new dataset var id = this.id; util.forEach(this.listeners, function (callback, event) { - me.groupsData.subscribe(event, callback, id); + me.groupsData.on(event, callback, id); }); // draw all new groups ids = this.groupsData.getIds(); this._onAdd(ids); @@ -214,10 +214,11 @@ throw new Error('Cannot repaint groupset: parent has no container element'); } if (!frame) { frame = document.createElement('div'); frame.className = 'groupset'; + frame['timeline-groupset'] = this; this.dom.frame = frame; var className = options.className; if (className) { util.addClassName(frame, util.option.asString(className)); @@ -541,6 +542,39 @@ if (this.controller) { //this.requestReflow(); this.requestRepaint(); } +}; + +/** + * Find the Group from an event target: + * searches for the attribute 'timeline-groupset' in the event target's element + * tree, then finds the right group in this groupset + * @param {Event} event + * @return {Group | null} group + */ +GroupSet.groupFromTarget = function groupFromTarget (event) { + var groupset, + target = event.target; + + 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; };