1(function($) { 2 3 var user_is_using_ie = false; 4 if (navigator.appName.indexOf("Internet Explorer") !== -1) { 5 if (navigator.appVersion.indexOf("MSIE 8") !== -1) { 6 // This does not work with IE8 7 return; 8 } 9 if (navigator.appVersion.indexOf("MSIE 1") !== -1) { 10 user_is_using_ie = 10; 11 } 12 } 13 14 var nggc_get_gallery = function(gallery_id) { 15 if ('undefined' == typeof window.galleries) { 16 return null; 17 } 18 var retval = null; 19 20 $.each(window.galleries, function(index, gallery) { 21 if (typeof gallery !== 'object') { 22 return false; 23 } 24 if (gallery.ID === gallery_id) { 25 retval = gallery; 26 } 27 }); 28 29 return retval; 30 }; 31 32 var nggc_get_setting = function(gallery, name, def) { 33 var tmp = def; 34 if (typeof gallery.display_settings[name] != 'undefined' && gallery.display_settings[name] != '') { 35 tmp = gallery.display_settings[name]; 36 } else { 37 tmp = def; 38 } 39 if (tmp == 1) tmp = true; 40 if (tmp == 0) tmp = false; 41 if (tmp == '1') tmp = true; 42 if (tmp == '0') tmp = false; 43 if (tmp == 'false') tmp = false; 44 if (tmp == 'true') tmp = true; 45 46 return tmp; 47 }; 48 49 var nggc_allowed_tags = [ 50 "EM", 51 "STRONG", 52 'B', 53 'DEL', 54 'I', 55 'INS', 56 'MARK', 57 'SMALL', 58 'STRIKE', 59 'SUB', 60 'SUP', 61 'TT', 62 'U' 63 ]; 64 65 var nggc_sanitize = function(string) { 66 var element = document.createElement('div'); 67 element.innerHTML = string; 68 nggc_real_sanitize(element); 69 return element.innerHTML; 70 }; 71 72 var nggc_real_sanitize = function(element) { 73 var allowed_tags = Array.prototype.slice.apply(element.getElementsByTagName("*"), [0]); 74 for (var i = 0; i < allowed_tags.length; i++) { 75 if (nggc_allowed_tags.indexOf(allowed_tags[i].nodeName) == -1) { 76 nggc_sanitize_replace(allowed_tags[i]); 77 } 78 } 79 }; 80 81 var nggc_sanitize_replace = function(element) { 82 var last = element; 83 for (var i = element.childNodes.length - 1; i >= 0; i--) { 84 var tmp = element.removeChild(element.childNodes[i]); 85 element.parentNode.insertBefore(tmp, last); 86 last = tmp; 87 } 88 element.parentNode.removeChild(element); 89 }; 90 91 nggc_share_icons = { 92 strip_html: function(html) { 93 var tmp = document.createElement('div'); 94 tmp.innerHTML = html; 95 return tmp.textContent || tmp.innerText || ""; 96 }, 97 create: function(target, image) { 98 var image_id = image.data('image-id'); 99 var gallery_id = image.data('nplmodal-gallery-id'); 100 101 var base_url = encodeURIComponent(this.get_share_url(gallery_id, image_id)); 102 var url = encodeURIComponent(window.location.toString()); 103 var title = this.strip_html(image.data('title')); 104 var summary = this.strip_html(image.data('description')); 105 106 var twitter_icon = $('<i/>', { 107 'data-href': 'https://twitter.com/share?url=' + this.get_share_url(gallery_id, image_id, 'full'), 108 'class': 'ngg-caption-icon fa-brands fa-square-x-twitter' 109 }); 110 111 var facebook_url = 'https://www.facebook.com/share.php'; 112 facebook_url += '?u=' + encodeURIComponent(this.get_share_url(gallery_id, image_id, 'full')); 113 var facebook_icon = $('<i/>', { 114 'data-href': facebook_url, 115 'class': 'ngg-caption-icon fa fa-facebook-square' 116 }); 117 118 var pinterest_url = encodeURIComponent(this.get_share_url(gallery_id, image_id, 'full')); 119 pinterest_url += '&url=' + url; 120 pinterest_url += '&media=' + image.attr('href'); 121 pinterest_url += '&description=' + summary; 122 var pinterest_icon = $('<i/>', { 123 'data-href': 'http://pinterest.com/pin/create/button/?s=100' + pinterest_url, 124 'class': 'ngg-caption-icon fa fa-pinterest-square' 125 }); 126 127 var icons = [twitter_icon, facebook_icon, pinterest_icon]; 128 $(icons).each(function() { 129 $(this).on('click', function(event) { 130 event.preventDefault(); 131 var share_window = window.open($(this).data('href'), '_blank'); 132 share_window.trigger('focus'); 133 // improper, but otherwise the pro lightbox will open 134 return false;
135 }); 136 }); 137 target.html('').append(icons); 138 }, 139 get_share_url: function(gallery_id, image_id, named_size) { 140 if (typeof(named_size) == 'undefined') { 141 named_size = 'thumb'; 142 } 143 144 var base_url = $.nplModal('get_setting', 'share_url') 145 .replace('{gallery_id}', gallery_id) 146 .replace('{image_id}', image_id) 147 .replace('{named_size}', named_size); 148 var site_url_link = $('<a/>').attr('href', $.nplModal('get_setting', 'wp_site_url'))[0]; 149 var parent_link = $('<a/>').attr('href', window.location.toString())[0]; 150 var base_link = $('<a/>').attr('href', base_url)[0]; 151 152 // check if site is in a sub-directory and shorten the prefix 153 if (parent_link.pathname.indexOf(site_url_link.pathname) >= 0) { 154 parent_link.pathname = parent_link.pathname.substr(site_url_link.pathname.length); 155 } 156 // shorten url by removing their common prefix 157 if (parent_link.pathname.indexOf(base_link.pathname) >= 0) { 158 parent_link.pathname = parent_link.pathname.substr(parent_link.pathname.length); 159 } 160 161 // this is odd but it's just how the 'share' controller expects it 162 base_link.search = parent_link.search; 163 if (base_link.search.length > 0) { 164 base_link.search += '&'; 165 } 166 base_link.search += 'uri=' + parent_link.pathname; 167 168 return base_link.href; 169 } 170 }; 171 172 $.fn.nggcaption = function() { 173 this.each(function() { 174 var $this = $(this); 175 176 var gallery = nggc_get_gallery($this.data('ngg-captions-id')); 177 var style = nggc_get_setting(gallery, 'captions_animation', 'slideup'); 178 var $img = $this.find('img').first(); 179 180 // There's no src attribute; dont process this yet 181 if (!$img.attr('src') && !$img.attr('srcset')) { 182 return true; 183 } 184 185 var $figure = $('<figure class="ngg-figure"></figure>'); 186 var $figcaption = $('<figcaption class="ngg-figcaption"></figcaption>'); 187 188 if (nggc_get_setting(gallery, 'captions_display_title', true)) { 189 var $header = $('<h6>' + nggc_sanitize($this.data('title')) + '</h6>'); 190 if (!nggc_get_setting(gallery, 'captions_display_title', true)) { 191 $figure.addClass('nggc_no_title'); 192 } 193 } 194 195 var $body_div = $('<div class="nggc-body"/>'); 196 var $body_p = $('<p>' + nggc_sanitize($this.data('description')) + '</p>'); 197 $body_div.append($body_p); 198 199 if (!nggc_get_setting(gallery, 'captions_display_description', true)) { 200 $figure.addClass('nggc_no_description'); 201 } 202 203 // remove any styles: they will be assigned to the new <figure> 204 var classList = $this.attr('class'); 205 var inlineStyles = $this.attr('style'); 206 var imageStyles = $img.attr('style'); 207 208 $this.removeAttr('title'); 209 if (!$this.data('ngg-captions-nostylecopy')) { 210 $this.removeAttr('class'); 211 $this.removeAttr('style'); 212 } 213 214 // Always keep this class assigned 215 this.classList.add('ngg-captions-processed'); 216 217 // each class is responsible for a different animation 218 $figure.addClass('ngg-figure-' + style); 219 $figcaption.addClass('ngg-figcaption-' + style); 220 221 // add share icons if the NextGen Pro Lightbox is active & allows routing 222 if ($.inArray(gallery.source, ['albums', 'random', 'random_images']) == -1 223 && typeof window.nplModalSettings != 'undefined' 224 && nplModalSettings['enable_routing'] == '1' 225 && nplModalSettings['enable_sharing'] == '1' 226 && nggc_get_setting(gallery, 'captions_display_sharing', true)) { 227 var slug = gallery.slug;
228 if (!slug || slug.indexOf('widget-ngg-images') == -1) { 229 var $iconwrapper = $('<div class="nggc-icon-wrapper"/>'); 230 nggc_share_icons.create($iconwrapper, $this); 231 $(document).trigger('ngg-caption-add-icons', { 232 el: $iconwrapper, 233 image_id: $this.data('image-id'), 234 gallery_id: $this.data('nplmodal-gallery-id') 235 }); 236 $figcaption.append($iconwrapper); 237 } 238 } else { 239 $figure.addClass('nggc_no_sharing'); 240 } 241 242 if (nggc_get_setting(gallery, 'captions_display_title', true)) { 243 $figcaption.append($header); 244 } 245 246 if (nggc_get_setting(gallery, 'captions_display_description', true)) { 247 $figcaption.append($body_div); 248 } 249 250 if (user_is_using_ie && user_is_using_ie === 10) { 251 // IE10 does not support nested flexboxes; it will display description text without wrapping 252 // to fix this "Titlebar" theme uses display:inline-block when the user has IE10 253 $($figure).addClass("nggc-ie10"); 254 } 255 256 // reassign the anchor & image styles to our figure 257 if (!$this.data('ngg-captions-nostylecopy')) { 258 $figure.attr('style', imageStyles); 259 $figure.attr('style', inlineStyles); 260 } 261 262 $img.removeAttr('style'); 263 264 // because the blog gallery wrappers are wider than the image itself 265 if (!$this.data('ngg-captions-nostylecopy')) { 266 $figure.css({'max-width': parseInt($img[0].getAttribute('width')) + 'px'}); 267 } 268 269 // put our figure object in its place as a wrapper 270 $newfigure = $img.wrap($figure); 271 $img.after($figcaption); 272 273 if (!$this.data('ngg-captions-nostylecopy')) { 274 $newfigure.addClass(classList); 275 } 276 277 // When the image has loaded then trigger the shave() processing 278 $newfigure.imagesLoaded().done(function() { 279 _unthrottled_nggc_adjust($figcaption); 280 }); 281 282 $newfigure.parent('p').before($newfigure); 283 }); 284 285 $(document).trigger('ngg-captions-added'); 286 }; 287 288 const _unthrottled_nggc_adjust = function($elements) { 289 if (typeof $elements == 'undefined') { 290 $elements = $('figcaption.ngg-figcaption'); 291 } 292 293 // This is a hack specific to thickbox, which insists on giving its class 294 // to the <img> element directly which doesn't work here 295 $('div.nextgen_pro_thumbnail_grid a').each(function() { 296 var $this = $(this); 297 var $img = $this.find('img'); 298 if ($img.hasClass('thickbox')) { 299 $img.removeClass('thickbox'); 300 $this.addClass('thickbox'); 301 } 302 }); 303 304 // Concatenate our text so it won't overflow 305 $elements.each(function() { 306 const $self = $(this); 307 const gallery = nggc_get_gallery($self.parents('a').first().data('ngg-captions-id')); 308 const style = nggc_get_setting(gallery, 'captions_animation', 'slideup'); 309 310 311 const h6 = $self.find('h6'); 312 const h6_height = h6.length !== 0 ? h6.outerHeight() : 0; 313 const total_height = $self.outerHeight(); 314 const icon_wrapper = $self.find('.nggc-icon-wrapper'); 315 const icon_wrapper_height = icon_wrapper.length !== 0 ? icon_wrapper.height() : 0; 316 const body = $self.find('.nggc-body'); 317 const p = $self.find('.nggc-body p'); 318 319 if (style === 'titlebar') { 320 // Because 'titlebar' only allows one line for image titles we can use CSS to trim the title length 321 // thus here we only process the image description 322 if (p.length !== 0) { 323 shave(p[0], body.height()); 324 } 325 } else { 326 // Users can disable titles and descriptions; check for their existence first 327 if (h6.length !== 0) { 328 shave(h6[0], (total_height - icon_wrapper_height)); 329 } 330 if (p.length !== 0) { 331 shave(p[0], (total_height - icon_wrapper_height - h6_height - 20)); 332 } 333 } 334 }); 335 }; 336 337 const nggc_adjust = _.debounce(_unthrottled_nggc_adjust, 500, true); 338 339 window.ngg_captions_adjust = nggc_adjust; 340 341 const nggc_init = function(bind) { 342 bind = bind || false; 343 $('a[data-ngg-captions-enabled]:not(".ngg-captions-processed")').each(function() { 344 this.classList.add('ngg-captions-processed'); 345 const $this = $(this); 346 if (bind) { 347 $(window).on('load', function () { 348 $this.nggcaption(); 349 }); 350 } else { 351 $this.nggcaption(); 352 } 353 }); 354 }; 355 356 nggc_init(true); 357 358 $(window).on('refreshed', function() { 359 nggc_init(); 360 nggc_adjust(); 361 }); 362 363 $(window).on('resize fullscreenchange mozfullscreenchange webkitfullscreenchange orientationchange', function() { 364 nggc_adjust(); 365 }); 366})(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.