PageSourceSearch

https://www.yarnsandfibers.com/wp-content/themes/ynfx/assets/js/jquery.slimscroll.js

js yarnsandfibers.com collected 2026-09-24 23:12:13 UTC 14,341 bytes, 499 lines download raw bytes

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