PageSourceSearch

https://ccnrb.org/wp-content/themes/space-ccnrb/js/lib/lb-slideshow.js?ver=635900394

js ccnrb.org collected 2026-09-25 04:43:55 UTC 15,597 bytes, 506 lines download raw bytes

1
2/* 
3	todo:
4	resize images
5
6	navigation
7	title slideshow
8	titles slides
9  */
10
11/*
12221124 change of plan
13we never go back left
140123456, click on 3, 3456012, click on 1, 1234560
15*/
16
17
18
19  var LBSlideshow = function(pEl,pOptions){
20
21   pOptions = pOptions == null ? new Object() : pOptions;
22   /*********************************************************************************************************************************  SLIDESHOW */
23    //simple slideshow : every image is stored on the right until called.
24    var mediac = -1;
25    var total = 0;
26    var _sliding = false;
27    var slideshow = jQuery(pEl);
28    var slideshow_inner = slideshow.parent();
29    var slideshow_parent = slideshow.parent().parent();
30    var slides = slideshow.find('.lbslide');
31    var dots = slideshow_parent.find('.lbslideshow-dots');
32    var aSlides = [];
33    var settings = pOptions;
34
35
36    var onChange = pOptions.onChange || null;
37    var onChangeRef = pOptions.onChangeRef || '';
38    // looping means that if we use previous or nexrt we're never stuck
39    // particularly useful when images don't have the same width
40    var looping = (pOptions.looping === false) ? false : true;
41    var btnPrevious = pOptions.previous || slideshow_parent.find('.lbslideshow-previous');
42    var btnNext = pOptions.next || slideshow_parent.find('.lbslideshow-next');
43    var clickableItems = pOptions.clickableItems || false;
44    var centerCurrentItem = pOptions.centerCurrentItem || false;
45    var transition = pOptions.transition || 'slide';
46    var veil = pOptions.veil || slideshow_parent.find('.lbslideshow-veil');
47
48    var slideMinHeight = pOptions.minHeight || 200;
49    var slideMinHeightDesktop = slideMinHeight;
50    var slideMinHeightTablet = pOptions.minHeightTablet || slideMinHeight;
51    var slideMinHeightMobile = pOptions.minHeightMobile || slideMinHeight;
52    // console.table(pOptions);
53
54    var total = slides.length;
55    var that = this;
56    var afs = new Array();
57    var ww,hh;
58    var firstTime = true;
59    //
60    var minh,minw;
61    var mode = pOptions.mode ? pOptions.mode : "manual";
62    var resizew = pOptions.width ? pOptions.width : "auto";
63    var resizeh = pOptions.height ? pOptions.height : "auto";
64
65    var smallestRatio; //castara slideshows take the smallest photo's height as a reference for the slideshow
66
67    // mode = 'manual';
68
69    //resizew & resizeh are the modes (auto*, fullscreen, number);
70    //minh & minw are the minimum width and height according to wrapper and mode
71    // * auto takes the minimum value for the different photos
72
73    if(Number(resizew) == resizew){
74    	minw = resizew;
75    	resizew = "number";
76    }
77
78    if(Number(resizeh) == resizeh){
79    	minh = resizeh;
80    	resizeh = "number";
81    }
82    
83    
84
85    this.init = function() {
86      TweenLite.killTweensOf(changeSlide)
87
88      mediac = total-1;
89      
90      for(var i = 0; i < total ; i++) {
91          aSlides.push(slides.eq(i));
92      }
93
94      if (total > 1) {
95        if(mode == "auto"){
96          TweenLite.delayedCall(.3, changeSlide);	
97        }else{
98    	    dots.children('li').not('.selected').on('click',function(){
99            changeSlide(null, jQuery(this).index());
100          }).css('cursor','pointer');
101        } 
102
103        btnPrevious.on('click',function(){
104          // changeSlide(-1, mediac-1);
105          changeSlide(-1);
106        }).css('cursor','pointer');
107        btnNext.on('click',function(){
108          changeSlide(1);
109        }).css('cursor','pointer');
110
111        TweenLite.set('.lbslideshow-arrow-wrapper', {opacity: 1});
112
113      }else{
114        btnPrevious.remove();
115        btnNext.remove();
116        dots.css('display', 'none');
117      }
118
119      if(total>0){
120        that.resize(jQuery(window).width(),jQuery(window).height());
121        changeSlide(1, 0);
122      }   
123
124      // requires swipe-detect.js
125        slideshow_inner.swipeDetector().on('swipeRight.sd swipeLeft.sd', function(event) { 
126          if (event.type === "swipeLeft") {
127          changeSlide();
128        } else if (event.type === "swipeRight") {
129          changeSlide(-1);
130        }
131      })
132
133    }
134
135   
136
137  var clubac, clubitac;
138
139  function changeSlide(pDir = null, pI) {
140    var animDuration = .5;/*.55;*/
141    var animDelay = 4.45;
142
143    if(total == 1) {
144      animDuration = animDelay = 0;
145    }
146
147    var direction = pDir || 1;
148    var next;
149
150    if(_sliding == true) {
151      return;
152    }
153
154    TweenLite.killTweensOf(changeSlide);
155
156    _sliding = true;
157    if(pI == undefined) {
158      next = pDir == 1 ? (mediac + 1) % total : (mediac == 0 ? total-1 : mediac-1);
159    } else {
160      next = pI;
161      direction = next > mediac ? 1 : -1;
162    }
163
164    var old = mediac;
165    mediac = next;
166        
167    // *********** dépendant de la taille du folio en fait ***********
168    slides.css('z-index', 1);
169    
170    slideshow_parent.css('pointer-events', 'none');
171
172     console.log('current is '+old+' and next is '+mediac, 'direction : '+direction, 'total:'+total);
173
174    var m1, m2, p1, p2;
175    // if I want 1, 0 and 6 should be on the left, 2 and 3 on the right // half 
176    if(looping == true) {
177      
178      // on laisse old, on prend tout ce qui avant (la moitié des slides) et on les prepend, puis on prend tout ce qui est apres (la moitié) et on append
179      var i, n;
180      var na = new Array();
181      na.push(mediac);
182
183      if(total > 1) {
184
185        for(i = 1 ; i < Math.ceil(aSlides.length/2)+1 ; i++) {
186          // on one side we prepend
187          n = mediac - i < 0 ? aSlides.length-i : mediac - i;
188         // console.log(mediac+" - "+i+" = "+n);
189          if(na.indexOf(parseInt(n)) == -1) {
190            na.unshift(n);
191          }
192          
193          n = mediac + i >= aSlides.length ? mediac + i - (aSlides.length) : mediac + i;
194         // console.log(mediac+" + "+i+" = "+n);
195          if(na.indexOf(parseInt(n)) == -1) {
196            na.push(n);
197          }
198           //console.log(n);
199        } 
200
201       // console.log(na);
202
203        for(i = 0; i< na.length; i++) {
204          aSlides[na[i]].detach().appendTo(slides.parent());
205        }
206      }
207
208    }
209
210    if(!firstTime) {
211      if(old == -1) {
212        old = aSlides.length-1;
213      }
214
215      console.log(old);
216      
217      TweenMax.set(slideshow, { x: - aSlides[old].position().left+getCenterX(old)});
218     // console.log( - aSlides[old].position().left+getCenterX(old));
219      var nnx = - aSlides[mediac].position().left + getCenterX(mediac);
220
221      console.log(transition)
222    } else {
223      firstTime = false;
224    }
225
226    if(transition == 'veil') {
227      
228      veil = aSlides[old].find('.lbslideshow-veil');
229
230      var vdir = direction < 0 ? 'left' : 'right';
231      var vdir2 = direction < 0 ? 'right' : 'left';
232      
233      TweenMax.to(veil, animDuration, {scaleX: 1, transformOrigin: vdir,  onComplete: function() {
234        TweenMax.set(slideshow, { x: nnx });
235        veil = aSlides[mediac].find('.lbslideshow-veil');
236        TweenMax.to(veil, animDuration, {scaleX: 0, transformOrigin: vdir2, onComplete: function() {
237          _sliding = false;
238          slideshow_parent.css('pointer-events', 'inherit');
239        }});
240      }});
241    } else {
242
243      slideshow.find('.lbslideshow-veil').css('opacity', 0);
244
245      TweenMax.to(slideshow, animDuration, {
246        x: nnx,
247        onComplete: function () {
248
249          _sliding = false;
250          slideshow_parent.css('pointer-events', 'inherit');
251        }
252      });
253    }
254
255    slideshow.find('.lbslide.inactive').off('click').removeClass('inactive');
256    slides.not(':eq('+mediac+')').addClass('inactive').css('z-index', 1);
257    slides.eq(mediac).css('z-index', 2);
258
259    if(clickableItems == true) {
260      slideshow.find('.lbslide.inactive').on('click', function () {
261          var ni = jQuery(this).data('ref').toString();
262         // console.log(ni);
263          ni = ni.substr(3,2);
264          //console.log(ni);
265          changeSlide(null, ni);
266        }).css('cursor', 'pointer');
267    }  
268          
269
270    if (total > 1) {
271      dots.children('li.selected').removeClass('selected').css('cursor', 'pointer');
272      dots.children('li').eq(mediac).addClass('selected').css('cursor', 'auto');
273
274      if(onChange != null) {
275        var ref = onChangeRef || '';
276        onChange(ref, mediac);
277      }
278    }
279
280    /*
281    TweenMax.to(jQuery('.selected'), animDuration/2, {
282        opacity: 1,
283        scaleX: 1,
284        scaleY: 1
285      });*/
286
287    if (total>1 && mode=="auto") TweenLite.delayedCall(animDelay, changeSlide);
288
289  }
290
291  function getCenterX(pE) {
292    // if slideshow is centered
293    return (slideshow_parent.width()/2 - slides.eq(pE).width()/2);
294  }
295
296
297  this.scroll = function(pY){
298    if(pY>0 && pY < slideshow.height()){
299      slides.css('margin-top',Math.round(pY/2)+"px");
300    }else{
301      slides.css('margin-top','0px');
302    }
303  }
304
305        this.resize = function(pw,ph, pDev){
306
307         ww = pw;
308         hh = ph;
309
310         slideMinHeight = pDev == 'mobile' ? slideMinHeightMobile : (pDev == 'tablet' ? slideMinHeightTablet : slideMinHeightDesktop);
311
312         // console.log(pDev, slideMinHeight);
313
314         var autoMoveX = true;
315    	//var h = maxh == "fullscreen" ? ph : maxh == "auto"
316
317      // 220916 Special Bella, do not use elsewhere
318      /*var inw = parseInt(jQuery('.entry-content').innerWidth());
319      inw -= parseInt(jQuery('.entry-content').css('padding-left'))+parseInt(jQuery('.entry-content').css('padding-right'));
320      jQuery('.slideshow-inner').css('width', inw+'px');*/
321      //
322        if(slideshow.hasClass('lbs-nolooping')){
323          if(looping == true) {
324            autoMoveX = false;
325            looping = false;
326            // reorganise
327            for(var i = 0; i< aSlides.length;i++) {
328              aSlides[i].detach().appendTo(slides.parent());
329            }
330            centerCurrentItem = true;
331            
332            minw = 180;
333            changeSlide(null, 0);
334          }
335        } else {
336          
337          if(looping == false && settings['looping'] == true) {
338            autoMoveX = false;
339            looping = true;
340            centerCurrentItem = false;
341            minw = 260;
342            changeSlide(null, 0);
343          }
344        }
345
346      slideshow.find('img').each(function(){
347
348        if(afs[jQuery(this)] == undefined){
349          smallestRatio = -1;
350          afs[jQuery(this)] = {w:jQuery(this).attr('width'), h:jQuery(this).attr('height'), nw:jQuery(this).attr('width'), nh:jQuery(this).attr('height')};
351          var rat = afs[jQuery(this)].h/afs[jQuery(this)].w;
352          if(smallestRatio == -1 || smallestRatio < rat){
353            smallestRatio = rat;
354          }
355        }
356
357      })
358
359
360      if(resizew != "auto" || resizeh != "auto"){
361        	//note: if resizew or resizeh are set to number, minh and minw don't change
362
363        	if(resizew == "fullscreen"){ //only one coded..
364        		minw = ww;
365        	}else{
366            //console.log('lbslideshowerror: only fullscreen & auto width are handled');
367
368          }
369
370          if(resizeh == "fullscreen"){
371            minh = hh;
372          } else if(resizeh == "auto" || ww <= 830){
373            minh = Math.max(slideMinHeight,minw*smallestRatio);
374          }
375
376          //230606 temporarily comment this for hayretreats keypoints
377          // console.log('minw', minw);
378          slides.css({width:minw+"px", height:minh+"px"});
379          /*var snw = 0;
380          for(var i = 0 ; i < total ; i++) {
381            snw += minw+16;
382          }
383          //slideshow.css({width:snw+"px", height:minh+"px"});*/
384          slideshow.css({width:((total)*minw)+"px", height:minh+"px"});
385
386          if(centerCurrentItem == true) {
387            slideshow.css({marginLeft: parseInt(ww/2 - minw/2)+'px'});
388          } else {
389            slideshow.css({marginLeft:0});
390          }
391          
392          // slideshow_parent.css({width:minw+"px", height:minh+"px"});
393
394          slideshow.find('img').each(function(){
395            resizeFSIMG(jQuery(this),'out',minw,minh);
396          })
397
398        }else{
399            // console.log("auto auto");
400            minw = slideshow_inner.width();
401            minh = parseInt(Math.max(slideMinHeight,minw*smallestRatio), 10);
402            // console.log(slideMinHeight);
403            //  console.log(minh);
404            minh = Math.min(slideMinHeight, minh);
405
406            // console.log(minh);
407            // slides.css({width:minw+"px", height:minh+"px"});
408            //slides.css({height:minh+"px", width: 'auto'});
409            //230523 update for a slideshow that centers the image while keeping the original height.
410            slides.css({height:minh+"px", width: Math.min(ww, 1366)});
411            slides.css({height:minh+"px", width: 'auto'});
412            
413            
414            // slideshow.css({width:((total+1)*minw)+"px"});
415            var totw = 0; 
416            // il faut resizer de la vraie largeur pas calculée sur minw parce aue les photos n'ont pas la meme largeur
417
418            // slideshow_parent.css({height:minh+"px"});
419            slideshow.find('img').each(function(){
420              resizeFSIMG(jQuery(this),'in',minw,minh);
421              totw += parseInt(jQuery(this).css('width'), 10)+40;
422            })
423
424            slideshow.css({width:totw+'px', height: minh+'px'});
425            //auto | auto
426            //100% width parent, min height
427
428          }
429          if(autoMoveX == true) {
430            var nnx = - slides.eq(mediac).position().left;
431            nnx += getCenterX(mediac);        
432            TweenMax.set(slideshow, { x: nnx });
433
434            _sliding = false;
435            slideshow_parent.css('pointer-events', 'inherit');
436          }
437
438          if(centerCurrentItem == true) {
439              var n = parseInt(ww/2);
440              if(ww <= 500) {
441                n += 20;
442              }
443              slideshow.css({marginLeft: parseInt(n - minw/2)+'px'});
444            } else {
445              slideshow.css({marginLeft:0});
446            }
447        }
448
449        function findSmallestH(){
450         minh = -1;
451         var smallestImage;
452
453         for(var u  in afs){
454           if(minh == -1 || afs[u].nh < minh){
455            minh = afs[u].nh;	
456       			//minh = minh*ww/afs[u].nw;
457       		}
458       	}
459       	
460       }
461
462       function resizeFSIMG(pImg,pMode,pw,ph){
463		//consolelog(pImg);
464		//consolelog('FSIMG : ',pImg.attr('src'));
465   var rat;
466   var refw = pw;
467   var refh = ph;
468
469   if(pMode == "in"){
470	        //tweaked version for Journe : don't upscale, just center and reduce size if needed
471	        rat = Math.max(afs[pImg].w / refw, afs[pImg].h / refh);
472          
473          if(rat >= 1 && afs[pImg].w != 0){
474           var w = parseInt(Math.ceil(afs[pImg].w / rat), 10);
475           var h = parseInt(Math.ceil(afs[pImg].h / rat), 10);
476           afs[pImg].nw = w;
477           afs[pImg].nh = h;
478           //TweenMax.to(pImg,0,{width:'auto',height:h,left:refw/2-w/2,top:refh/2-h/2});
479           // TweenMax.to(pImg,0,{width:'auto',height:h})
480           TweenMax.to(pImg,0,{width:'auto',height:ph+'px'});
481           //TweenMax.to(pImg,0,{width:ww,height:ph+'px'});
482         }
483       }else{
484
485        refh = refh == "auto" ? afs[pImg].h : refh;
486        refw = refw == "auto" ? afs[pImg].w : refw;
487
488        rat = Math.min(afs[pImg].w / refw, afs[pImg].h / refh);
489
490        if(rat != 0){
491          var w = parseInt(Math.ceil(afs[pImg].w / rat), 10);
492          var h = parseInt(Math.ceil(afs[pImg].h / rat), 10);
493          afs[pImg].nw = w;
494          afs[pImg].nh = h;
495	            //console.log(rat, w, h);
496	           //TweenMax.set(pImg,{width:w,height:h}); 
497
498             //TweenMax.set(pImg,{width:w,height:h, left:refw/2-w/2,top:refh/2-h/2});
499             TweenMax.to(pImg,0,{width:w,height:h});
500
501           }
502
503         }
504       }
505
506     }

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.