Browse Source

Added Timeline itemover, itemout events (#2099)

codeClimate
Iskander508 8 years ago
committed by Alexander Wunschik
parent
commit
d37bcea02f
3 changed files with 63 additions and 1 deletions
  1. +23
    -1
      docs/timeline/index.html
  2. +15
    -0
      examples/timeline/interaction/eventListeners.html
  3. +25
    -0
      lib/timeline/component/ItemSet.js

+ 23
- 1
docs/timeline/index.html View File

@ -1187,7 +1187,7 @@ document.getElementById('myTimeline').onclick = function (event) {
<tr> <tr>
<td>on(event, callback)</td> <td>on(event, callback)</td>
<td>none</td> <td>none</td>
<td>Create an event listener. The callback function is invoked every time the event is triggered. Avialable events: <code>rangechange</code>, <code>rangechanged</code>, <code>select</code>. The callback function is invoked as <code>callback(properties)</code>, where <code>properties</code> is an object containing event specific properties. See section <a href="#Events">Events for more information</a>.</td>
<td>Create an event listener. The callback function is invoked every time the event is triggered. Avialable events: <code>rangechange</code>, <code>rangechanged</code>, <code>select</code>, <code>itemover</code>, <code>itemout</code>. The callback function is invoked as <code>callback(properties)</code>, where <code>properties</code> is an object containing event specific properties. See section <a href="#Events">Events for more information</a>.</td>
</tr> </tr>
<tr> <tr>
@ -1442,6 +1442,28 @@ timeline.off('select', onSelect);
</td> </td>
</tr> </tr>
<tr>
<td>itemover</td>
<td>
<ul>
<li><code>item</code>: hovered item id</li>
<li><code>event</code>: the original mouseover event</li>
</ul>
</td>
<td>Fired when the user moves the mouse over an item.</td>
</tr>
<tr>
<td>itemout</td>
<td>
<ul>
<li><code>item</code>: hovered item id</li>
<li><code>event</code>: the original mouseout event</li>
</ul>
</td>
<td>Fired when the user moves the mouse out of an item.</td>
</tr>
<tr> <tr>
<td>timechange</td> <td>timechange</td>
<td> <td>

+ 15
- 0
examples/timeline/interaction/eventListeners.html View File

@ -19,6 +19,7 @@
</p> </p>
<div id="visualization"></div> <div id="visualization"></div>
<p></p> <p></p>
<div id="hoveredItem"></div>
<div id="log"></div> <div id="log"></div>
<script type="text/javascript"> <script type="text/javascript">
@ -47,6 +48,15 @@
logEvent('select', properties); logEvent('select', properties);
}); });
timeline.on('itemover', function (properties) {
logEvent('itemover', properties);
setHoveredItem(properties.item);
});
timeline.on('itemout', function (properties) {
logEvent('itemout', properties);
setHoveredItem('none');
});
items.on('*', function (event, properties) { items.on('*', function (event, properties) {
logEvent(event, properties); logEvent(event, properties);
}); });
@ -59,6 +69,11 @@
log.firstChild ? log.insertBefore(msg, log.firstChild) : log.appendChild(msg); log.firstChild ? log.insertBefore(msg, log.firstChild) : log.appendChild(msg);
} }
function setHoveredItem(id) {
var hoveredItem = document.getElementById('hoveredItem');
hoveredItem.innerHTML = 'hoveredItem=' + id;
}
</script> </script>
</body> </body>
</html> </html>

+ 25
- 0
lib/timeline/component/ItemSet.js View File

@ -237,6 +237,9 @@ ItemSet.prototype._create = function(){
this.groupHammer.on('panend', this._onGroupDragEnd.bind(this)); this.groupHammer.on('panend', this._onGroupDragEnd.bind(this));
this.groupHammer.get('pan').set({threshold:5, direction: Hammer.DIRECTION_HORIZONTAL}); this.groupHammer.get('pan').set({threshold:5, direction: Hammer.DIRECTION_HORIZONTAL});
this.body.dom.centerContainer.addEventListener('mouseover', this._onMouseOver.bind(this));
this.body.dom.centerContainer.addEventListener('mouseout', this._onMouseOut.bind(this));
// attach to the DOM // attach to the DOM
this.show(); this.show();
}; };
@ -1745,6 +1748,28 @@ ItemSet.prototype._onSelectItem = function (event) {
} }
}; };
/**
* Handle hovering an item
* @param {Event} event
* @private
*/
ItemSet.prototype._onMouseOver = function (event) {
var item = this.itemFromTarget(event);
if (!item) return;
this.body.emitter.emit('itemover', {
item: item.id,
event: event
});
};
ItemSet.prototype._onMouseOut = function (event) {
var item = this.itemFromTarget(event);
if (!item) return;
this.body.emitter.emit('itemout', {
item: item.id,
event: event
});
};
/** /**
* Handle creation and updates of an item on double tap * Handle creation and updates of an item on double tap
* @param event * @param event

Loading…
Cancel
Save