PageSourceSearch

https://sherl.ru/bitrix/templates/sherl/js/jquery.jcarousellite.js

js sherl.ru collected 2026-10-07 17:58:36 UTC 12,695 bytes, 285 lines download raw bytes

1/*!
2 * jCarouselLite - v1.1 - 2014-09-28
3 * http://www.gmarwaha.com/jquery/jcarousellite/
4 * Copyright (c) 2014 Ganeshji Marwaha
5 * Licensed MIT (https://github.com/ganeshmax/jcarousellite/blob/master/LICENSE)
6 */
7
8(function($) {                                          // Compliant with jquery.noConflict()
9    $.jCarouselLite = {
10        version: '1.1'
11    };
12
13    $.fn.jCarouselLite = function(options) {
14
15        options = $.extend({}, $.fn.jCarouselLite.options, options || {});
16
17        return this.each(function() {   // Returns the element collection. Chainable.
18
19            var running,
20                animCss, sizeCss,
21                div = $(this), ul, initialLi, li,
22                liSize, ulSize, divSize,
23                numVisible, initialItemLength, itemLength, calculatedTo, autoTimeout;
24
25            initVariables();                    // Set the above variables after initial calculations
26            initStyles();                       // Set the appropriate styles for the carousel div, ul and li
27            initSizes();                        // Set appropriate sizes for the carousel div, ul and li
28            attachEventHandlers();              // Attach event handlers for carousel to respond
29
30            function go(to) {
31                if(!running) {
32                    clearTimeout(autoTimeout);  // Prevents multiple clicks while auto-scrolling - edge case
33                    calculatedTo = to;
34
35                    if(options.beforeStart) {   // Call the beforeStart() callback
36                        options.beforeStart.call(this, visibleItems());
37                    }
38
39                    if(options.circular) {      // If circular, and "to" is going OOB, adjust it
40                        adjustOobForCircular(to);
41                    } else {                    // If non-circular and "to" is going OOB, adjust it.
42                        adjustOobForNonCircular(to);
43                    }                           // If neither overrides "calculatedTo", we are not in edge cases.
44
45                    animateToPosition({         // Animate carousel item to position based on calculated values.
46                        start: function() {
47                            running = true;
48                        },
49                        done: function() {
50                            if(options.afterEnd) {
51                                options.afterEnd.call(this, visibleItems());
52                            }
53                            if(options.auto) {
54                                setupAutoScroll();
55                            }
56                            running = false;
57                        }
58                    });
59
60                    if(!options.circular) {     // Enabling / Disabling buttons is applicable in non-circular mode only.
61                        disableOrEnableButtons();
62                    }
63
64                }
65                return false;
66            }
67
68            function initVariables() {
69                running = false;
70                animCss = options.vertical ? "top" : "left";
71                sizeCss = options.vertical ? "height" : "width";
72                ul = div.find(">ul");
73                initialLi = ul.find(">li");
74                initialItemLength = initialLi.size();
75
76                // To avoid a scenario where number of items is just 1 and visible is 3 for example.
77                numVisible = initialItemLength < options.visible ? initialItemLength : options.visible;
78
79                if(options.circular) {
80                /*    var $lastItemSet = initialLi.slice(initialItemLength-numVisible).clone();
81                    var $firstItemSet = initialLi.slice(0,numVisible).clone();
82
83                    ul.prepend($lastItemSet)        // Prepend the lis with final items so that the user can click the back button to start with
84                        .append($firstItemSet);     // Append the lis with first items so that the user can click the next button even after reaching the end
85
86                    options.start += numVisible;    // Since we have a few artificial lis in the front, we will have to move the pointer to point to the real first item
87				*/	
88                    var $firstItemSet = initialLi.slice(0,numVisible).clone();
89                    ul.append($firstItemSet);					
90                }
91
92                li = $("li", ul);
93                itemLength = li.size();
94                calculatedTo = options.start;
95            }
96
97            function initStyles() {
98                div.css("visibility", "visible");   // If the div was set to hidden in CSS, make it visible now
99
100                li.css({
101                    overflow: "hidden",
102                    "float": options.vertical ? "none" : "left" // Some minification tools fail if "" is not used
103                });
104
105                ul.css({
106                    margin: "0",
107                    padding: "0",
108                    position: "relative",
109                    "list-style": "none",
110                    "z-index": "1"
111                });
112
113                div.css({
114                    overflow: "hidden",
115                    position: "relative",
116                    "z-index": "2",
117                    left: "0px"
118                });
119
120                // For a non-circular carousel, if the start is 0 and btnPrev is supplied, disable the prev button
121                if(!options.circular && options.btnPrev && options.start == 0) {
122                    $(options.btnPrev).addClass("disabled");
123                }
124            }
125
126            function initSizes() {
127
128                liSize = options.vertical ?         // Full li size(incl margin)-Used for animation and to set ulSize
129                    li.outerHeight(true) :
130                    li.outerWidth(true);
131                ulSize = liSize * itemLength;       // size of full ul(total length, not just for the visible items)
132                divSize = liSize * numVisible;      // size of entire div(total length for just the visible items)
133
134                // Generally, LI's dimensions should be specified explicitly in a style-sheet
135                // But in the case of img (with width and height attr), we can derive L
135I's dimensions and set here
136                // May be applicable for other types of LI children if their dimensions are explicitly specified
137                // Individual LI dimensions
138                li.css({
139                    width: li.width(),
140                    height: li.height()
141                });
142
143                // Size of the entire UL. Including hidden and visible elements
144                // Will include LI's (width + padding + border + margin) * itemLength - Using outerwidth(true)
145                ul.css(sizeCss, ulSize+"px")
146                    .css(animCss, -(calculatedTo * liSize));
147
148                // Width of the DIV. Only the width of the visible elements
149                // Will include LI's (width + padding + border + margin) * numVisible - Using outerwidth(true)
150                div.css(sizeCss, divSize+"px");
151
152            }
153
154            function attachEventHandlers() {
155                if(options.btnPrev) {
156                    $(options.btnPrev).click(function() {
157                        return go(calculatedTo - options.scroll);
158                    });
159                }
160
161                if(options.btnNext) {
162                    $(options.btnNext).click(function() {
163                        return go(calculatedTo + options.scroll);
164                    });
165                }
166
167                if(options.btnGo) {
168                    $.each(options.btnGo, function(i, val) {
169                        $(val).click(function() {
170					//	alert(numVisible + i);
171                            return go(i);//go(options.circular ? numVisible + i : i);
172                        });
173                    });
174                }
175
176                if(options.mouseWheel && div.mousewheel) {
177                    div.mousewheel(function(e, d) {
178                        return d > 0 ?
179                            go(calculatedTo - options.scroll) :
180                            go(calculatedTo + options.scroll);
181                    });
182                }
183
184                if(options.auto) {
185                    setupAutoScroll();
186                }
187            }
188
189            function setupAutoScroll() {
190                autoTimeout = setTimeout(function() {
191                    go(calculatedTo + options.scroll);
192                }, options.auto);
193            }
194
195            function visibleItems() {
196                return li.slice(calculatedTo).slice(0,numVisible);
197            }
198
199            function adjustOobForCircular(to) {
200                var newPosition;
201
202                // If first, then goto last
203                if(to <= options.start-1) {// - numVisible - 1
204                    newPosition = to + initialItemLength + options.scroll;
205                    ul.css(animCss, -(newPosition * liSize) + "px");
206                    calculatedTo = newPosition - options.scroll;
207
208                    //console.log("Before - Positioned at: " + newPosition + " and Moving to: " + calculatedTo);
209                }
210
211                // If last, then goto first
212                else if(to >= itemLength - numVisible + 1) {
213                    newPosition = to - initialItemLength - options.scroll;
214                    ul.css(animCss, -(newPosition * liSize) + "px");
215                    calculatedTo = newPosition + options.scroll;
216
217                   // console.log("After - Positioned at: " + newPosition + " and Moving to: " + calculatedTo);
218                }
219            }
220
221            function adjustOobForNonCircular(to) {
222                // If user clicks "prev" and tries to go before the first element, reset it to first element.
223                if(to < 0) {
224                    calculatedTo = 0;
225                }
226                // If "to" is greater than the max index that we can use to show another set of elements
227                // it means that we will have to reset "to" to a smallest possible index that can show it
228                else if(to > itemLength - numVisible) {
229                    calculatedTo = itemLength - numVisible;
230                }
231
232              /*  console.log("Item Length: " + itemLength + "; " +
233                    "To: " + to + "; " +
234                    "CalculatedTo: " + calculatedTo + "; " +
235                    "Num Visible: " + numVisible);*/
236            }
237
238            function disableOrEnableButtons() {
239                $(options.btnPrev + "," + options.btnNext).removeClass("disabled");
240                $( (calculatedTo-options.scroll<0 && options.btnPrev)
241                    ||
242                    (calculatedTo+options.scroll > itemLength-numVisible && options.btnNext)
243                    ||
244                    []
245                ).addClass("disabled");
246            }
247
248            function animateToPosition(animationOptions) {
249                running = true;
250
251                ul.animate(
252                    animCss == "left" ?
253                    { left: -(calculatedTo*liSize) } :
254                    { top: -(calculatedTo*liSize) },
255
256                    $.extend({
257                        duration: options.speed,
258                        easing: options.easing
259                    }, animationOptions)
260                );
261            }
262        });
263    };
264
265    $.fn.jCarouselLite.options = {
266        btnPrev: null,              // CSS Selector for the previous button
267        btnNext: null,              // CSS Selector for the next button
268        btnGo: null,                // CSS Selector for the go button
269        mouseWheel: false,          // Set "true" if you want the carousel scrolled using mouse wheel
270        auto: null,                 // Set to a numeric value (800) in millis. Time period between auto scrolls
271
272        speed: 200,                 // Set to a numeric value in millis. Speed of scroll
273        easing: null,               // Set to easing (bounceout) to specify the animation easing
274
275        vertical: false,            // Set to "true" to make the carousel scroll vertically
276        circular: true,             // Set to "true" to make it an infinite carousel
277        visible: 3,                 // Set to a numeric value to specify the number of visible elements at a time
278        start: 0,                   // Set to a numeric value to specify which item to start from
279        scroll: 1,                  // Set to a numeric value to specify how many items to scroll for one scroll event
280
281        beforeStart: null,          // Set to a function to receive a callback before every scroll start
282        afterEnd: null              // Set to a function to receive a callback after every scroll end
283    };
284
285})(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.