From c9e252cd2d09afc303a676e521ca0d5b67a32bd3 Mon Sep 17 00:00:00 2001 From: Chris Lawton <chris.lawton@torchbox.com> Date: Fri, 15 Jun 2018 10:23:37 +0100 Subject: [PATCH] move all reviews table logic in to it's own partial --- .../components/all-reviews-table.js | 23 +++++++++++++++++++ opentech/static_src/src/javascript/main.js | 20 +--------------- 2 files changed, 24 insertions(+), 19 deletions(-) create mode 100644 opentech/static_src/src/javascript/components/all-reviews-table.js diff --git a/opentech/static_src/src/javascript/components/all-reviews-table.js b/opentech/static_src/src/javascript/components/all-reviews-table.js new file mode 100644 index 000000000..8fd7cb67c --- /dev/null +++ b/opentech/static_src/src/javascript/components/all-reviews-table.js @@ -0,0 +1,23 @@ +import $ from './../globals'; + +export default () => { + // Allow click and drag scrolling within reviews table wrapper + $('.js-reviews-table').attachDragger(); +}; + +// 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); +}; diff --git a/opentech/static_src/src/javascript/main.js b/opentech/static_src/src/javascript/main.js index 84364b566..75f993dbb 100755 --- a/opentech/static_src/src/javascript/main.js +++ b/opentech/static_src/src/javascript/main.js @@ -8,6 +8,7 @@ import toggleActionsPanel from './components/toggle-actions-panel'; import activityFeed from './components/activity-feed'; import fancyboxGlobal from './components/fancybox-global'; import allSubmissions from './components/all-submissions-table'; +import allReviews from './components/all-reviews-table'; (function ($) { $(document).ready(function(){ @@ -45,8 +46,6 @@ import allSubmissions from './components/all-submissions-table'; // Submissions overview table logic allSubmissions(); - // Allow click and drag scrolling within reviews table wrapper - $('.js-reviews-table').attachDragger(); // Add colspan and accordion classes to review table header table rows const accordionTableHeaders = $('.table--reviews tr th:only-child'); @@ -155,23 +154,6 @@ import allSubmissions from './components/all-submissions-table'; } } - // 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