1$.fn.buttonScroller = function(options) { 2 options = $.extend({ 3 speed: 15, 4 tick: 15, 5 hover: false, 6 type: 'horizontal', 7 position: 'relative', 8 wheel: false, 9 gradient: false, 10 scrollSpeed: 30 11 }, options || {}); 12 function createScroller() { 13 var enabled = false; 14 var container = $(this); 15 function getPositions() { 16 if (options.type === 'horizontal') { 17 var size = $(container).width() 18 , position = $(container).scrollLeft() 19 , scrollSize = $(container).prop('scrollWidth'); 20 return { 21 size: size, 22 position: position, 23 scroll: scrollSize 24 }; 25 } else { 26 var size = $(container).height() 27 , position = $(container).scrollTop() 28 , scrollSize = $(container).prop('scrollHeight'); 29 return { 30 size: size, 31 position: position, 32 scroll: scrollSize 33 }; 34 } 35 } 36 function isScrollNeeded(pos) { 37 return (pos.position <= 0 && pos.scroll <= pos.position + pos.size) ? false : true; 38 } 39 function initializeScroller() { 40 enabled = true; 41 var wrapper = $('<div class=scroll-button-wrapper></div>'); 42 container.replaceWith(wrapper.css('position', options.position)); 43 var scrollB = $('<div class="scroll-button scroll-back"><span></span></div>'); 44 var scrollF = $('<div class="scroll-button scroll-forward"><span></span></div>'); 45 function checkButtons(pos) { 46 if (pos.position <= 0) 47 scrollB.addClass('disabled'); 48 else 49 scrollB.removeClass('disabled'); 50 if (pos.scroll <= pos.position + pos.size) 51 scrollF.addClass('disabled'); 52 else 53 scrollF.removeClass('disabled'); 54 } 55 if (options.gradient) { 56 scrollB.addClass('with-gradient'); 57 scrollF.addClass('with-gradient'); 58 } 59 scrollB.addClass(options.type === 'horizontal' ? 'horisontal-scroll' : 'vertical-scroll'); 60 scrollF.addClass(options.type === 'horizontal' ? 'horisontal-scroll' : 'vertical-scroll'); 61 scrollB.attr('direction', 'back'); 62 scrollF.attr('direction', 'forward'); 63 container.appendTo(wrapper).css('overflow', 'hidden'); 64 container.data('scroller', true); 65 $(wrapper).append(scrollB).append(scrollF); 66 var timerHandle = false; 67 function timerFunction(dir, speed) { 68 var pos = getPositions(); 69 if (typeof (speed) === 'undefined') 70 speed = options.speed; 71 if (dir === 'back') { 72 if (options.type === 'vertical') 73 $(container).scrollTop(pos.position - speed) 74 else if (options.type === 'horizontal') 75 $(container).scrollLeft(pos.position - speed); 76 } else if (dir === 'forward') { 77 if (options.type === 'vertical') 78 $(container).scrollTop(pos.position + speed) 79 else if (options.type === 'horizontal') 80 $(container).scrollLeft(pos.position + speed); 81 } 82 checkButtons(pos); 83 } 84 function doScroll() { 85 var dir = $(this).attr('direction'); 86 if (timerHandle) 87 clearInterval(timerHandle); 88 timerHandle = setInterval(timerFunction, options.tick, dir); 89 } 90 function stopScroll() { 91 if (timerHandle) 92 clearInterval(timerHandle); 93 timerHandle = false; 94 } 95 scrollB.on('mousedown', doScroll).on('mouseup', stopScroll).on('mouseout', stopScroll); 96 scrollF.on('mousedown', doScroll).on('mouseup', stopScroll).on('mouseout', stopScroll); 97 if (options.hover) { 98 scrollB.on('mouseover', doScroll); 99 scrollF.on('mouseover', doScroll); 100 } 101 timerFunction(false); 102 function mouseWheel(event) { 103 if (enabled) { 104 var delta = event.originalEvent.deltaY; 105 delta = (delta < 0 ? -1 : 1) * options.scrollSpeed; 106 timerFunction(delta < 0 ? 'back' : 'forward', Math.abs(delta)); 107 } 108 event.preventDefault(); 109 return false; 110 } 111 if (options.wheel) { 112 scrollB.on('wheel', { 113 type: 'whell' 114 }, mouseWheel); 115 scrollF.on('wheel', { 116 type: 'whell' 117 }, mouseWheel); 118 container.on('wheel', { 119 type: 'whell' 120 }, mouseWheel); 121 } 122 function enableScroller(event, state) { 123 if (state) { 124 scrollB.show(); 125 scrollF.show(); 126 } else { 127 scrollB.hide(); 128 scrollF.hide(); 129 } 130 enabled = state; 131 } 132 container.on('scroller.enable', enableScroller); 133 container.on('scroller.visible', becomeVisible); 134 } 135 function becomeVisible() { 136 var positions = getPositions(); 137 if (container.data('scroller')) { 138 container.trigger('scroller.enable', isScrollNeeded(positions)); 139 } else { 140 if (isScrollNeeded(positions)) 141 initializeScroller(); 142 } 143 } 144 container.on('scroller.visible', becomeVisible).trigger('scroller.visible'); 145 } 146 $(this).each(createScroller); 147}
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.