PageSourceSearch

https://inhabitat.com/wp-content/themes/inhabitatresponsive/js/mod…/jquery.gallery-extend.js?ver=260806-145309

js inhabitat.com collected 2026-09-24 08:25:59 UTC 11,778 bytes, 379 lines download raw bytes

1;function getParameterByName(name) {
2    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
3    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
4        results = regex.exec(location.search);
5    return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
6}
7
8;(function( $, window, document, undefined){
9
10    var pluginName = 'galleryExtend';
11    if(typeof mainConfig.gallerySlideDelay != 'undefined'){
12        var defaults = {
13            sleep: parseInt(mainConfig.gallerySlideDelay),
14            start: 1,
15            type: 'gallery',
16            keyboard: true,
17            auto: false
18        };
19    } else {
20        var defaults = {
21            sleep: 12000,
22            start: 1,
23            type: 'gallery',
24            keyboard: true,
25            auto: false
26        };
27    }
28
29    function Plugin(element, options){
30        this.element = element;
31        this.options = $.extend( {}, defaults, options) ;
32        this._defaults = defaults;
33        this._name = pluginName;
34        this._slides = null;
35        this._opened = false;
36        this._currentUrl = '';
37        this.init();
38    }
39
40    Plugin.prototype.init = function(){
41        var $Gallery = $(this.element),
42            $Widget = $(document).find('.gallery-extend .content-slide'),
43            Slides = $Gallery.find('.slideset .slide'),
44            self= this;
45
46        this.current = this.options.start;
47        this.Slides = Slides;
48
49        self.changeSlide(self.current);
50
51        if(!$Gallery.hasClass('isLightbox')){
52            for (var i = Slides.length - 1; i >= 0; i--) {
53                $ImageContainer = $(Slides[i]);
54            };
55        }
56
57        //Keyboard listeners
58        if(this.options.keyboard){
59            $(document).keyup(function(event){
60                if(!self._opened)
61                    return;
62
63                if(typeof globalOpen === "undefined"){
64                    globalOpen = false;
65                }
66                if(globalOpen && $Gallery.hasClass('isLightbox') || !globalOpen && !$Gallery.hasClass('isLightbox')){
67                    if(event.keyCode == '39'){ //right
68                        self.next.call(self,[]);
69                    }else if(event.keyCode == '37'){ //left
70                        self.prev.call(self,[]);
71                    }
72                }
73            });
74        }
75
76        /**
77         * Listeners for Check when move to next and prev page
78         */
79
80        $Gallery.on("gallery:next", function(){
81            self.next.call(self,[]);
82        });
83
84        $Gallery.on("gallery:prev", function(){
85            self.prev.call(self,[]);
86        });
87
88        $Gallery.on("gallery:start", function(){
89            self.start.call(self,[]);
90        });
91
92        $Gallery.on("gallery:pause", function(){
93            self.pause.call(self,[]);
94        });
95
96        $Gallery.on("gallery:lightbox-open", function(){
97            var currentLocation = window.location;
98            self._opened = true;
99            globalOpen = true;
100            self._currentUrl = currentLocation.pathname + currentLocation.search;
101        });
102
103        $Gallery.on("gallery:refresh", function(){
104            self.changeSlide(self.current);
105        });
106
107        $Gallery.on("gallery:closed", function(){
108            self.closed.call(self);
109            globalOpen = false;
110        });
111
112
113        $Gallery.find('.btn.prev').on('click', function(){
114            $Gallery.trigger('gallery:prev');
115        });
116
117        $Gallery.find('.btn.next').on('click', function(){
118            $Gallery.trigger('gallery:next');
119        });
120
121        $Gallery.find('.slide-init').on('click', function(){
122            $Gallery.trigger('gallery:start');
123        });
124
125        $Gallery.find('a.change-gallery').on('click', function(e){
126            var $this = $(this),
127                idx;
128            if ($this.hasClass('active')){
129                return false;
130            }
131
132            idx = parseInt($this.attr('data-idx'));
133
134            if (idx){
135                self.current = idx;
136                self.changeSlide(idx);
137            }
138
139
140            if(self.options.type && self.options.type === "article"){
141                var $Lightbox = $('.gallery-lightbox .gallery-extend'),
142                    $Data = $Lightbox.data('plugin_galleryExtend');
143                $Data.setSlide(idx);
144                $Data.changeSlide(idx);
145            }
146
147        });
148
149        if (this.options.start > Slides.length && this.options.start < 1){
150            this.current = this.options.start = 1;
151        }
152
153        if (Slides.length){
154            this.changeSlide(this.options.start);
155        }
156
157        $(window).load(function(){
158            if(self.options.auto){
159                $('.start-slide.lightbox-opener').click();
160            }
161            self.changeSlide(self.current);
162        });
163
164    };
165
166    Plugin.prototype.start = function(){
167        var self = this,
168            $Gallery = $(this.element),
169            $Start = $Gallery.find('.slide-init').first();
170
171
172
173        if($Start.hasClass('started')){
174            $Start.removeClass('started');
175            //$Start.find('.action').html('Start');
176            $Start.find('.action').html('Start').data('event','Pause Gallery');
177            self.pause();
178        }else {
179
180            $Start.addClass('started');
181            //$Start.find('.action').html('Pause');
182            $Start.find('.action').html('Pause').data('event','Start Gallery');
183            this._slides = setInterval(function(){
184                self.next.call(self,[]);
185            }, self.options.sleep);
186            self.next();
187        }
188    };
189
190    Plugin.prototype.reset = function(){
191        var self = this;
192
193        clearInterval(self._slides);
194        self._slides = null;
195
196        self._slides = setInterval(function(){
197            self.next.call(self,[]);
198        },self.options.sleep);
199    }
200
201    Plugin.prototype.pause = function(){
202        var self = this,
203            $Gallery = $(this.element),
204            $Start = $Gallery.find('.slide-init').first();
205
206        $Start.removeClass('started');
207        $Start.find('.action').html('Start').data('event','Pause Gallery');
208
209        clearInterval(this._slides);
210        this._slides = null;
211    };
212
213    Plugin.prototype.next = function(){
214        var $Gallery = $(this.element),
215            $Widget = $(document).find('.gallery-extend .content-slide'),
216            Slides = $Gallery.find('.slideset .slide'),
217            self= this;
218
219        if (self.current < Slides.length){
220            self.current ++;
221        }else{
222            self.current =1;
223        }
224
225        if(self._slides !== null){
226            self.reset();
227        }
228        self.changeSlide(self.current);
229    };
230
231    Plugin.prototype.prev = function(){
232        var $Gallery = $(this.element),
233            $Widget = $(document).find('.gallery-extend .content-slide'),
234            Slides = $Gallery.find('.slideset .slide'),
235            self= this;
236
237        if (self.current > 1){
238            self.current --;
239
240        }else{
241            self.current = Slides.length;
242        }
243
244        if(self._slides !== null){
245            self.reset();
246        }
247        self.changeSlide(self.current);
248    }
249
250    Plugin.prototype.setSlide = function(slide){
251        slide = slide || 0;
252        this.current = slide;
253    };
254
255    Plugin.prototype.changeSlide = function(page){
256
257        if(typeof(page) === 'undefined'){
258            var page = 1;
259        }
260
261        if(!this._opened && this.options.type == 'article') {
262            return;
263        }
264        var $Gallery = $(this.element),
265            Slides = $Gallery.find('.slideset .slide'),
266            $Slideset = $Gallery.find('.slideset'),
267            $Current =  $(Slides[page-1]),
268            $Widget = $(document).find('.gallery-extend .content-slide'),
269            Thumbnails = $Gallery.find('.thumbnails .thumbnails-list .thumbnail'),
270            self = this;
271
272
273        if (Slides.length){
274            $(Slides).removeClass('current');
275            $(Thumbnails).removeClass('active');
276            $(Slides[page-1]).addClass('current');
277            $(Thumbnails[page-1]).addClass('active');
278            Post = this.options.content[page-1];
279
280            $Widget.find('.content h2').html(Post.post_title);
281            $Widget.find('.content p').html(Post.post_content);
282            $Widget.find('span.counter').html('Photo '+this.current+ ' of '+ Slides.length);
283
284            $Socials = $('.lightbox aside .socials,.gallery-extend .socials');
285
286            if ($Socials.length){
287
288                $Socials.find('.facebook')
289                    .data('permalink', Post.permalink);
290
291                $Socials.find('.twitter')
292                    .data('permalink', Post.permalink)
293                    .data('shortTitle', Post.shortTitle)
294                    .data('siteUrl', Post.siteUrl);
295
296                $Socials.find('.pinterest')
297                    .data('permalink', Post.permalink)
298                    .data('imgUrl', Post.guid)
299                    .data('imgDescription', Post.post_title);
300
301            }
302
303            /** Added Change HTML5  */
304            //console.log(self._opened, self.options.type);
305            if( (history.replaceState && self.options.type === 'gallery') || (self._opened && self.options.type === 'article') ){
306                window.history.replaceState({idx:page}, Post.post_title, Post.permalink);
307
308                //Google Analytics
309                ga_url = Post.permalink.replace(window.location.protocol+"//"+window.location.host,"")+window.location.search;
310                let args = {
311                    'page_location': ga_url,
312                    'content_group1': '/gallery-overlay/'
313                }
314                gtag('event','page_view',args);
315            }
316
317            $Gallery.trigger("gallery:changeSlide");
318
319            console.log($Current, $Slideset.height(), $Current.find('img').first().height(), $Slideset.width(), $Current.find('img').first().width());
320
321            var checkInterval = setInterval(function(){
322                //console.log($Gallery.hasClass('gallery-lightbox'), $Gallery);
323                if ($Current.find('img').first().height() === 0 || $Current.find('img').first().width() === 0) return false;
324
325                if ($Gallery.hasClass('isLightbox')) {
326                    clearInterval(checkInterval);
327                    return false
328                };
329
330                if($Current.find('img').length){
331                    $Current.css({
332                        top: '50%',
333                        'margin-top': ($Current.find('img').first().height()*-1/2) + 'px'
334                    });
335
336                    $Current.find('img').first().css('top', 0);
337                }
338
339                if($Current.find('img').length){
340                    $Current.css({
341                        left: '50%',
342                        'margin-left': ($Current.find('img').first().width()*-1/2) + 'px'
343                    });
344
345                    $Current.find('img').first().css('left', 0);
346                }
347
348                clearInterval(checkInterval);
349            },50);
350        }
351
352    };
353
354    Plugin.prototype.closed = function(){
355        var $Gallery = $(this.element);
356        var url, title;
357        var self = this;
358
359        this.pause();
360        this._opened = false;
361
362        if($Gallery.hasClass('isLightbox') && self.options.type === 'article'){
363
364            if( history.replaceState  ){
365                window.history.replaceState({}, '', self._currentUrl);
366            }
367        }
368    };
369
370    $.fn[pluginName] = function(options){
371        return this.each(function(){
372            if (!$.data(this, 'plugin_' + pluginName)){
373                $.data(this, 'plugin_' + pluginName,
374                    new Plugin(this, options));
375            }
376        });
377    }
378
379})(jQuery, window, document);

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.