diff --git a/opentech/static_src/src/javascript/main.js b/opentech/static_src/src/javascript/main.js index 55ebf6b7980a5d6eb00fc8325ecdbe52b7a9ae55..1fc1ee3eaa8cc91c1a41ca3cc8ad7d12345539b7 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) {