Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/remark/controllers/inputs/mouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ exports.unregister = function (events) {
removeMouseEventListeners(events);
};

function throttle(events, eventName) {
var timestamp = null;
return function() {
var now = Date.now();
if (timestamp === null || now - timestamp > 100) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about making this optional?

Right now you can enable/disable scrolling - would it make sense to add an option to throttle and the time value e.g.:

var slideshow = remark.create({
  navigation: {
      scrollThrottle: 100,  // default value would be 0 or the same behavior we have today.
  }
});

events.emit(eventName);
}
timestamp = now;
};
}

function addMouseEventListeners (events, options) {
if (options.click) {
events.on('click', function (event) {
Expand All @@ -27,13 +38,15 @@ function addMouseEventListeners (events, options) {
});
}

var throttledPrev = throttle(events, 'gotoPreviousSlide');
var throttledNext = throttle(events, 'gotoNextSlide');
if (options.scroll !== false) {
var scrollHandler = function (event) {
if (event.wheelDeltaY > 0 || event.detail < 0) {
events.emit('gotoPreviousSlide');
throttledPrev();
}
else if (event.wheelDeltaY < 0 || event.detail > 0) {
events.emit('gotoNextSlide');
throttledNext();
}
};

Expand Down