PageSourceSearch

https://cgt-nantes.fr/plugins/auto/photoswipe/v1.2.2/photoswipe_insert.js?1771362502

js cgt-nantes.fr collected 2026-10-08 12:03:32 UTC 8,529 bytes, 222 lines download raw bytes

1function photoshow_hover() {
2    var me = this;
3    var a = photoshow_identify(me);
4    if (a) {
5        $(me).addClass('photoshow');
6        $(me).removeClass('lity-enabled'); // remove mediabox!
7    }
8}
9function photoshow() {
10    var imgs = [],
11        g = [];
12    var a = photoshow_identify(this),
13        index = 0;
14	
15    if (!a) return;
16    
17    //On regarde si c'est une galerie indépendante
18    var galerie = $(this).parents( photoswipe.conteneur );
19    
20    if(galerie.length){
21		//Si oui, on prend uniquement les éléments qui en font partie
22		elsgalerie=galerie.find(photoswipe.selector);
23	} else {
24		//Sinon, on prends tous les éléments de galerie définis dans les paramètres du plugin, mais pas ceux faisant partie d'une galerie indépendante
25		elsgalerie=$(photoswipe.selector).filter(function(){return $(this).parents(photoswipe.conteneur).length ? false : true;});
26	}
27    
28    //Si on a aucun élément à afficher, on échappe    
29    if(elsgalerie.length===0){return false;}
30    
31    // gallery
32    var idx = 0;
33    if (photoswipe.gallery) {
34		//On sélectionne uniquement les éléments présents dans la galerie demandée
35		elsgalerie
36            .each(function (i, e) {
37                var b = photoshow_identify(e);
38                if (b) {
39                    if (!a.rel || b.rel == a.rel) {
40                        imgs.push(b);
41                        if (b.src == a.src) index = idx;
42                        idx ++;
43                    }
44                }
45            });
46    } else {
47        imgs.push(a);
48    }
49
50    if (photoswipe.debug) {
51        console.log(JSON.stringify(imgs));
52    }
53    
54    //Si on veut une galerie particulière, on envoie son numéro
55    photoshow_gallery(imgs, index, galerie.data( "pswp-uid"));
56    return false; // interdire l'action d'un <a> englobant
57}
58
59function photoshow_identify(me) {
60    var me = $(me), a = {};
61    a.title = "";
62    a.alt = "";
63
64    if (me.is('a')) {
65        if (!me.attr('type').match(/image\/(jpeg|gif|png|webp)/)) {
66            return null;
67        }
68        a.src = me.attr('href');
69        a.w = me.attr('data-photo-w');
70        a.h = me.attr('data-photo-h');
71        a.alt = me.attr('title') || '';
72        a.title = me.attr('data-photo-title') || a.alt;
73        if (!(a.src && a.w && a.h)) {
74            return;
75        }
76        a.thumbnail = me.find('img');
77        a.rel = me.attr('rel') || a.thumbnail.attr('rel');
78    } else if (me.is('img')) {
79        var photosrc = me.attr('data-photo');
80        a.thumbnail = me;
81        if (photosrc) {
82            a.src = photosrc.replace(/__\.__/g, '.');
83            a.w = parseInt(me.attr('data-photo-w'));
84            a.h = parseInt(me.attr('data-photo-h'));
85            a.title = me.attr('data-photo-title');
86        } else {
87            a.src = me.attr('src');
88            a.w = parseInt(me.attr('naturalWidth'));
89            a.h = parseInt(me.attr('naturalHeight'));
90        }
91        a.rel = me.attr('rel');
92
93    } else {
94        // cas non prevu !
95        return;
96    }
97
98    // recuperer la legende
99
100    // 1. figure / figcaption
101    var p = me.parents('figure').find('figcaption');
102    if (p.length) {
103      a.title = p.html();
104    }
105    // 2. title
106    if (!a.title) {
107      a.title = me.attr('title');
108    }
109
110    // on verifie que la taille du fichier grand est superieure a celle du fichier petit
111    // -> dans tous les cas, si c'est un lien hypertexte, il faut l'activer
112    if ( me.is('a') || a.w > me.width() || a.w > $(window).width() || a.h > $(window).height()) {
113        return a;
114    }
115}
116
117function photoshow_gallery(items, index, galerie) {
118	galerie = typeof galerie !== 'undefined' ? galerie : 1;
119    var pswpElement = document.querySelectorAll('.pswp')[0];
120
121    // define options (if needed)
122    var options = {
123        // optionName: 'option value'
124        // for example:
125        index: index, // start slide,
126        shareEl: false, // no "share on pinterest!"
127        fullscreenEl: false,
128        loop: false,
129        galleryUID: galerie, //Si pas de galerie particulière, on demande la galerie 1
130        addCaptionHTMLFn: function (item, captionEl, isFake) {
131            // item      - slide object
132            // captionEl - caption DOM element
133            // isFake    - true when content is added to fake caption container
134            //             (used to get size of next or previous caption)
135
136            if (!item.title) {
137                captionEl.children[0].innerHTML = '';
138                return false;
139            }
140            captionEl.children[0].innerHTML = item.title;
141            return true;
142        },
143        getThumbBoundsFn: function (index) {
144            // find thumbnail element
145            var thumbnail = items[index].thumbnail[0];
146
147            if (!thumbnail) return;
148
149            // get window scroll Y
150            var pageYScroll = window.pageYOffset || document.documentElement.scrollTop;
151            // optionally get horizontal scroll
152
153            // get position of element relative to viewport
154            var rect = thumbnail.getBoundingClientRect();
155
156            // w = width
157            return {
158                x: rect.left,
159                y: rect.top + pageYScroll,
160                w: rect.width
161            };
162        },
163        errorMsg: photoswipe.errorMsg
164    };
165
166    // Initializes and opens PhotoSwipe
167    gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, options);
168    // Handle images with unkown size ref https://github.com/dimsemenov/PhotoSwipe/issues/796#issuecomment-269765635
169	gallery.listen('gettingData', function (index, item) {
170		if (item.w < 1 || item.h < 1) {
171			var img = new Image();
172			img.onload = function () {
173				item.w = this.width;
174				item.h = this.height;
175				gallery.updateSize(true);
176			};
177			img.src = item.src;
178		}
179	});
180	gallery.init();
181
182    // Forcer l'insertion du alt dans le img, en recuperant le pswp__caption
183    function applyAlt(gallery, pswpElement) {        
184        var img_caption = $(".pswp__caption:not(.pswp__caption--fake) .pswp__caption__center").text();
185        $(pswpElement).find(".pswp__img").attr("alt", img_caption);
186    }
187    // Déclencher pour plusieurs événements (ceinture et bretelles, parce que PSWP 4…)
188    const events = ['initialZoomInEnd', 'imageLoadComplete', 'afterChange'];
189    events.forEach(event => {
190        gallery.listen(event, () => {
191            applyAlt(gallery, pswpElement);
192        });
193    });
194    
195
196}
197
198
199
200function photoswipe_init() {
201    $.ajaxSetup({ cache: true });
202    $('<div>')
203        .html('<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true" aria-modal="true" aria-label="Visionneuse d’images"> <div class="pswp__bg"></div> <div class="pswp__scroll-wrap"> <div class="pswp__container"> <div class="pswp__item"></div> <div class="pswp__item"></div> <div class="pswp__item"></div> </div> <div class="pswp__ui pswp__ui--hidden"> <div class="pswp__top-bar"> <div class="pswp__counter"></div> <button class="pswp__button pswp__button--close" title="Close (Esc)"></button> <button class="pswp__button pswp__button--share" title="Share"></button> <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button> <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button> <div class="pswp__preloader"> <div class="pswp__preloader__icn"> <div class="pswp__preloader__cut"> <div class="pswp__preloader__donut"></div> </div> </div> </div> </div> <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap"> <div class="pswp__share-tooltip"></div> </div> <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)"> </button> <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)"> </button> <div class="pswp__caption"> <div class="pswp__caption__center"></div> </div> </div> </div></div>')
204        .appendTo('body');
205}
206
207$(function() {
208    photoswipe_init();
209    // loop through all gallery elements and bind events
210	var galleryElements = document.querySelectorAll( photoswipe.conteneur );
211    for(var i = 0, l = galleryElements.length; i < l; i++) {
212        galleryElements[i].setAttribute('data-pswp-uid', i+2);
212 //Le numéro de la galerie doit être toujours 2 au-dessus
213    }
214    
215    if (!!$.fn.on) {
216      $(document).on("mouseover", photoswipe.selector, photoshow_hover);
217      $(document).on("click", photoswipe.selector, photoshow);
218    } else if (!!$.fn.live) {
219      $(photoswipe.selector).live("mouseover", photoshow_hover);
220      $(photoswipe.selector).live("click", photoshow);
221    }
222});

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.