From 9a0d81ef6bbf61c132ee6845ce0a92e45c63e66f Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Mon, 24 Oct 2016 11:12:39 -0400 Subject: [PATCH] closes #5152 --- package.json | 2 +- public/src/modules/scrollStop.js | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 public/src/modules/scrollStop.js diff --git a/package.json b/package.json index f62006105d..d90e4a710c 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "morgan": "^1.3.2", "mousetrap": "^1.5.3", "nconf": "~0.8.2", - "nodebb-plugin-composer-default": "4.2.12", + "nodebb-plugin-composer-default": "4.2.13", "nodebb-plugin-dbsearch": "1.0.3", "nodebb-plugin-emoji-extended": "1.1.1", "nodebb-plugin-emoji-one": "1.1.5", diff --git a/public/src/modules/scrollStop.js b/public/src/modules/scrollStop.js new file mode 100644 index 0000000000..3bb96aed8b --- /dev/null +++ b/public/src/modules/scrollStop.js @@ -0,0 +1,32 @@ +'use strict'; + +/* globals console, define */ + +/* + The point of this library is to enhance(tm) a textarea so that if scrolled, + you can only scroll to the top of it and the event doesn't bubble up to + the document... because it does... and it's annoying at times. + + While I'm here, might I say this is a solved issue on Linux? +*/ + +define('scrollStop', function () { + var Module = {}; + + Module.apply = function (element) { + $(element).on('mousewheel', function (e) { + var scrollTop = this.scrollTop; + var scrollHeight = this.scrollHeight; + var elementHeight = this.getBoundingClientRect().height; + + if ( + (e.originalEvent.deltaY < 0 && scrollTop === 0) || // scroll up + (e.originalEvent.deltaY > 0 && (elementHeight + scrollTop) > scrollHeight) // scroll down + ) { + return false; + } + }); + }; + + return Module; +}); \ No newline at end of file