/* * slimscroll * http://github.com/yawetse/slimscroll * * Copyright (c) 2014 Yaw Joseph Etse. All rights reserved. */ 'use strict'; var classie = require('classie'), extend = require('util-extend'), domhelper = require('domhelper'); /** * Slimscroll is a small commonjs module with no library dependencies (sans jquery) that transforms any div into a scrollable area with a nice scrollbar * @{@link https://github.com/yawetse/slimscroll} * @author Yaw Joseph Etse * @copyright Copyright (c) 2014 Yaw Joseph Etse. All rights reserved. * @license MIT * @module slimscroll * @requires module:classie * @requires module:util-extent * @requires module:util * @requires module:domhelper * @requires module:events * @todo need to switch to node events */ var slimscroll = function(options,elementsArray){ /** module default configuration */ var defaults = { idSelector: 'body', width : 'auto',// width in pixels of the visible scroll area height : '250px',// height in pixels of the visible scroll area size : '7px',// width in pixels of the scrollbar and rail color: '#000',// scrollbar color, accepts any hex/color value position : 'right',// scrollbar position - left/right distance : '1px',// distance in pixels between the side edge and the scrollbar start : 'top',// default scroll position on load - top / bottom / $('selector') opacity : 0.4,// sets scrollbar opacity alwaysVisible : false,// enables always-on mode for the scrollbar disableFadeOut : false,// check if we should hide the scrollbar when user is hovering over railVisible : false,// sets visibility of the rail railColor : '#333',// sets rail color railOpacity : 0.2,// sets rail opacity railDraggable : true,// whether we should use jQuery UI Draggable to enable bar dragging railClass : 'slimScrollRail',// defautlt CSS class of the slimscroll rail barClass : 'slimScrollBar',// defautlt CSS class of the slimscroll bar wrapperClass : 'slimScrollDiv',// defautlt CSS class of the slimscroll wrapper allowPageScroll : false,// check if mousewheel should scroll the window if we reach top/bottom wheelStep : 20,// scroll amount applied to each mouse wheel step touchScrollStep : 200,// scroll amount applied when user is using gestures addedOriginalClass: 'originalScrollableElement', borderRadius: '7px',// sets border radius railBorderRadius : '7px'// sets border radius of the rail }, o = extend( defaults,options ), thisElements = (elementsArray) ? elementsArray : document.querySelectorAll(options.idSelector), me, rail, bar, barHeight, minBarHeight = 30, mousedownPageY, mousedownT, isDragg, currentBar, currentTouchDif, releaseScroll, isOverBar, percentScroll, queueHide, lastScroll, isOverPanel; /** * creates new slimscrolls */ this.init = function(){ // do it for every element that matches selector for(var x=0; x