PageSourceSearch

https://connectzing.com/_server/jquery/jquery.tinyscrollbar.js?v=90

js connectzing.com collected 2026-09-26 00:35:48 UTC 12,997 bytes, 393 lines download raw bytes

1;(function(factory) {
2    if (typeof define === 'function' && define.amd) {
3        define(['jquery'], factory);
4    }
5    else if (typeof exports === 'object') {
6        module.exports = factory(require("jquery"));
7    }
8    else {
9        factory(jQuery);
10    }
11}
12(function($) {
13    "use strict";
14
15    var pluginName = "tinyscrollbar"
16    ,   defaults = {
17            axis : 'y'
18        ,   wheel : true
19        ,   wheelSpeed : 40
20        ,   wheelLock : true
21        ,   touchLock : true
22        ,   trackSize : false
23        ,   thumbSize : false
24        ,   thumbSizeMin : 20
25        ,   deltaHeight : 0
26        }
27    ;
28
29    function Plugin($container, options) {
30        /**
31         * The options of the carousel extend with the defaults.
32         *
33         * @property options
34         * @type Object
35         */
36        this.options = $.extend({}, defaults, options);
37
38        /**
39         * @property _defaults
40         * @type Object
41         * @private
42         * @default defaults
43         */
44        this._defaults = defaults;
45
46        /**
47         * @property _name
48         * @type String
49         * @private
50         * @final
51         * @default 'tinyscrollbar'
52         */
53        this._name = pluginName;
54
55        var self = this
56        ,   $viewport = $container.find(".viewport")
57        ,   $overview = $container.find(".overview")
58        ,   $scrollbar = $container.find(".scrollbar")
59        ,   $track = $scrollbar.find(".track")
60        ,   $thumb = $scrollbar.find(".thumb")
61
62        ,   hasTouchEvents = ("ontouchstart" in document.documentElement)
63        ,   wheelEvent = "onwheel" in document.createElement("div") ? "wheel" : // Modern browsers support "wheel"
64                         document.onmousewheel !== undefined ? "mousewheel" : // Webkit and IE support at least "mousewheel"
65                         "DOMMouseScroll" // let's assume that remaining browsers are older Firefox
66        ,   isHorizontal = this.options.axis === 'x'
67        ,   sizeLabel = isHorizontal ? "width" : "height"
68        ,   posiLabel = isHorizontal ? "left" : "top"
69
70        ,   mousePosition = 0
71        ;
72
73        /**
74         * The position of the content relative to the viewport.
75         *
76         * @property contentPosition
77         * @type Number
78         */
79        this.contentPosition = 0;
80
81        /**
82         * The height or width of the viewport.
83         *
84         * @property viewportSize
85         * @type Number
86         */
87        this.viewportSize = 0;
88
89        /**
90         * The height or width of the content.
91         *
92         * @property contentSize
93         * @type Number
94         */
95        this.contentSize = 0;
96
97        /**
98         * The ratio of the content size relative to the viewport size.
99         *
100         * @property contentRatio
101         * @type Number
102         */
103        this.contentRatio = 0;
104
105        /**
106         * The height or width of the content.
107         *
108         * @property trackSize
109         * @type Number
110         */
111        this.trackSize = 0;
112
113        /**
114         * The size of the track relative to the size of the content.
115         *
116         * @property trackRatio
117         * @type Number
118         */
119        this.trackRatio = 0;
120
121        /**
122         * The height or width of the thumb.
123         *
124         * @property thumbSize
125         * @type Number
126         */
127        this.thumbSize = 0;
128
129        /**
130         * The position of the thumb relative to the track.
131         *
132         * @property thumbPosition
133         * @type Number
134         */
135        this.thumbPosition = 0;
136
137        /**
138         * Will be true if there is content to scroll.
139         *
140         * @property hasContentToSroll
141         * @type Boolean
142         */
143        this.hasContentToSroll = false;
144
145        /**
146         * @method _initialize
147         * @private
148         */
149        function _initialize() {
150            self.update();
151            _setEvents();
152
153            return self;
154        }
155
156        /**
157         * You can use the update method to adjust the scrollbar to new content or to move the scrollbar to a certain point.
158         *
159         * @method update
160         * @chainable
161         * @param {Number|String} [scrollTo] Number in pixels or the values "relative" or "bottom". If you dont specify a parameter it will default to top
162         */
163        this.update = function(scrollTo,call) {
164            var sizeLabelCap = sizeLabel.charAt(0).toUpperCase() + sizeLabel.slice(1).toLowerCase();
165            this.viewportSize = $viewport[0]['offset'+ sizeLabelCap] - this.options.deltaHeight;
166            this.contentSize = $overview[0]['scroll'+ sizeLabelCap] - this.options.deltaHeight;
167            this.contentRatio = this.viewportSize / this.contentSize;
168            this.trackSize = this.options.trackSize || this.viewportSize;
169            this.thumbSize = Math.min(this.trackSize, Math.max(this.options.thumbSizeMin, (this.options.thumbSize || (this.trackSize * this.contentRatio))));
170            this.trackRatio = (this.contentSize - this.viewportSize) / (this.trackSize - this.thumbSize);
171            this.hasContentToSroll = this.contentRatio < 1;
172
173            $scrollbar.toggleClass("disable", !this.hasContentToSroll);
174
175            switch (scrollTo) {
176                case "bottom":
177                    this.contentPosition = Math.max(this.contentSize - this.viewportSize, 0);
178                    break;
179
180                case "relative":
181                    this.contentPosition = Math.min(Math.max(this.contentSize - this.viewportSize, 0), Math.max(0, this.contentPosition));
182                    break;
183
184                default:
185                    this.contentPosition = parseInt(scrollTo, 10) || 0;
186            }
187
188            this.thumbPosition = this.contentPosition / this.trackRatio;
189
190            _setCss();
191            if (typeof call== 'function') {
192                call()
193            }
194
195            return self;
196        };
197
198        /**
199         * @method _setCss
200         * @private
201         */
202        function _setCss() {
203            $thumb.css(posiLabel, self.thumbPosition);
204            $overview.css(posiLabel, -self.contentPosition);
205            $scrollbar.css(sizeLabel, self.trackSize);
206            $track.css(sizeLabel, self.trackSize);
207            $thumb.css(sizeLabel, self.thumbSize);
208        }
209
210        /**
211         * @method _setEvents
212         * @private
213         */
214        function _setEvents() {
215            if(hasTouchEvents) {
216                $viewport[0].ontouchstart = function(event) {
217                    if(1 === event.touches.length) {
218                        event.stopPropagation();
219
220                        _start(event.touches[0]);
221                    }
222                };
223            }
224            $thumb.bind("mousedown", function(event){
225                event.stopPropagation();
226                _start(event);
227            });
228            $track.bind("mousedown", function(event){
229                _start(event, true);
230            });
231
232            $(window).resize(function() {
233                self.update("relative");
234            });
235
236            var isFixMouseWheel = false;
237            if ($.fn.wheel && wheelEvent == 'mousewheel') {
238                wheelEvent = 'wheel';
239                isFixMouseWheel = true;
240            }
241
242            if (isFixMouseWheel) {
243                $container.wheel(_wheel);
244            }
245            else if(self.options.wheel && window.addEventListener) {
246                $container[0].addEventListener(wheelEvent, _wheel, false);
247            }
248            else if(self.options.wheel) {
249                $container[0].onmousewheel = _wheel;
250            }
251        }
252
253        /**
254         * @method _isAtBegin
255         * @private
256         */
257        function _isAtBegin() {
258            return self.contentPosition > 0;
259        }
260
261        /**
262         * @method _isAtEnd
263         * @private
264         */
265        function _isAtEnd() {
266            return self.contentPosition <= (self.contentSize - self.viewportSize) - 5;
267        }
268
269        /**
270         * @method _start
271         * @private
272         */
273        function _start(event, gotoMouse) {
274            if(self.hasContentToSroll) {
275                $("body").addClass("noSelect");
276
277                mousePosition = gotoMouse ? $thumb.offset()[posiLabel] : (isHorizontal ? event.pageX : event.pageY);
278
279                if(hasTouchEvents) {
280                    document.ontouchmove = function(event) {
281                        if(self.options.touchLock || _isAtBegin() && _isAtEnd()) {
282                            event.preventDefault();
283                        }
284                        event.touches[0][pluginName + "Touch"] = 1;
285                        _drag(event.touches[0]);
286                    };
287                    document.ontouchend = _end;
288                }
289                $(document).bind("mousemove", _drag);
290                $(document).bind("mouseup", _end);
291                $thumb.bind("mouseup", _end);
292                $track.bind("mouseup", _end);
293
294                _drag(event);
295            }
296        }
297
298        /**
299         * @method _wheel
300         * @private
301         */
302        function _wheel(event) {
303            if(self.hasContentToSroll) {
304                // Trying to make sense of all the different wheel event implementations..
305
306                var evntObj = event || window.event;
307                var dY = isNaN(evntObj.deltaY) ? 1 : evntObj.deltaY;
308                var wheelDelta = -(dY || evntObj.detail || (-1 / 3 * evntObj.wheelDelta)) / 40
309                ,   multiply = (evntObj.deltaMode === 1) ? self.options.wheelSpeed : 1
310                ;
311
312                self.contentPosition -= wheelDelta * multiply * self.options.wheelSpeed;
313                self.contentPosition = Math.min((self.contentSize - self.viewportSize), Math.max(0, self.contentPosition));
314                self.thumbPosition = self.contentPosition / self.trackRatio;
315
316                /**
317                 * The move event will trigger when the carousel slides to a new slide.
318                 *
319                 * @event move
320                 */
321                $container.trigger("move");
322                $thumb.css(posiLabel, self.thumbPosition);
323                $overview.css(posiLabel, -self.contentPosition);
324
325                if(self.options.wheelLock || _isAtBegin() && _isAtEnd()) {
326                    evntObj = $.event.fix(evntObj);
327                    evntObj.preventDefault();
328                }
329
330            }
331            event.stopPropagation();
332        }
333
334        /**
335         * @method _drag
336         * @private
337         */
338        function _drag(event) {
339            if(self.hasContentToSroll) {
340                var mousePositionNew = isHorizontal ? event.pageX : event.pageY
341                ,   thumbPositionDelta = event[pluginName + "Touch"] ?
342                        (mousePosition - mousePositionNew) : (mousePositionNew - mousePosition)
343                ,   thumbPositionNew = Math.min((self.trackSize - self.thumbSize), Math.max(0, self.thumbPosition + thumbPositionDelta))
344                ;
345
346                self.contentPosition = thumbPositionNew * self.trackRatio;
347
348                $container.trigger("move");
349
350                $thumb.css(posiLabel, thumbPositionNew);
351                $overview.css(posiLabel, -self.contentPosition);
352            }
353        }
354
355        /**
356         * @method _end
357         * @private
358         */
359        function _end() {
360            self.thumbPosition = parseInt($thumb.css(posiLabel), 10) || 0;
361
362            $("body").removeClass("noSelect");
363            $(document).unbind("mousemove", _drag);
364            $(document).unbind("mouseup", _end);
365            $thumb.unbind("mouseup", _end);
366            $track.unbind("mouseup", _end);
367            document.ontouchmove = document.ontouchend = null;
368        }
369
370        return _initialize();
371    }
372
373    /**
374    * @class tinyscrollbar
375    * @constructor
376    * @param {Object} options
377        @param {String} [options.axis='y'] Vertical or horizontal scroller? ( x || y ).
378        @param {Boolean} [options.wheel=true] Enable or disable the mousewheel.
379        @param {Boolean} [options.wheelSpeed=40] How many pixels must the mouswheel scroll at a time.
380        @param {Boolean} [options.wheelLock=true] Lock default window wheel scrolling when there is no more content to scroll.
381        @param {Number} [options.touchLock=true] Lock default window touch scrolling when there is no more content to scroll.
382        @param {Boolean|Number} [options.trackSize=false] Set the size of the scrollbar to auto(false) or a fixed number.
383        @param {Boolean|Number} [options.thumbSize=false] Set the size of the thumb to auto(false) or a fixed number
384        @param {Boolean} [options.thumbSizeMin=20] Minimum thumb size.
385    */
386    $.fn[pluginName] = function(options) {
387        return this.each(function() {
388            if(!$.data(this, "plugin_" + pluginName)) {
389                $.data(this, "plugin_" + pluginName, new Plugin($(this), options));
390            }
391        });
392    };
393}));

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.