legacy
2 weeks ago
admin-notifications.js
2 weeks ago
jquery.matchHeight-min.js
2 weeks ago
sb-blocks.js
2 weeks ago
sb-instagram-admin-6.js
2 weeks ago
sbi-scripts.js
2 weeks ago
sbi-scripts.min.js
2 weeks ago
vue.min.js
2 weeks ago
sbi-scripts.js
1137 lines
| 1 | var sbi_js_exists = (typeof sbi_js_exists !== 'undefined') ? true : false; |
| 2 | if (!sbi_js_exists) { |
| 3 | (function ($) { |
| 4 | function sbiAddVisibilityListener() { |
| 5 | /* Detect when element becomes visible. Used for when the feed is initially hidden, in a tab for example. https://github.com/shaunbowe/jquery.visibilityChanged */ |
| 6 | !function (i) { |
| 7 | var n = { |
| 8 | callback: function () { |
| 9 | }, runOnLoad: !0, frequency: 100, sbiPreviousVisibility: null |
| 10 | }, c = {}; |
| 11 | c.sbiCheckVisibility = function (i, n) { |
| 12 | if (jQuery.contains(document, i[0])) { |
| 13 | var e = n.sbiPreviousVisibility, t = i.is(":visible"); |
| 14 | n.sbiPreviousVisibility = t, null == e ? n.runOnLoad && n.callback(i, t) : e !== t && n.callback(i, t), setTimeout(function () { |
| 15 | c.sbiCheckVisibility(i, n) |
| 16 | }, n.frequency) |
| 17 | } |
| 18 | }, i.fn.sbiVisibilityChanged = function (e) { |
| 19 | var t = i.extend({}, n, e); |
| 20 | return this.each(function () { |
| 21 | c.sbiCheckVisibility(i(this), t) |
| 22 | }) |
| 23 | } |
| 24 | }(jQuery); |
| 25 | } |
| 26 | |
| 27 | function Sbi() { |
| 28 | this.feeds = {}; |
| 29 | this.options = sb_instagram_js_options; |
| 30 | } |
| 31 | |
| 32 | Sbi.prototype = { |
| 33 | createPage: function (createFeeds, createFeedsArgs) { |
| 34 | if (typeof sb_instagram_js_options.ajax_url !== 'undefined' && typeof window.sbiajaxurl === 'undefined') { |
| 35 | window.sbiajaxurl = sb_instagram_js_options.ajax_url; |
| 36 | } |
| 37 | if (typeof window.sbiajaxurl === 'undefined' || window.sbiajaxurl.indexOf(window.location.hostname) === -1) { |
| 38 | window.sbiajaxurl = location.protocol + '//' + window.location.hostname + '/wp-admin/admin-ajax.php'; |
| 39 | } |
| 40 | |
| 41 | if ($('#sbi-builder-app').length && typeof window.sbiresizedImages === 'undefined') { |
| 42 | if ($('.sbi_resized_image_data').length |
| 43 | && typeof $('.sbi_resized_image_data').attr('data-resized') !== 'undefined' |
| 44 | && $('.sbi_resized_image_data').attr('data-resized').indexOf('{"') === 0) { |
| 45 | window.sbiresizedImages = JSON.parse($('.sbi_resized_image_data').attr('data-resized')); |
| 46 | $('.sbi_resized_image_data').remove(); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | $('.sbi_no_js_error_message').remove(); |
| 51 | $('.sbi_no_js').removeClass('sbi_no_js'); |
| 52 | createFeeds(createFeedsArgs); |
| 53 | }, |
| 54 | createFeeds: function (args) { |
| 55 | args.whenFeedsCreated( |
| 56 | $('.sbi').each(function (index) { |
| 57 | $(this).attr('data-sbi-index', index + 1); |
| 58 | var $self = $(this), |
| 59 | flags = typeof $self.attr('data-sbi-flags') !== 'undefined' ? $self.attr('data-sbi-flags').split(',') : [], |
| 60 | general = typeof $self.attr('data-options') !== 'undefined' ? JSON.parse($self.attr('data-options')) : {}; |
| 61 | if (flags.indexOf('testAjax') > -1) { |
| 62 | window.sbi.triggeredTest = true; |
| 63 | var submitData = { |
| 64 | 'action': 'sbi_on_ajax_test_trigger' |
| 65 | }, |
| 66 | onSuccess = function (data) { |
| 67 | console.log('did test'); |
| 68 | }; |
| 69 | sbiAjax(submitData, onSuccess) |
| 70 | } |
| 71 | var feedOptions = { |
| 72 | cols: $self.attr('data-cols'), |
| 73 | colsmobile: typeof $self.attr('data-colsmobile') !== 'undefined' && $self.attr('data-colsmobile') !== 'same' ? $self.attr('data-colsmobile') : $self.attr('data-cols'), |
| 74 | colstablet: typeof $self.attr('data-colstablet') !== 'undefined' && $self.attr('data-colstablet') !== 'same' ? $self.attr('data-colstablet') : $self.attr('data-cols'), |
| 75 | num: $self.attr('data-num'), |
| 76 | imgRes: $self.attr('data-res'), |
| 77 | feedID: $self.attr('data-feedid'), |
| 78 | postID: typeof $self.attr('data-postid') !== 'undefined' ? $self.attr('data-postid') : 'unknown', |
| 79 | imageaspectratio: typeof $self.attr('data-imageaspectratio') !== 'undefined' ? $self.attr('data-imageaspectratio') : '1:1', |
| 80 | shortCodeAtts: $self.attr('data-shortcode-atts'), |
| 81 | resizingEnabled: (flags.indexOf('resizeDisable') === -1), |
| 82 | imageLoadEnabled: (flags.indexOf('imageLoadDisable') === -1), |
| 83 | debugEnabled: (flags.indexOf('debug') > -1), |
| 84 | favorLocal: (flags.indexOf('favorLocal') > -1), |
| 85 | ajaxPostLoad: (flags.indexOf('ajaxPostLoad') > -1), |
| 86 | gdpr: (flags.indexOf('gdpr') > -1), |
| 87 | overrideBlockCDN: (flags.indexOf('overrideBlockCDN') > -1), |
| 88 | consentGiven: false, |
| 89 | locator: (flags.indexOf('locator') > -1), |
| 90 | autoMinRes: 1, |
| 91 | general: general |
| 92 | }; |
| 93 | |
| 94 | window.sbi.feeds[index] = sbiGetNewFeed(this, index, feedOptions); |
| 95 | window.sbi.feeds[index].setResizedImages(); |
| 96 | window.sbi.feeds[index].init(); |
| 97 | |
| 98 | var evt = jQuery.Event('sbiafterfeedcreate'); |
| 99 | evt.feed = window.sbi.feeds[index]; |
| 100 | jQuery(window).trigger(evt); |
| 101 | |
| 102 | }) |
| 103 | ); |
| 104 | }, |
| 105 | afterFeedsCreated: function () { |
| 106 | // enable header hover action |
| 107 | $('.sb_instagram_header').each(function () { |
| 108 | var $thisHeader = $(this); |
| 109 | $thisHeader.find('.sbi_header_link').on('mouseenter mouseleave', function (e) { |
| 110 | switch (e.type) { |
| 111 | case 'mouseenter': |
| 112 | $thisHeader.find('.sbi_header_img_hover').addClass('sbi_fade_in'); |
| 113 | break; |
| 114 | case 'mouseleave': |
| 115 | $thisHeader.find('.sbi_header_img_hover').removeClass('sbi_fade_in'); |
| 116 | break; |
| 117 | } |
| 118 | }); |
| 119 | }); |
| 120 | |
| 121 | }, |
| 122 | encodeHTML: function (raw) { |
| 123 | // make sure passed variable is defined |
| 124 | if (typeof raw === 'undefined') { |
| 125 | return ''; |
| 126 | } |
| 127 | // replace greater than and less than symbols with html entity to disallow html in comments |
| 128 | var encoded = raw.replace(/(>)/g, '>'), |
| 129 | encoded = encoded.replace(/(<)/g, '<'); |
| 130 | encoded = encoded.replace(/(<br\/>)/g, '<br>'); |
| 131 | encoded = encoded.replace(/(<br>)/g, '<br>'); |
| 132 | |
| 133 | return encoded; |
| 134 | }, |
| 135 | urlDetect: function (text) { |
| 136 | var urlRegex = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/g; |
| 137 | return text.match(urlRegex); |
| 138 | } |
| 139 | }; |
| 140 | |
| 141 | function SbiFeed(el, index, settings) { |
| 142 | this.el = el; |
| 143 | this.index = index; |
| 144 | this.settings = settings; |
| 145 | this.minImageWidth = 0; |
| 146 | this.imageResolution = 150; |
| 147 | this.resizedImages = {}; |
| 148 | this.needsResizing = []; |
| 149 | this.outOfPages = false; |
| 150 | this.page = 1; |
| 151 | this.isInitialized = false; |
| 152 | } |
| 153 | |
| 154 | SbiFeed.prototype = { |
| 155 | init: function () { |
| 156 | var feed = this; |
| 157 | feed.settings.consentGiven = feed.checkConsent(); |
| 158 | if ($(this.el).find('.sbi_photo').parent('p').length) { |
| 159 | $(this.el).addClass('sbi_no_autop'); |
| 160 | } |
| 161 | if ($(this.el).find('#sbi_mod_error').length) { |
| 162 | $(this.el).prepend($(this.el).find('#sbi_mod_error')); |
| 163 | } |
| 164 | if (this.settings.ajaxPostLoad) { |
| 165 | this.getNewPostSet(); |
| 166 | } else { |
| 167 | this.afterInitialImagesLoaded(); |
| 168 | //Only check the width once the resize event is over |
| 169 | } |
| 170 | var sbi_delay = (function () { |
| 171 | var sbi_timer = 0; |
| 172 | return function (sbi_callback, sbi_ms) { |
| 173 | clearTimeout(sbi_timer); |
| 174 | sbi_timer = setTimeout(sbi_callback, sbi_ms); |
| 175 | }; |
| 176 | })(); |
| 177 | jQuery(window).on('resize', function () { |
| 178 | sbi_delay(function () { |
| 179 | feed.afterResize(); |
| 180 | }, 500); |
| 181 | }); |
| 182 | |
| 183 | $(this.el).find('.sbi_item').each(function () { |
| 184 | feed.lazyLoadCheck($(this)); |
| 185 | }); |
| 186 | }, |
| 187 | initLayout: function () { |
| 188 | |
| 189 | }, |
| 190 | afterInitialImagesLoaded: function () { |
| 191 | this.initLayout(); |
| 192 | this.loadMoreButtonInit(); |
| 193 | this.hideExtraImagesForWidth(); |
| 194 | this.beforeNewImagesRevealed(); |
| 195 | this.revealNewImages(); |
| 196 | this.afterNewImagesRevealed(); |
| 197 | }, |
| 198 | afterResize: function () { |
| 199 | this.setImageHeight(); |
| 200 | this.setImageResolution(); |
| 201 | this.maybeRaiseImageResolution(); |
| 202 | this.setImageSizeClass(); |
| 203 | }, |
| 204 | afterLoadMoreClicked: function ($button) { |
| 205 | $button.find('.sbi_loader').removeClass('sbi_hidden'); |
| 206 | $button.find('.sbi_btn_text').addClass('sbi_hidden'); |
| 207 | $button.closest('.sbi').find('.sbi_num_diff_hide').addClass('sbi_transition').removeClass('sbi_num_diff_hide'); |
| 208 | }, |
| 209 | afterNewImagesLoaded: function () { |
| 210 | var $self = $(this.el), |
| 211 | feed = this; |
| 212 | this.beforeNewImagesRevealed(); |
| 213 | this.revealNewImages(); |
| 214 | this.afterNewImagesRevealed(); |
| 215 | setTimeout(function () { |
| 216 | //Hide the loader in the load more button |
| 217 | $self.find('.sbi_loader').addClass('sbi_hidden'); |
| 218 | $self.find('.sbi_btn_text').removeClass('sbi_hidden'); |
| 219 | feed.maybeRaiseImageResolution(); |
| 220 | }, 500); |
| 221 | }, |
| 222 | beforeNewImagesRevealed: function () { |
| 223 | this.setImageHeight(); |
| 224 | this.maybeRaiseImageResolution(true); |
| 225 | this.setImageSizeClass(); |
| 226 | }, |
| 227 | revealNewImages: function () { |
| 228 | var $self = $(this.el), |
| 229 | feed = this; |
| 230 | |
| 231 | $self.find('.sbi-screenreader').each(function () { |
| 232 | $(this).find('img').remove(); |
| 233 | }); |
| 234 | |
| 235 | // Call Custom JS if it exists |
| 236 | if (typeof sbi_custom_js == 'function') setTimeout(function () { sbi_custom_js(); }, 100); |
| 237 | |
| 238 | $self.find('.sbi_item').each(function (index) { |
| 239 | var $self = jQuery(this); |
| 240 | |
| 241 | //Photo links |
| 242 | $self.find('.sbi_photo').on('mouseenter mouseleave', function (e) { |
| 243 | switch (e.type) { |
| 244 | case 'mouseenter': |
| 245 | jQuery(this).fadeTo(200, 0.85); |
| 246 | break; |
| 247 | case 'mouseleave': |
| 248 | jQuery(this).stop().fadeTo(500, 1); |
| 249 | break; |
| 250 | } |
| 251 | }); |
| 252 | }); //End .sbi_item each |
| 253 | |
| 254 | //Remove the new class after 500ms, once the sorting is done |
| 255 | setTimeout(function () { |
| 256 | jQuery('#sbi_images .sbi_item.sbi_new').removeClass('sbi_new'); |
| 257 | //Loop through items and remove class to reveal them |
| 258 | var time = 10; |
| 259 | $self.find('.sbi_transition').each(function () { |
| 260 | var $sbi_item_transition_el = jQuery(this); |
| 261 | |
| 262 | setTimeout(function () { |
| 263 | $sbi_item_transition_el.removeClass('sbi_transition'); |
| 264 | }, time); |
| 265 | time += 10; |
| 266 | }); |
| 267 | }, 500); |
| 268 | }, |
| 269 | lazyLoadCheck: function ($item) { |
| 270 | var feed = this; |
| 271 | if ($item.find('.sbi_photo').length && !$item.closest('.sbi').hasClass('sbi-no-ll-check')) { |
| 272 | var imgSrcSet = feed.getImageUrls($item), |
| 273 | maxResImage = typeof imgSrcSet[640] !== 'undefined' ? imgSrcSet[640] : $item.find('.sbi_photo').attr('data-full-res'); |
| 274 | |
| 275 | if (!feed.settings.consentGiven) { |
| 276 | if (maxResImage.indexOf('scontent') > -1) { |
| 277 | return; |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | $item.find('.sbi_photo img').each(function () { |
| 282 | if (maxResImage && typeof $(this).attr('data-src') !== 'undefined') { |
| 283 | $(this).attr('data-src', maxResImage); |
| 284 | } |
| 285 | if (maxResImage && typeof $(this).attr('data-orig-src') !== 'undefined') { |
| 286 | $(this).attr('data-orig-src', maxResImage); |
| 287 | } |
| 288 | $(this).on('load', function () { |
| 289 | if (!$(this).hasClass('sbi-replaced') |
| 290 | && $(this).attr('src').indexOf('placeholder') > -1) { |
| 291 | $(this).addClass('sbi-replaced'); |
| 292 | if (maxResImage) { |
| 293 | $(this).attr('src', maxResImage); |
| 294 | if ($(this).closest('.sbi_imgLiquid_bgSize').length) { |
| 295 | $(this).closest('.sbi_imgLiquid_bgSize').css('background-image', 'url(' + maxResImage + ')'); |
| 296 | } |
| 297 | } |
| 298 | } |
| 299 | }); |
| 300 | }); |
| 301 | } |
| 302 | }, |
| 303 | afterNewImagesRevealed: function () { |
| 304 | this.listenForVisibilityChange(); |
| 305 | this.sendNeedsResizingToServer(); |
| 306 | if (!this.settings.imageLoadEnabled) { |
| 307 | $('.sbi_no_resraise').removeClass('sbi_no_resraise'); |
| 308 | } |
| 309 | |
| 310 | var evt = $.Event('sbiafterimagesloaded'); |
| 311 | evt.el = $(this.el); |
| 312 | $(window).trigger(evt); |
| 313 | }, |
| 314 | setResizedImages: function () { |
| 315 | if ($(this.el).find('.sbi_resized_image_data').length |
| 316 | && typeof $(this.el).find('.sbi_resized_image_data').attr('data-resized') !== 'undefined' |
| 317 | && $(this.el).find('.sbi_resized_image_data').attr('data-resized').indexOf('{"') === 0) { |
| 318 | this.resizedImages = JSON.parse($(this.el).find('.sbi_resized_image_data').attr('data-resized')); |
| 319 | $(this.el).find('.sbi_resized_image_data').remove(); |
| 320 | } else if (typeof window.sbiresizedImages !== 'undefined') { |
| 321 | this.resizedImages = window.sbiresizedImages; |
| 322 | } |
| 323 | }, |
| 324 | sendNeedsResizingToServer: function () { |
| 325 | var feed = this, |
| 326 | $self = $(this.el); |
| 327 | if (feed.needsResizing.length > 0 && feed.settings.resizingEnabled) { |
| 328 | var itemOffset = $(this.el).find('.sbi_item').length, |
| 329 | cacheAll = typeof feed.settings.general.cache_all !== 'undefined' ? feed.settings.general.cache_all : false; |
| 330 | var locatorNonce = ''; |
| 331 | if (typeof $self.attr('data-locatornonce') !== 'undefined') { |
| 332 | locatorNonce = $self.attr('data-locatornonce'); |
| 333 | } |
| 334 | |
| 335 | if ($('#sbi-builder-app').length) { |
| 336 | if (typeof window.sbiresizeTriggered !== 'undefined' && window.sbiresizeTriggered) { |
| 337 | return; |
| 338 | } else { |
| 339 | window.sbiresizeTriggered = true; |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | var submitData = { |
| 344 | action: 'sbi_resized_images_submit', |
| 345 | needs_resizing: feed.needsResizing, |
| 346 | offset: itemOffset, |
| 347 | feed_id: feed.settings.feedID, |
| 348 | atts: feed.settings.shortCodeAtts, |
| 349 | location: feed.locationGuess(), |
| 350 | post_id: feed.settings.postID, |
| 351 | cache_all: cacheAll, |
| 352 | locator_nonce: locatorNonce |
| 353 | }; |
| 354 | var onSuccess = function (data) { |
| 355 | var response = data?.data; |
| 356 | |
| 357 | if (typeof data !== 'object' && data.trim().indexOf('{') === 0) { |
| 358 | response = JSON.parse(data.trim()); |
| 359 | } |
| 360 | if (feed.settings.debugEnabled) { |
| 361 | console.log(response); |
| 362 | } |
| 363 | for (var property in response) { |
| 364 | if (response.hasOwnProperty(property)) { |
| 365 | feed.resizedImages[property] = response[property]; |
| 366 | } |
| 367 | } |
| 368 | feed.maybeRaiseImageResolution(); |
| 369 | |
| 370 | setTimeout(function () { |
| 371 | feed.afterResize(); |
| 372 | }, 500); |
| 373 | if ($('#sbi-builder-app').length) { |
| 374 | window.sbiresizeTriggered = false; |
| 375 | } |
| 376 | }; |
| 377 | sbiAjax(submitData, onSuccess); |
| 378 | } else if (feed.settings.locator) { |
| 379 | var locatorNonce = ''; |
| 380 | if (typeof $self.attr('data-locatornonce') !== 'undefined') { |
| 381 | locatorNonce = $self.attr('data-locatornonce'); |
| 382 | } |
| 383 | var submitData = { |
| 384 | action: 'sbi_do_locator', |
| 385 | feed_id: feed.settings.feedID, |
| 386 | atts: feed.settings.shortCodeAtts, |
| 387 | location: feed.locationGuess(), |
| 388 | post_id: feed.settings.postID, |
| 389 | locator_nonce: locatorNonce |
| 390 | }; |
| 391 | var onSuccess = function (data) { |
| 392 | |
| 393 | }; |
| 394 | sbiAjax(submitData, onSuccess); |
| 395 | } |
| 396 | }, |
| 397 | loadMoreButtonInit: function () { |
| 398 | var $self = $(this.el), |
| 399 | feed = this; |
| 400 | $self.find('#sbi_load .sbi_load_btn').off().on('click', function () { |
| 401 | |
| 402 | feed.afterLoadMoreClicked(jQuery(this)); |
| 403 | feed.getNewPostSet(); |
| 404 | |
| 405 | }); //End click event |
| 406 | }, |
| 407 | getNewPostSet: function () { |
| 408 | var $self = $(this.el), |
| 409 | feed = this; |
| 410 | feed.page++; |
| 411 | |
| 412 | var locatorNonce = ''; |
| 413 | if (typeof $self.attr('data-locatornonce') !== 'undefined') { |
| 414 | locatorNonce = $self.attr('data-locatornonce'); |
| 415 | } |
| 416 | |
| 417 | var itemOffset = $self.find('.sbi_item').length, |
| 418 | submitData = { |
| 419 | action: 'sbi_load_more_clicked', |
| 420 | offset: itemOffset, |
| 421 | page: feed.page, |
| 422 | feed_id: feed.settings.feedID, |
| 423 | atts: feed.settings.shortCodeAtts, |
| 424 | location: feed.locationGuess(), |
| 425 | post_id: feed.settings.postID, |
| 426 | current_resolution: feed.imageResolution, |
| 427 | locator_nonce: locatorNonce |
| 428 | }; |
| 429 | var onSuccess = function (data) { |
| 430 | var response = data?.data; |
| 431 | |
| 432 | if (typeof data !== 'object' && data.trim().indexOf('{') === 0) { |
| 433 | response = JSON.parse(data.trim()); |
| 434 | } |
| 435 | if (feed.settings.debugEnabled) { |
| 436 | console.log(response); |
| 437 | } |
| 438 | feed.appendNewPosts(response.html); |
| 439 | feed.addResizedImages(response.resizedImages); |
| 440 | if (feed.settings.ajaxPostLoad) { |
| 441 | feed.settings.ajaxPostLoad = false; |
| 442 | feed.afterInitialImagesLoaded(); |
| 443 | } else { |
| 444 | feed.afterNewImagesLoaded(); |
| 445 | } |
| 446 | |
| 447 | if (!response.feedStatus.shouldPaginate) { |
| 448 | feed.outOfPages = true; |
| 449 | $self.find('.sbi_load_btn').hide(); |
| 450 | } else { |
| 451 | feed.outOfPages = false; |
| 452 | } |
| 453 | $('.sbi_no_js').removeClass('sbi_no_js'); |
| 454 | |
| 455 | }; |
| 456 | sbiAjax(submitData, onSuccess); |
| 457 | }, |
| 458 | appendNewPosts: function (newPostsHtml) { |
| 459 | var $self = $(this.el), |
| 460 | feed = this; |
| 461 | if ($self.find('#sbi_images .sbi_item').length) { |
| 462 | $self.find('#sbi_images .sbi_item').last().after(newPostsHtml); |
| 463 | } else { |
| 464 | $self.find('#sbi_images').append(newPostsHtml); |
| 465 | } |
| 466 | }, |
| 467 | addResizedImages: function (resizedImagesToAdd) { |
| 468 | for (var imageID in resizedImagesToAdd) { |
| 469 | this.resizedImages[imageID] = resizedImagesToAdd[imageID]; |
| 470 | } |
| 471 | }, |
| 472 | setImageHeight: function () { |
| 473 | var $self = $(this.el); |
| 474 | |
| 475 | var sbi_photo_width = $self.find('.sbi_photo').eq(0).innerWidth(); |
| 476 | |
| 477 | //Figure out number of columns for either desktop or mobile |
| 478 | var sbi_num_cols = this.getColumnCount(); |
| 479 | |
| 480 | //Figure out what the width should be using the number of cols |
| 481 | //Figure out what the width should be using the number of cols |
| 482 | var imagesPadding = $self.find('#sbi_images').innerWidth() - $self.find('#sbi_images').width(), |
| 483 | imagepadding = imagesPadding / 2; |
| 484 | sbi_photo_width_manual = ($self.find('#sbi_images').width() / sbi_num_cols) - imagesPadding; |
| 485 | //If the width is less than it should be then set it manually |
| 486 | //if( sbi_photo_width <= (sbi_photo_width_manual) ) sbi_photo_width = sbi_photo_width_manual; |
| 487 | |
| 488 | // Get the selected aspect ratio from settings |
| 489 | var aspectRatio = '1:1'; // Default to square |
| 490 | if (typeof this.settings.imageaspectratio !== 'undefined') { |
| 491 | aspectRatio = this.settings.imageaspectratio; |
| 492 | } |
| 493 | |
| 494 | // Calculate height based on aspect ratio |
| 495 | var height; |
| 496 | if (aspectRatio === '4:5') { |
| 497 | height = sbi_photo_width * 1.25; // 4:5 ratio (1.25) |
| 498 | } else if (aspectRatio === '3:4') { |
| 499 | height = sbi_photo_width * 1.33; // 3:4 ratio (1.33) |
| 500 | } else { |
| 501 | height = sbi_photo_width; // 1:1 ratio (square) |
| 502 | } |
| 503 | |
| 504 | $self.find('.sbi_photo').css('height', height); |
| 505 | |
| 506 | //Set the position of the carousel arrows |
| 507 | if ($self.find('.sbi-owl-nav').length) { |
| 508 | setTimeout(function () { |
| 509 | //If there's 2 rows then adjust position |
| 510 | var sbi_ratio = 2; |
| 511 | if ($self.find('.sbi_owl2row-item').length) sbi_ratio = 1; |
| 512 | |
| 513 | var sbi_arrows_top = ($self.find('.sbi_photo').eq(0).innerWidth() / sbi_ratio); |
| 514 | sbi_arrows_top += parseInt(imagepadding) * (2 + (2 - sbi_ratio)); |
| 515 | $self.find('.sbi-owl-nav div').css('top', sbi_arrows_top); |
| 516 | }, 100); |
| 517 | } |
| 518 | |
| 519 | }, |
| 520 | maybeRaiseSingleImageResolution: function ($item, index, forceChange) { |
| 521 | var feed = this, |
| 522 | imgSrcSet = feed.getImageUrls($item), |
| 523 | currentUrl = $item.find('.sbi_photo img').attr('src'), |
| 524 | currentRes = 150, |
| 525 | imagEl = $item.find('img').get(0), |
| 526 | aspectRatio = currentUrl === window.sbi.options.placeholder ? 1 : imagEl.naturalWidth / imagEl.naturalHeight, |
| 527 | forceChange = typeof forceChange !== 'undefined' ? forceChange : false; |
| 528 | |
| 529 | if ($item.hasClass('sbi_no_resraise') || $item.hasClass('sbi_had_error') || ($item.find('.sbi_link_area').length && $item.find('.sbi_link_area').hasClass('sbi_had_error'))) { |
| 530 | return; |
| 531 | } |
| 532 | |
| 533 | if (imgSrcSet.length < 1) { |
| 534 | if ($item.find('.sbi_link_area').length) { |
| 535 | $item.find('.sbi_link_area').attr('href', window.sbi.options.placeholder.replace('placeholder.png', 'thumb-placeholder.png')) |
| 536 | } |
| 537 | return; |
| 538 | } else if ($item.find('.sbi_link_area').length && $item.find('.sbi_link_area').attr('href') === window.sbi.options.placeholder.replace('placeholder.png', 'thumb-placeholder.png') |
| 539 | || !feed.settings.consentGiven) { |
| 540 | $item.find('.sbi_link_area').attr('href', imgSrcSet[imgSrcSet.length - 1]) |
| 541 | } |
| 542 | if (typeof imgSrcSet[640] !== 'undefined') { |
| 543 | $item.find('.sbi_photo').attr('data-full-res', imgSrcSet[640]); |
| 544 | } |
| 545 | |
| 546 | $.each(imgSrcSet, function (index, value) { |
| 547 | if (value === currentUrl) { |
| 548 | currentRes = parseInt(index); |
| 549 | // If the image has already been changed to an existing real source, don't force the change |
| 550 | forceChange = false; |
| 551 | } |
| 552 | }); |
| 553 | //Image res |
| 554 | var newRes = 640; |
| 555 | switch (feed.settings.imgRes) { |
| 556 | case 'thumb': |
| 557 | newRes = 150; |
| 558 | break; |
| 559 | case 'medium': |
| 560 | newRes = 320; |
| 561 | break; |
| 562 | case 'full': |
| 563 | newRes = 640; |
| 564 | break; |
| 565 | default: |
| 566 | var minImageWidth = Math.max(feed.settings.autoMinRes, $item.find('.sbi_photo').innerWidth()), |
| 567 | thisImageReplace = feed.getBestResolutionForAuto(minImageWidth, aspectRatio, $item); |
| 568 | switch (thisImageReplace) { |
| 569 | case 320: |
| 570 | newRes = 320; |
| 571 | break; |
| 572 | case 150: |
| 573 | newRes = 150; |
| 574 | break; |
| 575 | } |
| 576 | break; |
| 577 | } |
| 578 | |
| 579 | if (newRes > currentRes || currentUrl === window.sbi.options.placeholder || forceChange) { |
| 580 | if (feed.settings.debugEnabled) { |
| 581 | var reason = currentUrl === window.sbi.options.placeholder ? 'was placeholder' : 'too small'; |
| 582 | console.log('rais res for ' + currentUrl, reason); |
| 583 | } |
| 584 | var newUrl = imgSrcSet[newRes].split("?ig_cache_key")[0]; |
| 585 | if (currentUrl !== newUrl) { |
| 586 | $item.find('.sbi_photo img').attr('src', newUrl); |
| 587 | } |
| 588 | currentRes = newRes; |
| 589 | |
| 590 | if (feed.settings.imgRes === 'auto') { |
| 591 | var checked = false; |
| 592 | $item.find('.sbi_photo img').on('load', function () { |
| 593 | |
| 594 | var $this_image = $(this); |
| 595 | var newAspectRatio = ($this_image.get(0).naturalWidth / $this_image.get(0).naturalHeight); |
| 596 | |
| 597 | if ($this_image.get(0).naturalWidth !== 1000 && newAspectRatio > aspectRatio && !checked) { |
| 598 | if (feed.settings.debugEnabled) { |
| 599 | console.log('rais res again for aspect ratio change ' + currentUrl); |
| 600 | } |
| 601 | checked = true; |
| 602 | minImageWidth = $item.find('.sbi_photo').innerWidth(); |
| 603 | thisImageReplace = feed.getBestResolutionForAuto(minImageWidth, newAspectRatio, $item); |
| 604 | newRes = 640; |
| 605 | |
| 606 | switch (thisImageReplace) { |
| 607 | case 320: |
| 608 | newRes = 320; |
| 609 | break; |
| 610 | case 150: |
| 611 | newRes = 150; |
| 612 | break; |
| 613 | } |
| 614 | |
| 615 | if (newRes > currentRes) { |
| 616 | newUrl = imgSrcSet[newRes].split("?ig_cache_key")[0]; |
| 617 | $this_image.attr('src', newUrl); |
| 618 | } |
| 619 | if (feed.layout === 'masonry' || feed.layout === 'highlight') { |
| 620 | $(feed.el).find('#sbi_images').smashotope(feed.isotopeArgs); |
| 621 | setTimeout(function () { |
| 622 | $(feed.el).find('#sbi_images').smashotope(feed.isotopeArgs); |
| 623 | }, 500) |
| 624 | } |
| 625 | } else { |
| 626 | if (feed.settings.debugEnabled) { |
| 627 | var reason = checked ? 'already checked' : 'no aspect ratio change'; |
| 628 | console.log('not raising res for replacement ' + currentUrl, reason); |
| 629 | } |
| 630 | } |
| 631 | }); |
| 632 | } |
| 633 | |
| 634 | |
| 635 | } |
| 636 | |
| 637 | $item.find('img').on('error', function () { |
| 638 | if (!$(this).hasClass('sbi_img_error')) { |
| 639 | $(this).addClass('sbi_img_error'); |
| 640 | var sourceFromAPI = ($(this).attr('src').indexOf('media/?size=') > -1 || $(this).attr('src').indexOf('cdninstagram') > -1 || $(this).attr('src').indexOf('fbcdn') > -1) |
| 641 | |
| 642 | if (!sourceFromAPI && feed.settings.consentGiven) { |
| 643 | |
| 644 | if ($(this).closest('.sbi_photo').attr('data-img-src-set') !== 'undefined') { |
| 645 | var srcSet = JSON.parse($(this).closest('.sbi_photo').attr('data-img-src-set').replace(/\\\//g, '/')); |
| 646 | if (typeof srcSet.d !== 'undefined') { |
| 647 | $(this).attr('src', srcSet.d); |
| 648 | $(this).closest('.sbi_item').addClass('sbi_had_error').find('.sbi_link_area').attr('href', srcSet[640]).addClass('sbi_had_error'); |
| 649 | } |
| 650 | } |
| 651 | } else { |
| 652 | feed.settings.favorLocal = true; |
| 653 | var srcSet = feed.getImageUrls($(this).closest('.sbi_item')); |
| 654 | if (typeof srcSet[640] !== 'undefined') { |
| 655 | $(this).attr('src', srcSet[640]); |
| 656 | $(this).closest('.sbi_item').addClass('sbi_had_error').find('.sbi_link_area').attr('href', srcSet[640]).addClass('sbi_had_error'); |
| 657 | } |
| 658 | } |
| 659 | setTimeout(function () { |
| 660 | feed.afterResize(); |
| 661 | }, 1500) |
| 662 | } else { |
| 663 | console.log('unfixed error ' + $(this).attr('src')); |
| 664 | } |
| 665 | }); |
| 666 | }, |
| 667 | maybeRaiseImageResolution: function (justNew) { |
| 668 | var feed = this, |
| 669 | itemsSelector = typeof justNew !== 'undefined' && justNew === true ? '.sbi_item.sbi_new' : '.sbi_item', |
| 670 | forceChange = !feed.isInitialized ? true : false; |
| 671 | $(feed.el).find(itemsSelector).each(function (index) { |
| 672 | if (!$(this).hasClass('sbi_num_diff_hide') |
| 673 | && $(this).find('.sbi_photo').length |
| 674 | && typeof $(this).find('.sbi_photo').attr('data-img-src-set') !== 'undefined') { |
| 675 | feed.maybeRaiseSingleImageResolution($(this), index, forceChange); |
| 676 | } |
| 677 | }); //End .sbi_item each |
| 678 | feed.isInitialized = true; |
| 679 | }, |
| 680 | getBestResolutionForAuto: function (colWidth, aspectRatio, $item) { |
| 681 | if (isNaN(aspectRatio) || aspectRatio < 1) { |
| 682 | aspectRatio = 1; |
| 683 | } |
| 684 | var bestWidth = colWidth * aspectRatio, |
| 685 | bestWidthRounded = Math.ceil(bestWidth / 10) * 10, |
| 686 | customSizes = [150, 320, 640]; |
| 687 | |
| 688 | if ($item.hasClass('sbi_highlighted')) { |
| 689 | bestWidthRounded = bestWidthRounded * 2; |
| 690 | } |
| 691 | |
| 692 | if (customSizes.indexOf(parseInt(bestWidthRounded)) === -1) { |
| 693 | var done = false; |
| 694 | $.each(customSizes, function (index, item) { |
| 695 | if (item > parseInt(bestWidthRounded) && !done) { |
| 696 | bestWidthRounded = item; |
| 697 | |
| 698 | done = true; |
| 699 | } |
| 700 | }); |
| 701 | } |
| 702 | |
| 703 | return bestWidthRounded; |
| 704 | }, |
| 705 | hideExtraImagesForWidth: function () { |
| 706 | if (this.layout === 'carousel') { |
| 707 | return; |
| 708 | } |
| 709 | var $self = $(this.el), |
| 710 | num = typeof $self.attr('data-num') !== 'undefined' && $self.attr('data-num') !== '' ? parseInt($self.attr('data-num')) : 1, |
| 711 | nummobile = typeof $self.attr('data-nummobile') !== 'undefined' && $self.attr('data-nummobile') !== '' ? parseInt($self.attr('data-nummobile')) : num; |
| 712 | |
| 713 | if ($(window).width() < 480 || window.sbi_preview_device === 'mobile') { |
| 714 | if (nummobile < $self.find('.sbi_item').length) { |
| 715 | $self.find('.sbi_item').slice(nummobile - $self.find('.sbi_item').length).addClass('sbi_num_diff_hide'); |
| 716 | } |
| 717 | } else { |
| 718 | if (num < $self.find('.sbi_item').length) { |
| 719 | $self.find('.sbi_item').slice(num - $self.find('.sbi_item').length).addClass('sbi_num_diff_hide'); |
| 720 | } |
| 721 | } |
| 722 | }, |
| 723 | setImageSizeClass: function () { |
| 724 | var $self = $(this.el); |
| 725 | $self.removeClass('sbi_small sbi_medium'); |
| 726 | var feedWidth = $self.innerWidth(), |
| 727 | photoPadding = parseInt(($self.find('#sbi_images').outerWidth() - $self.find('#sbi_images').width())) / 2, |
| 728 | cols = this.getColumnCount(), |
| 729 | feedWidthSansPadding = feedWidth - (photoPadding * (cols + 2)), |
| 730 | colWidth = (feedWidthSansPadding / cols); |
| 731 | if (colWidth > 120 && colWidth < 240) { |
| 732 | $self.addClass('sbi_medium'); |
| 733 | } else if (colWidth <= 120) { |
| 734 | $self.addClass('sbi_small'); |
| 735 | } |
| 736 | }, |
| 737 | setMinImageWidth: function () { |
| 738 | if ($(this.el).find('.sbi_item .sbi_photo').first().length) { |
| 739 | this.minImageWidth = $(this.el).find('.sbi_item .sbi_photo').first().innerWidth(); |
| 740 | } else { |
| 741 | this.minImageWidth = 150; |
| 742 | } |
| 743 | }, |
| 744 | setImageResolution: function () { |
| 745 | if (this.settings.imgRes === 'auto') { |
| 746 | this.imageResolution = 'auto'; |
| 747 | } else { |
| 748 | switch (this.settings.imgRes) { |
| 749 | case 'thumb': |
| 750 | this.imageResolution = 150; |
| 751 | break; |
| 752 | case 'medium': |
| 753 | this.imageResolution = 320; |
| 754 | break; |
| 755 | default: |
| 756 | this.imageResolution = 640; |
| 757 | } |
| 758 | } |
| 759 | }, |
| 760 | getImageUrls: function ($item) { |
| 761 | var srcSet = JSON.parse($item.find('.sbi_photo').attr('data-img-src-set').replace(/\\\//g, '/')), |
| 762 | id = $item.attr('id').replace('sbi_', ''); |
| 763 | if (!this.settings.consentGiven && !this.settings.overrideBlockCDN) { |
| 764 | srcSet = []; |
| 765 | } |
| 766 | if (typeof this.resizedImages[id] !== 'undefined' |
| 767 | && this.resizedImages[id] !== 'video' |
| 768 | && this.resizedImages[id] !== 'pending' |
| 769 | && this.resizedImages[id].id !== 'error' |
| 770 | && this.resizedImages[id].id !== 'video' |
| 771 | && this.resizedImages[id].id !== 'pending') { |
| 772 | |
| 773 | if (typeof this.resizedImages[id]['sizes'] !== 'undefined') { |
| 774 | var foundSizes = []; |
| 775 | var extension = (typeof this.resizedImages[id]['extension'] !== 'undefined') ? this.resizedImages[id]['extension'] : '.jpg'; |
| 776 | if (typeof this.resizedImages[id]['sizes']['full'] !== 'undefined') { |
| 777 | srcSet[640] = sb_instagram_js_options.resized_url + this.resizedImages[id].id + 'full' + extension; |
| 778 | foundSizes.push(640); |
| 779 | } |
| 780 | if (typeof this.resizedImages[id]['sizes']['low'] !== 'undefined') { |
| 781 | srcSet[320] = sb_instagram_js_options.resized_url + this.resizedImages[id].id + 'low' + extension; |
| 782 | foundSizes.push(320); |
| 783 | } |
| 784 | if (typeof this.resizedImages[id]['sizes']['thumb'] !== 'undefined') { |
| 785 | foundSizes.push(150); |
| 786 | srcSet[150] = sb_instagram_js_options.resized_url + this.resizedImages[id].id + 'thumb' + extension; |
| 787 | } |
| 788 | if (this.settings.favorLocal) { |
| 789 | if (foundSizes.indexOf(640) === -1) { |
| 790 | if (foundSizes.indexOf(320) > -1) { |
| 791 | srcSet[640] = sb_instagram_js_options.resized_url + this.resizedImages[id].id + 'low' + extension; |
| 792 | } |
| 793 | } |
| 794 | if (foundSizes.indexOf(320) === -1) { |
| 795 | if (foundSizes.indexOf(640) > -1) { |
| 796 | srcSet[320] = sb_instagram_js_options.resized_url + this.resizedImages[id].id + 'full' + extension; |
| 797 | } else if (foundSizes.indexOf(150) > -1) { |
| 798 | srcSet[320] = sb_instagram_js_options.resized_url + this.resizedImages[id].id + 'thumb' + extension; |
| 799 | } |
| 800 | } |
| 801 | if (foundSizes.indexOf(150) === -1) { |
| 802 | if (foundSizes.indexOf(320) > -1) { |
| 803 | srcSet[150] = sb_instagram_js_options.resized_url + this.resizedImages[id].id + 'low' + extension; |
| 804 | } else if (foundSizes.indexOf(640) > -1) { |
| 805 | srcSet[150] = sb_instagram_js_options.resized_url + this.resizedImages[id].id + 'full' + extension; |
| 806 | } |
| 807 | } |
| 808 | } |
| 809 | } |
| 810 | } else if (typeof this.resizedImages[id] === 'undefined' |
| 811 | || (typeof this.resizedImages[id]['id'] !== 'undefined' && this.resizedImages[id]['id'] !== 'pending' && this.resizedImages[id]['id'] !== 'error')) { |
| 812 | this.addToNeedsResizing(id); |
| 813 | } |
| 814 | |
| 815 | return srcSet; |
| 816 | }, |
| 817 | getAvatarUrl: function (username, favorType) { |
| 818 | if (username === '') { |
| 819 | return ''; |
| 820 | } |
| 821 | |
| 822 | var availableAvatars = this.settings.general.avatars, |
| 823 | favorType = typeof favorType !== 'undefined' ? favorType : 'local'; |
| 824 | |
| 825 | if (favorType === 'local') { |
| 826 | if (typeof availableAvatars['LCL' + username] !== 'undefined' && parseInt(availableAvatars['LCL' + username]) === 1) { |
| 827 | return sb_instagram_js_options.resized_url + username + '.jpg'; |
| 828 | } else if (typeof availableAvatars[username] !== 'undefined') { |
| 829 | return availableAvatars[username]; |
| 830 | } else { |
| 831 | return ''; |
| 832 | } |
| 833 | } else { |
| 834 | if (typeof availableAvatars[username] !== 'undefined') { |
| 835 | return availableAvatars[username]; |
| 836 | } else if (typeof availableAvatars['LCL' + username] !== 'undefined' && parseInt(availableAvatars['LCL' + username]) === 1) { |
| 837 | return sb_instagram_js_options.resized_url + username + '.jpg'; |
| 838 | } else { |
| 839 | return ''; |
| 840 | } |
| 841 | } |
| 842 | }, |
| 843 | addToNeedsResizing: function (id) { |
| 844 | if (this.needsResizing.indexOf(id) === -1) { |
| 845 | this.needsResizing.push(id); |
| 846 | } |
| 847 | }, |
| 848 | listenForVisibilityChange: function () { |
| 849 | var feed = this; |
| 850 | sbiAddVisibilityListener(); |
| 851 | if (typeof $(this.el).filter(':hidden').sbiVisibilityChanged == 'function') { |
| 852 | //If the feed is initially hidden (in a tab for example) then check for when it becomes visible and set then set the height |
| 853 | $(this.el).filter(':hidden').sbiVisibilityChanged({ |
| 854 | callback: function (element, visible) { |
| 855 | feed.afterResize(); |
| 856 | }, |
| 857 | runOnLoad: false |
| 858 | }); |
| 859 | } |
| 860 | }, |
| 861 | getColumnCount: function () { |
| 862 | var $self = $(this.el), |
| 863 | cols = this.settings.cols, |
| 864 | colsmobile = this.settings.colsmobile, |
| 865 | colstablet = this.settings.colstablet, |
| 866 | returnCols = cols; |
| 867 | |
| 868 | sbiWindowWidth = window.innerWidth; |
| 869 | |
| 870 | if ($self.hasClass('sbi_mob_col_auto')) { |
| 871 | if (sbiWindowWidth < 640 && (parseInt(cols) > 2 && parseInt(cols) < 7)) returnCols = 2; |
| 872 | if (sbiWindowWidth < 640 && (parseInt(cols) > 6 && parseInt(cols) < 11)) returnCols = 4; |
| 873 | if (sbiWindowWidth <= 480 && parseInt(cols) > 2) returnCols = 1; |
| 874 | } else if (sbiWindowWidth > 480 && sbiWindowWidth <= 800) { |
| 875 | returnCols = colstablet; |
| 876 | } else if (sbiWindowWidth <= 480) { |
| 877 | returnCols = colsmobile; |
| 878 | } |
| 879 | |
| 880 | return parseInt(returnCols); |
| 881 | }, |
| 882 | checkConsent: function () { |
| 883 | if (this.settings.consentGiven || !this.settings.gdpr) { |
| 884 | return true; |
| 885 | } |
| 886 | if (typeof window.WPConsent !== 'undefined') { |
| 887 | if (window.WPConsent.hasConsent('marketing')) { |
| 888 | try { |
| 889 | this.settings.consentGiven = true; |
| 890 | } catch (e) { |
| 891 | // Fallback to window object if cookie parsing fails |
| 892 | this.settings.consentGiven = false; |
| 893 | } |
| 894 | } else { |
| 895 | // Fallback to window object if cookie not found |
| 896 | this.settings.consentGiven = false; |
| 897 | } |
| 898 | } else if (typeof window.cookieyes !== "undefined") { // CookieYes | GDPR Cookie Consent by CookieYes |
| 899 | if (typeof window.cookieyes._ckyConsentStore.get !== 'undefined') { |
| 900 | this.settings.consentGiven = window.cookieyes._ckyConsentStore.get('functional') === 'yes'; |
| 901 | } |
| 902 | } else if (typeof CLI_Cookie !== "undefined") { // GDPR Cookie Consent by WebToffee |
| 903 | if (CLI_Cookie.read(CLI_ACCEPT_COOKIE_NAME) !== null) { |
| 904 | |
| 905 | // WebToffee no longer uses this cookie but being left here to maintain backwards compatibility |
| 906 | if (CLI_Cookie.read('cookielawinfo-checkbox-non-necessary') !== null) { |
| 907 | this.settings.consentGiven = CLI_Cookie.read('cookielawinfo-checkbox-non-necessary') === 'yes'; |
| 908 | } |
| 909 | |
| 910 | if (CLI_Cookie.read('cookielawinfo-checkbox-necessary') !== null) { |
| 911 | this.settings.consentGiven = CLI_Cookie.read('cookielawinfo-checkbox-necessary') === 'yes'; |
| 912 | } |
| 913 | } |
| 914 | |
| 915 | } else if (typeof window.cnArgs !== "undefined") { // Cookie Notice by dFactory |
| 916 | var value = "; " + document.cookie, |
| 917 | parts = value.split('; cookie_notice_accepted='); |
| 918 | |
| 919 | if (parts.length === 2) { |
| 920 | var val = parts.pop().split(';').shift(); |
| 921 | |
| 922 | this.settings.consentGiven = (val === 'true'); |
| 923 | } |
| 924 | } else if (typeof window.cookieconsent !== 'undefined' || typeof window.cmplz_has_consent === 'function') { // Complianz by Really Simple Plugins |
| 925 | // Check for Complianz v6+ using cmplz_has_consent function |
| 926 | if (typeof window.cmplz_has_consent === 'function') { |
| 927 | this.settings.consentGiven = cmplz_has_consent('marketing'); |
| 928 | } else { |
| 929 | this.settings.consentGiven = sbiCmplzGetCookie('cmplz_consent_status') === 'allow'; |
| 930 | } |
| 931 | } else if (typeof window.Cookiebot !== "undefined") { // Cookiebot by Cybot A/S |
| 932 | this.settings.consentGiven = Cookiebot.consented; |
| 933 | } else if (typeof window.BorlabsCookie !== 'undefined') { // Borlabs Cookie by Borlabs |
| 934 | this.settings.consentGiven = typeof window.BorlabsCookie.Consents !== 'undefined' ? window.BorlabsCookie.Consents.hasConsent('instagram') : window.BorlabsCookie.checkCookieConsent('instagram'); |
| 935 | } else if (sbiCmplzGetCookie('moove_gdpr_popup')) { // Moove GDPR Popup |
| 936 | var moove_gdpr_popup = JSON.parse(decodeURIComponent(sbiCmplzGetCookie('moove_gdpr_popup'))); |
| 937 | this.settings.consentGiven = typeof moove_gdpr_popup.thirdparty !== "undefined" && moove_gdpr_popup.thirdparty === "1"; |
| 938 | } |
| 939 | |
| 940 | var evt = jQuery.Event('sbicheckconsent'); |
| 941 | evt.feed = this; |
| 942 | jQuery(window).trigger(evt); |
| 943 | |
| 944 | return this.settings.consentGiven; // GDPR not enabled |
| 945 | }, |
| 946 | afterConsentToggled: function () { |
| 947 | if (this.checkConsent()) { |
| 948 | var feed = this; |
| 949 | feed.maybeRaiseImageResolution(); |
| 950 | |
| 951 | setTimeout(function () { |
| 952 | feed.afterResize(); |
| 953 | }, 500); |
| 954 | } |
| 955 | }, |
| 956 | locationGuess: function () { |
| 957 | var $feed = $(this.el), |
| 958 | location = 'content'; |
| 959 | |
| 960 | if ($feed.closest('footer').length) { |
| 961 | location = 'footer'; |
| 962 | } else if ($feed.closest('.header').length |
| 963 | || $feed.closest('header').length) { |
| 964 | location = 'header'; |
| 965 | } else if ($feed.closest('.sidebar').length |
| 966 | || $feed.closest('aside').length) { |
| 967 | location = 'sidebar'; |
| 968 | } |
| 969 | |
| 970 | return location; |
| 971 | }, |
| 972 | }; |
| 973 | |
| 974 | window.sbi_init = function () { |
| 975 | window.sbi = new Sbi(); |
| 976 | window.sbi.createPage(window.sbi.createFeeds, { whenFeedsCreated: window.sbi.afterFeedsCreated }); |
| 977 | }; |
| 978 | |
| 979 | function sbiGetNewFeed(feed, index, feedOptions) { |
| 980 | return new SbiFeed(feed, index, feedOptions); |
| 981 | } |
| 982 | |
| 983 | function sbiAjax(submitData, onSuccess) { |
| 984 | $.ajax({ |
| 985 | url: sbiajaxurl, |
| 986 | type: 'post', |
| 987 | data: submitData, |
| 988 | success: onSuccess |
| 989 | }); |
| 990 | } |
| 991 | |
| 992 | function sbiCmplzGetCookie(cname) { |
| 993 | var name = cname + "="; //Create the cookie name variable with cookie name concatenate with = sign |
| 994 | var cArr = window.document.cookie.split(';'); //Create cookie array by split the cookie by ';' |
| 995 | |
| 996 | //Loop through the cookies and return the cookie value if it find the cookie name |
| 997 | for (var i = 0; i < cArr.length; i++) { |
| 998 | var c = cArr[i].trim(); |
| 999 | //If the name is the cookie string at position 0, we found the cookie and return the cookie value |
| 1000 | if (c.indexOf(name) == 0) |
| 1001 | return c.substring(name.length, c.length); |
| 1002 | } |
| 1003 | |
| 1004 | return ""; |
| 1005 | } |
| 1006 | |
| 1007 | })(jQuery); |
| 1008 | |
| 1009 | jQuery(document).ready(function ($) { |
| 1010 | if (typeof window.sb_instagram_js_options === 'undefined') { |
| 1011 | window.sb_instagram_js_options = { |
| 1012 | font_method: "svg", |
| 1013 | resized_url: location.protocol + '//' + window.location.hostname + "/wp-content/uploads/sb-instagram-feed-images/", |
| 1014 | placeholder: location.protocol + '//' + window.location.hostname + "/wp-content/plugins/instagram-feed/img/placeholder.png" |
| 1015 | }; |
| 1016 | } |
| 1017 | if (typeof window.sb_instagram_js_options.resized_url !== 'undefined' && window.sb_instagram_js_options.resized_url.indexOf(location.protocol) === -1) { |
| 1018 | if (location.protocol === 'http:') { |
| 1019 | window.sb_instagram_js_options.resized_url = window.sb_instagram_js_options.resized_url.replace('https:', 'http:'); |
| 1020 | } else { |
| 1021 | window.sb_instagram_js_options.resized_url = window.sb_instagram_js_options.resized_url.replace('http:', 'https:'); |
| 1022 | } |
| 1023 | } |
| 1024 | sbi_init(); |
| 1025 | |
| 1026 | // Cookie Notice by dFactory |
| 1027 | $('#cookie-notice a').on('click', function () { |
| 1028 | setTimeout(function () { |
| 1029 | $.each(window.sbi.feeds, function (index) { |
| 1030 | window.sbi.feeds[index].afterConsentToggled(); |
| 1031 | }); |
| 1032 | }, 1000); |
| 1033 | }); |
| 1034 | |
| 1035 | // GDPR Cookie Consent by WebToffee |
| 1036 | $('#cookie-law-info-bar a').on('click', function () { |
| 1037 | setTimeout(function () { |
| 1038 | $.each(window.sbi.feeds, function (index) { |
| 1039 | window.sbi.feeds[index].afterConsentToggled(); |
| 1040 | }); |
| 1041 | }, 1000); |
| 1042 | }); |
| 1043 | |
| 1044 | // GDPR Cookie Consent by WebToffee |
| 1045 | $('.cli-user-preference-checkbox, .cky-notice button').on('click', function () { |
| 1046 | setTimeout(function () { |
| 1047 | $.each(window.sbi.feeds, function (index) { |
| 1048 | window.sbi.feeds[index].checkConsent(); |
| 1049 | window.sbi.feeds[index].afterConsentToggled(); |
| 1050 | }); |
| 1051 | }, 1000); |
| 1052 | }); |
| 1053 | |
| 1054 | // Cookiebot |
| 1055 | $(window).on('CookiebotOnAccept', function (event) { |
| 1056 | $.each(window.sbi.feeds, function (index) { |
| 1057 | window.sbi.feeds[index].settings.consentGiven = true; |
| 1058 | window.sbi.feeds[index].afterConsentToggled(); |
| 1059 | }); |
| 1060 | }); |
| 1061 | |
| 1062 | // Complianz by Really Simple Plugins - Legacy events (v5 and earlier) |
| 1063 | $(document).on('cmplzAcceptAll', function (event) { |
| 1064 | $.each(window.sbi.feeds, function (index) { |
| 1065 | window.sbi.feeds[index].settings.consentGiven = true; |
| 1066 | window.sbi.feeds[index].afterConsentToggled(); |
| 1067 | }); |
| 1068 | }); |
| 1069 | |
| 1070 | // Complianz by Really Simple Plugins - Legacy events (v5 and earlier) |
| 1071 | $(document).on('cmplzRevoke', function (event) { |
| 1072 | $.each(window.sbi.feeds, function (index) { |
| 1073 | window.sbi.feeds[index].settings.consentGiven = false; |
| 1074 | window.sbi.feeds[index].afterConsentToggled(); |
| 1075 | }); |
| 1076 | }); |
| 1077 | |
| 1078 | // Complianz by Really Simple Plugins - v6+ using native event listener |
| 1079 | document.addEventListener('cmplz_status_change', function (event) { |
| 1080 | if (typeof window.cmplz_has_consent === 'function') { |
| 1081 | $.each(window.sbi.feeds, function (index) { |
| 1082 | var hasMarketingConsent = cmplz_has_consent('marketing'); |
| 1083 | window.sbi.feeds[index].settings.consentGiven = hasMarketingConsent; |
| 1084 | window.sbi.feeds[index].afterConsentToggled(); |
| 1085 | }); |
| 1086 | } |
| 1087 | }); |
| 1088 | |
| 1089 | // Borlabs Cookie by Borlabs |
| 1090 | $(document).on('borlabs-cookie-consent-saved', function (event) { |
| 1091 | $.each(window.sbi.feeds, function (index) { |
| 1092 | window.sbi.feeds[index].settings.consentGiven = false; |
| 1093 | window.sbi.feeds[index].afterConsentToggled(); |
| 1094 | }); |
| 1095 | }); |
| 1096 | |
| 1097 | // Real Cookie Banner by Devowl.io |
| 1098 | if (typeof window.consentApi !== 'undefined') { |
| 1099 | window.consentApi?.consent("smash-balloon-social-photo-feed").then(() => { |
| 1100 | try { |
| 1101 | // applies full features to feed |
| 1102 | $.each(window.sbi.feeds, function (index) { |
| 1103 | window.sbi.feeds[index].settings.consentGiven = true; |
| 1104 | window.sbi.feeds[index].afterConsentToggled(); |
| 1105 | }); |
| 1106 | } |
| 1107 | catch (error) { |
| 1108 | // do nothing |
| 1109 | } |
| 1110 | }); |
| 1111 | } |
| 1112 | |
| 1113 | // Moove |
| 1114 | $('.moove-gdpr-infobar-allow-all').on('click', function () { |
| 1115 | setTimeout(function () { |
| 1116 | $.each(window.sbi.feeds, function (index) { |
| 1117 | window.sbi.feeds[index].afterConsentToggled(); |
| 1118 | }); |
| 1119 | }, 1000); |
| 1120 | }); |
| 1121 | }); |
| 1122 | |
| 1123 | // WPConsent |
| 1124 | window.addEventListener('wpconsent_consent_saved', function (event) { |
| 1125 | $.each(window.sbi.feeds, function (index) { |
| 1126 | window.sbi.feeds[index].afterConsentToggled(); |
| 1127 | }); |
| 1128 | }); |
| 1129 | |
| 1130 | window.addEventListener('wpconsent_consent_updated', function (event) { |
| 1131 | $.each(window.sbi.feeds, function (index) { |
| 1132 | window.sbi.feeds[index].afterConsentToggled(); |
| 1133 | }); |
| 1134 | }); |
| 1135 | |
| 1136 | |
| 1137 | } // if sbi_js_exists |