`); } if (post.type == 'image' && post.media) { if (post.media.length > 1) { let content = '' for (let index = 0; index < post.media.length; index++) { const element = post.media[index]; content += `
${post.quoted_spout_data.owner.name} ${data.owner.verified == 1 ? '' + icon_verified + '' : ''} ${post.quoted_spout_data.owner.verified == 1 ? '' + verified + '' : ''} @${post.quoted_spout_data.owner.username}${post.quoted_spout_data.text}
'
for (let index = 0; index < post.poll.options.length; index++) {
const pollData = post.poll.options[index];
content += `
`;
}
content += '
'
$('div[data-app="embed-post-modal"] .spout-media').html(content);
} else if (post.og_data) {
let content = ''
if (post.og_data.url) {
content = `
`;
}
$('div[data-app="embed-post-modal"] .spout-media').html(content);
}
$('div[data-app="embed-post-modal"]').modal('show');
}
_smc.show_edits = function(id = false) {
if ($.isNumeric(id) && id) {
if ( $('.edits--spout-' + id).length ) {
$('div[data-app="black-hole"]').append($('.edits--spout-' + id).html()).find('div[data-app="post-edits"]').modal('show');
return
}
$.ajax({
url: 'https://spoutible.com/sptbl_system_api/main/show_edits',
type: 'POST',
dataType: 'json',
data: {id: id},
}).done(function(data) {
if (data.status == 200) {
$('div[data-app="black-hole"]').append($(data.html)).find('div[data-app="post-edits"]').modal('show');
}
else if(data.status == 404) {
_smc.info("No edits yet!", "This post appears to have edits made yet.");
}
else {
_smc.errorMSG();
}
});
}
}
_smc.edit_post = function(id = false) {
if ($.isNumeric(id) && id) {
$.ajax({
url: 'https://spoutible.com/sptbl_system_api/edit_post/get_data',
type: 'GET',
dataType: 'json',
data: {id: id},
}).done(function(data) {
if (data.status == 200) {
$('div[data-app="black-hole"]').append($(data.html)).find('div[data-app="post-text-edit"]').modal('show');
}
else {
_smc.errorMSG();
}
});
}
}
_smc.edit_collaborative_thread_users = function(id = false) {
if ($.isNumeric(id) && id) {
$.ajax({
url: 'https://spoutible.com/sptbl_system_api/edit_post/get_collaborative_thread_users',
type: 'GET',
dataType: 'json',
data: {id: id},
}).done(function(data) {
if (data.status == 200) {
$('div[data-app="black-hole"]').append($(data.html)).find('div[data-app="post-edit_collaborative_thread_users"]').modal('show');
}
else {
_smc.errorMSG();
}
});
}
}
_smc.bookmark_post = function(id = false, _self = false) {
if (_smc.is_logged()) {
if ($.isNumeric(id) && id) {
$.ajax({
url: 'https://spoutible.com/sptbl_system_api/main/bookmark_post',
type: 'POST',
dataType: 'json',
data: {id: id, a: 'save'},
}).done(function(data) {
if (data.status == 200) {
if (data.status_code == '1') {
sptbl_bs_notify("Post has been bookmarked!", 500);
$(_self).text("Remove Bookmark");
}
else {
sptbl_bs_notify("Post has been deleted from bookmarks!",500);
$(_self).text("Bookmark");
}
}
else {
_smc.errorMSG();
}
});
}
}
else {
_smc.req_auth();
}
}
_smc.load_likes = function(id = false, event = false) {
if ($.isNumeric(id) && id) {
var _self = $(event);
var likes_ls = $('div[data-app="post-likes-list"]');
var last_item = likes_ls.find('div[data-list-item]').last();
if (last_item.length) {
$.ajax({
url: 'https://spoutible.com/sptbl_system_api/main/load_likes',
type: 'GET',
dataType: 'json',
data: {id: id, offset: last_item.data('list-item')},
beforeSend: function() {
_self.attr('disabled', 'true').text("Please wait");
}
}).done(function(data) {
if (data.status == 200) {
likes_ls.find('div[data-an="users-ls"]').append($(data.html));
_self.removeAttr('disabled').text("Show more");
}
else {
_self.text("That is all for now!");
}
});
}
}
}
_smc.follow = function(event = false) {
if (event) {
if (_smc.is_logged()) {
var target = $(event);
if(target.data('action') == 'unfollow') {
var promise = SPTBL_APP.confirm_action({
btn_1: "Cancel",
btn_2: "Unfollow",
title: "Delete?",
message: "Please note that, if you unsubscribe then this user's posts will no longer appear in the feed on your main page.",
});
promise.done(function() {
target.data('action', 'follow');
target.text("Follow");
target.replaceClass('main-inline','main-outline');
$.ajax({
url: 'https://spoutible.com/sptbl_system_api/main/follow',
type: 'POST',
dataType: 'json',
data: {id: target.data('id')},
}).done(function(data) {
if (data.status != 200) {
_smc.errorMSG();
}
else {
if (_smc.curr_pn == "profile") {
if (data.refresh != undefined) {
$(window).reloadPage(1000);
}
}
}
}).always(function() {
$("div.confirm-actions-modal").modal("hide");
});
sptbl_bs_notify("You unfollowed @{0}".format(target.data("user-name")), 1500);
});
promise.fail(function() {
$("div.confirm-actions-modal").modal("hide");
});
}
else {
target.data('action', 'unfollow');
target.text("Following");
target.replaceClass('main-outline','main-inline');
delay(function(){
target.text("Unfollow");
}, 1500);
$.ajax({
url: 'https://spoutible.com/sptbl_system_api/main/follow',
type: 'POST',
dataType: 'json',
data: {id: target.data('id')},
}).done(function(data) {
if (data.status != 200) {
_smc.errorMSG();
}
else {
if (_smc.curr_pn == "profile") {
if (data.refresh != undefined) {
$(window).reloadPage(1000);
}
}
}
});
sptbl_bs_notify("You followed @{0}".format(target.data("user-name")), 1500);
}
}
else{
_smc.req_auth();
}
}
}
_smc.req_follow = function(event = false) {
if (event) {
if (_smc.is_logged()) {
var target = $(event);
if(target.data('action') == 'unfollow') {
var promise = SPTBL_APP.confirm_action({
btn_1: "Cancel",
btn_2: "Unfollow",
title: "Delete?",
message: "Please note that, if you unsubscribe then this user's posts will no longer appear in the feed on your main page.",
});
promise.done(function() {
target.data('action', 'follow');
target.text("Follow");
target.replaceClass('main-inline','main-outline');
$.ajax({
url: 'https://spoutible.com/sptbl_system_api/main/follow',
type: 'POST',
dataType: 'json',
data: {id: target.data('id')},
}).done(function(data) {
if (data.status != 200) {
_smc.errorMSG();
}
}).always(function() {
$("div.confirm-actions-modal").modal("hide");
});
sptbl_bs_notify("You unfollowed @{0}".format(target.data("user-name")), 1500);
});
promise.fail(function() {
$("div.confirm-actions-modal").modal("hide");
});
}
else if(target.data('action') == 'cancel') {
var promise = SPTBL_APP.confirm_action({
btn_1: "Cancel",
btn_2: "Cancel request",
title: "Delete?",
message: "This will cancel your pending request and this user will no longer see it.",
});
promise.done(function() {
target.data('action', 'follow');
target.text("Follow");
target.replaceClass('main-inline','main-outline');
$.ajax({
url: 'https://spoutible.com/sptbl_system_api/main/follow',
type: 'POST',
dataType: 'json',
data: {id: target.data('id')},
}).done(function(data) {
if (data.status != 200) {
_smc.errorMSG();
}
}).always(function() {
$("div.confirm-actions-modal").modal("hide");
});
sptbl_bs_notify("You unfollowed @{0}".format(target.data("user-name")), 1500);
});
promise.fail(function() {
$("div.confirm-actions-modal").modal("hide");
});
}
else {
target.data('action', 'cancel');
target.text("Requested");
target.replaceClass('main-outline', 'main-inline');
delay(function() {
target.text("Pending");
}, 1500);
$.ajax({
url: 'https://spoutible.com/sptbl_system_api/main/follow',
type: 'POST',
dataType: 'json',
data: {id: target.data('id')},
}).done(function(data) {
if (data.status != 200) {
_smc.errorMSG();
}
});
sptbl_bs_notify("Follow request sent to @{0}".format(target.data("user-name")), 1500);
}
}
else{
_smc.req_auth();
}
}
}
_smc.block = function(event = false) {
if (event) {
if (_smc.is_logged()) {
var target = $(event);
if(target.data('action') == 'block') {
var promise = SPTBL_APP.confirm_action({
btn_1: "Cancel",
btn_2: "Block",
title: "Delete?",
message: "Blocked users will no longer be able to write a message to you, follow you, or see your profile and spouts, etc.",
});
promise.done(function() {
target.data('action','unblock');
target.text("Unblock");
if (target.hasClass('toggle-class')) {
target.replaceClass('main-inline', 'main-outline');
}
$.ajax({
url: 'https://spoutible.com/sptbl_system_api/main/block',
type: 'POST',
dataType: 'json',
data: {id: target.data('id')},
}).done(function(data) {
if (data.status != 200) {
SPTBL_APP.errorMSG();
}
else {
if (_smc.curr_pn == 'profile') {
_smc.spa_reload();
}
}
}).always(function() {
$("div.confirm-actions-modal").modal("hide");
});
});
promise.fail(function() {
$("div.confirm-actions-modal").modal("hide");
});
}
else if(target.data('action') == 'unblock') {
var promise = SPTBL_APP.confirm_action({
btn_1: "Cancel",
btn_2: "Unblock",
title: "Delete?",
message: "Are you sure you want to unblock this user? Now they can follow you or see your posts, etc.",
});
promise.done(function() {
target.data('action','block');
target.text("Block");
if (target.hasClass('toggle-class')) {
target.replaceClass('main-outline', 'main-inline');
}
$.ajax({
url: 'https://spoutible.com/sptbl_system_api/main/block',
type: 'POST',
dataType: 'json',
data: {id: target.data('id')},
}).done(function(data) {
if (data.status != 200) {
SPTBL_APP.errorMSG();
}
else {
if (_smc.curr_pn == 'profile') {
$(window).reloadPage();
}
}
}).always(function() {
$("div.confirm-actions-modal").modal("hide");
});
});
promise.fail(function() {
$("div.confirm-actions-modal").modal("hide");
});
}
}
else{
_smc.req_auth();
}
}
}
_smc.mute = function(event = false) {
if (event) {
if (_smc.is_logged()) {
var target = $(event);
if(target.data('action') == 'mute') {
var promise = SPTBL_APP.confirm_action({
btn_1: "Cancel",
btn_2: "Mute",
title: "Delete?",
message: "Are you sure you want to Mute this user? You will not be able to see the Muted user Spouts.",
});
promise.done(function() {
target.data('action','unmute');
target.text("Unmute");
if (target.hasClass('toggle-class')) {
target.replaceClass('main-inline', 'main-outline');
}
$.ajax({
url: 'https://spoutible.com/sptbl_system_api/main/mute',
type: 'POST',
dataType: 'json',
data: {id: target.data('id')},
}).done(function(data) {
if (data.status != 200) {
SPTBL_APP.errorMSG();
}
else {
sptbl_bs_notify(`You Muted The user!`, 1500);
if (_smc.curr_pn == 'profile') {
_smc.spa_reload();
}
}
}).always(function() {
$("div.confirm-actions-modal").modal("hide");
});
});
promise.fail(function() {
$("div.confirm-actions-modal").modal("hide");
});
} else if(target.data('action') == 'unmute') {
var promise = SPTBL_APP.confirm_action({
btn_1: "Cancel",
btn_2: "Unmute",
title: "Delete?",
message: "Are you sure you want to Unmute this user? Now you will see his spouts.",
});
promise.done(function() {
target.data('action','mute');
target.text("Mute");
if (target.hasClass('toggle-class')) {
target.replaceClass('main-outline', 'main-inline');
}
$.ajax({
url: 'https://spoutible.com/sptbl_system_api/main/mute',
type: 'POST',
dataType: 'json',
data: {id: target.data('id')},
}).done(function(data) {
if (data.status != 200) {
SPTBL_APP.errorMSG();
}
else {
sptbl_bs_notify(`You Unmuted The user!`, 1500);
if (_smc.curr_pn == 'profile') {
$(window).reloadPage();
}
}
}).always(function() {
$("div.confirm-actions-modal").modal("hide");
});
});
promise.fail(function() {
$("div.confirm-actions-modal").modal("hide");
});
}
}
else{
_smc.req_auth();
}
}
}
_smc.errorMSG = function(error) {
sptbl_bs_notify(error || "An error occurred while processing your request. Please try again later.", 3000, "danger");
}
_smc.extend_vue = function(app_name = "", vue_instance = {}) {
_smc.vue[app_name] = vue_instance;
}
_smc.progress_bar = function(a = "show") {
if (a == "show") {
window.waitMe.start();
}
else {
window.waitMe.end();
}
}
// _smc.update_msb_indicators = function() {
// if (_smc.is_logged()) {
// var main_left_sb = $('div[data-app="left-sidebar"]');
// var main_bottom_nb = $('div[data-app="mobile-navbar"]');
// var timer_id = setInterval(function() {
// $.ajax({
// url: 'https://spoutible.com/sptbl_system_api/main/update_msb_indicators',
// type: 'GET',
// dataType: 'json',
// }).done(function(data) {
// if (data.status == 200) {
// // if (data.notifications > 0) {
// // var notifs_total = data.notifications;
// // if (data.notifications > 99) {
// // notifs_total = "99+";
// // }
// // main_left_sb.find('[data-an="group-ind"]').addClass("group-ind-active");
// // main_left_sb.find('[data-an="new-notifs"]').text($.trim(notifs_total));
// // main_bottom_nb.find('[data-an="new-notifs"]').text($.trim(notifs_total));
// // }
// // else {
// // main_left_sb.find('[data-an="group-ind"]').removeClass("group-ind-active");
// // main_left_sb.find('[data-an="new-notifs"]').empty();
// // main_bottom_nb.find('[data-an="new-notifs"]').empty();
// // }
// // if (data.messages) {
// // var messages_total = data.messages;
// // if (data.messages > 99) {
// // messages_total = "99+";
// // }
// // main_left_sb.find('[data-an="group-ind"]').addClass("group-ind-active");
// // main_left_sb.find('[data-an="new-messages"]').text($.trim(messages_total));
// // main_bottom_nb.find('[data-an="new-messages"]').text($.trim(messages_total));
// // }
// // else {
// // main_left_sb.find('[data-an="group-ind"]').removeClass("group-ind-active");
// // main_left_sb.find('[data-an="new-messages"]').empty();
// // main_bottom_nb.find('[data-an="new-messages"]').empty();
// // }
// }
// else {
// clearInterval(timer_id);
// }
// });
// }, (Number(_smc.msb_upinterval) * 1000));
// }
// }
_smc.hide_sb = function() {
$('div[data-app="lsb-back-drop"]').trigger('click');
}
_smc.spa_load = function(url = "", push_state = true) {
var timeline = $('[data-el="timeline-container-wrapper"]');
var preloader = timeline.find('[data-el="spa-preloader"]');
var left_sidebar = $('[data-app="left-sidebar"]');
var mobile_navbar = $('[data-app="mobile-navbar"]');
if (push_state == true) {
// if user is going to a single post from timeline,
// then store the scroll height to get back to it when he is back
if ((window.location.pathname == "/" || window.location.pathname == '/home') && url.includes('thread')) {
var post_ls = $('[data-app="homepage"]').find('[data-an="entry-list"]');
}
if (window.location.pathname.includes('conversation') && window.websocket !== undefined) {
window.websocket.close();
window.websocket = undefined;
}
window.history.pushState({state: "new", back_url: url}, "", url);
}
// else if (! push_state && ((window.location.pathname == "/" || window.location.pathname == '/home') && sessionStorage.getItem('dataLimit'))) {
// data.limit = sessionStorage.getItem('dataLimit');
// }
if (window.mobileCheck()) {
_smc.hide_sb();
}
// after pushing to state we can check the path correctly
// for vue refactor, we set the component name to null to use the old way for SPA (non-refactored components)
var currentRoute = window.location.pathname.replace(/^\/+/, '').split('/')[0];
if (currentRoute === "" || currentRoute === 'home') {
if (window.vue_instance.timelineComponent) {
window.vue_instance.timelineComponent.reset();
}
window.vue_instance.swapComponent('timeline');
window.scrollTo(0, 0);
timeline.find('[data-el="timeline-content"]').html('');
left_sidebar.find('[data-navitem]').each(function(index, el) {
$(el).removeClass('active');
}).promise().done(function() {
left_sidebar.find('[data-navitem="home"]').addClass('active');
});
if (_smc.timeout !== false) {
clearTimeout(_smc.timeout);
}
if ( 'Gifffer' in window && $('img[data-gifffer]').length > 0 ) {
Gifffer()
}
preloader.removeClass('d-none');
$("div.dropdown-menu.show").each(function(index, el) {
$(el).removeClass("show");
});
mobile_navbar.find('[data-navitem]').each(function(index, el) {
$(el).removeClass('active');
}).promise().done(function() {
mobile_navbar.find('[data-navitem="home"]').addClass('active');
});
const body = document.querySelector('body')
body.classList = ''
body.classList.add('sptbl-app-home')
_smc.toggleSB("hide");
this.previous_url = window.location.pathname
return;
} else if (currentRoute === 'search') {
if (window.vue_instance.searchComponent) {
window.vue_instance.searchComponent.reset()
}
window.vue_instance.swapComponent('search')
window.scrollTo(0, 0);
timeline.find('[data-el="timeline-content"]').html('');
left_sidebar.find('[data-navitem]').each(function(index, el) {
$(el).removeClass('active');
}).promise().done(function() {
left_sidebar.find('[data-navitem="search"]').addClass('active');
});
if (_smc.timeout !== false) {
clearTimeout(_smc.timeout);
}
if ( 'Gifffer' in window && $('img[data-gifffer]').length > 0 ) {
Gifffer()
}
preloader.removeClass('d-none');
$("div.dropdown-menu.show").each(function(index, el) {
$(el).removeClass("show");
});
mobile_navbar.find('[data-navitem]').each(function(index, el) {
$(el).removeClass('active');
}).promise().done(function() {
mobile_navbar.find('[data-navitem="search"]').addClass('active');
});
const body = document.querySelector('body')
body.classList = ''
body.classList.add('sptbl-app-search')
_smc.toggleSB("hide");
this.previous_url = window.location.pathname
return;
} else {
window.vue_instance.swapComponent(null)
}
this.previous_url = window.location.pathname
$.ajax({
url: url,
type: 'GET',
data: {spa_load: 1, limit: 160},
dataType: 'json',
async: true,
beforeSend: function() {
_smc.user_lbox_rm();
$("html, body").animate({
scrollTop: 0
}, 10).promise().done(function() {
preloader.removeClass('d-none');
});
_smc.toggleSB("hide");
sptbl_close_all_modals();
}
}).done(function(data = {}) {
if (data.status == 200) {
var prevapp = _smc.curr_pn;
var json_data = data.json_data;
_smc.curr_pn = json_data.pn;
$('head').find('title').text(json_data.page_title);
$('head').find('meta[name="title"]').attr('content', json_data.page_title);
$('head').find('meta[name="description"]').attr('content', json_data.page_desc);
$('head').find('meta[name="keywords"]').attr('content', json_data.page_kw);
if (json_data.page_img) {
$('head').find('meta[name="image"]').attr('content', json_data.page_img);
}
if ($('body').hasClass('sptbl-app-{0}'.format(prevapp))) {
$('body').removeClass('sptbl-app-{0}'.format(prevapp));
$('body').addClass('sptbl-app-{0}'.format(json_data.pn));
}
else {
$('body').addClass('sptbl-app-{0}'.format(json_data.pn));
}
$('body').attr('data-page-tab', json_data.page_tab);
timeline.find('[data-el="timeline-content"]').html(data.html);
// if (! push_state && sessionStorage.getItem('scrollHeight') && window.location.pathname == '/') {
// $("html, body").animate({
// scrollTop: sessionStorage.getItem('scrollHeight')
// }, 100);
// sessionStorage.removeItem('scrollHeight')
// }
left_sidebar.find('[data-navitem]').each(function(index, el) {
$(el).removeClass('active');
}).promise().done(function() {
if (_smc.curr_pn == "profile") {
if (json_data.page_xdata.is_me) {
left_sidebar.find('[data-navitem="profile"]').addClass('active');
}
}
else{
left_sidebar.find('[data-navitem="{0}"]'.format(_smc.curr_pn)).addClass('active');
}
});
mobile_navbar.find('[data-navitem]').each(function(index, el) {
$(el).removeClass('active');
}).promise().done(function() {
mobile_navbar.find('[data-navitem="{0}"]'.format(_smc.curr_pn)).addClass('active');
});
if ( /\/notifications($|\?|#)/.test(url) ) {
$('[data-an="new-notifs"]').empty()
}
}
else if(data.status == 302) {
_smc.spa_load(data.redirect_url);
}
else {
_smc.spa_load("https://spoutible.com/404");
}
}).always(function() {
if (_smc.timeout !== false) {
clearTimeout(_smc.timeout);
}
if ( 'Gifffer' in window && $('img[data-gifffer]').length > 0 ) {
Gifffer()
}
preloader.addClass('d-none');
$("div.dropdown-menu.show").each(function(index, el) {
$(el).removeClass("show");
});
setTimeout(() => {
window.load_videos()
}, 200);
});
return false;
}
_smc.spa_reload = function() {
if (window.location.href != undefined) {
_smc.spa_load(window.location.href);
}
else {
_smc.spa_load(data['url']);
}
return false;
}
_smc.go_back = function() {
history.back();
}
_smc.jump_back = function(step = 1) {
history.go(step);
}
_smc.report_post = function(id = false) {
if (_smc.is_logged()) {
if (_smc.vue.report_post != undefined && id) {
_smc.vue.report_post.open(id);
}
else {
_smc.errorMSG();
}
}
else {
_smc.req_auth();
}
}
_smc.add_user_to_list = function(user) {
if (!_smc.is_logged()) {
_smc.req_auth();
}
window.vue_instance.$refs.timelineListsModal.showWithUserLists(user)
}
_smc.update_ilb = function() {
$('a[href].fbox-media:not(.has-alt-text)').fancybox({
arrows: true,
openEffect: 'elastic',
closeEffect: false,
hash: false,
i18n: {
en: {
ERROR: "The requested content could not be loaded. Please try again later.", } } }); } return _smc; } if (window.SPTBL_APP === undefined) { window.SPTBL_APP = _SPTBL_APP(); } })(window); $(document).ready(function($) { SPTBL_APP.init(); var clipboard = new ClipboardJS('.clip-board-copy'); var page_height = $(document).height(); clipboard.on('success', function(event) { sptbl_bs_notify("Copied to your clipboard!",500); }); clipboard.on('error', function(event) { sptbl_bs_notify("Failed to copy to clipboard!",3000); }); if (navigator.cookieEnabled == false) { $('[data-app="announcement"]').html("
Oops! It looks like you have cookies disabled. For this site to work properly, you need to enable cookies.
");
}
$(document).on('click', 'div[data-app="lsb-back-drop"]', function(event) {
event.preventDefault();
SPTBL_APP.toggleSB();
});
var _lozad_ = lozad();
setTimeout(() => {
_lozad_.observe();
}, 500);
$(document).on("ajaxComplete", function(event, request, settings) {
setTimeout(() => {
_lozad_.observe();
// SPTBL_APP.fix_sidebars();
SPTBL_APP.update_ilb();
}, 500);
});
// terminated on 30-7-2023 for bad performance
// setInterval(function() {
// var new_page_height = $(document).height();
// var _lozad_ = lozad();
// _lozad_.observe();
// if (page_height != new_page_height) {
// page_height = new_page_height;
// SPTBL_APP.fix_sidebars();
// SPTBL_APP.update_ilb();
// }
// if ($('video[data-el="sptbl-video"]').length) {
// $('video[data-el="sptbl-video"]').each(function(index, el) {
// if ($(el).hasClass('afterglow') != true) {
// var video_src = $(el).find("source").first().attr("src");
// $(el).width("100%").height("100%").addClass('afterglow');
// $(el).find("source").remove();
// $(el).append($("