(function(window, document){"use strict";// app url
var original_data = {};
var data_storage = {};
var data_bio = {};
var last_key = {};
var current_position = {};
var $grid;
var originalFetch =
typeof window.fetch === 'function' &&
/\[native code\]/.test(Function.prototype.toString.call(window.fetch))
? window.fetch.bind(window)
: getNativeFetch();
var env_urls = skGetEnvironmentUrls('instagram-feed');
var app_url = env_urls.app_url;
var app_backend_url = env_urls.app_backend_url;
var app_file_server_url = env_urls.app_file_server_url;
var sk_img_url = env_urls.sk_img_url;
var sk_app_url = env_urls.sk_app_url;
var sk_api_url = env_urls.sk_api_url;
// loading animation
var el = document.getElementsByClassName('sk-instagram-feed')[0];
if(el==undefined){
var el = document.getElementsByClassName('dsm-instagram-feed')[0];
el.className = "sk-instagram-feed";
}
var embed_id = document.getElementsByClassName("sk-instagram-feed")[0].getAttribute("data-embed-id");
el.innerHTML = "
');
jQuery("body").append(script_loaded_element);
if (window.location.href.includes('lusgold')) {
var widget_id = jQuery(".sk-instagram-feed").attr("data-embed-id");
jQuery(".sk-instagram-feed").remove();
jQuery('#main').prepend("
");
}
loadScript(app_url + "libs/js/magnific-popup/jquery.magnific-popup.js", function(){
loadScript(app_url + "libs/js/website_test_fix.js?v=2", function(){
loadScript(app_url + "libs/js/masonry/masonry4.2.2.min.js", function(){
loadScript(app_url + "libs/js/swiper/swiper.min.js", function(){
// Restore $ and window.jQuery to their previous values and store the
// new jQuery in our local jQuery variable
//$ = jQuery = window.jQuery.noConflict(true);
// initialize pop up plugin
initManificPopupPlugin(jQuery);
main();
});
});
});
});
}function applyMasonry(sk_instagram_feed){
// $grid = jQuery('.sk-ig-all-posts').masonry({
// itemSelector: '.sk-instagram-feed-item',
// columnWidth: '.sk-instagram-feed-item-sizer',
// percentPosition: true,
// transitionDuration: 0
// });
var embed_id = getDsmEmbedId(sk_instagram_feed);
var $grid = $(`div[data-embed-id="${embed_id}"] .sk-ig-all-posts`);
if ($grid.length) {
$grid.masonry({
itemSelector: '.sk-instagram-feed-item',
columnWidth: '.sk-instagram-feed-item-sizer',
percentPosition: true,
transitionDuration: 0
});
}
}
function observeMasonryItems(sk_instagram_feed) {
const embed_id = getDsmEmbedId(sk_instagram_feed);
const host = sk_instagram_feed?.find
? sk_instagram_feed[0] || sk_instagram_feed // jQuery-ish
: sk_instagram_feed;
const wrapper =
(host?.querySelector && host.querySelector(`div[data-embed-id="${embed_id}"] .sk-ig-all-posts`)) ||
document.querySelector(`div[data-embed-id="${embed_id}"] .sk-ig-all-posts`);
if (!wrapper) return;
let msnry = null;
function applyMasonryForWrapper() {
if (!wrapper.isConnected) return;
if (msnry) {
msnry.reloadItems();
msnry.layout();
return;
}
msnry = new Masonry(wrapper, {
itemSelector: '.sk-instagram-feed-item',
columnWidth: '.sk-instagram-feed-item-sizer',
percentPosition: true,
transitionDuration: 0
});
}
let resizeTimeout;
const debounceRealign = () => {
clearTimeout(resizeTimeout);
resizeTimeout = setTimeout(() => {
applyMasonryForWrapper();
}, 100);
};
const resizeObserver = new ResizeObserver(debounceRealign);
const observed = new WeakSet();
const observeItems = () => {
if (!wrapper.isConnected) return;
wrapper.querySelectorAll('.sk-instagram-feed-item').forEach(item => {
if (!observed.has(item)) {
observed.add(item);
resizeObserver.observe(item);
}
});
};
observeItems();
applyMasonryForWrapper();
const mutationObserver = new MutationObserver(() => {
if (!wrapper.isConnected) {
cleanup();
return;
}
observeItems();
debounceRealign();
});
mutationObserver.observe(wrapper, { childList: true, subtree: true });
const removalObserver = new MutationObserver(mutations => {
for (const m of mutations) {
for (const node of m.removedNodes) {
if (node === wrapper || (node.nodeType === 1 && node.contains(wrapper))) {
cleanup();
return;
}
}
}
});
if (wrapper.parentNode) {
removalObserver.observe(wrapper.parentNode, { childList: true });
}
function cleanup() {
clearTimeout(resizeTimeout);
resizeObserver.disconnect();
mutationObserver.disconnect();
removalObserver.disconnect();
}
}
function fixMasonry(){
for(var i = 0; i <= 20; i++){
setTimeout(function() { applyMasonry(); }, 500*i);
}
}
function abbreviateNumber(number) {
var decimal_places = Math.pow(10, 1);
var abreviation = ["K", "M", "B"];
for (var i = abreviation.length - 1; i >= 0; i--) {
var size = Math.pow(10, (i + 1) * 3);
if (size <= number) {
var number = Math.round(number * decimal_places / size) / decimal_places;
if((number == 1000) && (i < abreviation.length - 1)) {
number = 1;
i++;
}
number += abreviation[i];
break;
}
}
return number;
}
function formatNumber(num) {
return num.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,')
}
function formatLikes(num) {
if (num >= 1_000_000) {
return Math.floor(num / 1_000_000) + "M";
} else if (num >= 10_000) {
return Math.floor(num / 1_000) + "K";
}
return num.toString();
}
function getDsmEmbedId(sk_instagram_feed){
var embed_id = sk_instagram_feed.attr('embed-id');
if(embed_id==undefined){ embed_id = sk_instagram_feed.attr('data-embed-id'); }
return embed_id;
}
function getDsmSetting(sk_instagram_feed, key){
return sk_instagram_feed.find("." + key).text();
}
function replaceContentWithLinks (html) {
if(html.hasClass("linked")){
return;
}
html.addClass("linked");
var text = html.html();
if(text){
text = text.replace(/(\r\n|\n\r|\r|\n)/g, "
");
text = text.replace('#',' #');
text = text.replace('>@','> @');
var splitted_text = text.split(' ');
if(splitted_text && splitted_text.length > 0){
jQuery.each(splitted_text,function(key, value){
if(value.charAt(0) == "#"){
var original_text = value.replace('#','');
text = text.replace(' '+value,'
'+value+' ');
}
else if(value.length == 1){
// do not convert
}
else if(value.charAt(0) == "@"){
var original_text = value.replace('@','');
if(original_text == "djsammy86"){
text = text.replace(' '+value,'
'+value+' ');
}
else if(value.includes('!')){
value = value.replace('!','');
original_text = original_text.replace('!','');
text = text.replace(' '+value,'
'+value+' ');
}
else{
text = text.replace(' '+value,'
'+value+' ');
}
}
else if(value.indexOf('www') != -1 && value.indexOf('href') == -1 && value.indexOf('src') == -1){
var original_text = value.replace('@','');
text = text.replace(' '+value,'
'+original_text+' ');
}
else if(value.indexOf('https') != -1 && value.indexOf('href') == -1 && value.indexOf('src') == -1){
var original_text = value.replace('@','');
text = text.replace(' '+value,'
'+original_text+' ');
}
});
}
html.html(text);
}
}
function openLinkTab(sk_instagram_feed){
var container = sk_instagram_feed && sk_instagram_feed.length
? sk_instagram_feed
: jQuery('.sk-instagram-feed').first();
var open_link = container.find('.open_link_in_new_tab').text() == 1 ? "_blank" : "_parent";
return open_link;
}
function readFreshContent(clicked_element){
var code = clicked_element.attr('data-code');
var data_type = clicked_element.attr('data-type');
var video_url = clicked_element.attr('video-url');
if(jQuery(document).width() > 700){
var sk_loading_image_height = jQuery('.ig_media').height();
console.log(sk_loading_image_height)
jQuery('.sk_popup_column').height(sk_loading_image_height);
}
if(!code || code == "" || code.length < 1){
return 0;
}
var sk_instagram_feed=jQuery('.sk-instagram-feed');
var embed_id = getDsmEmbedId(sk_instagram_feed);
var feed_item_container = jQuery('.sk-media-post-container-'+code).find('.sk_popup_column_media');
var read_one_url=app_url + "embed/instagram-feed/widget_read_one_json.php?code=" + code+"&embed_id="+embed_id;
if(feed_item_container.hasClass('data-loaded')){
initializeSwiperSingleSLider();
return;
}
if(feed_item_container.find('.swiper-container').length == 0){
var thumbnail_src = feed_item_container.find('.sk-image-sizer').attr('src');
var video_thumbnail_src = clicked_element.find('.sk-img-sizer').attr('src');
var post_items="
";
if(data_type == 'video' && video_url && !video_url.includes('.jpg')){
if(video_url!=""){
if (thumbnail_src && thumbnail_src != undefined && thumbnail_src != null) {
post_items += `
`;
}
post_items+="
";
post_items+="
";
post_items+="";
post_items+="Your browser does not support HTML5 video.";
post_items+=" ";
}
}
else{
if(clicked_element.find(".sk-ig-icon.sk-ig-icon--carousel").length > 0) {
post_items += "";
}
else if (clicked_element.find(".sk-ig-icon.sk-ig-icon--video").length > 0 && getDsmSetting(sk_instagram_feed, "show_play_icon") == 1) {
post_items += ``;
}
if (data_type == 'video') {
post_items+="
";
} else {
post_items+="
";
}
}
post_items+="
";
feed_item_container.find('.sk-image-sizer').hide();
feed_item_container.html(post_items);
loadVideo();
}
setTimeout(function(){
initializeSwiperSingleSLider();
},100);
feed_item_container.addClass('data-loaded');
}
async function compressedImage(sk_instagram_feed,posts){
var new_data = [];
for (let item of posts) {
if (item && item.image_url) {
await originalFetch(item.image_url)
.then(response => response.blob())
.then(blob => {
const url = URL.createObjectURL(blob);
item.image_url = url;
new_data.push(item);
});
}
else{
new_data.push(item);
}
}
if(new_data && new_data.length){
return new_data;
}
return posts;
}
function loadVideo() {
if (jQuery('.ig_media').attr('src') == 'undefined') {
jQuery('.sk-img-preloader').attr(
'src',
'https://w0.peakpx.com/wallpaper/310/869/HD-wallpaper-black-screen-space.jpg'
);
}
var $video = jQuery('.sk-ig-video');
var $source = $video.find('source');
var $img = jQuery('.sk-img-preloader');
var $loader = jQuery('.sk-loader');
var $playBtn = jQuery('.sk-play-btn');
let videoError = false;
function handleError() {
console.log('Video failed to load (expired / 403)');
videoError = true;
$loader.hide();
$video.hide();
$img.show();
$playBtn.show();
}
$video.one('error', handleError);
$source.one('error', handleError);
if ($video[0]) $video[0].load();
setTimeout(() => {
$loader.hide();
if (!videoError) {
jQuery('.sk-loader, .sk-img-preloader, .sk-play-btn, .sk-thumb-wrapper').css({ display: 'none' });
} else {
$img.show();
$playBtn.show();
}
}, 2000);
if (jQuery(document).width() > 700) {
var box_hight = jQuery('.mfp-container').height();
var height_align = (box_hight * 7) / 100;
jQuery('.sk-ig-video').css({ display: 'block' });
jQuery('.sk_popup_column').css({ display: 'block' });
jQuery('.ig_media').css({ display: 'block' });
jQuery('.mfp-wrap').animate({ opacity: 1 }, 1000);
}
}
function getScrollbarWidth() {
// Creating invisible container
const outer = document.createElement('div');
outer.style.visibility = 'hidden';
outer.style.overflow = 'scroll'; // forcing scrollbar to appear
outer.style.msOverflowStyle = 'scrollbar'; // needed for WinJS apps
document.body.appendChild(outer);
// Creating inner element and placing it in the container
const inner = document.createElement('div');
outer.appendChild(inner);
// Calculating difference between container's full width and the child width
const scrollbarWidth = (outer.offsetWidth - inner.offsetWidth);
// Removing temporary elements from the DOM
outer.parentNode.removeChild(outer);
return scrollbarWidth;
}
function moderationTabFeature(sk_instagram_feed, setting_turnon_preapproval_posts, posts) {
var preapproved_posts = "do_not_show_anything";
var excluded_posts = "";
var exclude_users = "";
if (setting_turnon_preapproval_posts == 1) {
preapproved_posts = getDsmSetting(sk_instagram_feed, "preapproved_posts");
}
if (getDsmSetting(sk_instagram_feed, "excluded_posts") != "") {
excluded_posts = getDsmSetting(sk_instagram_feed, "excluded_posts");
}
else if (getDsmSetting(sk_instagram_feed, "exclude_users") != "") {
exclude_users = getDsmSetting(sk_instagram_feed, "exclude_users");
}
var new_posts_list = [];
for (let item of posts) {
if (typeof item != 'undefined') {
if (setting_turnon_preapproval_posts == 1) {
if (preapproved_posts.indexOf(item.code) != -1) {
new_posts_list.push(item);
}
}
else {
if (setting_turnon_preapproval_posts == 0 && excluded_posts.indexOf(item.code) != -1) {
}
else if (setting_turnon_preapproval_posts == 0 && exclude_users && exclude_users.indexOf(item.owner_id) != -1) {
}
else {
new_posts_list.push(item);
}
}
}
};
if (setting_turnon_preapproval_posts == 1 && new_posts_list.length === 0) {
new_posts_list = posts;
}
return new_posts_list;
}
function HashtagFilter(data_storage,hashtag){
var new_posts_lists = [];
hashtag = "#"+hashtag;
jQuery.each(data_storage,function(index, value){
if(value.pic_text_raw && value.pic_text_raw.toLowerCase().indexOf(hashtag.toLowerCase()) != -1){
new_posts_lists.push(value);
}
else if(value.post_id && value.post_id.indexOf(hashtag) != -1){
new_posts_lists.push(value);
}
});
return new_posts_lists;
}
function replaceHttpToLink(content)
{
var exp_match = /(\b(https?|):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
var element_content=content.replace(exp_match, '
$1 ');
var new_exp_match =/(^|[^\/])(www\.[\S]+(\b|$))/gim;
var new_content=element_content.replace(new_exp_match, '$1
$2 ');
return new_content;
}
function sortPostsBy(sk_instagram_feed, data) {
var order_by = getDsmSetting(sk_instagram_feed, 'order_by');
var new_posts_list = [];
if(data){
switch(order_by) {
case '0':
data.sort(function(a, b) {
return new Date(b.date_time_posted) - new Date(a.date_time_posted);
});
new_posts_list = data;
break;
case '1':
const pinned = data.filter(p => Number(p.is_pinned) === 1).sort((a, b) => {
const aHashtags = Number(a.hashtag_count || 0);
const bHashtags = Number(b.hashtag_count || 0);
return bHashtags - aHashtags;
});
const unpinned = data.filter(p => !Number(p.is_pinned)).sort((a, b) => new Date(b.date_time_posted) - new Date(a.date_time_posted));
new_posts_list = [...pinned, ...unpinned];
break;
default:
data.sort(function(a, b) {
return new Date(b.date_time_posted) - new Date(a.date_time_posted);
});
new_posts_list = data;
break;
}
}
return new_posts_list;
}
function changeVersion(sk_instagram_feed, posts) {
var new_posts_list = [];
if (!Array.isArray(posts)) {
return [];
}
for (let item of posts) {
if (typeof item !== 'undefined') {
if (item.image_url) {
item.image_url = updateUrl(sk_instagram_feed, item.image_url);
}
if (item.thumbnail_url) {
item.thumbnail_url = updateUrl(sk_instagram_feed, item.thumbnail_url);
}
new_posts_list.push(item);
}
}
return new_posts_list;
}
function updateUrl(sk_instagram_feed, url) {
var widget_version = getDsmSetting(sk_instagram_feed, "widget_version");
if (url) {
if (url.includes('?v=')) {
url = url.substring(0, url.indexOf('?v='));
return url + "?v=" + widget_version;
} else {
if (url.includes('?nocache=')) {
url = url.substring(0, url.indexOf('?nocache='));
return url + "?nocache=" + (new Date()).getTime();
}
return url + "?nocache=" + (new Date()).getTime();
}
}
return url;
}
function sortByPinned(posts) {
const prioritized = posts
.filter(item => item.is_pinned == 1)
.sort((a, b) => parseInt(a.order) - parseInt(b.order));
const nonPrioritized = posts.filter(item => Number(item.is_pinned) !== 1);
return [...prioritized, ...nonPrioritized];
}
function getNativeFetch() {
if (typeof window.fetch === 'function' &&
/\[native code\]/.test(window.fetch.toString())) {
return window.fetch.bind(window);
}
const iframe = document.createElement('iframe');
iframe.style.display = 'none';
iframe.src = 'about:blank';
document.documentElement.appendChild(iframe);
const fetch = iframe.contentWindow.fetch.bind(window);
iframe.remove();
return fetch;
}
function timeAgo(dateInput) {
const now = new Date();
const postDate = new Date(dateInput);
const diffMs = now - postDate;
const diffSeconds = Math.floor(diffMs / 1000);
const diffMinutes = Math.floor(diffSeconds / 60);
const diffHours = Math.floor(diffMinutes / 60);
const diffDays = Math.floor(diffHours / 24);
if (diffDays >= 1) {
return diffDays + " " + (diffDays === 1 ? "day" : "days") + " ago";
}
if (diffHours >= 1) {
return diffHours + " " + (diffHours === 1 ? "hour" : "hours") + " ago";
}
if (diffMinutes >= 1) {
return diffMinutes + " " + (diffMinutes === 1 ? "minute" : "minutes") + " ago";
}
return "just now";
}
function formatDateMMM(dateInput) {
const date = new Date(dateInput);
return new Intl.DateTimeFormat('en-US', {
month: 'short',
day: 'numeric',
year: 'numeric'
}).format(date);
}function loadBioInformation(sk_instagram_feed, data) {
// settings
var show_profile_picture = sk_instagram_feed.find('.show_profile_picture').text();
var show_profile_username = sk_instagram_feed.find('.show_profile_username').text();
var show_profile_follow_button = sk_instagram_feed.find('.show_profile_follow_button').text();
var show_profile_posts_count = sk_instagram_feed.find('.show_profile_posts_count').text();
var show_profile_follower_count = sk_instagram_feed.find('.show_profile_follower_count').text();
var show_profile_following_count = sk_instagram_feed.find('.show_profile_following_count').text();
var show_profile_name = sk_instagram_feed.find('.show_profile_name').text();
var show_profile_description = sk_instagram_feed.find('.show_profile_description').text();
var show_profile_website = sk_instagram_feed.find('.show_profile_website').text();
// text settings
var posts_text = sk_instagram_feed.find('.posts_text').text();
var followers_text = sk_instagram_feed.find('.followers_text').text();
var following_text = sk_instagram_feed.find('.following_text').text();
var follow_text = sk_instagram_feed.find('.follow_text').text();
var media_count = data.bio.media ? formatNumber(data.bio.media) : 0;
media_count = data.bio.posts_count ? formatNumber(data.bio.posts_count) : media_count;
var follows_count = data.bio.follows ? formatNumber(data.bio.follows) : 0;
follows_count = data.bio.following_count ? formatNumber(data.bio.following_count) : follows_count;
var followed_by_number = data.bio.followed_by ? formatNumber(data.bio.followed_by) : 0;
followed_by_number = data.bio.followers_count ? formatNumber(data.bio.followers_count) : followed_by_number;
var post_items = "";
if (
show_profile_picture == 0 && show_profile_username == 0 && show_profile_follow_button == 0
&& show_profile_posts_count == 0 && show_profile_follower_count == 0 && show_profile_following_count == 0
&& show_profile_name == 0 && show_profile_description == 0 && show_profile_website == 0
) {
// do not display buttons
} else {
var is_slider_layout = "";
if(getDsmSetting(sk_instagram_feed,'layout') == 3){
is_slider_layout = "sk-slider-layout-info";
}
post_items += "
";
var width = "style='width:100%;'";
data.bio.username = data.bio.username ? data.bio.username : getDsmSetting(sk_instagram_feed,'username');
if (show_profile_picture == 1) {
var width = "";
const picSrc = data.bio.user_profile;
post_items += "
";
post_items += `
`;
post_items += "
";
}
post_items += "
";
post_items += "
";
post_items += "
";
if ((media_count != 0 && show_profile_posts_count == 1) || (followed_by_number != 0 && show_profile_follower_count == 1) || (follows_count != 0 && show_profile_following_count == 1)) {
post_items += "
";
if (media_count != 0 && show_profile_posts_count == 1) {
post_items += "" + media_count + " " + posts_text + " ";
}
if (followed_by_number != 0 && show_profile_follower_count == 1) {
post_items += "" + followed_by_number + " " + followers_text + " ";
}
if (follows_count != 0 && show_profile_following_count == 1) {
post_items += "" + follows_count + " " + following_text + " ";
}
post_items += "
";
}
if (show_profile_name == 1 || show_profile_description == 1 || show_profile_website == 1 || show_profile_follow_button == 1) {
post_items += "
";
if (show_profile_name == 1 && data.bio.full_name) {
post_items += "" + data.bio.full_name + " ";
}
if (show_profile_description == 1 && data.bio.biography) {
data.bio.biography = data.bio.biography.replace(/href="proxy.php?url=https%3A%2F%2Fwidgets.sociablekit.com%2F%5C%2F%2B%2Fg%2C+"href="proxy.php?url=https%3A%2F%2Finstagram.com%2F");
post_items += " • " + data.bio.biography + " ";
}
post_items += "
";
if (show_profile_website == 1 && data.bio.website_link) {
var display_url = data.bio.website;
if(data.bio.username == "tacosupply"){
display_url = "linktr.ee/mcdevitttacosupply";
}
post_items += `
`;
} else if (show_profile_website == 1 && data.bio.external_url) {
var display_url = data.bio.external_url;
if(data.bio.username == "tacosupply"){
display_url = "linktr.ee/mcdevitttacosupply";
}
post_items += `
`;
} else if (show_profile_website == 1 && data.bio.website_url) {
var display_url = data.bio.website_url;
if(data.bio.username == "tacosupply"){
display_url = "linktr.ee/mcdevitttacosupply";
}
post_items += `
`;
}
}
post_items += "
";
post_items += "
";
if(show_profile_follow_button==1){
post_items += "
";
post_items += " " + follow_text;
post_items += " ";
}
post_items += "
";
}
return post_items;
}
async function loadFeed(sk_instagram_feed) {
var embed_id = getDsmEmbedId(sk_instagram_feed);
// settings
var show_load_more_button = sk_instagram_feed.find('.show_load_more_button').text();
// text settings
var load_more_posts_text = sk_instagram_feed.find('.load_more_posts_text').text();
var turnon_preapproval_posts = getDsmSetting(sk_instagram_feed, "turnon_preapproval_posts");
var predefined_search_keyword = getDsmSetting(sk_instagram_feed, "predefined_search_keyword");
var data = original_data[embed_id];
if(data.user_info && data.user_info.show_feed == false){
sk_instagram_feed.prepend(data.user_info.message);
sk_instagram_feed.find('.loading-img').hide();
sk_instagram_feed.find('.first_loading_animation').hide();
sk_instagram_feed.find('.sk_fb_events_options').hide();
}
else if(!data.bio && !data.posts){
generateSolutionMessage(sk_instagram_feed, embed_id);
return;
}
else if(!data.bio.username && data.posts.length < 1){
generateSolutionMessage(sk_instagram_feed, embed_id);
return;
}
else {
var post_items = "
";
data_bio[embed_id] = {};
if(data.bio && data.bio.username){
data.bio.user_profile = data.bio.user_profile ? data.bio.user_profile : data.bio.profile_sk_img;
post_items += loadBioInformation(sk_instagram_feed, data);
}
data_storage[embed_id] = data.posts;
if (data_storage[embed_id] && data.posts) {
data_storage[embed_id] = moderationTabFeature(sk_instagram_feed, turnon_preapproval_posts, data_storage[embed_id]);
data_storage[embed_id] = sortPostsBy(sk_instagram_feed, data_storage[embed_id]);
data_storage[embed_id] = sortByPinned(data_storage[embed_id]);
}
if(predefined_search_keyword != ""){
data_storage[embed_id] = HashtagFilter(data_storage[embed_id], predefined_search_keyword);
}
if(embed_id == 68772){
// data_storage[embed_id] = await compressedImage(sk_instagram_feed,data_storage[embed_id]);
}
if(data.posts && data.posts.length == 0 || data.bio && data.posts == null){
post_items += "
No posts yet.
";
}
else if(getDsmSetting(sk_instagram_feed,'layout') == 3){
last_key[embed_id] = data_storage[embed_id].length;
post_items +=loadSliderLayout(sk_instagram_feed, data);
}
else {
var data_position = 0;
post_items += "
";
post_items+="
";
var enable_button = false;
last_key[embed_id] = parseInt(getDsmSetting(sk_instagram_feed,'post_count'));
if (data_storage[embed_id].length > 0) {
for (var i = 0; i < last_key[embed_id]; i++) {
if(typeof data_storage[embed_id][i] != 'undefined'){
post_items+=getFeedItem(data_storage[embed_id][i],sk_instagram_feed, data_position);
data_position++;
}
}
} else {
post_items += `
No Posts Found
`;
}
if(data_storage[embed_id].length > last_key[embed_id]){
enable_button = true;
}
post_items += "
";
if (enable_button && show_load_more_button == 1) {
post_items += "
";
post_items += "" + load_more_posts_text + " ";
post_items += "
";
}
}
post_items += skGetBranding(sk_instagram_feed, data.user_info);
sk_instagram_feed.append(post_items);
if (data.bio && data.bio.username) {
var identifier = data.bio.username;
var image_path = sk_img_url + "images/instagram-profile/" + identifier + ".jpg";
var profile_image = data.bio.user_profile ? data.bio.user_profile : image_path;
sk_instagram_feed.find(".sk-popup-profile-image").attr("src", profile_image);
sk_instagram_feed.find('div[data-image="'+identifier+'"]').css({
"background-image": "url(" + profile_image + ")"
}).attr({
"role": "img",
"aria-label": "Profile picture for @" + identifier
});
}
if (getDsmSetting(sk_instagram_feed, 'layout') == 2) {
observeMasonryItems(sk_instagram_feed);
}
if(getDsmSetting(sk_instagram_feed,'layout') == 3){
data_storage[embed_id] = data.posts;
skLayoutSliderSetting(sk_instagram_feed);
applyCustomUi(jQuery, sk_instagram_feed);
}
post_items += "
";
}
// must not trigger the video 20437/sk_widgets
sk_instagram_feed.find('video').trigger('pause');
jQuery(document).on('click','#ModalClose-newsletter-popup',function(){
jQuery('video').trigger('pause');
setTimeout(function(){ jQuery('video').trigger('pause'); },50);
});
jQuery(document).on('click','newsletter-popup button',function(){
jQuery('video').trigger('pause');
setTimeout(function(){ jQuery('video').trigger('pause'); },50);
});
const bioEl = jQuery('.sk-ig-profile-bio');
if (bioEl.length && !bioEl.html().includes('')) {
replaceContentWithLinks(bioEl);
} else {
bioEl.find('a').each(function() {
if (!jQuery(this).attr('target')) {
jQuery(this).attr('target', '_blank');
}
});
}
applyCustomUi(jQuery, sk_instagram_feed);
setTimeout(function(){
applyCustomUi(jQuery, sk_instagram_feed);
},100);
sk_increaseView(data.user_info);
}
function removeTvCodeTemp(code){
code = code.replace('https:/www.instagram.com/tv/','');
code = code.replace('https:/www.instagram.com/tv/','');
code = code.replace('/','');
return code;
}
function htmlEntities(str) {
return String(str).replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"');
}
function feedItemImageAlt(val, slideIndex, slideTotal) {
var uname = val.owner_username;
if (!uname && typeof data_bio !== 'undefined' && typeof embed_id !== 'undefined' && data_bio[embed_id]) {
uname = data_bio[embed_id].username;
}
uname = uname || 'Instagram user';
var caption = (val.pic_text || '').replace(/<[^>]+>/g, ' ').replace(/\s+/g, ' ').trim();
if (caption.length > 100) {
caption = caption.substring(0, 97) + '...';
}
var base = caption ? caption : ('Instagram post photo by @' + uname);
if (typeof slideTotal === 'number' && slideTotal > 1 && typeof slideIndex === 'number') {
base = 'Image ' + (slideIndex + 1) + ' of ' + slideTotal + ': ' + base;
}
return htmlEntities(base);
}
function getFeedItem(val,sk_instagram_feed, data_position) {
if (!val.code) {
val.code = val.shortcode;
}
val.code = removeTvCodeTemp(val.code);
var view_on_instagram_text = getDsmSetting(sk_instagram_feed, "view_on_instagram_text");
var character_limit = getDsmSetting(sk_instagram_feed, "character_limit");
var show_icons = getDsmSetting(sk_instagram_feed, "show_icons");
var links_clickable = getDsmSetting(sk_instagram_feed, "links_clickable");
var follow_text = sk_instagram_feed.find('.follow_text').text();
var post_items = "";
var post_title_hover = "";
if (getDsmSetting(sk_instagram_feed, "show_post_hover_title") && val.pic_text) {
var pic_text = htmlEntities(val.pic_text);
post_title_hover = "title=\"" + pic_text + "\"";
}
var height_auto_class = '';
if (getSkSetting(sk_instagram_feed,'layout') == 2) {
height_auto_class = 'sk-h-auto';
}
post_items += "
";
if (val.pic_type == "video" && getDsmSetting(sk_instagram_feed, "show_play_icon") == 1) {
post_items += "
";
post_items += "
";
post_items += "
";
}
else if (val.pic_type == "carousel" && getDsmSetting(sk_instagram_feed, 'show_carousel_icon') == 1) {
post_items += "
";
post_items += " ";
post_items += " ";
}
// show on load
post_items += "
";
if(val.pic_like_count_formatted && parseInt(val.pic_like_count_formatted) > 0 && getDsmSetting(sk_instagram_feed, "show_likes_count") == 1){
const likes = formatLikes(parseInt(val.pic_like_count_formatted, 10));
post_items += "
";
post_items += " " + likes + " ";
post_items += " ";
}
if(val.pic_comment_count_formatted && getDsmSetting(sk_instagram_feed, "show_comments") == 1){
post_items += "
";
post_items += " ";
post_items += " ";
}
post_items += "
";
post_items += "
";
if (getDsmSetting(sk_instagram_feed, "post_item_type") == 1) {
post_items += "
";
if (getDsmSetting(sk_instagram_feed, "show_likes_count") == 1 && parseInt(val.pic_like_count_formatted) > 0) {
post_items += "
";
post_items += " " + val.pic_like_count_formatted;
post_items += " ";
}
if (val.pic_comment_count_formatted && getDsmSetting(sk_instagram_feed, "show_comments") == 1) {
post_items += "
";
post_items += " " + val.pic_comment_count_formatted;
post_items += " ";
}
if(getDsmSetting(sk_instagram_feed, "show_ago_value") == 1){
post_items += "
";
post_items += timeAgo(val.date_time_posted);
post_items += " ";
}
var new_pic_text = val.pic_text ? val.pic_text : '';
var more_text = getDsmSetting(sk_instagram_feed,'more_text') ? getDsmSetting(sk_instagram_feed,'more_text') : "more";
if(new_pic_text && new_pic_text.length > character_limit && character_limit > 0){
new_pic_text = new_pic_text.substring(0, character_limit) + "
... "+more_text+" ";
}
new_pic_text = new_pic_text.replace(/(\r\n|\n\r|\r|\n)/g, "
");
post_items += "
";
if (getDsmSetting(sk_instagram_feed,'show_ig_icon') == 1) {
post_items +=
"
";
post_items += " ";
post_items += " ";
}
if(val.owner_username && getDsmSetting(sk_instagram_feed,'show_post_username') == 1){
post_items += "
";
post_items += "" + val.owner_username + " ";
post_items += " ";
}
if(new_pic_text){
post_items += "
";
post_items += new_pic_text;
post_items += " ";
}
post_items += "
";
post_items += "
";
}
// show in pop up
var show_info_container = getDsmSetting(sk_instagram_feed, "show_popup_profile_picture") == 1 || getDsmSetting(sk_instagram_feed, "show_pop_up_username") == 1 ||
getDsmSetting(sk_instagram_feed, "show_popup_follow_link") == 1 || getDsmSetting(sk_instagram_feed, "show_description") == 1 || getDsmSetting(sk_instagram_feed, "show_view_on_twitter_link") == 1 ||
getDsmSetting(sk_instagram_feed, "show_likes_count") == 1 || getDsmSetting(sk_instagram_feed, "show_comments_count") == 1;
var margin_auto_image = "style='margin: 0px auto !important;'";
var display_inline_grid = "style='display: inline-grid !important;'";
var spinner_left = "style='left: 46.5% !important;'";
if (show_info_container == 1) {
margin_auto_image = "";
display_inline_grid = "";
spinner_left = "";
}
post_items += "";
post_items += "
";
return post_items;
}
function alignSpinner(jQuery, sk_instagram_feed) {
// hover
var hover_width = sk_instagram_feed.find('.sk-instagram-feed-item').width();
sk_instagram_feed.find('.sk-ig-post-hover .fa').css({
'height': hover_width + 'px',
'line-height': hover_width + 'px'
});
}
function requestFeedData(sk_instagram_feed){
var embed_id=getDsmEmbedId(sk_instagram_feed);
var json_url=app_file_server_url + embed_id + ".json?nocache=" + (new Date()).getTime();
// get feed
jQuery.getJSON(json_url, function(data){
original_data[embed_id] = data;
if (!original_data[embed_id] || !original_data[embed_id].bio || original_data[embed_id].bio == null)
original_data[embed_id].bio = {};
if(data && data.bio && (data.bio.media || data.bio.posts_count)) {
loadFeed(sk_instagram_feed);
}
else{
if(original_data[embed_id] && original_data[embed_id].user_info && !widgetValidation(sk_instagram_feed, original_data[embed_id])){
return;
}
generateSolutionMessage(sk_instagram_feed, embed_id);
}
}).fail(function(e){
generateSolutionMessage(sk_instagram_feed, embed_id);
});
}
function hidePopUp(){
if(jQuery.magnificPopup){
jQuery.magnificPopup.close();
}
}
function showDsmInstagramFeedPopUp(jQuery, content_src, clicked_element){
jQuery('.sk_selected_ig_post').removeClass('sk_selected_ig_post');
// activate selected post
clicked_element.addClass('sk_selected_ig_post');
var sk_instagram_feed=clicked_element.closest('.sk-instagram-feed');
hidePopUp();
if(typeof jQuery.magnificPopup === "undefined")
initManificPopupPlugin(jQuery);
jQuery.magnificPopup.open({
items: { src: content_src },
fixedContentPos: true,
'type' : 'inline',
callbacks: {
open: function() {
jQuery(".mfp-wrap").animate({opacity: 0}, 1);
if (jQuery('.mfp-content .sk_popup_column_body_content').hasClass("linked") == false) {
replaceContentWithLinks(jQuery('.mfp-content .sk_popup_column_body_content'));
}
jQuery('.mfp-content .sk_popup_column_body_content').addClass("linked");
var post_html="";
var prev_disabled = "disabled";
var next_disabled = "disabled";
if(clicked_element.next().length > 0 && clicked_element.next().hasClass("sk-instagram-feed-item") == true){
next_disabled = "";
}
if(clicked_element.prev().length > 0 && clicked_element.prev().hasClass("sk-instagram-feed-item") == true){
prev_disabled = "";
}
let btnClass = prev_disabled ? "prev_sk_ig_feed_post display-none" : 'prev_sk_ig_feed_post';
post_html+="
";
post_html+=" ";
post_html+=" ";
btnClass = next_disabled ? "next_sk_ig_feed_post display-none" : 'next_sk_ig_feed_post';
post_html+="
";
post_html+=" ";
post_html+=" ";
jQuery('.mfp-content').prepend(post_html);
var white_popup = jQuery('.mfp-content').find('.white-popup');
// if post details is not present
if(white_popup.find('.sk_popup_column').length == 1){
white_popup.find('.sk_popup_row').css('display','block');
white_popup.find('.sk_popup_row').css('height','auto');
white_popup.find('.sk_popup_column').css('width','100%');
white_popup.find('.sk_popup_column .fa-spinner').css('top','45%');
white_popup.find('.sk_popup_column .ig_media').css('height','auto');
white_popup.find('.sk_popup_column .ig_media').css('width','100%');
}
if (getDsmSetting(sk_instagram_feed, "layout") == 1 || getDsmSetting(sk_instagram_feed, "layout") == 2) {
$('html').css('margin-right', '');
}
// apply font settings
white_popup.find('.sk_popup_column_body_content').css('font-size',getDsmSetting(sk_instagram_feed, "details_font_size")+'px');
var line_height = parseInt(getDsmSetting(sk_instagram_feed, "details_font_size")) + 4;
white_popup.find('.sk_popup_column_body_content').css({
"font-size" : getDsmSetting(sk_instagram_feed, "details_font_size")+'px',
"line-height" : line_height + "px"
});
white_popup.find('.sk-instagram-feed-username').css('font-size',getDsmSetting(sk_instagram_feed, "details_font_size")+'px');
white_popup.find('.sk_popup_column_user').css('font-size',getDsmSetting(sk_instagram_feed, "details_font_size")+'px');
white_popup.find('.sk_popup_column_footer').css('font-size',getDsmSetting(sk_instagram_feed, "details_font_size")+'px');
setTimeout(function(){
//white_popup.find('.sk_popup_column_body').mouseover(function() {
// var sk_popup_column_body_height = jQuery(this).height();
// var sk_popup_column_body_content_height = jQuery(this).find('.sk_popup_column_body_content').height();
// if(sk_popup_column_body_height < sk_popup_column_body_content_height){
// jQuery(this).css({
// 'overflow' : 'hidden scroll'
// });
// }
//}).mouseout(function() {
// jQuery(this).css({
// 'overflow' : 'hidden'
// });
//});
// popup colors
white_popup.find('.sk_popup_column_user span').css({
'font-size' : getDsmSetting(sk_instagram_feed,'details_font_size'),
});
white_popup.css({
'background' : getDsmSetting(sk_instagram_feed,'pop_up_bg_color'),
'color' : getDsmSetting(sk_instagram_feed,'pop_up_font_color'),
'font-size' : getDsmSetting(sk_instagram_feed,'details_font_size'),
});
white_popup.find('.sk_popup_column,.sk_popup_column_body_content').css({
'color' : getDsmSetting(sk_instagram_feed,'pop_up_font_color'),
'font-size' : getDsmSetting(sk_instagram_feed,'details_font_size'),
});
white_popup.find('.sk_popup_column a').css({
'color' : getDsmSetting(sk_instagram_feed,'pop_up_link_color'),
});
// popup height
var H = white_popup.find('.sk_popup_column').height();
initializeSwiperSingleSLider(clicked_element);
var video_slide = jQuery('.mfp-content .sk-pop-ig-post .swiper-slide:first video.ig_media');
if(jQuery('.mfp-content .sk-pop-ig-post video.ig_media').get(0)!==undefined && video_slide.length){
video_slide.get(0).play();
}
jQuery('.mfp-content').find(".mfp-close").remove();
jQuery('.mfp-content').prepend('
✖ ');
jQuery('.mfp-content').find(".mfp-close").css({
"right" : parseInt(jQuery('.mfp-content').find(".white-popup").css("marginRight"))+"px"
});
if(sk_instagram_feed.width() <= 820){
jQuery('.mfp-content').find(".mfp-close").css({
"right" : parseInt(jQuery('.mfp-content').find(".white-popup").css("marginRight"))+"px"
});
}
jQuery(".mfp-wrap").css({ height: "0%" });
setTimeout(function () {
jQuery(".mfp-wrap").animate({opacity: 1}, 100);
jQuery(".mfp-wrap").css({ height: "100%" });
}, 5);
},50);
},
close: function() {
jQuery(".prev_sk_ig_feed_post, .next_sk_ig_feed_post").remove();
jQuery('video').each(function() {
jQuery(this)[0].pause();
});
}
}
});
}
function initializeSwiperSingleSLider(clicked_element){
var singleSwiper = new Swiper('.swiper-container-single.swiper-container', {
slidesPerView: 1,
spaceBetween: 30,
effect : 'fade',
autoplay: 3000,
loop: false,
pagination: {
el: '.swiper-pagination',
clickable: true,
},
navigation: {
nextEl: '.swiper-button-next-single',
prevEl: '.swiper-button-prev-single',
},
});
singleSliderLayout();
setTimeout(function(){
singleSliderLayout();
},1000);
setTimeout(function(){
singleSliderLayout();
},2000);
jQuery('.swiper-button-next-single').click({swiper:singleSwiper},skSliderSingleNextClickEvent);
jQuery('.swiper-button-prev-single').click({swiper:singleSwiper},skSliderSinglePrevClickEvent);
// play video
if(jQuery('.mfp-content .swiper-slide-active video.carousel-video').get(0)!==undefined){
jQuery('.mfp-content .swiper-slide-active video.carousel-video').get(0).play();
}
}
function skSliderSingleNextClickEvent(){
jQuery('.mfp-content .sk_popup_column .ig_media').css('width','100%');
jQuery('video').each(function() {
jQuery(this)[0].pause();
});
if(jQuery('.mfp-content .swiper-slide-active video.carousel-video').get(0)!==undefined){
jQuery('.mfp-content .swiper-slide-active video.carousel-video').get(0).play();
}
}
function skSliderSinglePrevClickEvent(){
jQuery('.mfp-content .sk_popup_column .ig_media').css('width','100%');
jQuery('video').each(function() {
jQuery(this)[0].pause();
});
if(jQuery('.mfp-content .swiper-slide-active video.carousel-video').get(0)!==undefined){
jQuery('.mfp-content .swiper-slide-active video.carousel-video').get(0).play();
}
}
function singleSliderLayout(){
var height = jQuery('.swiper-container-single img,.sk_loading_image img,.sk_loading_video video').innerHeight();
if(jQuery('.mfp-content .sk_loading_image').length){
height = jQuery('.mfp-content .sk_loading_image').height();
jQuery('.mfp-content .sk_loading_image img').height(height);
}
var type = jQuery('.white-popup').attr('data-type');
var mfp_content = jQuery('.white-popup');
var media_container = jQuery('.mfp-content .sk-media-post-pop-up');
var media_height = media_container.find('img').height();
if(media_container.find('img').length == 0){
media_height = media_container.find('video').height();
}
if(type !='picture'){
media_container.css('height',media_height +'px');
}
media_container.css('height',media_height +'px');
var _h = jQuery('.white-popup').find('.sk_popup_row:first').height();
if(media_container.find('.swiper-slide-active').length > 0){
var height = media_container.find('.swiper-slide-active img,.swiper-slide-active video').height();
var height = _h;
media_container.css('height',height +'px');
mfp_content.find('.sk-popup-container').css('height',height +'px');
mfp_content.find('.sk-media-post-container').css('height',height +'px');
mfp_content.find('.swiper-container').css('height',height +'px');
mfp_content.find('.swiper-wrapper').css('height',height +'px');
mfp_content.find('.swiper-slide').css('height',height +'px');
mfp_content.find('.sk_loading_image img').css('height', 'auto');
}
}
function loadSliderLayout(sk_instagram_feed, data) {
var column_count = getDsmSetting(sk_instagram_feed,'column_count');
var post_count = getDsmSetting(sk_instagram_feed,'post_count');
var mobile_column_count = getDsmSetting(sk_instagram_feed, "mobile_column_count");
if (column_count && column_count == 0) {
column_count = 3;
}
if (mobile_column_count && mobile_column_count == 0) {
mobile_column_count = 1;
}
if (jQuery(document).width() <= 769) {
column_count = mobile_column_count ? parseInt(mobile_column_count) : 1;
}
if (jQuery(document).width() > 500) {
if (window.location.href.includes("iframe/242046")) {
column_count = getDsmSetting(sk_instagram_feed,'column_count');
}
}
column_count = parseInt(column_count);
var post_items= "
";
post_items+="
";
post_items+=" ";
post_items+=" ";
post_items+="
";
post_items+=" ";
post_items+=" ";
post_items+= "
";
post_items+= "
";
var data_position = 0;
var data_slider = data_storage[embed_id];
data_slider = data_slider.slice(0, post_count);
var pages = Math.ceil(data_slider.length/column_count);
if (data_slider.length > 0) {
for(var slide = 1; slide <= pages; slide++){
post_items+= "
";
post_items += "
";
var slide_data = getPaginationResult(sk_instagram_feed,data_slider,slide,column_count);
jQuery.each(slide_data, function(key, val){
if(typeof val != 'undefined')
post_items+=getFeedItem(val, sk_instagram_feed, data_position);
data_position++;
});
post_items += "
";
post_items += "
";
}
} else {
post_items += `
No Posts Found
`;
}
post_items+= "
";
post_items+= "
";
post_items+= "
";
return post_items;
}
function getPaginationResult(sk_instagram_feed, post_data, page, column_count){
var start = 0;
var end = parseInt(column_count);
var multiplicand = page - 1;
var return_post_data = [];
if(page != 1){
start = multiplicand * end;
end = start + end;
}
if((end - 1) > post_data.length){
end = post_data.length;
}
for(var i = start; i < end; i++){
return_post_data.push(post_data[i]);
}
return return_post_data;
}
function skLayoutSliderSetting(sk_instagram_feed){
var autoplay = false;
var loop = false;
if(getDsmSetting(sk_instagram_feed, "autoplay") == 1){
var delay = getDsmSetting(sk_instagram_feed, "delay") * 1500;
autoplay = {delay: delay};
loop = true;
}
var swiper = new Swiper('.sk-instagram-feed .swiper-layout-slider.swiper-container', {
loop: loop,
autoplay: autoplay,
navigation: {
nextEl: '.sk-instagram-feed .swiper-button-next',
prevEl: '.sk-instagram-feed .swiper-button-prev',
},
});
if(getDsmSetting(sk_instagram_feed, "autoplay") == 1){
sk_instagram_feed.find(".swiper-container").hover(function() {
(this).swiper.autoplay.stop();
}, function() {
(this).swiper.autoplay.start();
});
}
}
function skLayoutSliderArrowUI(sk_instagram_feed){
var arrow_background_color = getDsmSetting(sk_instagram_feed, "arrow_background_color");
var arrow_color = getDsmSetting(sk_instagram_feed, "arrow_color");
var arrow_opacity = getDsmSetting(sk_instagram_feed, "arrow_opacity");
// Apply Opacity
sk_instagram_feed.find(".swiper-button-prev i,.swiper-button-next i")
.mouseover(function(){
jQuery(this).css({
"opacity":"1",
"border-color":arrow_background_color,
});
}).mouseout(function(){
jQuery(this).css({
"border-color": arrow_color,
"opacity":arrow_opacity
});
});
sk_instagram_feed.find(".swiper-button-prev i,.swiper-button-next i").css({
"border-color": arrow_color,
"opacity":arrow_opacity,
"color": arrow_color
});
// Get the height
var feed_h = sk_instagram_feed.find('.sk-instagram-feed-item .sk-ig-post-img').innerHeight();
// position button to center
var feed_h_2 = feed_h / 2;
sk_instagram_feed.find(".swiper-button-prev,.swiper-button-next").css({
"top":feed_h_2 +"px"
});
}
// make widget responsive
function makeResponsive(jQuery, sk_instagram_feed){
var sk_instagram_feed_width = sk_instagram_feed.width();
/* smartphones, iPhone, portrait 480x320 phones */
if(sk_instagram_feed_width<=320){
}
/* portrait e-readers (Nook/Kindle), smaller tablets @ 600 or @ 640 wide. */
else if(sk_instagram_feed_width<=481){
}
/* portrait tablets, portrait iPad, landscape e-readers, landscape 800x480 or 854x480 phones */
else if(sk_instagram_feed_width<=641){
}
/* tablet, landscape iPad, lo-res laptops ands desktops */
else if(sk_instagram_feed_width<=961){
}
/* big landscape tablets, laptops, and desktops */
else if(sk_instagram_feed_width<=1025){
}
/* hi-res laptops and desktops */
else if(sk_instagram_feed_width<=1281){
}
/* wider screen */
else if(sk_instagram_feed_width>1281){
}
if(getDsmSetting(sk_instagram_feed, "post_item_type") == 1){
if (getDsmSetting(sk_instagram_feed, 'column_count') == 1) {
sk_instagram_feed.find('.sk-ig-post-img').css({
'background-size' : 'contain',
'background-repeat' : 'no-repeat'
})
}
var thisH = 0;
var maxHeight = 0;
jQuery(".sk-instagram-feed-item").each(function(){
thisH = jQuery(this).outerHeight(true);
if (thisH > maxHeight) { maxHeight = thisH; }
});
jQuery(".sk-instagram-feed-item ").height(maxHeight);
}
}
function skChangeImageRatio(sk_instagram_feed,column_count,margin_between_images ){
var masonry_width = "100%";
if(column_count == 4){
masonry_width = "25%";
}
if(column_count == 3){
masonry_width = "33.3%";
}
if(column_count == 2){
masonry_width = "50%";
}
sk_instagram_feed.find(".sk-instagram-feed-item-sizer").css({"width" : masonry_width});
sk_instagram_feed.find('.sk-img-sizer').each(function(index, element){
var _H = jQuery(element).height() + "px";
jQuery(element).closest('.sk-instagram-feed-item').css({
'width' : masonry_width,
'height' : _H,
});
var sk_feed_item_w = jQuery(element).closest('.sk-instagram-feed-item').width() - (margin_between_images * 2);
jQuery(element).closest('div').css({
'width' : sk_feed_item_w,
'height' : 'auto'
});
var sk_feed_item_h = parseInt(jQuery(element).closest('div .sk-instagram-feed-item').find('.sk-ig-post-img').height());
sk_feed_item_h = sk_feed_item_h < 100 ? 350 : sk_feed_item_h;
var post_id = jQuery(element).closest('.sk-instagram-feed-item').attr("data-code");
jQuery(element).closest('div').css({
'height' : sk_feed_item_h+'px',
});
jQuery(element).closest('.sk-instagram-feed-item').find('.sk-ig-post-hover').css({
'width' : sk_feed_item_w,
'line-height' : sk_feed_item_h,
'height' : sk_feed_item_h
});
jQuery(element).closest('.sk-instagram-feed-item').find('.sk-ig-post-img').css({
'width' : '100%',
});
if(post_id == "CjJGWSrI4pc" && jQuery(document).width() > 500){
sk_feed_item_h = 453;
} else if(post_id == "CjJGWSrI4pc" && jQuery(document).width() <= 500){
sk_feed_item_h = 253;
}
jQuery(element).closest('.sk-instagram-feed-item').css({
'height' : sk_feed_item_h,
'margin' : margin_between_images + 'px'
});
});
var this_height = sk_instagram_feed.find('.sk-ig-post-img').height();
sk_instagram_feed.find('.sk-ig-post-img').each(function(index, element){
jQuery(element).css('height', (this_height + Math.floor(Math.random() * 100)) + 'px');
var post_id = jQuery(element).attr("data-code");
if(post_id == "CjJGWSrI4pc" && jQuery(document).width() > 500){
jQuery(element).css({
'height' : "403px",
});
} else if(post_id == "CjJGWSrI4pc" && jQuery(document).width() <= 500){
jQuery(element).css({
'height' : "203px",
});
}
});
// fixMasonry(sk_instagram_feed);
}function applyCustomUi(jQuery, sk_instagram_feed){
// hide 'loading animation' image
sk_instagram_feed.closest("div.lp-element").css('height','auto'); // QF: https://www.reality-reboot.com/
sk_instagram_feed.find(".loading-img").hide();
// check if first page
var feed_width_item =sk_instagram_feed.find('.sk-instagram-feed-item').width();
// feed width
var sk_instagram_feed_width = feed_width_item == 0 ? sk_instagram_feed.outerWidth(true).toFixed(0) : sk_instagram_feed.outerWidth(true).toFixed(0) - 8;
// change height to normal
var sk_instagram_post_container_width = sk_instagram_feed.find('.sk-ig-all-posts').width();
// container width
sk_instagram_feed.css({
'height' : 'auto',
'display' : 'block'
});
if(getDsmSetting(sk_instagram_feed, "layout") == 3){
sk_instagram_feed_width = sk_instagram_feed.find('.sk-ig-all-posts').width();
sk_instagram_feed.find('.sk-ww-ig-feed-container').css({
'padding-bottom' : '10px'
});
}
var column_count = getDsmSetting(sk_instagram_feed,'column_count');
var mobile_column_count = getDsmSetting(sk_instagram_feed, "mobile_column_count");
if (column_count && column_count == 0) {
column_count = 3;
}
if (mobile_column_count && mobile_column_count == 0) {
mobile_column_count = 1;
}
if (jQuery(document).width() <= 769) {
column_count = mobile_column_count ? parseInt(mobile_column_count) : 1;
}
column_count = parseInt(column_count);
/* portrait tablets, portrait iPad, landscape e-readers, landscape 800x480 or 854x480 phones */
/* || sk_instagram_feed_width<=641*/
// size settings
var border_size=0;
var space_between_images = parseFloat(getDsmSetting(sk_instagram_feed, 'space_between_images'));
var margin_between_images = parseFloat(parseFloat(space_between_images).toFixed(2) / 2);
var scroll_width = getScrollbarWidth();
var pic_width = parseFloat((sk_instagram_post_container_width / column_count) - (space_between_images/column_count));
pic_width = parseFloat(pic_width);
const aspectRatioWidth = 4;
const aspectRatioHeight = 5;
var pic_height = pic_width;
if (getDsmSetting(sk_instagram_feed, "use_45_ratio") == 1) {
pic_height = (pic_width * aspectRatioHeight) / aspectRatioWidth;
}
// font & color settings
var font_family=sk_instagram_feed.find('.font_family').text();
var details_bg_color=sk_instagram_feed.find('.details_bg_color').text();
var details_font_color=sk_instagram_feed.find('.details_font_color').text();
var details_link_color=sk_instagram_feed.find('.details_link_color').text();
var details_link_hover_color=sk_instagram_feed.find('.details_link_hover_color').text();
var button_bg_color=sk_instagram_feed.find('.button_bg_color').text();
var button_text_color=sk_instagram_feed.find('.button_text_color').text();
var button_hover_bg_color=sk_instagram_feed.find('.button_hover_bg_color').text();
var button_hover_text_color=sk_instagram_feed.find('.button_hover_text_color').text();
setTimeout(function(){ sk_instagram_feed.find('.sk-instagram-feed-item').css('background-image','none'); },500);
setTimeout(function(){ sk_instagram_feed.find('.sk-instagram-feed-item').css('background-image','none'); },1000);
if(getSkSetting(sk_instagram_feed,'layout') == 1){
sk_instagram_feed.find('.sk-ig-all-posts').css({
'padding' : '3px'
});
}
if(getSkSetting(sk_instagram_feed,'layout') == 2){
setTimeout(function(){
skChangeImageRatio(sk_instagram_feed, column_count, margin_between_images);
},500);
}
else{
sk_instagram_feed.find('.sk-instagram-feed-item').css({
'width' : pic_width - 4 + 'px',
'padding' : border_size
});
}
// profile username
var profile_username=getDsmSetting(sk_instagram_feed, "title_all_caps")==1 ? "uppercase" : "normal";
sk_instagram_feed.find('.sk-ig-profile-usename').css({
'text-transform' : profile_username,
'font-size' : getDsmSetting(sk_instagram_feed, "title_font_size") + 'px'
});
// default text
var profile_username=getDsmSetting(sk_instagram_feed, "details_all_caps")==1 ? "uppercase" : "normal";
sk_instagram_feed.find('.sk-ig-profile-info').css({
'text-transform' : profile_username,
'font-size' : getDsmSetting(sk_instagram_feed, "details_font_size") + 'px'
});
var post_content_padding = parseInt(getDsmSetting(sk_instagram_feed, 'post_content_padding'));
post_content_padding = post_content_padding ? post_content_padding : 30;
if (sk_instagram_feed_width < 520) {
post_content_padding -= 10;
}
sk_instagram_feed.find('.sk-ig-caption').css({
'font-size' : getDsmSetting(sk_instagram_feed, "details_font_size") + 'px',
'padding' : post_content_padding + 'px'
});
sk_instagram_feed.find('.sk-ago-data').css({
'font-size' : getDsmSetting(sk_instagram_feed, "details_font_size") + 'px'
});
sk_instagram_feed.find('.sk_popup_column_spacer').css({
'padding' : post_content_padding + 'px'
});
sk_instagram_feed.find('.sk_popup_column_footer').css({
'bottom' : post_content_padding + 'px'
});
jQuery('.sk-ig-post-meta').css({
'text-transform' : profile_username
});
// hover
var hover_width=sk_instagram_feed.find('.sk-instagram-feed-item').width() || Math.floor(pic_width) || 0;
var hover_height=sk_instagram_feed.find('.sk-ig-post-img').height();
if(getDsmSetting(sk_instagram_feed, "show_post_hover")==1){
sk_instagram_feed.find('.sk-ig-post-hover').css({
'width' : hover_width + 'px',
'margin' : 0,
'padding' : 0,
'line-height' : hover_width + 'px',
});
}else{
sk_instagram_feed.find('.sk-ig-post-hover').css({
'width' : hover_width + 'px',
'height' : hover_width + 'px',
'margin' : 0,
'padding' : 0,
'line-height' : hover_width + 'px',
'background-color' : 'rgba(0, 0, 0, 0)',
'display' : 'none'
});
}
// fix hover height
setTimeout(function(){
// hover
var hover_height=sk_instagram_feed.find('.sk-ig-post-img').height();
if(getDsmSetting(sk_instagram_feed, "show_post_hover")==1){
sk_instagram_feed.find('.sk-ig-post-hover').css({
'line-height' : hover_height + 'px',
});
}else{
sk_instagram_feed.find('.sk-ig-post-hover').css({
'height' : hover_height + 'px',
'line-height' : hover_height + 'px'
});
}
},500);
sk_instagram_feed.find('.sk-ig-post-hover .fa').css({
'height' : hover_width + 'px',
'line-height' : hover_width + 'px'
});
sk_instagram_feed.find('.sk-ig-profile-usename').css({
'width' : '100%',
});
// resize the actual image as well
sk_instagram_feed.find('.sk-instagram-feed-item .sk-ig-post-img').css({
'width' : pic_width - 6 + 'px',
'height' : pic_height + 100 + 'px'
});
if (getDsmSetting(sk_instagram_feed, 'post_item_type') == 1) {
sk_instagram_feed.find('.sk-instagram-feed-item .sk-ig-post-img').css({
'border-top-left-radius' : '8px',
'border-top-right-radius' : '8px',
'border-bottom-left-radius' : '0',
'border-bottom-right-radius' : '0',
});
}
sk_instagram_feed.find('.sk-instagram-feed-item, .sk-ig-post-img').css({
'border-radius' : getDsmSetting(sk_instagram_feed, 'post_border_radius'),
});
if (getDsmSetting(sk_instagram_feed, 'disable_posts') == 1) {
sk_instagram_feed.find('.sk-instagram-feed-item').css({
"cursor" : "unset"
});
}
// apply font family
sk_instagram_feed.css({
'font-family' : font_family,
'background-color' : details_bg_color
});
console.log(getDsmSetting(sk_instagram_feed, 'show_widget_border'))
if(getDsmSetting(sk_instagram_feed, 'show_widget_border') == 1){
sk_instagram_feed.css({
'border' : '2px solid #E5E5E5'
});
} else {
sk_instagram_feed.css({
'border' : 'none'
});
}
// pop up settings
jQuery('.sk-pop-ig-post').css({
'font-family' : font_family
});
// details
sk_instagram_feed.find('.instagram-user-root-container,.sk-ig-profile-usename,.sk-ig-caption, .sk-instagram-feed-item, .sk-ago-data').css({
'color' : details_font_color
});
// details link
sk_instagram_feed.find('.instagram-user-root-container a,.sk-ig-caption a').css({
'color' : details_link_color
});
sk_instagram_feed.find(".instagram-user-root-container a").mouseover(function() {
jQuery(this).css({'color' : details_link_hover_color});
}).mouseout(function() {
jQuery(this).css({'color' : details_link_color});
});
sk_instagram_feed.find(".sk-ig-profile-bio").css({
"white-space": "pre-line"
});
sk_instagram_feed.find(".sk-ig-bottom-btn-container").css({
"display": "block",
"overflow": "hidden",
"margin": "0",
});
// buttons
var margin_bottom_sk_ig_load_more_posts=space_between_images/2;
if(margin_bottom_sk_ig_load_more_posts==0){
margin_bottom_sk_ig_load_more_posts=3;
}
sk_instagram_feed.find(".sk-ig-load-more-posts, .sk-ig-bottom-follow-btn").css({
'margin-bottom' : margin_bottom_sk_ig_load_more_posts + 'px',
});
sk_instagram_feed.find(".instagram-user-container, .sk-ig-load-more-posts, .sk-ig-bottom-follow-btn")
.css({
'background-color' : button_bg_color,
'border-color' : button_bg_color,
'color' : button_text_color
});
sk_instagram_feed.find(".instagram-user-container, .sk-ig-load-more-posts, .sk-ig-bottom-follow-btn")
.mouseover(function(){
jQuery(this).css({
'background-color' : button_hover_bg_color,
'border-color' : button_hover_bg_color,
'color' : button_hover_text_color
});
}).mouseout(function(){
jQuery(this).css({
'background-color' : button_bg_color,
'border-color' : button_bg_color,
'color' : button_text_color
});
});
// bottom buttons container
var padding_sk_ig_bottom_btn_container=margin_between_images;
if(padding_sk_ig_bottom_btn_container==0){
padding_sk_ig_bottom_btn_container=5;
}
sk_instagram_feed.find(".sk-ig-bottom-btn-container").css({
'padding' : padding_sk_ig_bottom_btn_container + 'px'
});
// remove customer class style
jQuery('.sk-instagram-feed').removeClass('col-sm-3');
// jQuery(".prev_sk_ig_feed_post, .next_sk_ig_feed_post")
// .mouseover(function(){
// jQuery(".prev_sk_ig_feed_post, .next_sk_ig_feed_post").attr("style", "opacity: 1;");
// }).mouseout(function(){
// jQuery(".prev_sk_ig_feed_post, .next_sk_ig_feed_post").attr("style", "opacity: 0.3;");
// });
// .sk-fb-event-item
sk_instagram_feed.find('.sk-fb-event-item, .sk_powered_by').css({
'margin-bottom' : getDsmSetting(sk_instagram_feed, "space_between_events") + 'px'
});
applyPopUpColors(sk_instagram_feed);
// reset container width to 100% after sk
if(sk_instagram_feed.width() > 550){
sk_instagram_feed.css({
'width' : '100%',
'display' : 'block'
});
}
if(getDsmSetting(sk_instagram_feed, "layout") == 3){
var all_post_container_width = sk_instagram_feed.find('.sk-ig-all-posts').width();
sk_instagram_feed.find('.swiper-container').css({
'width' : all_post_container_width,
});
}
if(getDsmSetting(sk_instagram_feed,'layout') == 3){
skLayoutSliderArrowUI(sk_instagram_feed);
setTimeout(
function() {
skLayoutSliderArrowUI(sk_instagram_feed);
}, 500);
setTimeout(
function() {
skLayoutSliderArrowUI(sk_instagram_feed);
}, 800);
/* Arrow positioning handled by CSS for outside placement on mobile */
}
// apply custom css
jQuery('head').append('');
makeResponsive(jQuery, sk_instagram_feed);
sk_instagram_feed.find('.sk-instagram-feed-item-sizer').css({
'display': 'none'
});
sk_instagram_feed.find('.sk-ig-all-posts').css({
'display': 'grid',
'grid-template-columns': 'repeat(' + column_count + ', 1fr)',
'gap': space_between_images + 'px'
});
sk_instagram_feed.find('.sk-instagram-feed-item, .sk-ig-post-img').css({
'width': '100%',
});
setTimeout(function(){
if(getDsmSetting(sk_instagram_feed, "links_clickable") == 0){
sk_instagram_feed.find('.href_status_trigger').removeAttr('href');
sk_instagram_feed.find('.href_status_trigger_container').find('a').removeAttr('href');
}
}, 500);
}
function applyPopUpColors(popup_container){
var pop_up_bg_color = popup_container.find('.pop_up_bg_color').text();
var pop_up_font_color = popup_container.find('.pop_up_font_color').text();
var pop_up_link_color = popup_container.find('.pop_up_link_color').text();
var details_font_size = popup_container.find('.details_font_size').text();
popup_container.find('.sk-popup-container').css({
'font-size':details_font_size,
'color':pop_up_font_color,
'background':pop_up_bg_color
});
popup_container.find('.white-popup a').css({
'color':pop_up_link_color
});
var sk_media_post_pop_up = jQuery('.mfp-s-ready .sk-media-post-pop-up .ig_media').innerHeight();
var sk_popup_user_container = jQuery('.mfp-s-ready .sk-popup-user-container').innerHeight();
var sk_ig_feed_m_t_3px = jQuery('.mfp-s-ready .sk-ig-feed-m-t-3px').innerHeight();
var sk_ig_pic_text = sk_media_post_pop_up - sk_popup_user_container - sk_ig_feed_m_t_3px -110;
jQuery('.mfp-s-ready .sk-ig-pic-text').css('line-height',' 1.5');
if(jQuery(window).innerWidth() >= 700) {
jQuery('.mfp-s-ready .sk-ig-pic-text').css('max-height',sk_ig_pic_text);
}
else{
jQuery('.mfp-s-ready .sk-ig-pic-text').css('max-height','70000');
}
}
function getWidgetLayoutWidth(widget) {
const rw = widget.getBoundingClientRect().width;
if (rw >= 2) {
return rw;
}
if (widget.offsetWidth >= 2) {
return widget.offsetWidth;
}
let el = widget.parentElement;
for (let depth = 0; el && depth < 8; depth++) {
const pw = el.getBoundingClientRect().width;
if (pw >= 2) {
return pw;
}
el = el.parentElement;
}
return window.innerWidth;
}
function getMediaColumn(widget,widgetState,settings){
let columns;
const innerWidth = getWidgetLayoutWidth(widget);
let tablet_size = 767;
if (widget.parentElement && widget.parentElement.id === 'embed-code-container') {
tablet_size = 1500;
}
if (innerWidth <= 575) {
columns = widgetState.column_count_small;
} else if (innerWidth <= tablet_size) {
columns = Number(settings.column_count) > 2 ? widgetState.column_count_medium : settings.column_count;
} else {
columns =
Number(settings.column_count) || widgetState.column_count_large || 3;
}
if (innerWidth <= 1250 && Number(settings.column_count) > 3) {
columns = Math.min(columns, 3);
}
return columns;
}
function getMediaColumnCarousel(widget,widgetState,settings){
let columns;
const innerWidth = getWidgetLayoutWidth(widget);
let tablet_size = 900;
if (widget.parentElement && widget.parentElement.id === 'embed-code-container') {
tablet_size = 1500;
}
if (innerWidth <= 520) {
columns = widgetState.column_count_small;
} else if (innerWidth <= tablet_size) {
columns = widgetState.column_count_medium;
} else {
columns =
Number(settings.column_count) || widgetState.column_count_large || 3;
}
if (Number(settings.column_count) < columns) {
columns = Number(settings.column_count);
}
if (innerWidth <= 1250 && Number(settings.column_count) > 3) {
columns = Math.min(columns, 3);
}
return columns;
}
async function skIncreaseView(widgetState) {
const solution_info = widgetState.widget_data.user_info;
// track only customer status [1,6,7]
if (solution_info && solution_info.status && ![1, 6, 7].includes(parseInt(solution_info.status))) {
return false;
}
try {
// Destructure necessary values from widgetState and widget_data
const user_id = solution_info.user_id;
const status = solution_info.status;
// Get or generate a unique ID
const widgetId = solution_info.embed_id;
var sk_views_url = "https://views.sociablekit.com/";
if(document.URL.includes("local")){
sk_views_url = "https://localtesting.com/WidgetAnalytics/views/";
}
const uniqueId = sessionStorage.getItem('unique_id') || generateUniqueId();
if (!sessionStorage.getItem('unique_id')) {
sessionStorage.setItem('unique_id', uniqueId);
}
const ipAddress = uniqueId;
// Prepare payload for tracking views
const payload = {
widgetId,
userId: user_id,
viewsCount: 1,
url: getCurrentUrl(),
ipAddress,
status,
};
// Send tracking data to the server
const trackResponse = await fetch(`${sk_views_url}track-widget-views.php`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload),
});
// Parse and log the server response
const responseData = await trackResponse.json();
console.log('Server Response:', responseData);
} catch (error) {
// Log errors with contextual information
console.error('Error in renderViews:', error);
}
}
function isTooDarkColor(hexColor) {
let r, g, b;
if (hexColor.startsWith('#')) {
r = parseInt(hexColor.substr(1, 2), 16);
g = parseInt(hexColor.substr(3, 2), 16);
b = parseInt(hexColor.substr(5, 2), 16);
}
if (hexColor.indexOf('rgb') !== -1) {
const rgbValues = getRGB(hexColor);
[r, g, b] = rgbValues;
}
b = isNaN(b) ? 0 : b;
const yiq = ((r * 299) + (g * 587) + (b * 114)) / 1000;
return yiq < 60;
}
function getRGB(rgbstr) {
return rgbstr.substring(4, rgbstr.length-1)
.replace(/ /g, '')
.replace('(', '')
.split(',');
}
function getTutorialLinkNew(userInfo) {
const d = new Date(userInfo.createdAt);
const date = d.getDate();
let tutorialLink = "";
if (userInfo.solution_name) {
let slug = slugifyString(userInfo.solution_name);
tutorialLink = "https://www.sociablekit.com/tutorials/embed-" + slug + "-website/";
if (userInfo.website_builder) {
slug = slug + "-" + slugifyString(userInfo.website_builder);
tutorialLink = "https://www.sociablekit.com/tutorials/embed-" + slug + "/";
}
}
if (date % 5 !== 0) {
switch (userInfo.type) {
case 4:
tutorialLink = "https://www.sociablekit.com/tutorials/embed-facebook-feed-website/";
break;
case 5:
tutorialLink = "https://www.sociablekit.com/tutorials/embed-instagram-feed-website/";
break;
case 33:
tutorialLink = "https://www.sociablekit.com/tutorials/embed-linkedin-feed-website/";
break;
case 16:
tutorialLink = "https://www.sociablekit.com/tutorials/embed-youtube-playlist-website/";
break;
}
}
return tutorialLink;
}
function getTutorialLink(userInfo) {
let tutorialLink = "";
if (userInfo.solution_name) {
let slug = slugifyString(userInfo.solution_name);
tutorialLink = "https://www.sociablekit.com/tutorials/embed-" + slug + "-website/";
if (userInfo.website_builder) {
slug = slugifyString(userInfo.website_builder);
tutorialLink = "https://www.sociablekit.com/tutorials/embed-" + slug;
}
}
if (userInfo.type === 9) {
tutorialLink = "https://www.sociablekit.com/sync-facebook-page-events-to-google-calendar/";
} else if (userInfo.type === 26) {
tutorialLink = "https://www.sociablekit.com/how-to-sync-facebook-group-events-to-google-calendar-on-website/";
}
if (tutorialLink && !tutorialLink.endsWith("/")) {
tutorialLink += "/";
}
const linkedinWidgets = [33, 34, 44, 58, 75, 99, 100, 103];
const facebookWidgets = [1, 4, 9, 10, 11, 36, 38, 43, 12, 24, 26, 49, 2, 8, 3, 18, 19, 28, 30, 61];
const threadsWidgets = [110];
if (linkedinWidgets.includes(userInfo.type) && userInfo.embed_id % 2 === 1) {
let websiteBuilder = userInfo.website_builder ? slugifyString(userInfo.website_builder) : "website";
tutorialLink = "https://www.sociablekit.com/tutorials/embed-linkedin-feed-" + websiteBuilder + "/";
} else if (facebookWidgets.includes(userInfo.type) && userInfo.embed_id % 2 === 1) {
let websiteBuilder = userInfo.website_builder ? slugifyString(userInfo.website_builder) : "website";
tutorialLink = "https://www.sociablekit.com/tutorials/embed-facebook-feed-" + websiteBuilder + "/";
} else if (threadsWidgets.includes(userInfo.type) && userInfo.embed_id % 2 === 0) {
let websiteBuilder = userInfo.website_builder ? slugifyString(userInfo.website_builder) : "website";
tutorialLink = "https://www.sociablekit.com/tutorials/embed-threads-" + websiteBuilder + "/";
}
if (userInfo.type === 5 && userInfo.embed_id % 2 === 1) {
tutorialLink = tutorialLink.replace("profile", "feed");
}
return tutorialLink;
}
function generateBlueMessage(_sk, user_info){
var tutorial_link = "";
var sk_error_message = "";
if(user_info.solution_name){
var slugify_string = slugifyString(user_info.solution_name);
tutorial_link = "https://www.sociablekit.com/tutorials/embed-"+ slugify_string +"-website/";
}
if(user_info.type == 9){
tutorial_link = "https://www.sociablekit.com/sync-facebook-page-events-to-google-calendar/";
}
else if(user_info.type == 26){
tutorial_link = "https://www.sociablekit.com/how-to-sync-facebook-group-events-to-google-calendar-on-website/";
}
if (user_info.widget_status == 1) {
var sk_error_message = "
";
sk_error_message += "
The widget does not exist. If you think this is a mistake, please contact support
";
sk_error_message += "
";
return sk_error_message;
}
if(user_info.show_feed == false) {
if(!user_info.message || user_info.message == ""){
var sk_error_message = "
";
sk_error_message += ""+user_info.solution_name+" powered by SociableKIT ";
sk_error_message += "If you’re the owner of this website or SociableKIT account used, we found some errors with your account. ";
sk_error_message += "Please login your SociableKIT account to fix it. ";
sk_error_message += " ";
user_info.message = sk_error_message;
}
sk_error_message = user_info.message;
}
else if (user_info.solution_name == null && user_info.type == null && user_info.start_date == null) {
sk_error_message ="
";
sk_error_message+="The SociableKIT solution does not exist. If you think this is a mistake, please contact support.";
sk_error_message+="
";
}
else{
sk_error_message ="
";
sk_error_message +="
";
sk_error_message +="
";
sk_error_message += "
";
sk_error_message += `
`;
sk_error_message += "
While waiting there are a few things you need to know:
";
sk_error_message +="
";
sk_error_message +="It usually takes only a few minutes. We appreciate your patience. ";
sk_error_message +="We will notify you via email once your "+user_info.solution_name+" feed is ready. ";
if(user_info.type == 5){
sk_error_message += "Make sure your instagram account @"+getDsmSetting(_sk,'username')+" is connected. ";
}
else if(user_info.type == 22 || user_info.type == 39){
sk_error_message +="Please make sure that you selected the correct Google Place or that the Google Place ID you entered is correct. ";
}
else if(user_info.type == 101){
sk_error_message +="Please make sure that you have added SociableKIT as your contact on WhatsApp . ";
}
else{
sk_error_message +="Please make sure that the Source ID/Username you enter is correct. ";
}
sk_error_message +="If you think there is a problem, chat with support here . We will solve it for you. ";
sk_error_message+=" ";
sk_error_message +="
";
sk_error_message+="
";
sk_error_message+="
";
}
return sk_error_message;
}
function generateSolutionMessage(container, embed_id, sk_api_url){
fetchEmbedInfo(embed_id, sk_api_url)
.then((data) => {
const styleElement = document.createElement('style');
styleElement.type = 'text/css';
styleElement.appendChild(document.createTextNode(errorCSS));
document.head.appendChild(styleElement)
if (Boolean(data.encoded) && data.type == "33") {
container.innerHTML = `
No posts yet.
Please try again later.
`;
} else {
let message = generateBlueMessage(container, data);
container.innerHTML = message;
}
})
.catch((err) => {
console.error(err)
})
}
async function fetchEmbedInfo(embed_id, sk_api_url) {
let jsonUrl = sk_api_url + "api/user_embed/info/" + embed_id;
try {
const response = await fetch(jsonUrl, { method: "GET" });
const data = response.json();
return data;
} catch (err) {
throw Error("Failed to fetch embed info")
}
}
function slugifyString(str){
if (typeof str === 'string' && str !== null) {
str = str.replace(/^\s+|\s+$/g, '');
} else {
str = '';
}
// Make the string lowercase
str = str.toLowerCase();
// Remove accents, swap ñ for n, etc
var from = "ÁÄÂÀÃÅČÇĆĎÉĚËÈÊẼĔȆÍÌÎÏŇÑÓÖÒÔÕØŘŔŠŤÚŮÜÙÛÝŸŽáäâàãåčçćďéěëèêẽĕȇíìîïňñóöòôõøðřŕšťúůüùûýÿžþÞĐđ߯a·/_,:;";
var to = "AAAAAACCCDEEEEEEEEIIIINNOOOOOORRSTUUUUUYYZaaaaaacccdeeeeeeeeiiiinnooooooorrstuuuuuyyzbBDdBAa------";
for (var i=0, l=from.length ; i
= 1 || other_result >= 1) {
var src_arr = src_str.split(folder_name);
app_url = src_arr[0];
// replace if displaysocialmedia.com
app_url = app_url.replace("displaysocialmedia.com", "sociablekit.com");
// get app backend url
if (app_url.search("local") >= 1) {
app_backend_url = "http://localhost:3000/v1/";
app_url = "https://localtesting.com/SociableKIT_Widgets/";
app_file_server_url = "https://localtesting.com/SociableKIT_FileServer/feed/";
sk_app_url = "https://localtesting.com/SociableKIT/";
sk_api_url = "http://127.0.0.1:8000/";
sk_img_url = "https://localtesting.com/SociableKIT_Data_Image/";
sk_fb_sync_url = "https://localtesting.com/SociableKIT_Facebook_Sync/";
sk_scrolls_url = "https://localtesting.com/WidgetAnalytics/scrolls/";
sk_views_url = "https://localtesting.com/WidgetAnalytics/views/";
sk_clicks_url = "https://localtesting.com/WidgetAnalytics/clicks/";
sk_yt_syc_url = "https://localtesting.com/SociableKIT_YouTube_Sync/";
} else {
app_url = "https://widgets.sociablekit.com/";
sk_scrolls_url = "https://scrolls.sociablekit.com/";
sk_views_url = "https://views.sociablekit.com/";
sk_clicks_url = "https://clicks.sociablekit.com/";
}
}
}
}
return {
"app_url": app_url,
"app_backend_url": app_backend_url,
"app_file_server_url": app_file_server_url,
"sk_api_url": sk_api_url,
"sk_app_url": sk_app_url,
"sk_img_url": sk_img_url,
"sk_scrolls_url": sk_scrolls_url,
"sk_views_url": sk_views_url,
"sk_clicks_url": sk_clicks_url,
"sk_yt_syc_url" : sk_yt_syc_url,
"sk_fb_sync_url": sk_fb_sync_url
};
}
function getEnvironmentUrls(widgetState, key) {
const env_urls = skGetEnvironmentUrls(key);
widgetState.app_url = env_urls.app_url;
widgetState.app_backend_url = env_urls.app_backend_url;
widgetState.app_file_server_url = env_urls.app_file_server_url;
widgetState.sk_img_url = env_urls.sk_img_url;
widgetState.sk_app_url = env_urls.sk_app_url;
widgetState.sk_api_url = env_urls.sk_api_url;
widgetState.sk_clicks_url = env_urls.sk_clicks_url;
widgetState.sk_scrolls_url = env_urls.sk_scrolls_url;
widgetState.sk_views_url = env_urls.sk_views_url;
widgetState.sk_yt_syc_url = env_urls.sk_yt_syc_url;
}
function renderClick(widget,widgetState){
// Add event listener for all clickable elements in the widget
const { sk_clicks_url,widget_data } = widgetState;
const { solution_info, settings, user_info } = widget_data;
let user_id =
(solution_info && solution_info.user_id) ||
(settings && settings.user_id) ||
(user_info && user_info.user_id);
// track only customer status [1,6,7]
if (solution_info && solution_info.status && ![1, 6, 7].includes(parseInt(solution_info.status))) {
return false;
}
widget.addEventListener('click', (event) => {
const target = event.target;
let elementType = '';
let elementContent = '';
// Determine the type and content of the clicked element
elementType = target.tagName.toLowerCase(); // Use the tag name as the element type
// Get meaningful content based on the tag type or attributes
if (target.tagName === 'BUTTON' || target.tagName === 'A') {
elementContent = target.innerText.trim() || target.getAttribute('href') || 'Unnamed Element';
} else if (target.tagName === 'IMG') {
elementContent = target.getAttribute('alt') || target.getAttribute('src') || 'Unnamed Image';
} else if (target.tagName === 'VIDEO' || target.tagName === 'AUDIO') {
elementContent = target.getAttribute('src') || 'Unnamed Media';
} else if (target.tagName === 'INPUT' || target.tagName === 'TEXTAREA') {
elementContent = target.value || 'Unnamed Input';
} else {
elementContent = (target.innerText ? target.innerText.trim() : '') || target.className || `Unnamed ${elementType}`;
}
// Get the widgetId from the widget container
const widgetId = widget.getAttribute('data-embed-id');
if (elementType) {
// Send click data to the backend
fetch(sk_clicks_url+'track-widget-click.php', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
widgetId: widgetId,
userId: user_id,
url: getCurrentUrl(),
elementType,
elementContent,
}),
})
.then((response) => response.json())
.then((data) => console.log('Click logged:', data))
.catch((error) => console.error('Error logging click:', error));
}
});
}
function renderScroll(widget,widgetState){
// Add event listener for all clickable elements in the widget
const { sk_scrolls_url,widget_data } = widgetState;
const { solution_info, settings, user_info } = widget_data;
let user_id =
(solution_info && solution_info.user_id) ||
(settings && settings.user_id) ||
(user_info && user_info.user_id);
// track only customer status [1,6,7]
if (solution_info && solution_info.status && ![1, 6, 7].includes(parseInt(solution_info.status))) {
return false;
}
let scrollCount = 0;
let scrollTimeout;
let uniqueId = null;
const widgetId = widget.getAttribute('data-embed-id');
// Save unique ID to sessionStorage to keep it persistent
try {
uniqueId = sessionStorage.getItem('unique_id') || generateUniqueId();
if (!sessionStorage.getItem('unique_id')) {
sessionStorage.setItem('unique_id', uniqueId);
}
} catch (e) {
uniqueId = generateUniqueId();
}
// Scroll event listener
window.addEventListener('scroll', () => {
scrollCount++;
// Clear the previous timeout and set a new one
clearTimeout(scrollTimeout);
scrollTimeout = setTimeout(sendScrollData, 2000); // Send data 1 second after scrolling stops
});
// Send scroll data to the server
function sendScrollData() {
if (scrollCount > 0) {
fetch(sk_scrolls_url + 'track-widget-scroll.php', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
widgetId: widgetId,
userId: user_id,
scrollCount: scrollCount,
url: getCurrentUrl(),
uniqueId: uniqueId
})
})
.then(response => response.json())
.then(data => console.log('Scroll Server Response:', data))
.catch(error => console.error('Error:', error));
// Reset scroll count after sending
scrollCount = 0;
}
}
}
// Function to generate a unique ID (fallback for unique identification)
function generateUniqueId() {
const currentDate = new Date().toISOString().split('T')[0]; // Get the current date in "Y-m-d" format
return 'USER:' + (Math.random().toString(36).substr(2, 16)).toUpperCase() + currentDate; // Concatenate the date to the unique ID
}
async function renderViews(widget, widgetState) {
const embedId = widgetState?.embedId;
if (!embedId) return;
window.__skViewsTracked ??= new Set();
window.__skViewsInflight ??= new Set();
if (window.__skViewsTracked.has(embedId)) return;
if (window.__skViewsInflight.has(embedId)) return;
window.__skViewsInflight.add(embedId);
try {
window.__skViewsTracked.add(embedId);
// Destructure necessary values from widgetState and widget_data
const { sk_views_url, widget_data } = widgetState;
const { solution_info, settings, user_info } = widget_data;
let user_id =
(solution_info && solution_info.user_id) ||
(settings && settings.user_id) ||
(user_info && user_info.user_id);
let status =
(solution_info && solution_info.status) ||
(settings && settings.status) ||
(user_info && user_info.status);
// track only customer status [1,6,7]
if (solution_info && solution_info.status && ![1, 6, 7].includes(parseInt(solution_info.status))) {
return false;
}
// Get or generate a unique ID
let uniqueId = null;
const widgetId = widget.getAttribute('data-embed-id');
// Save unique ID to localStorage if not already present
try {
uniqueId = sessionStorage.getItem('unique_id') || generateUniqueId();
if (!sessionStorage.getItem('unique_id')) {
sessionStorage.setItem('unique_id', uniqueId);
}
} catch (e) {
uniqueId = generateUniqueId();
}
const ipAddress = uniqueId;
// Prepare payload for tracking views
const payload = {
widgetId,
userId: user_id,
viewsCount: 1,
url: getCurrentUrl(),
ipAddress,
status,
};
// Send tracking data to the server
const trackResponse = await fetch(`${sk_views_url}track-widget-views.php`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload),
});
// Parse and log the server response
const responseData = await trackResponse.json();
console.log('Views Server Response:', responseData);
} catch (error) {
// Log errors with contextual information
console.error('Error in renderViews:', error);
}
finally {
window.__skViewsInflight.delete(embedId);
}
}
function skLoader(container) {
const loaderHTML = `
`;
const showLoader = () => {
const loader = container.querySelector('.sk-widget-loader');
if (!loader) {
container.insertAdjacentHTML('afterbegin', loaderHTML);
}
}
// use { offset } to adjust timing of when to remove loader
// Used in widgets with additional setTimeout (eg. fb-page-events)
const hideLoader = ({ offset } = {}) => {
const loader = container.querySelector('.sk-widget-loader');
if (loader) {
if (offset) {
setTimeout(() => {
loader.style.display = 'none';
}, offset)
} else {
loader.style.display = 'none';
}
}
}
return { showLoader, hideLoader };
}
function addLoader(widget, widgetState) {
widget.insertAdjacentHTML('beforeend', `
`)
}
async function sendGchatAlert(payload, widgetState) {
const { sk_app_url, widget_data } = widgetState;
const { embed_id } = widget_data.solution_info;
let baseUrl = "https://alert.sociablekit.com/google-alert.php";
const localIdentifiers = ["localhost", "127.0.0.1", "localtesting"];
if (localIdentifiers.some(id => window.location.hostname.includes(id))) {
baseUrl = "https://localtesting.com/Codalify_Alerts/google-alert.php";
}
try {
const response = await fetch(baseUrl, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(payload)
});
const result = await response.text();
return result;
} catch (error) {
console.error("Error sending GChat alert:", error);
}
}
function fixMasonryListener(widget, widgetState, realignMasonry) {
const wrapper = widget.querySelector('.sk-posts-masonry, .sk-events-masonry');
if (!wrapper) return;
let resizeTimeout;
const debounceRealign = () => {
clearTimeout(resizeTimeout);
resizeTimeout = setTimeout(() => realignMasonry(widget, widgetState), 100);
};
const observer = new ResizeObserver(() => debounceRealign());
const mutationObserver = new MutationObserver(() => observeItems());
const observeItems = () => {
wrapper.querySelectorAll('.sk-post-item, .sk-event-item').forEach(item => observer.observe(item));
};
observeItems();
mutationObserver.observe(wrapper, { childList: true, subtree: true });
}
function observeImages(img, callback) {
if (img.tagName === 'IMG') {
if (img.complete) {
callback()
} else {
img.addEventListener('load', callback);
}
}
};
function debounceGlobal(func, delay) {
let timeoutId;
return function (...args) {
const context = this;
clearTimeout(timeoutId);
timeoutId = setTimeout(() => {
func.apply(context, args);
}, delay);
};
}
function fixMasonryGlobal(widget, widgetState) {
const timeouts = [0, 1000, 3000, 5000, 8000, 10000];
timeouts.forEach(delay => {
setTimeout(() => realignMasonry(widget, widgetState), delay);
});
}
function decodeHtmlEntities(str) {
const txt = document.createElement("textarea");
txt.innerHTML = str;
return txt.value;
}
function initUpdatePreview(widget, widgetState, renderLayout, applySettings, classNames = {}) {
const {
body = '.sk-posts-body',
header = '.sk-posts-header',
footer = '.sk-posts-footer'
} = classNames;
window.addEventListener("previewDataUpdated", (event) => {
const previewData = event.detail.previewData;
widgetState.widget_data.settings = {
...widgetState.widget_data.settings,
...previewData.settings,
};
if (widget) {
widget.innerHTML = "";
}
widgetState.hasBeenEdited = true
renderLayout(widget, widgetState);
applySettings(widget, widgetState);
const postsBody = widget.querySelector(body);
if (postsBody) postsBody.style.visibility = "visible";
const postsHeader = widget.querySelector(header);
if (postsHeader) postsHeader.style.visibility = "visible";
const postsFooter = widget.querySelector(footer);
if (postsFooter) postsFooter.style.visibility = "visible";
if (window.location.pathname.includes('widgets/update')) {
// class for determining if the widget has re-rendered
widget.classList.add('--sk-disable-anim');
}
});
}
function renderedCharCount(htmlString) {
const tempDiv = document.createElement("div");
tempDiv.innerHTML = htmlString;
const renderedText = tempDiv.textContent || tempDiv.innerText || "";
return renderedText.length;
}
function getCurrentUrl() {
const isInIframe = window.self !== window.top;
let embedUrl = isInIframe ? (document.referrer || window.location.href) : window.location.href;
embedUrl = (embedUrl || "").split('?')[0];
return embedUrl;
}
function applyImageFallback(img, sources) {
const validSources = sources.filter(Boolean);
if (!img || validSources.length === 0) return;
let index = 0;
img.src = validSources[index];
img.onerror = () => {
index++;
if (index < validSources.length) {
img.src = validSources[index];
} else {
img.onerror = null;
}
};
}
function decodeFontString(font) {
const textarea = document.createElement('textarea');
textarea.innerHTML = font;
return textarea.value;
}
function isSafeFont(font) {
const decodedFont = decodeFontString(font);
var web_safe_fonts = [
"Arial",
"Inherit",
"Impact, Charcoal, sans-serif",
"'Palatino Linotype', 'Book Antiqua', Palatino, serif",
"Century Gothic, sans-serif",
"'Lucida Sans Unicode', 'Lucida Grande', sans-serif",
"Verdana, Geneva, sans-serif",
"Copperplate, 'Copperplate Gothic Light', fantasy",
"'Courier New', Courier, monospace",
"Georgia, Serif"
];
return web_safe_fonts.indexOf(decodedFont) !== -1;
}function skGetBranding(sk, widgetState) {
let userInfo = "";
let widgetSettings = "";
if(widgetState.widget_data){
userInfo = widgetState.widget_data.user_info;
widgetSettings = widgetState.widget_data.settings;
}
else{
var embed_id = "";
if (sk && typeof sk.attr === "function") {
embed_id = sk.attr("embed-id") || sk.attr("data-embed-id") || "";
}
if (!embed_id && sk && sk.getAttribute) {
embed_id = sk.getAttribute("embed-id") || sk.getAttribute("data-embed-id") || "";
}
if (typeof original_data === "undefined" || !original_data) {
return '';
}
let originalData = original_data?.[embed_id] ?? original_data;
if(original_data.settings){
userInfo = original_data.user_info;
widgetSettings = original_data.settings;
}
else if(originalData.settings){
userInfo = originalData.user_info;
widgetSettings = originalData.settings;
}
}
// if the widget already has the branding link, return empty string
if (sk && sk.querySelector && sk.querySelector('.sk_branding')) {
return "";
}
// if the widget does not have the user info, return empty string
if (!userInfo) return "";
// if the widget will show the branding link
if (
userInfo.show_branding === 1 ||
userInfo.show_branding === "true" ||
userInfo.show_branding === true
) {
const fontFamily = widgetSettings.font_family;
let linkColor = widgetSettings.details_link_color || "rgb(52, 128, 220)";
const detailsBgColor = widgetSettings.details_bg_color;
let widget_type_slug = slugifyStringBranding(userInfo.solution_name);
let website_builder_slug = slugifyStringBranding(userInfo.website_builder || 'website');
// list supported website builders
const supportedBuilders = [
"wordpress",
"wix",
"squarespace",
"google-sites",
"shopify",
"sharepoint",
"webflow",
"godaddy",
"weebly",
"adobe-portfolio",
"html"
];
let website_builder_for_link = "website";
for (let b of supportedBuilders) {
if (website_builder_slug.includes(b)) {
website_builder_for_link = website_builder_slug;
break;
}
}
// build default tutorial link and link text
userInfo.tutorial_link = "https://www.sociablekit.com/tutorials/embed-" + widget_type_slug + "-" + website_builder_for_link + "/";
let widget_type_name_for_link = userInfo.solution_name;
// new rules for tutorial links
if (widget_type_slug.includes("linkedin")) {
userInfo.tutorial_link = "https://www.sociablekit.com/tutorials/embed-linkedin-feed-" + website_builder_for_link + "/";
widget_type_name_for_link = "LinkedIn Feed";
} else if (widget_type_slug.includes("facebook")) {
userInfo.tutorial_link = "https://www.sociablekit.com/tutorials/embed-facebook-feed-" + website_builder_for_link + "/";
widget_type_name_for_link = "Facebook Feed";
} else if (widget_type_slug.includes("instagram")) {
userInfo.tutorial_link = "https://www.sociablekit.com/tutorials/embed-instagram-feed-" + website_builder_for_link + "/";
widget_type_name_for_link = "Instagram Feed";
} else if (widget_type_slug === "x" || widget_type_slug.includes("twitter")) {
userInfo.tutorial_link = "https://www.sociablekit.com/tutorials/embed-x-feed-" + website_builder_for_link + "/";
widget_type_name_for_link = "X Feed";
} else if (widget_type_slug.includes("tiktok")) {
userInfo.tutorial_link = "https://www.sociablekit.com/tutorials/embed-tiktok-feed-" + website_builder_for_link + "/";
widget_type_name_for_link = "TikTok Feed";
}
// build tutorial link text
let tutorial_link_text = widget_type_name_for_link + " Widget by SociableKIT";
if (supportedBuilders.includes(website_builder_slug)) {
tutorial_link_text = userInfo.website_builder + " " + widget_type_name_for_link + " Widget by SociableKIT";
}
// build CSS
let sk_branding_css = "margin-top:20px; padding:10px; display:block !important; text-align:center; text-decoration: none !important; color:#555; font-family:" + fontFamily + "; font-size:15px; visibility: visible;";
let tutorial_link_css = "text-underline-position:under; color:" + linkColor + ";font-size:15px;display:block !important;";
// build the branding HTML
let html =
"";
// return the branding HTML
return html;
}
return "";
}
function slugifyStringBranding(str) {
str = str.replace(/^\s+|\s+$/g, "");
// Make the string lowercase
str = str.toLowerCase();
// Remove accents, swap ñ for n, etc
var from = "ÁÄÂÀÃÅČÇĆĎÉĚËÈÊẼĔȆÍÌÎÏŇÑÓÖÒÔÕØŘŔŠŤÚŮÜÙÛÝŸŽáäâàãåčçćďéěëèêẽĕȇíìîïňñóöòôõøðřŕšťúůüùûýÿžþÞĐđ߯a·/_,:;";
var to = "AAAAAACCCDEEEEEEEEIIIINNOOOOOORRSTUUUUUYYZaaaaaacccdeeeeeeeeiiiinnooooooorrstuuuuuyyzbBDdBAa------";
for (var i = 0, l = from.length; i < l; i++) {
str = str.replace(new RegExp(from.charAt(i), "g"), to.charAt(i));
}
// Remove invalid chars
str = str
.replace(/[^a-z0-9 -]/g, "")
// Collapse whitespace and replace by -
.replace(/\s+/g, "-")
// Collapse dashes
.replace(/-+/g, "-");
return str;
}function loadGoogleFont(font_family){
// add here the requested font
var web_safe_fonts = [
"Inherit", "Impact, Charcoal, sans-serif", "'Palatino Linotype', 'Book Antiqua', Palatino, serif",
"Century Gothic, sans-serif", "'Lucida Sans Unicode', 'Lucida Grande', sans-serif", "Verdana, Geneva, sans-serif",
"Copperplate, 'Copperplate Gothic Light', fantasy", "'Courier New', Courier, monospace", "Georgia, Serif"
];
if(!web_safe_fonts.includes(font_family)){
try {
loadCssFile("https://fonts.googleapis.com/css?family=" + font_family);
} catch (error) {
}
}
}
function readableNumber(number){
number= parseInt(number);
number = number ? number.toLocaleString("en-US") : 0;
return number;
}
function addDescriptiveTagAttributes(_sk, add_to_img = true){
_sk.find('a').each(function(i,v){
var title = jQuery(v).text();
if(!jQuery(v).attr('title')){
jQuery(v).attr('title',title);
}
});
if (add_to_img) {
_sk.find('img').each(function(i,v){
var src = jQuery(v).attr('src');
jQuery(v).attr('alt','Post image');
});
}
}
function getClientId(){
var _gaCookie = document.cookie.match(/(^|[;,]\s?)_ga=([^;,]*)/);
if(_gaCookie) return _gaCookie[2].match(/\d+\.\d+$/)[0];
}
function getSkEmbedId(sk_class) {
var embed_id = sk_class.attr('embed-id');
if (embed_id == undefined) { embed_id = sk_class.attr('data-embed-id'); }
return embed_id;
}
function getSkSetting(sk_class, key) {
if (typeof skIsHTMLElement === "function" && skIsHTMLElement(sk_class)) {
var el = sk_class.querySelector("div." + key);
return el ? (el.textContent || "").trim() : "";
}
return sk_class.find("div." + key).text();
}
function setCookieSameSite() {
document.cookie = "AC-C=ac-c;expires=Fri, 31 Dec 2025 23:59:59 GMT;path=/;HttpOnly;SameSite=Lax";
}
//setCookieSameSite();
function getIEVersion() {
var sAgent = window.navigator.userAgent;
var Idx = sAgent.indexOf("MSIE");
// If IE, return version number.
if (Idx > 0)
return parseInt(sAgent.substring(Idx + 5, sAgent.indexOf(".", Idx)));
// If IE 11 then look for Updated user agent string.
else if (!!navigator.userAgent.match(/Trident\/7\./))
return 11;
else
return 0; //It is not IE
}
function isSafariBrowser() {
var ua = navigator.userAgent.toLowerCase();
if (ua.indexOf('safari') != -1) {
if (ua.indexOf('chrome') > -1) {
return 0; // Chrome
} else {
return 1; // Safari
}
}
}
function loadIEScript(url) {
/* Load script from url and calls callback once it's loaded */
var scriptTag = document.createElement('script');
scriptTag.setAttribute("type", "text/javascript");
scriptTag.setAttribute("src", url);
(document.getElementsByTagName("head")[0] || document.documentElement).appendChild(scriptTag);
}
function kFormatter(num) {
return Math.abs(num) > 999 ? Math.sign(num) * ((Math.abs(num) / 1000).toFixed(1)) + 'k' : Math.sign(num) * Math.abs(num)
}
function generateUniqueId() {
const currentDate = new Date().toISOString().split('T')[0]; // Get the current date in "Y-m-d" format
return 'USER:' + (Math.random().toString(36).substr(2, 16)).toUpperCase() + currentDate; // Concatenate the date to the unique ID
}
async function sk_increaseView(solution_info) {
// track only customer status [1,6,7]
if (solution_info && solution_info.status && ![1, 6, 7].includes(parseInt(solution_info.status))) {
return false;
}
try {
// Destructure necessary values from widgetState and widget_data
const user_id = solution_info.user_id;
const status = solution_info.status;
// Get or generate a unique ID
const widgetId = solution_info.embed_id;
var sk_views_url = "https://views.sociablekit.com/";
if(app_url.includes('local')){
sk_views_url = "https://localtesting.com/WidgetAnalytics/views/";
}
const uniqueId = sessionStorage.getItem('unique_id') || generateUniqueId();
if (!sessionStorage.getItem('unique_id')) {
sessionStorage.setItem('unique_id', uniqueId);
}
const ipAddress = uniqueId;
// Prepare payload for tracking views
const payload = {
widgetId,
userId: user_id,
viewsCount: 1,
url: getCurrentUrl(),
ipAddress,
status,
};
// Send tracking data to the server
const trackResponse = await fetch(`${sk_views_url}track-widget-views.php`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload),
});
// Parse and log the server response
const responseData = await trackResponse.json();
console.log('Server Response:', responseData);
} catch (error) {
// Log errors with contextual information
console.error('Error in renderViews:', error);
}
}
function isTooDarkColor(hexcolor) {
var r = parseInt(hexcolor.substr(1, 2), 16);
var g = parseInt(hexcolor.substr(3, 2), 16);
var b = parseInt(hexcolor.substr(4, 2), 16);
if (hexcolor.indexOf('rgb') != -1) {
let rgbstr = hexcolor;
let v = getRGB(rgbstr);
r = v[0];
g = v[1];
b = v[2];
}
b = isNaN(b) ? 0 : b;
var yiq = ((r * 299) + (g * 587) + (b * 114)) / 1000;
// Return new color if to dark, else return the original
if (yiq < 60) {
}
else {
}
return yiq < 60 ? true : false;
}
function linkify(html) {
var temp_text = html.split("https://www.").join("https://");
temp_text = temp_text.split("www.").join("https://www.");
var exp = /((href|src)=["']|)(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
return temp_text.replace(exp, function () {
return arguments[1] ?
arguments[0] :
"" + arguments[3] + " "
});
}
function skGetEnvironmentUrls(folder_name) {
// auto detect live and dev version
var scripts = document.getElementsByTagName("script");
var scripts_length = scripts.length;
var search_result = -1;
var other_result = -1;
var app_url = "https://widgets.sociablekit.com/";
var app_backend_url = "https://api.accentapi.com/v1/";
var app_file_server_url = "https://data.accentapi.com/feed/";
var sk_app_url = "https://sociablekit.com/app/";
var sk_api_url = "https://api.sociablekit.com/";
var sk_img_url = "https://images.sociablekit.com/";
var sk_fb_sync_url = "https://facebook-sync.sociablekit.com/";
var sk_yt_syc_url = "https://youtube-sync.sociablekit.com/";
var sk_widget_sync_url = "https://widget-sync.sociablekit.com/";
var sk_clicks_url = "https://clicks.sociablekit.com/";
var sk_scrolls_url = "https://scrolls.sociablekit.com/";
for (var i = 0; i < scripts_length; i++) {
var src_str = scripts[i].getAttribute('src');
if (src_str != null) {
var other_folder = "";
if (folder_name == 'facebook-page-playlists') {
other_folder = 'facebook-page-playlist';
}
else if (folder_name == 'linkedin-page-posts') {
other_folder = 'linkedin-page-post';
}
else if (folder_name == 'linkedin-profile-posts') {
other_folder = 'linkedin-profile-post';
}
else if (folder_name == 'facebook-hashtag-posts') {
other_folder = 'facebook-hashtag-feed';
}
else if (folder_name == 'facebook-page-events') {
other_folder = 'facebook-events';
}
else if (folder_name == 'facebook-page-posts') {
other_folder = 'facebook-feed';
if (document.querySelector(".sk-ww-facebook-feed")) {
var element = document.getElementsByClassName("sk-ww-facebook-feed")[0];
element.classList.add("sk-ww-facebook-page-posts");
}
}
other_result = src_str.search(other_folder);
search_result = src_str.search(folder_name);
// app-dev found if greater than or equal to 1
if (search_result >= 1 || other_result >= 1) {
var src_arr = src_str.split(folder_name);
app_url = src_arr[0];
// replace if displaysocialmedia.com
app_url = app_url.replace("displaysocialmedia.com", "sociablekit.com");
// get app backend url
if (app_url.search("local") >= 1) {
app_backend_url = "http://localhost:3000/v1/";
app_url = "https://localtesting.com/SociableKIT_Widgets/";
app_file_server_url = "https://localtesting.com/SociableKIT_FileServer/feed/";
sk_app_url = "https://localtesting.com/SociableKIT/";
sk_api_url = "http://127.0.0.1:8000/";
sk_img_url = "https://localtesting.com/SociableKIT_Images/";
sk_fb_sync_url = "https://localtesting.com/SociableKIT_Facebook_Sync/";
sk_yt_syc_url = "https://localtesting.com/SociableKIT_YouTube_Sync/";
sk_scrolls_url = "https://localtesting.com/WidgetAnalytics/scrolls/";
sk_clicks_url = "https://localtesting.com/WidgetAnalytics/clicks/";
sk_widget_sync_url = "https://localtesting.com/SociableKIT_Widget_Sync/";
}
else {
app_url = "https://widgets.sociablekit.com/";
}
}
}
}
return {
"app_url": app_url,
"app_backend_url": app_backend_url,
"app_file_server_url": app_file_server_url,
"sk_api_url": sk_api_url,
"sk_app_url": sk_app_url,
"sk_img_url" : sk_img_url,
"sk_fb_sync_url" : sk_fb_sync_url,
"sk_yt_syc_url" : sk_yt_syc_url,
"sk_scrolls_url": sk_scrolls_url,
"sk_clicks_url" : sk_clicks_url,
"sk_widget_sync_url" : sk_widget_sync_url
};
}
function changeBackSlashToBR(text) {
if (text) {
for (var i = 1; i <= 10; i++) {
text = text.replace('\n', '');
}
}
return text;
}
function sKGetScrollbarWidth() {
// Creating invisible container
var outer = document.createElement('div');
outer.style.visibility = 'hidden';
outer.style.overflow = 'scroll'; // forcing scrollbar to appear
outer.style.msOverflowStyle = 'scrollbar'; // needed for WinJS apps
document.body.appendChild(outer);
// Creating inner element and placing it in the container
var inner = document.createElement('div');
outer.appendChild(inner);
// Calculating difference between container's full width and the child width
var scrollbarWidth = (outer.offsetWidth - inner.offsetWidth);
// Removing temporary elements from the DOM
outer.parentNode.removeChild(outer);
return scrollbarWidth;
}
function isValidURL(url) {
const urlPattern = /^(http(s)?:\/\/)?(www\.)?[a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)$/;
return urlPattern.test(url);
}
async function showUrlData(element, url,post_id, type="", show_thumbnail=1) {
element.hide();
var check_url = url && url.includes('&') ? encodeURIComponent(url) : url;
var free_data_url = app_file_server_url.replace("feed/", "get_fresh_url_tags.php") + '?post_id='+post_id+'&url='+check_url;
var read_one_url = app_file_server_url.replace("feed", "url-tags") + post_id + ".json";
if(jQuery('.sk_version').text()){
read_one_url+="?v="+jQuery('.sk_version').text();
}
fetch(read_one_url, { method: 'get', cache:'no-cache' })
.then(async response => {
if (response.ok) {
let data = await response.json();
if (data && data.status && data.status == 418) {
displayUrlData(data, element, type, show_thumbnail, post_id); // to have content in the feed: display thumbnail first before request
data = await jQuery.ajax(free_data_url);
}
return data;
}
else{
response = await jQuery.ajax(free_data_url);
displayUrlData(response, element, type, show_thumbnail, post_id);
return response;
}
})
.then(async response => {
if (response != undefined) {
displayUrlData(response, element, type, show_thumbnail, post_id);
} else {
response = await jQuery.ajax(free_data_url);
displayUrlData(response, element, type, show_thumbnail, post_id);
}
}).catch(async error => {
var data = await jQuery.ajax(free_data_url);
displayUrlData(data, element, type, show_thumbnail, post_id);
});
}
async function displayUrlData(response, element, type, show_thumbnail=1, post_id) {
var meta_holder = jQuery(element);
var html = "";
if (!response || response.error) {
if(meta_holder.html()){
meta_holder.show();
}
return;
}
if (response.message && response.message == "Data not available. Please try again.") {
return;
}
if (response.messages && response.messages.length > 0 &&
response.messages[0] == "PDF files that are over 10Mb are not supported by Google Docs Viewer") {
var data = response.url;
if(response.url){
data = response.url.replace("https://", "").split("/");
}
if(data.length > 0){
if(data.length > 1){
response.title = data[data.length - 1];
}
response.description = data[0].replace("www.", "");
}
}
if (post_id == "7059257055500492800") {
response.url += "?id=122630";
}
if ((response.title && response.title.includes("NCBI - WWW Error Blocked Diagnostic")) ||
(response.messages && response.messages[1] && response.messages[1].includes("profile badges")) ||
(response.messages && response.messages[0] && response.messages[0].includes("profiles except the badge"))) {
html += "";
html += "";
if (show_thumbnail == 1) {
html += "
";
}
if ((response.title && response.title.includes("NCBI - WWW Error Blocked Diagnostic")) ||
(response.messages && response.messages[1] && response.messages[1].includes("profile badges")) ||
(response.messages && response.messages[0] && response.messages[0].includes("profiles except the badge"))) {
html += "
" + meta_holder.data('title') + "
";
}
html += "
";
html += " ";
}
else{
html += "";
html += "";
let attr_thumbnail = meta_holder.attr("data-img");
let display_none = '';
if (show_thumbnail == 1 && response.thumbnail_url) {
if (response.thumbnail_url.includes("err.ch")) {
display_none = 'style="display:none;"';
}
html += "
";
} else if (attr_thumbnail && attr_thumbnail.length > 0){
html += "
";
}
if (response.title) {
html += "
" + response.title + "
";
}
else if (response.url && response.url.indexOf(".pdf") != -1) {
html += response.html;
}
if (type && type == 6) {
if (response.description && response.description.length > 0) {
response.description = response.description.length > 140 ? response.description.substring(0, 140) + ' ...' : response.description;
}
}
if(response.description && response.description.indexOf("[vc_row]") !== -1 && response.url){
var pathArray = response.url.split( '/' );
var protocol = pathArray[0];
if(pathArray.length > 2){
var host = pathArray[2];
var url = protocol + '//' + host;
html+="
" + url + "
";
}
}
else if (response.description && response.description.indexOf("fb_built") == -1 && response.description != "null") {
if(response.url){
var domain = new URL(response.url).hostname;
response.description = domain;
}
html += "
" + response.description + "
";
}
else if(response.url && response.url.includes('instagram.com/p/')){
html += "
";
html += "
View this post in instagram
";
html += "
"+response.url+"
";
}
html += "
";
html += " ";
}
meta_holder.html(html);
meta_holder.css('display', 'block');
meta_holder.css('margin-bottom', '15px');
meta_holder.find('.sk-ig-default').closest('.sk-link-article-container').css('display', 'inline-block');
meta_holder.find('.sk-ig-default').closest('.sk-link-article-container').css('width', '100%');
meta_holder.find('.sk-ig-default').css('width', '20%');
meta_holder.find('.sk-ig-default').css('float', 'left');
applyMasonry();
}
window.handleImageError = function(element) {
if (!element.dataset.fallbackUsed && element.dataset.realUrl) {
element.src = element.dataset.realUrl;
element.dataset.fallbackUsed = "true";
} else {
element.style.display = 'none';
}
};
// Slugify a string
function slugifyString(str){
str = str.replace(/^\s+|\s+$/g, '');
// Make the string lowercase
str = str.toLowerCase();
// Remove accents, swap ñ for n, etc
var from = "ÁÄÂÀÃÅČÇĆĎÉĚËÈÊẼĔȆÍÌÎÏŇÑÓÖÒÔÕØŘŔŠŤÚŮÜÙÛÝŸŽáäâàãåčçćďéěëèêẽĕȇíìîïňñóöòôõøðřŕšťúůüùûýÿžþÞĐđ߯a·/_,:;";
var to = "AAAAAACCCDEEEEEEEEIIIINNOOOOOORRSTUUUUUYYZaaaaaacccdeeeeeeeeiiiinnooooooorrstuuuuuyyzbBDdBAa------";
for (var i=0, l=from.length ; iSociableKIT . ";
sk_error_message+="If you're the owner of this website, your 7-day Free Trial has ended. ";
sk_error_message+="If you want to continue using our services, please subscribe now .";
sk_error_message+=" ";
return sk_error_message;
}
function privateFBGroupMessage () {
var sk_error_message = "";
sk_error_message+="The SociableKIT solution does not exist. If you think this is a mistake, please contact support.";
sk_error_message+="
";
}
else{
sk_error_message ="