From 31096e04f622e505d1f4417bc60ffe549f2dceaf Mon Sep 17 00:00:00 2001 From: Yotam Berkowitz Date: Thu, 20 Oct 2016 19:45:13 +0300 Subject: [PATCH] Add vertical scroll when zoom is inactive --- lib/timeline/Core.js | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/timeline/Core.js b/lib/timeline/Core.js index cca32f9c..612a6fc1 100644 --- a/lib/timeline/Core.js +++ b/lib/timeline/Core.js @@ -161,6 +161,35 @@ Core.prototype._create = function (container) { this.dom.root.addEventListener('mousewheel', onMouseWheel); this.dom.root.addEventListener('DOMMouseScroll', onMouseWheel); + function onMouseWheelCenter(event) { + // prevent scrolling when zoomKey defined or activated + if (!me.options.zoomKey || event[me.options.zoomKey]) return + + var delta = 0; + if (event.wheelDelta) { /* IE/Opera. */ + delta = event.wheelDelta / 120; + } else if (event.detail) { /* Mozilla case. */ + // In Mozilla, sign of delta is different than in IE. + // Also, delta is multiple of 3. + delta = -event.detail / 3; + } + + var current = me.props.scrollTop; + var adjusted = current + delta * 120; + if (me.isActive()) { + me._setScrollTop(adjusted); + me._redraw(); + me.emit('scroll', event); + } + + // Prevent default actions caused by mouse wheel + // (else the page and timeline both scroll) + event.preventDefault(); + } + + this.dom.center.addEventListener('mousewheel', onMouseWheelCenter); + this.dom.center.addEventListener('DOMMouseScroll', onMouseWheelCenter); + // size properties of each of the panels this.props = { root: {}, @@ -222,7 +251,7 @@ Core.prototype.setOptions = function (options) { var fields = [ 'width', 'height', 'minHeight', 'maxHeight', 'autoResize', 'start', 'end', 'clickToUse', 'dataAttributes', 'hiddenDates', - 'locale', 'locales', 'moment', 'rtl' + 'locale', 'locales', 'moment', 'rtl', 'zoomKey' ]; util.selectiveExtend(fields, this.options, options);