PageSourceSearch

https://www.schlosskammer.at/plugins/content/responsivegallery/js/helpers/jquery.cycle2.carousel.js

js schlosskammer.at collected 2026-10-07 01:04:08 UTC 9,894 bytes, 268 lines download raw bytes

vendor: 4,445 bytes, lines 1-120
1/*! carousel transition plugin for Cycle2;  version: 20130411 */
2(function($) {
3"use strict";
4
5$( document ).on('cycle-bootstrap', function( e, opts, API ) {
6    if ( opts.fx !== 'carousel' )
7        return;
8
9    API.getSlideIndex = function( el ) {
10        var slides = this.opts()._carouselWrap.children();
11        var i = slides.index( el );
12        return i % slides.length;
13    };
14
15    // override default 'next' function
16    API.next = function() {
17        var count = opts.reverse ? -1 : 1;
18        if ( opts.allowWrap === false && ( opts.currSlide + count ) > opts.slideCount - opts.carouselVisible )
19            return;
20        opts.API.advanceSlide( count );
21        opts.API.trigger('cycle-next', [ opts ]).log('cycle-next');
22    };
23
24});
25
26
27$.fn.cycle.transitions.carousel = {
28    // transition API impl
29    preInit: function( opts ) {
30        opts.hideNonActive = false;
31        
32        opts.container.on('cycle-destroyed', $.proxy(this.onDestroy, opts.API));
33        // override default API implementation
34        opts.API.stopTransition = this.stopTransition;
35
36        // issue #10
37        for (var i=0; i < opts.startingSlide; i++) {
38            opts.container.append( opts.slides[0] );
39        }        
40    },
41
42    // transition API impl
43    postInit: function( opts ) {
44        var i, j, slide, pagerCutoffIndex, wrap;
45        var vert = opts.carouselVertical;
46        if (opts.carouselVisible && opts.carouselVisible > opts.slideCount)
47            opts.carouselVisible = opts.slideCount - 1;
48        var visCount = opts.carouselVisible || opts.slides.length;
49        var slideCSS = { display: vert ? 'block' : 'inline-block', position: 'static' };
50
51        // required styles
52        opts.container.css({ position: 'relative', overflow: 'hidden' });
53        opts.slides.css( slideCSS );
54
55        opts._currSlide = opts.currSlide;
56
57        // wrap slides in a div; this div is what is animated
58        wrap = $('<div class="cycle-carousel-wrap"></div>')
59            .prependTo( opts.container )
60            .css({ margin: 0, padding: 0, top: 0, left: 0, position: 'absolute' })
61            .append( opts.slides );
62
63        opts._carouselWrap = wrap;
64
65        if ( !vert )
66            wrap.css('white-space', 'nowrap');
67
68        if ( opts.allowWrap !== false ) {
69            // prepend and append extra slides so we don't see any empty space when we
70            // near the end of the carousel.  for fluid containers, add even more clones
71            // so there is plenty to fill the screen
72            // @todo: optimzie this based on slide sizes
73
74            for ( j=0; j < (opts.carouselVisible === undefined ? 2 : 1); j++ ) {
75                for ( i=0; i < opts.slideCount; i++ ) {
76                    wrap.append( opts.slides[i].cloneNode(true) );
77                }
78                for ( i=0; i < opts.slideCount; i++ ) {
79                    wrap.prepend( opts.slides[i].cloneNode(true) );
80                }
81            }
82
83            wrap.find('.cycle-slide-active').removeClass('cycle-slide-active');
84            opts.slides.eq(opts.startingSlide).addClass('cycle-slide-active');
85        }
86
87        if ( opts.pager && opts.allowWrap === false ) {
88            // hide "extra" pagers
89            pagerCutoffIndex = opts.slideCount - visCount;
90            $( opts.pager ).children().filter( ':gt('+pagerCutoffIndex+')' ).hide();
91        }
92
93        opts._nextBoundry = opts.slideCount - opts.carouselVisible;
94
95        this.prepareDimensions( opts );
96    },
97
98    prepareDimensions: function( opts ) {
99        var dim, offset, pagerCutoffIndex, tmp;
100        var vert = opts.carouselVertical;
101        var visCount = opts.carouselVisible || opts.slides.length;
102
103        if ( opts.carouselFluid && opts.carouselVisible ) {
104            if ( ! opts._carouselResizeThrottle ) {
105            // fluid container AND fluid slides; slides need to be resized to fit container
106                this.fluidSlides( opts );
107            }
108        }
109        else if ( opts.carouselVisible && opts.carouselSlideDimension ) {
110            dim = visCount * opts.carouselSlideDimension;
111            opts.container[ vert ? 'height' : 'width' ]( dim );
112        }
113        else if ( opts.carouselVisible ) {
114            dim = visCount * $(opts.slides[0])[vert ? 'outerHeight' : 'outerWidth'](true);
115            opts.container[ vert ? 'height' : 'width' ]( dim );
116        }
117        // else {
118        //     // fluid; don't size the container
119        // }
120
121        offset = ( opts.carouselOffset || 0 );
122        if ( opts.allowWrap !== false ) {
123            if ( opts.carouselSlideDimension ) {
124                offset -= ( (opts.slideCount + opts.currSlide) * opts.carouselSlideDimension );
125            }
126            else {
127                // calculate offset based on actual slide dimensions
128                tmp = opts._carouselWrap.children();
129                for (var j=0; j < (opts.slideCount + opts.currSlide); j++) {
130                    offset -= $(tmp[j])[vert?'outerHeight':'outerWidth'](true);
131                }
132            }
133        }
134
135        opts._carouselWrap.css( vert ? 'top' : 'left', offset );
136    },
137
138    fluidSlides: function( opts ) {
139        var timeout;
140        var slide = opts.slides.eq(0);
141        var adjustment = slide.outerWidth() - slide.width();
142        var prepareDimensions = this.prepareDimensions;
143
144        // throttle resize event
145        $(window).on( 'resize', resizeThrottle);
146
147        opts._carouselResizeThrottle = resizeThrottle;
148        onResize();
149
150        function resizeThrottle() {
151            clearTimeout( timeout );
152            timeout = setTimeout( onResize, 20 );
153        }
154
155        function onResize() {
156            opts._carouselWrap.stop( false, true );
157            var slideWidth = opts.container.width() / opts.carouselVisible;
158            slideWidth = Math.ceil( slideWidth - adjustment );
159            opts._carouselWrap.children().width( slideWidth );
160            if ( opts._sentinel )
161                opts._sentinel.width( slideWidth );
162            prepareDimensions( opts );
163        }
164    },
165
166    // transition API impl
167    transition: function( opts, curr, next, fwd, callback ) {
168        var moveBy, props = {};
169        var hops = opts.nextSlide - opts.currSlide;
170        var vert = opts.carouselVertical;
171        var speed = opts.speed;
172
173        // handle all the edge cases for wrapping & non-wrapping
174        if ( opts.allowWrap === false ) {
175            fwd = hops > 0;
176            var currSlide = opts._currSlide;
177            var maxCurr = opts.slideCount - opts.carouselVisible;
178            if ( hops > 0 && opts.nextSlide > maxCurr && currSlide == maxCurr ) {
179                hops = 0;
180            }
181            else if ( hops > 0 && opts.nextSlide > maxCurr ) {
182                hops = opts.nextSlide - currSlide - (opts.nextSlide - maxCurr);
183            }
184            else if ( hops < 0 && opts.currSlide > maxCurr && opts.nextSlide > maxCurr ) {
185                hops = 0;
186            }
187            else if ( hops < 0 && opts.currSlide > maxCurr ) {
188                hops += opts.currSlide - maxCurr;
189            }
190            else 
191                currSlide = opts.currSlide;
192
193            moveBy = this.getScroll( opts, vert, currSlide, hops );
194            opts.API.opts()._currSlide = opts.nextSlide > maxCurr ? maxCurr : opts.nextSlide;
195        }
196        else {
197            if ( fwd && opts.nextSlide === 0 ) {
198                // moving from last slide to first
199                moveBy = this.getDim( opts, opts.currSlide, vert );
200                callback = this.genCallback( opts, fwd, vert, callback );
201            }
202            else if ( !fwd && opts.nextSlide == opts.slideCount - 1 ) {
203                // moving from first slide to last
204                moveBy = this.getDim( opts, opts.currSlide, vert );
205                callback = this.genCallback( opts, fwd, vert, callback );
206            }
207            else {
208                moveBy = this.getScroll( opts, vert, opts.currSlide, hops );
209            }
210        }
211
212        props[ vert ? 'top' : 'left' ] = fwd ? ( "-=" + moveBy ) : ( "+=" + moveBy );
213
214        // throttleSpeed means to scroll slides at a constant rate, rather than
215        // a constant speed
216        if ( opts.throttleSpeed )
217            speed = (moveBy / $(opts.slides[0])[vert ? 'height' : 'width']() ) * opts.speed;
218
219        opts._carouselWrap.animate( props, speed, opts.easing, callback );
220    },
221
222    getDim: function( opts, index, vert ) {
223        var slide = $( opts.slides[index] );
224        return slide[ vert ? 'outerHeight' : 'outerWidth'](true);
225    },
226
227    getScroll: function( opts, vert, currSlide, hops ) {
228        var i, moveBy = 0;
229
230        if (hops > 0) {
231            for (i=currSlide; i < currSlide+hops; i++)
232                moveBy += this.getDim( opts, i, vert);
233        }
234        else {
235            for (i=currSlide; i > currSlide+hops; i--)
236                moveBy += this.getDim( opts, i, vert);
237        }
238        return moveBy;
239    },
240
241    genCallback: function( opts, fwd, vert, callback ) {
242        // returns callback fn that resets the left/top wrap position to the "real" slides
243        return function() {
244            var pos = $(opts.slides[opts.nextSlide]).position();
245            var offset = 0 - pos[vert?'top':'left'] + (opts.carouselOff
245set || 0);
246            opts._carouselWrap.css( opts.carouselVertical ? 'top' : 'left', offset );
247            callback();
248        };
249    },
250
251    // core API override
252    stopTransition: function() {
253        var opts = this.opts();
254        opts.slides.stop( false, true );
255        opts._carouselWrap.stop( false, true );
256    },
257
258    // core API supplement
259    onDestroy: function( e ) {
260        var opts = this.opts();
261        if ( opts._carouselResizeThrottle )
262            $( window ).off( 'resize', opts._carouselResizeThrottle );
263        opts.slides.prependTo( opts.container );
264        opts._carouselWrap.remove();
265    }
266};
267
268})(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.