From de79af872ae950b25afce9d8f3c955990e8dda1a Mon Sep 17 00:00:00 2001 From: Chris Lawton <chris.lawton@torchbox.com> Date: Tue, 20 Mar 2018 12:19:15 +0000 Subject: [PATCH] method to allow click and drag scrolling of a given element, in this case the reviews table --- opentech/static_src/src/javascript/main.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/opentech/static_src/src/javascript/main.js b/opentech/static_src/src/javascript/main.js index 55ebf6b79..1fc1ee3ea 100755 --- a/opentech/static_src/src/javascript/main.js +++ b/opentech/static_src/src/javascript/main.js @@ -95,6 +95,8 @@ import '@fancyapps/fancybox'; }); }); + // Allow click and drag scrolling within reviews table wrapper + $('.js-reviews-table').attachDragger(); }); // Add active class to filters - dropdowns are dynamically appended to the dom, @@ -178,6 +180,23 @@ import '@fancyapps/fancybox'; } } + // Enable click and drag scrolling within a div + $.fn.attachDragger = function(){ + let attachment = false, lastPosition, position, difference; + $($(this).selector ).on('mousedown mouseup mousemove', (e) => { + if(e.type == 'mousedown') attachment = true, lastPosition = [e.clientX, e.clientY]; + if(e.type == 'mouseup') attachment = false; + if(e.type == 'mousemove' && attachment == true ){ + position = [e.clientX, e.clientY]; + difference = [ (position[0]-lastPosition[0]), (position[1]-lastPosition[1])]; + $(this).scrollLeft( $(this).scrollLeft() - difference[0]); + $(this).scrollTop( $(this).scrollTop() - difference[1]); + lastPosition = [e.clientX, e.clientY]; + } + }); + $(window).on('mouseup', () => attachment = false); + }; + // reset mobile filters if they're open past the tablet breakpoint $(window).resize(function resize(){ if ($(window).width() < 768) { -- GitLab