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 var replacement = false; 53 html.find(self.container_name).each(function() { 54 if (replacement) { 55 return true; 56 } 57 if ($(this).data('nextgen-gallery-id') != self.dis
57played_gallery_id) { 58 return true; 59 } 60 replacement = $(this); 61 }); 62 if (replacement) { 63 self.container.each(function () { 64 var $this = $(this); 65 66 if ($this.data('nextgen-gallery-id') != self.displayed_gallery_id) { 67 return true; 68 } 69 70 // If the image gallery makes up the bulk of the post/page content the .html() call 71 // below will empty the contents causing the browser's scroll position to be reset to 72 // zero as the browser believes it has been pushed back to the top of the page. Here 73 // we give the parent container a min-height equal to the gallery's height to prevent 74 // this flicker and resetting of the scroll position. 75 var $new_element = $(replacement.html()); 76 var promises = $new_element.find('img').toArray().map(function(img){ 77 return new Promise(function(resolve, reject){ 78 var i = new Image(); 79 i.src = img.src; 80 $(i).on('load', resolve); 81 }); 82 }); 83 84 Promise.all(promises).then(function(){ 85 $this.html($new_element); 86 87 // Let the user know that we've refreshed the content 88 $(document).trigger('refreshed'); 89 90 // Emit an event that doesn't require jQuery 91 const event = new Event("nextgen_page_refreshed"); 92 document.dispatchEvent(event); 93 }); 94 95 return true; 96 }); 97 } 98 } 99 } 100 }); 101 }); 102 }; 103 104 // Initialize 105 var displayed_gallery = this.get_displayed_gallery_obj(); 106 if (displayed_gallery) { 107 if (typeof(displayed_gallery.display_settings['ajax_pagination']) != 'undefined') { 108 if (parseInt(displayed_gallery.display_settings['ajax_pagination'])) { 109 this.enable_ajax_pagination(); 110 } 111 } 112 } 113 114 // We maintain a count of all the current AJAX actions initiated 115 if (typeof(window['ngg_ajax_operation_count']) == 'undefined') { 116 window['ngg_ajax_operaton_count'] = 0; 117 } 118 }; 119 120 // Polyfill for older browsers 121 Object.setPrototypeOf = Object.setPrototypeOf || function(obj, proto) { 122 obj.__proto__ = proto; 123 return obj; 124 }; 125 126 if (typeof window.galleries !== 'undefined') { 127 Object.setPrototypeOf( 128 window.galleries, 129 { 130 get_api_version: function() { 131 return '0.1'; 132 }, 133 134 get_from_id: function (gallery_id) { 135 var self = this; 136 var retval = null; 137 var keys = Object.keys(this); 138 139 for (var i = 1; i <= keys.length; i++) { 140 var gallery = self[keys[i - 1]]; 141 if (gallery.ID === gallery_id || gallery.ID === 'gallery_' + gallery_id || gallery.ID === parseInt(gallery_id)) { 142 retval = gallery; 143 break; 144 } 145 } 146 147 return retval; 148 }, 149 150 get_from_slug: function (slug) { 151 var self = this; 152 var retval = null; 153 var keys = Object.keys(this); 154 155 for (var i = 1; i <= keys.length; i++) { 156 var gallery = self[keys[i - 1]]; 157 if (gallery.slug === slug) { 158 retval = gallery; 159 break; 160 } 161 } 162 163 return retval; 164 }, 165 166 get_setting: function(gallery_id, name, def) { 167 var tmp = ''; 168 var gallery = this.get_from_id(gallery_id); 169 if (gallery && typeof gallery[name] !== 'undefined') { 170 tmp = gallery[name]; 171 } else { 172 tmp = def; 173 } 174 175 if (tmp === 1) tmp = true; 176 if (tmp === 0) tmp = false;
177 if (tmp === '1') tmp = true; 178 if (tmp === '0') tmp = false; 179 if (tmp === 'false') tmp = false; 180 if (tmp === 'true') tmp = true; 181 182 return tmp; 183 }, 184 185 get_display_setting: function(gallery_id, name, def) { 186 var tmp = ''; 187 var gallery = this.get_from_id(gallery_id); 188 if (gallery && typeof gallery.display_settings[name] !== 'undefined') { 189 tmp = gallery.display_settings[name]; 190 } else { 191 tmp = def; 192 } 193 194 if (tmp === 1) tmp = true; 195 if (tmp === 0) tmp = false; 196 if (tmp === '1') tmp = true; 197 if (tmp === '0') tmp = false; 198 if (tmp === 'false') tmp = false; 199 if (tmp === 'true') tmp = true; 200 201 return tmp; 202 }, 203 204 is_widget: function(gallery_id) { 205 var retval = false; 206 var gallery = this.get_from_id(gallery_id); 207 var slug = gallery.slug; 208 209 if (slug) { 210 return slug.indexOf('widget-ngg-images') !== -1; 211 } 212 213 return retval; 214 } 215 } 216 ); } 217 218})(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.