PageSourceSearch

https://runningmagazine.ca/wp-content/plugins/nextgen-gallery/static/GalleryDisplay/common.js?ver=4.5.1

js runningmagazine.ca collected 2026-09-24 08:35:41 UTC 8,913 bytes, 220 lines download raw bytes

1(function($) {
2    window.NggPaginatedGallery = function(displayed_gallery_id, container) {
3        this.displayed_gallery_id = displayed_gallery_id;
4        this.container            = $(container);
5        this.container_name       = container;
6
7        this.get_displayed_gallery_obj = function() {
8            var index = 'gallery_' + this.displayed_gallery_id;
9            if (typeof(window.galleries[index]) == 'undefined') {
10                return false;
11            } else {
12                return window.galleries[index];
13            }
14        };
15
16        this.enable_ajax_pagination = function() {
17            var self = this;
18            // Attach a click event handler for each pagination link to adjust the request to be sent via XHR
19            $('body').on('click', 'a.ngg-browser-prev, a.ngg-browser-next', function (event) {
20
21                var skip = true;
22                $(this).parents(container).each(function() {
23                    if ($(this).data('nextgen-gallery-id') != self.displayed_gallery_id) {
24                        return true;
25                    }
26                    skip = false;
27                });
28
29                if (!skip) {
30                    event.preventDefault();
31                } else {
32                    return;
33                }
34
35                // Adjust the user notification
36                window['ngg_ajax_operaton_count']++;
37                $('body, a').css('cursor', 'wait');
38
39                // Send the AJAX request
40                $.get({
41                    url: $(this).attr('href'),
42                    headers: { 'X-NGG-Pagination-Request': true },
43                    success: function (response) {
44                        window['ngg_ajax_operaton_count']--;
45                        if (window['ngg_ajax_operaton_count'] <= 0) {
46                            window['ngg_ajax_operaton_count'] = 0;
47                            $('body, a').css('cursor', 'auto');
48                        }
49
50                        if (response) {
51                            var html = $(response);
52                            // Match the container whether it parsed as a top-level node or a descendant.
53                            var candidates = html.filter(self.container_name).add(html.find(self.container_name));
54                            var replacement = false;
55                            candidates.each(function() {
56                                if (replacement) {
57                                    return true;
58                                }
59                                if ($(this).data('nextgen-gallery-id') != self.dis
59played_gallery_id) {
60                                    return true;
61                                }
62                                replacement = $(this);
63                            });
64                            if (replacement) {
65                                self.container.each(function () {
66                                    var $this = $(this);
67
68                                    if ($this.data('nextgen-gallery-id') != self.displayed_gallery_id) {
69                                        return true;
70                                    }
71
72                                    // If the image gallery makes up the bulk of the post/page content the .html() call
73                                    // below will empty the contents causing the browser's scroll position to be reset to
74                                    // zero as the browser believes it has been pushed back to the top of the page. Here
75                                    // we give the parent container a min-height equal to the gallery's height to prevent
76                                    // this flicker and resetting of the scroll position.
77                                    var $new_element = $(replacement.html());
78                                    var promises = $new_element.find('img').toArray().map(function(img){
79                                        return new Promise(function(resolve, reject){
80                                            var i = new Image();
81                                            i.src = img.src;
82                                            $(i).on('load', resolve);
83                                        });
84                                    });
85
86                                    Promise.all(promises).then(function(){
87                                        $this.html($new_element);
88
89                                        // Let the user know that we've refreshed the content
90                                        $(document).trigger('refreshed');
91
92                                        // Emit an event that doesn't require jQuery
93                                        const event = new Event("nextgen_page_refreshed");
94                                        document.dispatchEvent(event);
95                                    });
96
97                                    return true;
98                                });
99                            }
100                        }
101                    }
102                });
103            });
104        };
105
106        // Initialize
107        var displayed_gallery = this.get_displayed_gallery_obj();
108        if (displayed_gallery) {
109            if (typeof(displayed_gallery.display_settings['ajax_pagination']) != 'undefined') {
110                if (parseInt(displayed_gallery.display_settings['ajax_pagination'])) {
111                    this.enable_ajax_pagination();
112                }
113            }
114        }
115
116        // We maintain a count of all the current AJAX actions initiated
117        if (typeof(window['ngg_ajax_operaton_count']) == 'undefined') {
118            window['ngg_ajax_operaton_count'] = 0;
119        }
120    };
121
122    // Polyfill for older browsers
123    Object.setPrototypeOf = Object.setPrototypeOf || function(obj, proto) {
124        obj.__proto__ = proto;
125        return obj;
126    };
127
128    if (typeof window.galleries !== 'undefined') {
129    Object.setPrototypeOf(
130        window.galleries,
131        {
132            get_api_version: function() {
133                return '0.1';
134            },
135
136            get_from_id: function (gallery_id) {
137                var self   = this;
138                var retval = null;
139                var keys   = Object.keys(this);
140
141                for (var i = 1; i <= keys.length; i++) {
142                    var gallery = self[keys[i - 1]];
143                    if (gallery.ID === gallery_id || gallery.ID === 'gallery_' + gallery_id || gallery.ID === parseInt(gallery_id)) {
144                        retval = gallery;
145                        break;
146                    }
147                }
148
149                return retval;
150            },
151
152            get_from_slug: function (slug) {
153                var self   = this;
154                var retval = null;
155                var keys   = Object.keys(this);
156
157                for (var i = 1; i <= keys.length; i++) {
158                    var gallery = self[keys[i - 1]];
159                    if (gallery.slug === slug) {
160                        retval = gallery;
161                        break;
162                    }
163                }
164
165                return retval;
166            },
167
168            get_setting: function(gallery_id, name, def) {
169                var tmp = '';
170                var gallery = this.get_from_id(gallery_id);
171                if (gallery && typeof gallery[name] !== 'undefined') {
172                    tmp = gallery[name];
173                } else {
174                    tmp = def;
175                }
176
177                if (tmp === 1)       tmp = true;
178                if (tmp === 0)       tmp = false;
179                if (tmp === '1')     tmp = true;
180                if (tmp === '0')     tmp = false;
181                if (tmp === 'false') tmp = false;
182                if (tmp === 'true')  tmp = true;
183
184                return tmp;
185            },
186
187            get_display_setting: function(gallery_id, name, def) {
188                var tmp = '';
189                var gallery = this.get_from_id(gallery_id);
190                if (gallery && typeof gallery.display_settings[name] !== 'undefined') {
191                    tmp = gallery.display_settings[name];
192                } else {
193                    tmp = def;
194                }
195
196                if (tmp === 1)       tmp = true;
197                if (tmp === 0)       tmp = false;
198                if (tmp === '1')     tmp = true;
199                if (tmp === '0')     tmp = false;
200                if (tmp === 'false') tmp = false;
201                if (tmp === 'true')  tmp = true;
202
203                return tmp;
204            },
205
206            is_widget: function(gallery_id) {
207                var retval  = false;
208                var gallery = this.get_from_id(gallery_id);
209                var slug    = gallery.slug;
210
211                if (slug) {
212                    return slug.indexOf('widget-ngg-images') !== -1;
213                }
214
215                return retval;
216            }
217        }
218    ); }
219
220})(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.