1/*! 2 * Tiny Scrollbar 1.66 3 * http://www.baijs.nl/tinyscrollbar/ 4 * 5 * Copyright 2010, Maarten Baijs 6 * Dual licensed under the MIT or GPL Version 2 licenses. 7 * http://www.opensource.org/licenses/mit-license.php 8 * http://www.opensource.org/licenses/gpl-2.0.php 9 * 10 * Date: 13 / 11 / 2011 11 * Depends on library: jQuery 12 * 13 */ 14 15(function($){ 16 $.tiny = $.tiny || { }; 17 18 $.tiny.scrollbar = { 19 options: { 20 axis: 'y', // vertical or horizontal scrollbar? ( x || y ). 21 wheel: 40, //how many pixels must the mouswheel scroll at a time. 22 scroll: true, //enable or disable the mousewheel; 23 size: 'auto', //set the size of the scrollbar to auto or a fixed number. 24 sizethumb: 'auto' //set the size of the thumb to auto or a fixed number. 25 } 26 }; 27 28 $.fn.tinyscrollbar = function(options) { 29 var options = $.extend({}, $.tiny.scrollbar.options, options); 30 this.each(function(){ $(this).data('tsb', new Scrollbar($(this), options)); }); 31 return this; 32 }; 33 $.fn.tinyscrollbar_update = function(sScroll) { return $(this).data('tsb').update(sScroll); }; 34 35 function Scrollbar(root, options){ 36 var oSelf = this; 37 var oWrapper = root; 38 var oViewport = { obj: $('.viewport', root) }; 39 var oContent = { obj: $('.overview', root) }; 40 var oScrollbar = { obj: $('.scrollbar', root) }; 41 var oTrack = { obj: $('.track', oScrollbar.obj) }; 42 var oThumb = { obj: $('.thumb', oScrollbar.obj) }; 43 var sAxis = options.axis == 'x', sDirection = sAxis ? 'left' : 'top', sSize = sAxis ? 'Width' : 'Height'; 44 var iScroll, iPosition = { start: 0, now: 0 }, iMouse = {}; 45 46 function initialize() { 47 oSelf.update(); 48 setEvents(); 49 return oSelf; 50 } 51 this.update = function(sScroll){ 52 oViewport[options.axis] = oViewport.obj[0]['offset'+ sSize]; 53 oContent[options.axis] = oContent.obj[0]['scroll'+ sSize]; 54 oContent.ratio = oViewport[options.axis] / oContent[options.axis]; 55 oScrollbar.obj.toggleClass('disable', oContent.ratio >= 1); 56 oTrack[options.axis] = options.size == 'auto' ? oViewport[options.axis] : options.size; 57 oThumb[options.axis] = Math.min(oTrack[options.axis], Math.max(0, ( options.sizethumb == 'auto' ? (oTrack[options.axis] * oContent.ratio) : options.sizethumb ))); 58 oScrollbar.ratio = options.sizethumb == 'auto' ? (oContent[options.axis] / oTrack[options.axis]) : (oContent[options.axis] - oViewport[options.axis]) / (oTrack[options.axis] - oThumb[options.axis]); 59 iScroll = (sScroll == 'relative' && oContent.ratio <= 1) ? Math.min((oContent[options.axis] - oViewport[options.axis]), Math.max(0, iScroll)) : 0; 60 iScroll = (sScroll == 'bottom' && oContent.ratio <= 1) ? (oContent[options.axis] - oViewport[options.axis]) : isNaN(parseInt(sScroll)) ? iScroll : parseInt(sScroll); 61 setSize(); 62 }; 63 function setSize(){ 64 oThumb.obj.css(sDirection, iScroll / oScrollbar.ratio); 65 oContent.obj.css(sDirection, -iScroll); 66 iMouse['start'] = oThumb.obj.offset()[sDirection]; 67 var sCssSize = sSize.toLowerCase(); 68 oScrollbar.obj.css(sCssSize, oTrack[options.axis]); 69 oTrack.obj.css(sCssSize, oTrack[options.axis]); 70 oThumb.obj.css(sCssSize, oThumb[options.axis]); 71 }; 72 function setEvents(){ 73 oThumb.obj.bind('mousedown', start); 74 oThumb.obj[0].ontouchstart = function(oEvent){ 75 oEvent.preventDefault(); 76 oThumb.obj.unbind('mousedown'); 77 start(oEvent.touches[0]); 78 return false; 79 }; 80 oTrack.obj.bind('mouseup', drag); 81 if(options.scroll && this.addEventListener){ 82 oWrapper[0].addEventListener('DOMMouseScroll', wheel, false); 83 oWrapper[0].addEventListener('mousewheel', wheel, false ); 84 } 85 else if(options.scroll){oWrapper[0].onmousewheel = wheel;} 86 }; 87 function start(oEvent){ 88 iMouse.start = sAxis ? oEvent.pageX : oEvent.pageY; 89 var oThumbDir = parseInt(oThumb.obj.css(sDirection)); 90 iPosition.start = oThumbDir == 'auto' ? 0 : oThumbDir; 91 $(document).bind('mousemove', drag); 92 document.ontouchmove = function(oEvent){ 93 $(document).unbind('mousemove'); 94 drag(oEvent.touches[0]); 95 }; 96 $(document).bind('mouseup', end); 97 oThumb.obj.bind('mouseup', end); 98 oThumb.obj[0].ontouchend = document.ontouchend = function(oEvent){ 99 $(document).unbind('mouseup'); 100 oThumb.obj.unbind('mouseup'); 101 end(oEvent.touches[0]); 102 }; 103 return false;
104 }; 105 function wheel(oEvent){ 106 if(!(oContent.ratio >= 1)){ 107 var oEvent = oEvent || window.event; 108 var iDelta = oEvent.wheelDelta ? oEvent.wheelDelta/120 : -oEvent.detail/3; 109 iScroll -= iDelta * options.wheel; 110 iScroll = Math.min((oContent[options.axis] - oViewport[options.axis]), Math.max(0, iScroll)); 111 oThumb.obj.css(sDirection, iScroll / oScrollbar.ratio); 112 oContent.obj.css(sDirection, -iScroll); 113 114 oEvent = $.event.fix(oEvent); 115 oEvent.preventDefault(); 116 }; 117 }; 118 function end(oEvent){ 119 $(document).unbind('mousemove', drag); 120 $(document).unbind('mouseup', end); 121 oThumb.obj.unbind('mouseup', end); 122 document.ontouchmove = oThumb.obj[0].ontouchend = document.ontouchend = null; 123 return false; 124 }; 125 function drag(oEvent){ 126 if(!(oContent.ratio >= 1)){ 127 iPosition.now = Math.min((oTrack[options.axis] - oThumb[options.axis]), Math.max(0, (iPosition.start + ((sAxis ? oEvent.pageX : oEvent.pageY) - iMouse.start)))); 128 iScroll = iPosition.now * oScrollbar.ratio; 129 oContent.obj.css(sDirection, -iScroll); 130 oThumb.obj.css(sDirection, iPosition.now); 131 } 132 return false; 133 }; 134
135 return initialize(); 136 }; 137})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.