PageSourceSearch

https://www.lycored.com/wp-content/themes/lycored/dist/scripts/jquery.slimscroll.js

js lycored.com collected 2026-10-02 07:54:40 UTC 14,042 bytes, 480 lines download raw bytes

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

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.