From 8b8df0d1e1e36b24a4a2df11ea0e855208c81fac Mon Sep 17 00:00:00 2001 From: Takashi Nakagawa Date: Mon, 24 Jun 2013 15:33:27 +0900 Subject: [PATCH 1/2] add support for scrolling by dragging --- script/jquery.jscrollpane.js | 56 ++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/script/jquery.jscrollpane.js b/script/jquery.jscrollpane.js index 95f4f6c2..0581a8d7 100644 --- a/script/jquery.jscrollpane.js +++ b/script/jquery.jscrollpane.js @@ -156,6 +156,62 @@ container.find('>.jspVerticalBar,>.jspHorizontalBar').remove().end(); } + // event for dragging list item + elem.bind('mousedown.jScrollPane', function(){ + $(document).bind('mousemove.jScrollPaneDragging', onTextSelectionScrollMouseMove); + $(document).bind('mouseup.jScrollPaneDragging', onSelectScrollMouseUp); + }); + + var textDragDistanceAway; + var textSelectionInterval; + + elem.scrollBy = function(delta) + { + var currentPos = -parseInt(pane.css('top')) || 0; + jsp.scrollTo(0,currentPos + delta); + }; + + function onTextSelectionInterval() + { + direction = textDragDistanceAway < 0 ? -1 : 1; + elem.scrollBy(textDragDistanceAway / 2); + } + + function clearTextSelectionInterval() + { + if (textSelectionInterval) { + clearInterval(textSelectionInterval); + textSelectionInterval = undefined; + } + } + + var getPos = function (event, c) { + var p = c == 'X' ? 'Left' : 'Top'; + return event['page' + c] || (event['client' + c] + (document.documentElement['scroll' + p] || document.body['scroll' + p])) || 0; + }; + + function onTextSelectionScrollMouseMove(e){ + var offset = elem.offset().top; + var maxOffset = offset + paneHeight; + var mouseOffset = getPos(e, 'Y'); + textDragDistanceAway = mouseOffset < offset ? mouseOffset - offset : (mouseOffset > maxOffset ? mouseOffset - maxOffset : 0); + if (textDragDistanceAway == 0) { + clearTextSelectionInterval(); + } else { + if (!textSelectionInterval) { + textSelectionInterval = setInterval(onTextSelectionInterval, 100); + } + } + } + + function onSelectScrollMouseUp(e) + { + $(document) + .unbind('mousemove.jScrollPaneDragging') + .unbind('mouseup.jScrollPaneDragging'); + clearTextSelectionInterval(); + } + pane.css('overflow', 'auto'); if (s.contentWidth) { contentWidth = s.contentWidth; From 825900dc68219dd307098a16a28f2a5a3584f154 Mon Sep 17 00:00:00 2001 From: Takashi Nakagawa Date: Wed, 16 Oct 2013 23:34:48 +0900 Subject: [PATCH 2/2] fixed indentation --- script/jquery.jscrollpane.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/script/jquery.jscrollpane.js b/script/jquery.jscrollpane.js index 0581a8d7..ba85cc1d 100644 --- a/script/jquery.jscrollpane.js +++ b/script/jquery.jscrollpane.js @@ -206,10 +206,10 @@ function onSelectScrollMouseUp(e) { - $(document) + $(document) .unbind('mousemove.jScrollPaneDragging') .unbind('mouseup.jScrollPaneDragging'); - clearTextSelectionInterval(); + clearTextSelectionInterval(); } pane.css('overflow', 'auto');