This repository was archived by the owner on Jul 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Fix scroll bugs with vertical scrollbar #2228
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
6242b64
Add initial scroller without options
yotamberk 3cd13e8
Add initial scroll without an option
yotamberk d716529
Add verticalScroll option
yotamberk 4690258
Fix scrollbar positions
yotamberk caadad0
Add docs
yotamberk bfc721d
fix example
yotamberk 614107c
remove jquery dependency
yotamberk 2cc20e9
Fix example
yotamberk cbe3ca6
Fix review comments
yotamberk 6793c41
Fix conflicts and deal wtih verticalScroll with horizontalScroll
yotamberk 4f92372
Fix verticalScroll and horizontalScroll docs
yotamberk 6a40bdf
fix conflicts
yotamberk 5040924
Merge branch 'develop' of https://github.com/almende/vis into vertica…
yotamberk dd993e3
Fix bug in timeline option.rtl if otion is undefined
yotamberk c297889
Remove hack
yotamberk bd6b5e0
Fix conflict
yotamberk 6d8ac06
Fix breaking of timeline
yotamberk 65d3107
Fix conflict
yotamberk e303b72
Fix scrolling bugs
yotamberk e78eff3
Remove silly mistake
yotamberk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -112,7 +112,7 @@ Core.prototype._create = function (container) { | |
| } | ||
| }.bind(this)); | ||
| this.on('touch', this._onTouch.bind(this)); | ||
| this.on('pan', this._onDrag.bind(this)); | ||
| this.on('panmove', this._onDrag.bind(this)); | ||
|
|
||
| var me = this; | ||
| this.on('_change', function (properties) { | ||
|
|
@@ -191,8 +191,13 @@ Core.prototype._create = function (container) { | |
|
|
||
| var current = this.props.scrollTop; | ||
| var adjusted = current + delta * 120; | ||
|
|
||
| if (this.isActive()) { | ||
| this._setScrollTop(adjusted); | ||
| if (this.options.verticalScroll) { | ||
| this.dom.left.parentNode.scrollTop = -adjusted; | ||
| this.dom.right.parentNode.scrollTop = -adjusted; | ||
| } | ||
| this._redraw(); | ||
| this.emit('scroll', event); | ||
| } | ||
|
|
@@ -202,29 +207,29 @@ Core.prototype._create = function (container) { | |
| event.preventDefault(); | ||
| } | ||
|
|
||
| if (this.dom.root.addEventListener) { | ||
| if (this.dom.center.addEventListener) { | ||
| // IE9, Chrome, Safari, Opera | ||
| this.dom.root.addEventListener("mousewheel", onMouseWheel.bind(this), false); | ||
| this.dom.center.addEventListener("mousewheel", onMouseWheel.bind(this), false); | ||
| // Firefox | ||
| this.dom.root.addEventListener("DOMMouseScroll", onMouseWheel.bind(this), false); | ||
| this.dom.center.addEventListener("DOMMouseScroll", onMouseWheel.bind(this), false); | ||
| } else { | ||
| // IE 6/7/8 | ||
| this.dom.root.attachEvent("onmousewheel", onMouseWheel.bind(this)); | ||
| this.dom.center.attachEvent("onmousewheel", onMouseWheel.bind(this)); | ||
| } | ||
|
|
||
| function onMouseScrollSide(event) { | ||
| var current = this.scrollTop; | ||
| var adjusted = -current; | ||
| if (!me.options.verticalScroll) return; | ||
| event.preventDefault(); | ||
| if (me.isActive()) { | ||
| var adjusted = -event.target.scrollTop; | ||
| me._setScrollTop(adjusted); | ||
|
|
||
| me._redraw(); | ||
| me.emit('scroll', event); | ||
| me.emit('scrollSide', event); | ||
| } | ||
| } | ||
|
|
||
| this.dom.left.parentNode.addEventListener('scroll', onMouseScrollSide); | ||
| this.dom.right.parentNode.addEventListener('scroll', onMouseScrollSide); | ||
| this.dom.left.parentNode.addEventListener('scroll', onMouseScrollSide.bind(this)); | ||
| this.dom.right.parentNode.addEventListener('scroll', onMouseScrollSide.bind(this)); | ||
|
|
||
| this.customTimes = []; | ||
|
|
||
|
|
@@ -820,10 +825,9 @@ Core.prototype._redraw = function() { | |
|
|
||
| // update the scrollTop, feasible range for the offset can be changed | ||
| // when the height of the Core or of the contents of the center changed | ||
| this._updateScrollTop(); | ||
| var offset = this._updateScrollTop(); | ||
|
|
||
| // reposition the scrollable contents | ||
| var offset = this.props.scrollTop; | ||
| if (options.orientation.item != 'top') { | ||
| offset += Math.max(this.props.centerContainer.height - this.props.center.height - | ||
| this.props.border.top - this.props.border.bottom, 0); | ||
|
|
@@ -844,12 +848,10 @@ Core.prototype._redraw = function() { | |
| dom.shadowBottomRight.style.visibility = visibilityBottom; | ||
|
|
||
| if (this.options.verticalScroll) { | ||
| this.dom.shadowTopRight.style.visibility = "hidden"; | ||
| this.dom.shadowBottomRight.style.visibility = "hidden"; | ||
| this.dom.shadowTopLeft.style.visibility = "hidden"; | ||
| this.dom.shadowBottomLeft.style.visibility = "hidden"; | ||
| document.getElementsByClassName('vis-left')[0].scrollTop = -offset; | ||
| document.getElementsByClassName('vis-right')[0].scrollTop = -offset; | ||
| dom.shadowTopRight.style.visibility = "hidden"; | ||
| dom.shadowBottomRight.style.visibility = "hidden"; | ||
| dom.shadowTopLeft.style.visibility = "hidden"; | ||
| dom.shadowBottomLeft.style.visibility = "hidden"; | ||
| } else { | ||
| dom.left.style.top = offset + 'px'; | ||
| dom.right.style.top = offset + 'px'; | ||
|
|
@@ -1070,6 +1072,7 @@ Core.prototype._onPinch = function (event) { | |
| * @private | ||
| */ | ||
| Core.prototype._onDrag = function (event) { | ||
| if (!event) return | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add curly braces and missing |
||
| // refuse to drag when we where pinching to prevent the timeline make a jump | ||
| // when releasing the fingers in opposite order from the touch screen | ||
| if (!this.touch.allowDragging) return; | ||
|
|
@@ -1079,6 +1082,10 @@ Core.prototype._onDrag = function (event) { | |
| var oldScrollTop = this._getScrollTop(); | ||
| var newScrollTop = this._setScrollTop(this.touch.initialScrollTop + delta); | ||
|
|
||
| if (this.options.verticalScroll) { | ||
| this.dom.left.parentNode.scrollTop = -this.props.scrollTop; | ||
| this.dom.right.parentNode.scrollTop = -this.props.scrollTop; | ||
| } | ||
|
|
||
| if (newScrollTop != oldScrollTop) { | ||
| this.emit("verticalDrag"); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -390,6 +390,8 @@ Range.prototype._onDragStart = function(event) { | |
| * @private | ||
| */ | ||
| Range.prototype._onDrag = function (event) { | ||
| if (!event) return | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above. |
||
|
|
||
| if (!this.props.touch.dragging) return; | ||
|
|
||
| // only allow dragging when configured as movable | ||
|
|
@@ -445,6 +447,9 @@ Range.prototype._onDrag = function (event) { | |
| end: endDate, | ||
| byUser: true | ||
| }); | ||
|
|
||
| // fire a panmove event | ||
| this.body.emitter.emit('panmove'); | ||
| }; | ||
|
|
||
| /** | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,8 +28,8 @@ import Validator from '../shared/Validator'; | |
| * @constructor | ||
| * @extends Core | ||
| */ | ||
| function Timeline (container, items, groups, options) { | ||
|
|
||
| function Timeline (container, items, groups, options) { | ||
| if (!(this instanceof Timeline)) { | ||
| throw new SyntaxError('Constructor must be called with the new operator'); | ||
| } | ||
|
|
@@ -61,11 +61,6 @@ function Timeline (container, items, groups, options) { | |
| }; | ||
| this.options = util.deepExtend({}, this.defaultOptions); | ||
|
|
||
| // apply options | ||
| if (options) { | ||
| this.setOptions(options); | ||
| } | ||
|
|
||
| // Create the DOM, props, and emitter | ||
| this._create(container); | ||
|
|
||
|
|
@@ -109,6 +104,11 @@ function Timeline (container, items, groups, options) { | |
| // current time bar | ||
| this.currentTime = new CurrentTime(this.body); | ||
| this.components.push(this.currentTime); | ||
|
|
||
| // apply options | ||
| if (options) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here we have the braces. Is this some Javascript style convention to omit them if it's a return? I'm not sure. |
||
| this.setOptions(options); | ||
| } | ||
|
|
||
| // item set | ||
| this.itemSet = new ItemSet(this.body, this.options); | ||
|
|
@@ -545,25 +545,4 @@ Timeline.prototype.getEventProperties = function (event) { | |
| } | ||
| }; | ||
|
|
||
| /** | ||
| * Extend the drag event handler from Core, move the timeline vertically | ||
| * @param {Event} event | ||
| * @private | ||
| */ | ||
| Timeline.prototype._onDrag = function (event) { | ||
| // refuse to drag when we where pinching to prevent the timeline make a jump | ||
| // when releasing the fingers in opposite order from the touch screen, and refuse | ||
| // to drag when an item is already being dragged | ||
| if (!this.touch.allowDragging || this.itemSet.touchParams.itemIsDragging) return; | ||
|
|
||
| var delta = event.deltaY; | ||
|
|
||
| var oldScrollTop = this._getScrollTop(); | ||
| var newScrollTop = this._setScrollTop(this.touch.initialScrollTop + delta); | ||
|
|
||
| if (newScrollTop != oldScrollTop) { | ||
| this.emit("verticalDrag"); | ||
| } | ||
| }; | ||
|
|
||
| module.exports = Timeline; | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should add curly braces here in order to be consistent with the code style.