vendor: 16,825 bytes, lines 1-443
1/*! Copyright (c) 2011 Piotr Rochala (http://rocha.la) 2 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) 3 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses. 4 * 5 * Version: 1.3.0 6 * 7 */ 8(function ($) { 9 10 jQuery.fn.extend({ 11 slimScroll: function (options) { 12 13 var defaults = { 14 15 // width in pixels of the visible scroll area 16 width: 'auto', 17 18 // height in pixels of the visible scroll area 19 height: '250px', 20 21 // width in pixels of the scrollbar and rail 22 size: '7px', 23 24 // scrollbar color, accepts any hex/color value 25 color: '#000', 26 27 // scrollbar position - left/right 28 position: 'right', 29 30 // distance in pixels between the side edge and the scrollbar 31 distance: '1px', 32 33 // default scroll position on load - top / bottom / $('selector') 34 start: 'top', 35 36 // sets scrollbar opacity 37 opacity: .4, 38 39 // enables always-on mode for the scrollbar 40 alwaysVisible: false, 41 42 // check if we should hide the scrollbar when user is hovering over 43 disableFadeOut: false, 44 45 // sets visibility of the rail 46 railVisible: false, 47 48 // sets rail color 49 railColor: '#333', 50 51 // sets rail opacity 52 railOpacity: .2, 53 54 // whether we should use jQuery UI Draggable to enable bar dragging 55 railDraggable: true, 56 57 // defautlt CSS class of the slimscroll rail 58 railClass: 'slimScrollRail', 59 60 // defautlt CSS class of the slimscroll bar 61 barClass: 'slimScrollBar', 62 63 // defautlt CSS class of the slimscroll wrapper 64 wrapperClass: 'slimScrollDiv', 65 66 // check if mousewheel should scroll the window if we reach top/bottom 67 allowPageScroll: false, 68 69 // scroll amount applied to each mouse wheel step 70 wheelStep: 20, 71 72 // scroll amount applied when user is using gestures 73 touchScrollStep: 200, 74 75 // sets border radius 76 borderRadius: '7px', 77 78 // sets border radius of the rail 79 railBorderRadius: '7px' 80 }; 81 82 var o = $.extend(defaults, options); 83 84 // do it for every element that matches selector 85 this.each(function () { 86 87 var isOverPanel, isOverBar, isDragg, queueHide, touchDif, 88 barHeight, percentScroll, lastScroll, 89 divS = '<div></div>', 90 minBarHeight = 30, 91 releaseScroll = false; 92 93 // used in event handlers and for better minification 94 var me = $(this); 95 96 // ensure we are not binding it again 97 if (me.parent().hasClass(o.wrapperClass)) { 98 // start from last bar position 99 var offset = me.scrollTop(); 100 101 // find bar and rail 102 bar = me.parent().find('.' + o.barClass); 103 rail = me.parent().find('.' + o.railClass); 104 105 getBarHeight(); 106 107 // check if we should scroll existing instance 108 if ($.isPlainObject(options)) { 109 // Pass height: auto to an existing slimscroll object to force a resize after contents have changed 110 if ('height' in options && options.height == 'auto') { 111 me.parent().css('height', 'auto'); 112 me.css('height', 'auto'); 113 var height = me.parent().parent().height(); 114 me.parent().css('height', height); 115 me.css('height', height); 116 } 117 118 if ('scrollTo' in options) { 119 // jump to a static point 120 offset = parseInt(o.scrollTo); 121 } 122 else if ('scrollBy' in options) { 123 // jump by value pixels 124 offset += parseInt(o.scrollBy); 125 } 126 else if ('destroy' in options) { 127 // remove slimscroll elements 128 bar.remove(); 129 rail.remove(); 130 me.unwrap(); 131 return; 132 } 133 134 // scroll content by the given offset 135 scrollContent(offset, false, true); 136 } 137 138 return; 139 } 140 141 // optionally set height to the parent's height 142 o.height = (o.height == 'auto') ? me.parent().height() : o.height; 143 144 // wrap content 145 var wrapper = $(divS) 146 .addClass(o.wrapperClass) 147 .css({ 148 position: 'relative', 149 overflow: 'hidden', 150 width: o.width, 151 height: o.height 152 }); 153 154 // update style for the div 155 me.css({ 156 overflow: 'hidden', 157 width: o.width, 158 height: o.height 159 }); 160 161 // create scrollbar rail 162 var rail = $(divS) 163 .addClass(o.railClass) 164 .css({ 165 width: o.size, 166 height: '100%', 167 position: 'absolute', 168 top: 0, 169 display: (o.alwaysVisible && o.railVisible) ? 'block' : 'none', 170 'border-radius': o.railBorderRadius, 171 background: o.railColor, 172 opacity: o.railOpacity, 173 zIndex: 90 174 }); 175 176 // create scrollbar 177 var bar = $(divS) 178 .addClass(o.barClass) 179 .css({ 180 background: o.color, 181 width: o.size, 182 position: 'absolute', 183 top: 0, 184 opacity: o.opacity, 185 display: o.alwaysVisible ? 'block' : 'none', 186 'border-radius': o.borderRadius, 187 BorderRadius: o.borderRadius, 188 MozBorderRadius: o.borderRadius, 189 WebkitBorderRadius: o.borderRadius, 190 zIndex: 99 191 }); 192 193 // set position 194 var posCss = (o.position == 'right') ? { right: o.distance } : { left: o.distance }; 195 rail.css(posCss); 196 bar.css(posCss); 197 198 // wrap it 199 me.wrap(wrapper); 200 201 // append to parent div 202 me.parent().append(bar); 203 me.parent().append(rail); 204 205 // make it draggable and no longer dependent on the jqueryUI 206 if (o.railDraggable) { 207 bar.bind("mousedown", function (e) { 208 var $doc = $(document); 209 isDragg = true; 210 t = parseFloat(bar.css('top')); 211 pageY = e.pageY; 212 213 $doc.bind("mousemove.slimscroll", function (e) { 214 currTop = t + e.pageY - pageY; 215 bar.css('top', currTop); 216 scrollContent(0, bar.position().top, false);// scroll content 217 }); 218 219 $doc.bind("mouseup.slimscroll", function (e) { 220 isDragg = false; hideBar(); 221 $doc.unbind('.slimscroll'); 222 }); 223 return false; 224 }).bind("selectstart.slimscroll", function (e) { 225 e.stopPropagation(); 226 e.preventDefault(); 227 return false; 228 }); 229 } 230 231 // on rail over 232 rail.hover(function () { 233 showBar(); 234 }, function () { 235 hideBar(); 236 }); 237 238 // on bar over 239 bar.hover(function () { 240 isOverBar = true; 241 }, function () { 242 isOverBar = false; 243 }); 244 245 // show on parent mouseover 246 me.hover(function () { 247 isOverPanel = true; 248 showBar(); 249 hideBar(); 250 }, function () { 251 isOverPanel = false; 252 hideBar(); 253 }); 254 255 // support for mobile 256 me.bind('touchstart', function (e, b) { 257 if (e.originalEvent.touches.length) { 258 // record where touch started 259 touchDif = e.originalEvent.touches[0].pageY; 260 } 261 }); 262 263 me.bind('touchmove', function (e) { 264 // prevent scrolling the page if necessary 265 if (!releaseScroll) { 266 e.originalEvent.preventDefault(); 267 } 268 if (e.originalEvent.touches.length) { 269 // see how far user swiped 270 var diff = (touchDif - e.originalEvent.touches[0].pageY) / o.touchScrollStep; 271 // scroll content 272 scrollContent(diff, true); 273 touchDif = e.originalEvent.touches[0].pageY; 274 } 275 }); 276 277 // set up initial height 278 getBarHeight(); 279 280 // check start position 281 if (o.start === 'bottom') { 282 // scroll content to bottom 283 bar.css({ top: me.outerHeight() - bar.outerHeight() }); 284 scrollContent(0, true); 285 } 286 else if (o.start !== 'top') { 287 // assume jQuery selector 288 scrollContent($(o.start).position().top, null, true); 289 290 // make sure bar stays hidden 291 if (!o.alwaysVisible) { bar.hide(); } 292 } 293 294 // attach scroll events 295 attachWheel(); 296 297 function _onWheel(e) { 298 // use mouse wheel only when mouse is over 299 if (!isOverPanel) { return; } 300 301 var e = e || window.event; 302 303 var delta = 0; 304 if (e.wheelDelta) { delta = -e.wheelDelta / 120; } 305 if (e.detail) { delta = e.detail / 3; } 306 307 var target = e.target || e.srcTarget || e.srcElement; 308 /* console.log($(target).closest('.' + o.wrapperClass).attr("class")); 309 console.log(me.parent().attr("class"));*/ 310 if ($(target).closest('.' + o.wrapperClass).is(me.parent())) { 311 // scroll content 312 313 scrollContent(delta, true); 314 } 315 316 // stop window scroll 317 if (e.preventDefault && !releaseScroll) { e.preventDefault(); } 318 if (!releaseScroll) { e.returnValue = false; } 319 } 320 321 function scrollContent(y, isWheel, isJump) { 322 323 releaseScroll = false; 324 var delta = y; 325 var maxTop = me.outerHeight() - bar.outerHeight(); 326 327 if (isWheel) { 328 // move bar with mouse wheel 329 delta = parseInt(bar.css('top')) + y * parseInt(o.wheelStep) / 100 * bar.outerHeight(); 330 331 // move bar, make sure it doesn't go out 332 delta = Math.min(Math.max(delta, 0), maxTop); 333 334 // if scrolling down, make sure a fractional change to the 335 // scroll position isn't rounded away when the scrollbar's CSS is set 336 // this flooring of delta would happened automatically when 337 // bar.css is set below, but we floor here for clarity 338 delta = (y > 0) ? Math.ceil(delta) : Math.floor(delta); 339 340 // scroll the scrollbar 341 bar.css({ top: delta + 'px' }); 342 } 343 344 // calculate actual scroll amount 345 percentScroll = parseInt(bar.css('top')) / (me.outerHeight() - bar.outerHeight()); 346 delta = percentScroll * (me[0].scrollHeight - me.outerHeight()); 347 348 if (isJump) { 349 delta = y; 350 var offsetTop = delta / me[0].scrollHeight * me.outerHeight(); 351 offsetTop = Math.min(Math.max(offsetTop, 0), maxTop); 352 bar.css({ top: offsetTop + 'px' }); 353 } 354 355 // scroll content 356 me.scrollTop(delta); 357 358 // fire scrolling event 359 me.trigger('slimscrolling', ~~delta); 360 361 // ensure bar is visible 362 showBar(); 363 364 // trigger hide when scroll is stopped 365 hideBar(); 366 } 367 368 function attachWheel() { 369 if (window.addEventListener) { 370 this.addEventListener('DOMMouseScroll', _onWheel, false); 371 this.addEventListener('mousewheel', _onWheel, false); 372 //this.addEventListener('MozMousePixelScroll', _onWheel, false ); 373 } 374 else { 375 document.attachEvent("onmousewheel", _onWheel) 376 } 377 } 378 379 function getBarHeight() { 380 // calculate scrollbar height and make sure it is not too small 381 barHeight = Math.max((me.outerHeight() / me[0].scrollHeight) * me.outerHeight(), minBarHeight); 382 bar.css({ height: barHeight + 'px' }); 383 384 // hide scrollbar if content is not long enough 385 var display = barHeight == me.outerHeight() ? 'none' : 'block'; 386 bar.css({ display: display }); 387 } 388 389 function showBar() { 390 // recalculate bar height 391 getBarHeight(); 392 clearTimeout(queueHide); 393 394 // when bar reached top or bottom 395 if (percentScroll == ~~percentScroll) { 396 //release wheel 397 releaseScroll = o.allowPageScroll; 398 399 // publish approporiate event 400 if (lastScroll != percentScroll) { 401 var msg = (~~percentScroll == 0) ? 'top' : 'bottom'; 402 me.trigger('slimscroll', msg); 403 } 404 } 405 else { 406 releaseScroll = false; 407 } 408 lastScroll = percentScroll; 409 410 // show only when required 411 if (barHeight >= me.outerHeight()) { 412 //allow window scroll 413 releaseScroll = true; 414 return; 415 } 416 bar.stop(true, true).fadeIn('fast'); 417 if (o.railVisible) { rail.stop(true, true).fadeIn('fast'); } 418 } 419 420 function hideBar() { 421 // only hide when options allow it 422 if (!o.alwaysVisible) { 423 queueHide = setTimeout(function () { 424 if (!(o.disableFadeOut && isOverPanel) && !isOverBar && !isDragg) { 425 bar.fadeOut('slow'); 426 rail.fadeOut('slow'); 427 } 428 }, 1000); 429 } 430 } 431 432 }); 433 434 // maintain chainability 435 return this; 436 } 437 }); 438 439 jQuery.fn.extend({ 440 slimscroll: jQuery.fn.slimScroll 441 }); 442 443})(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.