1/*! 2 * jQuery Scrollbox 3 * (c) 2009-2013 Hunter Wu <[email protected]> 4 * MIT Licensed. 5 * 6 * http://github.com/wmh/jquery-scrollbox 7 */ 8 9(function($) { 10 11$.fn.scrollbox = function(config) { 12 //default config 13 var defConfig = { 14 linear: false, // Scroll method 15 startDelay: 2, // Start delay (in seconds) 16 delay: 3, // Delay after each scroll event (in seconds) 17 step: 5, // Distance of each single step (in pixels) 18 speed: 32, // Delay after each single step (in milliseconds) 19 switchItems: 1, // Items to switch after each scroll event 20 direction: 'vertical', 21 distance: 'auto', 22 autoPlay: true, 23 onMouseOverPause: true, 24 paused: false, 25 queue: null, 26 listElement: 'ul', 27 listItemElement:'li' 28 }; 29 config = $.extend(defConfig, config); 30 config.scrollOffset = config.direction === 'vertical' ? 'scrollTop' : 'scrollLeft'; 31 if (config.queue) { 32 config.queue = $('#' + config.queue); 33 } 34 35 return this.each(function() { 36 var container = $(this), 37 containerUL, 38 scrollingId = null, 39 nextScrollId = null, 40 paused = false, 41 backward, 42 forward, 43 resetClock, 44 scrollForward, 45 scrollBackward; 46 47 if (config.onMouseOverPause) { 48 container.bind('mouseover', function() { paused = true; }); 49 container.bind('mouseout', function() { paused = false; }); 50 } 51 containerUL = container.children(config.listElement + ':first-child'); 52 53 scrollForward = function() { 54 if (paused) { 55 return; 56 } 57 var curLi, 58 i, 59 newScrollOffset, 60 scrollDistance, 61 theStep; 62 63 curLi = containerUL.children(config.listItemElement + ':first-child'); 64 65 scrollDistance = config.distance !== 'auto' ? config.distance : 66 config.direction === 'vertical' ? curLi.outerHeight(true) : curLi.outerWidth(true); 67 68 // offset 69 if (!config.linear) { 70 theStep = Math.max(3, parseInt((scrollDistance - container[0][config.scrollOffset]) * 0.3, 10)); 71 newScrollOffset = Math.min(container[0][config.scrollOffset] + theStep, scrollDistance); 72 } else { 73 newScrollOffset = Math.min(container[0][config.scrollOffset] + config.step, scrollDistance); 74 } 75 container[0][config.scrollOffset] = newScrollOffset; 76 77 if (newScrollOffset >= scrollDistance) { 78 for (i = 0; i < config.switchItems; i++) { 79 if (config.queue && config.queue.find(config.listItemElement).length > 0) { 80 containerUL.append(config.queue.find(config.listItemElement)[0]); 81 containerUL.children(config.listItemElement + ':first-child').remove(); 82 } else { 83 containerUL.append(containerUL.children(config.listItemElement + ':first-child')); 84 } 85 } 86 container[0][config.scrollOffset] = 0; 87 clearInterval(scrollingId); 88 if (config.autoPlay) { 89 nextScrollId = setTimeout(forward, config.delay * 1000); 90 } 91 } 92 }; 93 94 // Backward 95 // 1. If forwarding, then reverse 96 // 2. If stoping, then backward once 97 scrollBackward = function() { 98 if (paused) { 99 return; 100 } 101 var curLi, 102 i, 103 liLen, 104 newScrollOffset, 105 scrollDistance, 106 theStep; 107 108 // init 109 if (container[0][config.scrollOffset] === 0) { 110 liLen = containerUL.children(config.listItemElement).length; 111 for (i = 0; i < config.switchItems; i++) { 112 containerUL.children(config.listItemElement + ':last-child').insertBefore(containerUL.children(config.listItemElement+':first-child')); 113 } 114 115 curLi = containerUL.children(config.listItemElement + ':first-child'); 116 scrollDistance = config.distance !== 'auto' ? 117 config.distance : 118 config.direction === 'vertical' ? curLi.height() : curLi.width(); 119 container[0][config.scrollOffset] = scrollDistance; 120 } 121 122 // new offset 123 if (!config.linear) { 124 theStep = Math.max(3, parseInt(container[0][config.scrollOffset] * 0.3, 10)); 125 newScrollOffset = Math.max(container[0][config.scrollOffset] - theStep, 0); 126 } else { 127 newScrollOffset = Math.max(container[0][config.scrollOffset] - config.step, 0); 128 } 129 container[0][config.scrollOffset] = newScrollOffset; 130 131 if (newScrollOffset === 0) { 132 clearInterval(scrollingId); 133 if (config.autoPlay) { 134 nextScrollId = setTimeout(forward, config.delay * 1000); 135 } 136 } 137 }; 138 139 forward = function() { 140 clearInterval(scrollingId); 141 scrollingId = setInterval(scrollForward, config.speed); 142 }; 143 144 backward = function() { 145 clearInterval(scrollingId); 146 scrollingId = setInterval(scrollBackward, config.speed); 147 }; 148 149 resetClock = function(delay) { 150 config.delay = delay || config.delay; 151 clearTimeout(nextScrollId); 152 if (config.autoPlay) { 153 nextScrollId = setTimeout(forward, config.delay * 1000); 154 } 155 }; 156 157 if (config.autoPlay) { 158 nextScrollId = setTimeout(forward, config.startDelay * 1000); 159 } 160 161 // bind events for container 162 container.bind('resetClock', function(delay) { resetClock(delay); }); 163 container.bind('forward', function() { clearTimeout(nextScrollId); forward(); }); 164 container.bind('backward', function() { clearTimeout(nextScrollId); backward(); }); 165 container.bind('speedUp', function(speed) { 166 if (typeof speed === 'undefined') { 167 speed = Math.max(1, parseInt(config.speed / 2, 10)); 168 } 169 config.speed = speed; 170 }); 171 container.bind('speedDown', function(speed) { 172 if (typeof speed === 'undefined') { 173 speed = config.speed * 2; 174 } 175 config.speed = speed; 176 }); 177 }); 178}; 179 180}(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.