2015-08-16 11:51:00 +02:00
/* via http://jsfiddle.net/elGrecode/00dgurnn/ */
window . initScrollable = function ( ) {
var scrollContainer = document . querySelector ( '.scrollable' ) ,
scrollContentWrapper = document . querySelector ( '.scrollable .content-wrapper' ) ,
scrollContent = document . querySelector ( '.scrollable .content' ) ,
contentPosition = 0 ,
scrollerBeingDragged = false ,
scroller ,
topPosition ,
scrollerHeight ;
function calculateScrollerHeight ( ) {
// *Calculation of how tall scroller should be
var visibleRatio = scrollContainer . offsetHeight / scrollContentWrapper . scrollHeight ;
if ( visibleRatio == 1 )
Rev571, Optional file sizes to sidebar, Download all optional files option in sidebar, Optional file number in peer stats, Delete removed or changed optional files, Auto download optional files if autodownloadoptional checked, SiteReload command, Peer use global file server if no site defined, Allow browser cache video files, Allow more keepalive connections, Gevent 1.1 ranged request bugfix, Dont sent optional files details on websocket, Remove files from workermanager tasks if no longer in bad_files, Notify local client about changes on external siteSign
2015-11-09 00:44:03 +01:00
scroller . style . display = "none" ;
2015-08-16 11:51:00 +02:00
else
Rev571, Optional file sizes to sidebar, Download all optional files option in sidebar, Optional file number in peer stats, Delete removed or changed optional files, Auto download optional files if autodownloadoptional checked, SiteReload command, Peer use global file server if no site defined, Allow browser cache video files, Allow more keepalive connections, Gevent 1.1 ranged request bugfix, Dont sent optional files details on websocket, Remove files from workermanager tasks if no longer in bad_files, Notify local client about changes on external siteSign
2015-11-09 00:44:03 +01:00
scroller . style . display = "block" ;
2015-08-16 11:51:00 +02:00
return visibleRatio * scrollContainer . offsetHeight ;
}
function moveScroller ( evt ) {
// Move Scroll bar to top offset
var scrollPercentage = evt . target . scrollTop / scrollContentWrapper . scrollHeight ;
topPosition = scrollPercentage * ( scrollContainer . offsetHeight - 5 ) ; // 5px arbitrary offset so scroll bar doesn't move too far beyond content wrapper bounding box
scroller . style . top = topPosition + 'px' ;
}
function startDrag ( evt ) {
normalizedPosition = evt . pageY ;
contentPosition = scrollContentWrapper . scrollTop ;
scrollerBeingDragged = true ;
Rev571, Optional file sizes to sidebar, Download all optional files option in sidebar, Optional file number in peer stats, Delete removed or changed optional files, Auto download optional files if autodownloadoptional checked, SiteReload command, Peer use global file server if no site defined, Allow browser cache video files, Allow more keepalive connections, Gevent 1.1 ranged request bugfix, Dont sent optional files details on websocket, Remove files from workermanager tasks if no longer in bad_files, Notify local client about changes on external siteSign
2015-11-09 00:44:03 +01:00
window . addEventListener ( 'mousemove' , scrollBarScroll ) ;
return false ;
2015-08-16 11:51:00 +02:00
}
function stopDrag ( evt ) {
scrollerBeingDragged = false ;
Rev571, Optional file sizes to sidebar, Download all optional files option in sidebar, Optional file number in peer stats, Delete removed or changed optional files, Auto download optional files if autodownloadoptional checked, SiteReload command, Peer use global file server if no site defined, Allow browser cache video files, Allow more keepalive connections, Gevent 1.1 ranged request bugfix, Dont sent optional files details on websocket, Remove files from workermanager tasks if no longer in bad_files, Notify local client about changes on external siteSign
2015-11-09 00:44:03 +01:00
window . removeEventListener ( 'mousemove' , scrollBarScroll ) ;
2015-08-16 11:51:00 +02:00
}
function scrollBarScroll ( evt ) {
if ( scrollerBeingDragged === true ) {
2015-11-05 23:19:36 +01:00
evt . preventDefault ( ) ;
2015-08-16 11:51:00 +02:00
var mouseDifferential = evt . pageY - normalizedPosition ;
var scrollEquivalent = mouseDifferential * ( scrollContentWrapper . scrollHeight / scrollContainer . offsetHeight ) ;
scrollContentWrapper . scrollTop = contentPosition + scrollEquivalent ;
}
}
function updateHeight ( ) {
Rev571, Optional file sizes to sidebar, Download all optional files option in sidebar, Optional file number in peer stats, Delete removed or changed optional files, Auto download optional files if autodownloadoptional checked, SiteReload command, Peer use global file server if no site defined, Allow browser cache video files, Allow more keepalive connections, Gevent 1.1 ranged request bugfix, Dont sent optional files details on websocket, Remove files from workermanager tasks if no longer in bad_files, Notify local client about changes on external siteSign
2015-11-09 00:44:03 +01:00
scrollerHeight = calculateScrollerHeight ( ) - 10 ;
2015-08-16 11:51:00 +02:00
scroller . style . height = scrollerHeight + 'px' ;
}
function createScroller ( ) {
// *Creates scroller element and appends to '.scrollable' div
// create scroller element
scroller = document . createElement ( "div" ) ;
scroller . className = 'scroller' ;
// determine how big scroller should be based on content
Rev571, Optional file sizes to sidebar, Download all optional files option in sidebar, Optional file number in peer stats, Delete removed or changed optional files, Auto download optional files if autodownloadoptional checked, SiteReload command, Peer use global file server if no site defined, Allow browser cache video files, Allow more keepalive connections, Gevent 1.1 ranged request bugfix, Dont sent optional files details on websocket, Remove files from workermanager tasks if no longer in bad_files, Notify local client about changes on external siteSign
2015-11-09 00:44:03 +01:00
scrollerHeight = calculateScrollerHeight ( ) - 10 ;
2015-08-16 11:51:00 +02:00
Rev571, Optional file sizes to sidebar, Download all optional files option in sidebar, Optional file number in peer stats, Delete removed or changed optional files, Auto download optional files if autodownloadoptional checked, SiteReload command, Peer use global file server if no site defined, Allow browser cache video files, Allow more keepalive connections, Gevent 1.1 ranged request bugfix, Dont sent optional files details on websocket, Remove files from workermanager tasks if no longer in bad_files, Notify local client about changes on external siteSign
2015-11-09 00:44:03 +01:00
if ( scrollerHeight / scrollContainer . offsetHeight < 1 ) {
2015-08-16 11:51:00 +02:00
// *If there is a need to have scroll bar based on content size
scroller . style . height = scrollerHeight + 'px' ;
// append scroller to scrollContainer div
scrollContainer . appendChild ( scroller ) ;
// show scroll path divot
scrollContainer . className += ' showScroll' ;
// attach related draggable listeners
scroller . addEventListener ( 'mousedown' , startDrag ) ;
window . addEventListener ( 'mouseup' , stopDrag ) ;
}
}
createScroller ( ) ;
// *** Listeners ***
scrollContentWrapper . addEventListener ( 'scroll' , moveScroller ) ;
Rev571, Optional file sizes to sidebar, Download all optional files option in sidebar, Optional file number in peer stats, Delete removed or changed optional files, Auto download optional files if autodownloadoptional checked, SiteReload command, Peer use global file server if no site defined, Allow browser cache video files, Allow more keepalive connections, Gevent 1.1 ranged request bugfix, Dont sent optional files details on websocket, Remove files from workermanager tasks if no longer in bad_files, Notify local client about changes on external siteSign
2015-11-09 00:44:03 +01:00
return updateHeight ;
2015-08-16 11:51:00 +02:00
} ;