vendor: 13,768 bytes, lines 1-468
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.1 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 : 1, 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 { 99 // start from last bar position 100 var offset = me.scrollTop(); 101 102 // find bar and rail 103 bar = me.parent().find('.' + o.barClass); 104 rail = me.parent().find('.' + o.railClass); 105 106 getBarHeight(); 107 108 // check if we should scroll existing instance 109 if ($.isPlainObject(options)) 110 { 111 // Pass height: auto to an existing slimscroll object to force a resize after contents have changed 112 if ( 'height' in options && options.height == 'auto' ) { 113 me.parent().css('height', 'auto'); 114 me.css('height', 'auto'); 115 var height = me.parent().parent().height(); 116 me.parent().css('height', height); 117 me.css('height', height); 118 } else if ('height' in options) { 119 var h = options.height; 120 me.parent().css('height', h); 121 me.css('height', h); 122 } 123 124 if ('scrollTo' in options) 125 { 126 // jump to a static point 127 offset = parseInt(o.scrollTo); 128 } 129 else if ('scrollBy' in options) 130 { 131 // jump by value pixels 132 offset += parseInt(o.scrollBy); 133 } 134 else if ('destroy' in options) 135 { 136 // remove slimscroll elements 137 bar.remove(); 138 rail.remove(); 139 me.unwrap(); 140 return; 141 } 142 143 // scroll content by the given offset 144 scrollContent(offset, false, true); 145 } 146 147 return; 148 } 149 150 // optionally set height to the parent's height 151 o.height = (o.height == 'auto') ? me.parent().height() : o.height; 152 153 // wrap content 154 var wrapper = $(divS) 155 .addClass(o.wrapperClass) 156 .css({ 157 position: 'relative', 158 overflow: 'hidden', 159 width: o.width, 160 height: o.height 161 }); 162 163 // update style for the div 164 me.css({ 165 overflow: 'hidden', 166 width: o.width, 167 height: o.height 168 }); 169 170 // create scrollbar rail 171 var rail = $(divS) 172 .addClass(o.railClass) 173 .css({ 174 width: o.size, 175 height: '100%', 176 position: 'absolute', 177 top: 0, 178 display: (o.alwaysVisible && o.railVisible) ? 'block' : 'none', 179 'border-radius': o.railBorderRadius, 180 background: o.railColor, 181 opacity: o.railOpacity, 182 zIndex: 90 183 }); 184 185 // create scrollbar 186 var bar = $(divS) 187 .addClass(o.barClass) 188 .css({ 189 background: o.color, 190 width: o.size, 191 position: 'absolute', 192 top: 0, 193 opacity: o.opacity, 194 display: o.alwaysVisible ? 'block' : 'none', 195 'border-radius' : o.borderRadius, 196 BorderRadius: o.borderRadius, 197 MozBorderRadius: o.borderRadius, 198 WebkitBorderRadius: o.borderRadius, 199 zIndex: 99 200 }); 201 202 // set position 203 var posCss = (o.position == 'right') ? { right: o.distance } : { left: o.distance }; 204 rail.css(posCss); 205 bar.css(posCss); 206 207 // wrap it 208 me.wrap(wrapper); 209 210 // append to parent div 211 me.parent().append(bar); 212 me.parent().append(rail); 213 214 // make it draggable and no longer dependent on the jqueryUI 215 if (o.railDraggable){ 216 bar.bind("mousedown", function(e) { 217 var $doc = $(document); 218 isDragg = true; 219 t = parseFloat(bar.css('top')); 220 pageY = e.pageY; 221 222 $doc.bind("mousemove.slimscroll", function(e){ 223 currTop = t + e.pageY - pageY; 224 bar.css('top', currTop); 225 scrollContent(0, bar.position().top, false);// scroll content 226 }); 227 228 $doc.bind("mouseup.slimscroll", function(e) { 229 isDragg = false;hideBar(); 230 $doc.unbind('.slimscroll'); 231 }); 232 return false; 233 }).bind("selectstart.slimscroll", function(e){ 234 e.stopPropagation(); 235 e.preventDefault(); 236 return false; 237 }); 238 } 239 240 // on rail over 241 rail.hover(function(){ 242 showBar(); 243 }, function(){ 244 hideBar(); 245 }); 246 247 // on bar over 248 bar.hover(function(){ 249 isOverBar = true; 250 }, function(){ 251 isOverBar = false; 252 }); 253 254 // show on parent mouseover 255 me.hover(function(){ 256 isOverPanel = true; 257 showBar(); 258 hideBar(); 259 }, function(){ 260 isOverPanel = false; 261 hideBar(); 262 }); 263 264 // support for mobile 265 me.bind('touchstart', function(e,b){ 266 if (e.originalEvent.touches.length) 267 { 268 // record where touch started 269 touchDif = e.originalEvent.touches[0].pageY; 270 } 271 }); 272 273 me.bind('touchmove', function(e){ 274 // prevent scrolling the page if necessary 275 if(!releaseScroll) 276 { 277 e.originalEvent.preventDefault(); 278 } 279 if (e.originalEvent.touches.length) 280 { 281 // see how far user swiped 282 var diff = (touchDif - e.originalEvent.touches[0].pageY) / o.touchScrollStep; 283 // scroll content 284 scrollContent(diff, true); 285 touchDif = e.originalEvent.touches[0].pageY; 286 } 287 }); 288 289 // set up initial height 290 getBarHeight(); 291 292 // check start position 293 if (o.start === 'bottom') 294 { 295 // scroll content to bottom 296 bar.css({ top: me.outerHeight() - bar.outerHeight() }); 297 scrollContent(0, true); 298 } 299 else if (o.start !== 'top') 300 { 301 // assume jQuery selector 302 scrollContent($(o.start).position().top, null, true); 303 304 // make sure bar stays hidden 305 if (!o.alwaysVisible) { bar.hide(); } 306 } 307 308 // attach scroll events 309 attachWheel(); 310 311 function _onWheel(e) 312 { 313 // use mouse wheel only when mouse is over 314 if (!isOverPanel) { return; } 315 316 var e = e || window.event; 317 318 var delta = 0; 319 if (e.wheelDelta) { delta = -e.wheelDelta/120; } 320 if (e.detail) { delta = e.detail / 3; } 321 322 var target = e.target || e.srcTarget || e.srcElement; 323 if ($(target).closest('.' + o.wrapperClass).is(me.parent())) { 324 // scroll content 325 scrollContent(delta, true); 326 } 327 328 // stop window scroll 329 if (e.preventDefault && !releaseScroll) { e.preventDefault(); } 330 if (!releaseScroll) { e.returnValue = false; } 331 } 332 333 function scrollContent(y, isWheel, isJump) 334 { 335 releaseScroll = false; 336 var delta = y; 337 var maxTop = me.outerHeight() - bar.outerHeight(); 338 339 if (isWheel) 340 { 341 // move bar with mouse wheel 342 delta = parseInt(bar.css('top')) + y * parseInt(o.wheelStep) / 100 * bar.outerHeight(); 343 344 // move bar, make sure it doesn't go out 345 delta = Math.min(Math.max(delta, 0), maxTop); 346 347 // if scrolling down, make sure a fractional change to the 348 // scroll position isn't rounded away when the scrollbar's CSS is set 349 // this flooring of delta would happened automatically when 350 // bar.css is set below, but we floor here for clarity 351 delta = (y > 0) ? Math.ceil(delta) : Math.floor(delta); 352 353 // scroll the scrollbar 354 bar.css({ top: delta + 'px' }); 355 } 356 357 // calculate actual scroll amount 358 percentScroll = parseInt(bar.css('top')) / (me.outerHeight() - bar.outerHeight()); 359 delta = percentScroll * (me[0].scrollHeight - me.outerHeight()); 360 361 if (isJump) 362 { 363 delta = y; 364 var offsetTop = delta / me[0].scrollHeight * me.outerHeight(); 365 offsetTop = Math.min(Math.max(offsetTop, 0), maxTop); 366 bar.css({ top: offsetTop + 'px' }); 367 } 368 369 // scroll content 370 me.scrollTop(delta); 371 372 // fire scrolling event 373 me.trigger('slimscrolling', ~~delta); 374 375 // ensure bar is visible 376 showBar(); 377 378 // trigger hide when scroll is stopped 379 hideBar(); 380 } 381 382 function attachWheel() 383 { 384 if (window.addEventListener) 385 { 386 this.addEventListener('DOMMouseScroll', _onWheel, false ); 387 this.addEventListener('mousewheel', _onWheel, false ); 388 this.addEventListener('MozMousePixelScroll', _onWheel, false ); 389 } 390 else 391 { 392 document.attachEvent("onmousewheel", _onWheel) 393 } 394 } 395 396 function getBarHeight() 397 { 398 // calculate scrollbar height and make sure it is not too small 399 barHeight = Math.max((me.outerHeight() / me[0].scrollHeight) * me.outerHeight(), minBarHeight); 400 bar.css({ height: barHeight + 'px' }); 401 402 // hide scrollbar if content is not long enough 403 var display = barHeight == me.outerHeight() ? 'none' : 'block'; 404 bar.css({ display: display }); 405 } 406 407 function showBar() 408 { 409 // recalculate bar height 410 getBarHeight(); 411 clearTimeout(queueHide); 412 413 // when bar reached top or bottom 414 if (percentScroll == ~~percentScroll) 415 { 416 //release wheel 417 releaseScroll = o.allowPageScroll; 418 419 // publish approporiate event 420 if (lastScroll != percentScroll) 421 { 422 var msg = (~~percentScroll == 0) ? 'top' : 'bottom'; 423 me.trigger('slimscroll', msg); 424 } 425 } 426 else 427 { 428 releaseScroll = false; 429 } 430 lastScroll = percentScroll; 431 432 // show only when required 433 if(barHeight >= me.outerHeight()) { 434 //allow window scroll 435 releaseScroll = true; 436 return; 437 } 438 bar.stop(true,true).fadeIn('fast'); 439 if (o.railVisible) { rail.stop(true,true).fadeIn('fast'); } 440 } 441 442 function hideBar() 443 { 444 // only hide when options allow it 445 if (!o.alwaysVisible) 446 { 447 queueHide = setTimeout(function(){ 448 if (!(o.disableFadeOut && isOverPanel) && !isOverBar && !isDragg) 449 { 450 bar.fadeOut('slow'); 451 rail.fadeOut('slow'); 452 } 453 }, 1000); 454 } 455 } 456 457 }); 458 459 // maintain chainability 460 return this; 461 } 462 }); 463 464 jQuery.fn.extend({ 465 slimscroll: jQuery.fn.slimScroll 466 }); 467 468})(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.