PageSourceSearch

https://mahoneyfarm.com/wp-content/plugins/nextgen-gallery-pro/sta…/Galleria/ngg_galleria.js?ver=4.5.2

js mahoneyfarm.com collected 2026-10-06 16:31:55 UTC 10,815 bytes, 259 lines download raw bytes

1/*! GetDevicePixelRatio | Author: Tyson Matanich, 2012 | License: MIT */
2(function (window) {
3    window.getDevicePixelRatio = function() {
4        var ratio = 1;
5        // To account for zoom, change to use deviceXDPI instead of systemXDPI
6        if (window.screen.systemXDPI !== undefined
7        &&  window.screen.logicalXDPI !== undefined
8        &&  window.screen.systemXDPI > window.screen.logicalXDPI) {
9            // Only allow for values > 1
10            ratio = window.screen.systemXDPI / window.screen.logicalXDPI;
11        } else if (window.devicePixelRatio !== undefined) {
12            ratio = window.devicePixelRatio;
13        }
14        return ratio;
15    };
16})(this);
17
18(function ($) {
19    "use strict";
20
21    window.ngg_galleria = {
22        gallery_selector: '.ngg-galleria-parent',
23        gallery_target_selector: '.ngg-galleria',
24
25        start: function(themename) {
26            const self     = this;
27            const selector = this.gallery_selector + '.' + themename;
28
29            // Galleria has issues initializing in hidden containers or off-screen
30            $(selector).each(function(ndx, gallery_parent) {
31                const observer = new IntersectionObserver(
32                    function(entries) {
33                        entries.forEach(function (entry) {
34                                // This gallery is now visible
35                                if (1 === entry.intersectionRatio) {
36                                    self.create(gallery_parent, themename);
37                                }
38                            }
39                        );
40                    }
41                );
42                observer.observe(gallery_parent);
43            });
44        },
45
46        get_gallery_from_id: function (gallery_id) {
47            var retval = null;
48
49            if ('undefined' == typeof window.galleries) {
50                return retval;
51            }
52
53            $.each(window.galleries, function(index, gallery) {
54                if (gallery.ID == gallery_id) {
55                    retval = gallery;
56                }
57            });
58
59            return $.extend({}, retval);
60        },
61
62        get_setting: function(gallery, name, def) {
63            if (typeof gallery != 'object') {
64                gallery = this.get_gallery_from_id(gallery);
65            }
66
67            var settings = gallery.display_settings;
68            var tmp = '';
69
70            if (typeof settings !== 'undefined'
71            &&  typeof settings[name] !== 'undefined'
72            &&  settings[name] !== '') {
73                tmp = settings[name];
74            } else {
75                tmp = def;
76            }
77
78            if (tmp == 1)   tmp = true;
79            if (tmp == 0)   tmp = false;
80            if (tmp == '1') tmp = true;
81            if (tmp == '0') tmp = false;
82            return tmp;
83        },
84
85        create: function(gallery_parent, themename) {
86            var gallery_id = $(gallery_parent).data('id');
87            var gallery = $.extend({}, this.get_gallery_from_id(gallery_id));
88            var target = $(gallery_parent).find(this.gallery_target_selector).first();
89
90            this.configure_galleria(gallery_parent, target, gallery);
91
92            var images = gallery.images_list;
93
94            // Massage our data for High-DPI screens
95            if (window.getDevicePixelRatio() > 1) {
96                $(images).each(function(ndx, image) {
97                    if (image.use_hdpi) {
98                        image.image = image.srcsets.hdpi;
99                    }
100                });
101            }
102
103            // Galleria is very picky about the data type provided to the imageMargin option
104            var border_margin = this.get_setting(gallery, 'border_size', '0');
105            if (typeof border_margin == 'boolean') {
106                if (border_margin)  border_margin = 1;
107                if (!border_margin) border_margin = 0;
108            }
109            border_margin = parseInt(border_margin);
110
111            var settings = {
112                theme:         themename,
113                responsive:    true,
114                debug:         true,
115                maxScaleRatio: 1,
116                dataSource:    images,
117
118                showInfo:    this.get_setting(gallery, 'show_captions', false),
119                imagePan:    this.get_setting(gallery, 'image_pan',     false),
120                imageCrop:   this.get_setting(gallery, 'image_crop',    false),
121                transition:  this.get_setting(gallery, 'transition',   'fade'),
122                imageMargin: border_margin,
123
124                transitionSpeed: this.get_setting(gallery, 'transition_speed', 1) * 1000,
125
126                _nggGalleryID:     gallery_id,
127                _nggGalleryParent: gallery_parent,
128                _nggCaptionClass:         this.get_setting(gallery, 'caption_class',          'caption_overlay_bottom'),
129                _nggCaptionHeight:        this.get_setting(gallery, 'caption_height',         52),
130                _nggShowPlaybackControls: this.get_setting(gallery, 'show_playback_controls', true),
131                _nggImageCrop:            this.get_setting(gallery, 'image_crop',             false),
132                _nggBorderSize:           border_margin,
133                _nggBorderColor:          this.get_setting(gallery, 'border_color',           '#ffffff'),
134                _nggSlideshowSpeed:       this.get_setting(gallery, 'slideshow_speed',        5) * 1000
135            };
136
137            Galleria.run(target, settings);
138
139            Galleria.ready(function() {
140                var api = this;
141                var $parent = $(api._options._nggGalleryParent);
142                var ensureOverlay = function($container) {
143                    var $overlay = $container.find('> .ngg-video-play-overlay');
144                    if ($overlay.length) return $overlay.first();
145                    $overlay = $('<span class="ngg-video-play-overlay" aria-hidden="true"></span>');
146                    $container.append($overlay);
147                    return $overlay;
148                };
149
150                var updateStage = function(index) {
151                    var data = api.getData(index);
152                    var shouldShow = data && (data.is_tiktok == 1 || data.is_tiktok == '1' || data.is_tiktok === true)
153                        && (data.show_play_button == 1 || data.show_play_button == '1' || data.show_play_button === true);
154                    var $stageImage = $parent.find('.galleria-stage .galleria-image').first();
155                    if (!$stageImage.length) return;
156                    $stageImage.find('> .ngg-video-play-overlay').remove();
157                    if (shouldShow) {
158                        ensureOverlay($stageImage);
159                    }
160                };
161
162                api.bind('loadfinish', function(e) {
163                    updateStage(e.index);
164                });
165
166                api.bind('thumbnail', function(e) {
167                    var data = api.getData(e.index);
168                    var shouldShow = data && (data.is_tiktok == 1 || data.is_tiktok == '1' || data.is_tiktok === true)
169                        && (data.show_play_button == 1 || data.show_play_button == '1' || data.show_play_button === true);
170                    if (!shouldShow) return;
171                    var $thumbContainer = $(e.thumbTarget).closest('.galleria-image');
172                    if ($thumbContainer.length) {
173                        $thumbContainer.find('> .ngg-video-play-overlay').remove();
174                        ensureOverlay($thumbContainer);
175                    }
176                });
177            });
178        },
179
180        configure_galleria: function(gallery_parent, target, gallery) {
181            // NOTE: .extend() is important! 'settings = displayed_gallery.settings' will
182            // create a 'pointer' -- changes to this 'settings' var will alter the
183            // displayed gallery settings. This causes havoc with fields like transition
184            // and slideshow speed.
185            gallery_parent = $(gallery_parent);
186            var self = this;
187            var settings = $.extend({}, gallery.display_settings);
188            for (var index in settings) {
189                var numeric_val = Number(settings[index]);
190                if (!isNaN(numeric_val)) {
191                    settings[index] = numeric_val;
192                }
193                if ((numeric_val == 0 || numeric_val == 1) && !index.match(/width|size|height|dimensions|percent|ratio/)) {
194                    settings[index] = numeric_val ? true : false;
195                }
196            }
197
198            this.adjust_size(gallery_parent, target, settings);
199
200            $(window).on('resize orientationchange onfullscreenchange onmozfullscreenchange onwebkitfullscreenchange', function() {
201                self.adjust_size(gallery_parent, target, settings);
202            });
203        },
204
205        adjust_size: function(gallery_parent, target, settings) {
206            var parent_width = gallery_parent.width();
207            var width = settings.width;
208
209            if (settings.width_unit == '%') {
210                width = Math.round(parent_width * (settings.width / 100));
211            }
212
213            if (parent_width > 0 && parent_width < width) {
214                width = parent_width;
215            }
216
217            target.width(width);
218
219            // Calculate height using aspect ratio of device/browser
220            var aspect_ratio = gallery_parent.width() / gallery_parent.height();
221            if (typeof(settings.aspect_ratio) != 'undefined' && settings.aspect_ratio != 0) {
222                aspect_ratio = settings.aspect_ratio;
223                if (!parseFloat(aspect_ratio)) {
224                    if (settings.aspect_ratio_computed && parseFloat(settings.aspect_ratio_computed)) {
225                        aspect_ratio = settings.aspect_ratio_computed;
226                    } else {
227                        aspect_ratio = 1.5;
228                    }
229                } else {
230                    aspect_ratio = parseFloat(aspect_ratio);
231                }
232            }
233
234            var frame_height = ((width - 20) / aspect_ratio);
235
236            if (typeof(settings.thumbnail_height) != 'undefined') {
237                var thumb_height = settings.thumbnail_height;
238                if (typeof(thumb_height) === 'string') {
239                    thumb_height = parseFloat(thumb_height);
240                }
241                frame_height += thumb_height;
242            }
243
244            frame_height += 20;
245
246            var caption = settings.caption_class;
247            if (caption == 'caption_above_stage' || caption == 'caption_below_stage') {
248                frame_height += 52;
249            }
250
251            gallery_parent.height(frame_height);
252        }
253    };
254
255    $(window).on('ngg.galleria.themeadded', function(event, themename) {
256        ngg_galleria.start(themename);
257    });
258
259})(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.