App.prototype.loadCommentForm = function() {
var commentTool = '';
var modalcontent = '';
this.commentForm = true;
if (!this.checkMyTioInit()) {
return;
}
if (!this.myTio || !this.myTio.user) {
commentTool += '
';
commentTool += '';
commentTool += ' Accedi per commentare';
commentTool += ' ';
commentTool += '
';
} else {
modalcontent += '';
commentTool += '';
var profileImg = '';
if (this.myTio.user.profile.photo) {
profileImg = ' ';
} else {
profileImg = this.myTio.user.tiolounge.nickname;
}
commentTool += '';
commentTool += modalcontent;
if (this.m.config.nativeFrame) {
if (window.webkit && window.webkit.messageHandlers) {
window.webkit.messageHandlers.login.postMessage({ status: true });
} else {
try { tionativehandler.nativeLogin(JSON.stringify({ 'status': true })); } catch (error) { }
}
}
this.loadCommentsActions();
}
jQuery("#usercommentbox").html(commentTool);
};
App.prototype.loadCommentsActions = function() {
jQuery('.comment-actions').each(function() {
if (typeof jQuery(this).attr('data-commentid') !== undefined) {
jQuery(this).removeClass('d-none');
}
});
};
App.prototype.newComment = function(el) {
_this = this;
if (this.netLock()) {
return false;
}
if (jQuery('#usercomment').val().trim().length <= 1) {
swal.fire({
title: 'Errore',
html: 'Scrivi un commento',
icon: 'error',
timer: 5000
});
jQuery('#usercomment').focus();
return false;
}
if (jQuery('#comment-terms').prop('checked') == false) {
swal.fire({
title: 'Errore',
html: 'Per inserire commenti è necessario accettare le condizioni del blog.',
icon: 'error',
timer: 5000
});
return false;
}
var p = {
'idarticolo': jQuery('#usercomment').attr('data-contentid'),
'commento': jQuery('#usercomment').val(),
'id_commento': jQuery('#usercomment').attr('data-replyto'),
'id_risposta': jQuery('#usercomment').attr('data-replyto'),
'risposta_a': jQuery('#usercomment').attr('data-replytoname'),
'id_blocco': jQuery('#usercomment').attr('data-blockid'),
'titolo': '',
};
jQuery(el).prop('disabled', true).addClass('btn-disabled');
jQuery("#c").html(' ').css({ 'display': 'block' }).stop().animate({ 'opacity': '.5' }, 200);
var token = this.myTio.fbAuth.currentUser.getIdToken();
token.then(function(jwt) {
_this.showLoading();
p.token = jwt;
p.action = 'blog';
jQuery.ajax({
url: '/ext/mytio/',
type: 'POST',
dataType: "json",
data: p,
success: function(data, textStatus, jqXHR) {
_this.hideLoading();
var displayError = '';
var errorClass = 'error';
var errorTitle = 'Errore';
var errorTimer = 6000;
if (data.message == 'SUCCESS') {
swal.fire({
title: "",
html: "Commento inserito con successo",
icon: "success",
timer: 5000
}).then(function() {
app.reloadPage();
});
} else if (data.message == "DATA_MISSING") {
displayError = "Manca il commento.
";
} else if (data.message == "ARTICLE_MISSING") {
displayError = "L'articolo non esiste o non è commentabile.
";
} else if (data.message == "PROFILE_NOT_COMPLETED") {
var messageText = 'Il profilo usato non è abilitato a scrivere su TioBlog.';
if (data.messageText) {
messageText = data.messageText;
}
displayError = '' + messageText + 'Clicca qui per completare il profilo.
';
errorClass = 'warning';
errorTitle = 'Attenzione';
errorTimer = 20000;
} else if (data.message == "DUPLICATED") {
displayError = "Commento Duplicato.
Non è permesso scrivere lo stesso commento due volte nel blog.
";
} else if (data.message == "HTML") {
displayError = "Del codice HTML è stato indentificato all'interno del commento.
";
} else if (data.message == "DELAYED") {
errorTitle = 'Attenzione';
displayError = "I commenti vengono pubblicati in automatico durante i giorni feriali dalle 07:00 alle 22:00.
Al di fuori da questo orario devono essere accettati manualmente dalla redazione e può volerci del tempo prima che appaiano sul sito.
";
errorClass = 'success';
} else if (data.message == "TIME_ENDED") {
displayError = "Gli articoli sono commentabili solo fino a 10 giorni dopo la loro pubblicazione.
";
} else if (data.message == "NIGHT_PAUSE") {
displayError = "Per questioni di moderazione è possibile commentare solo dalle 07:00 alle 22:00.
";
} else if (data.message == 'NOT_LOGGED') {
displayError = "Sessione scaduta: Per favore cliccare su logout ed eseguire di nuovo il login.
";
} else if (data.message == 'COMMENT_WORDS') {
errorTitle = 'Attenzione';
errorClass = 'warning';
errorTimer = 10000;
displayError = '' + data.messageText + '
';
} else if (data.messageText) {
displayError = data.messageText;
} else {
displayError = "Non è stato possibile inserire il commento.
";
debug.log('Unknown reply: ' + data.message);
}
if (displayError.length > 0) {
swal.fire({
title: errorTitle,
html: displayError,
icon: errorClass,
timer: errorTimer,
backdrop: true
});
}
jQuery(el).prop('disabled', false).removeClass('btn-disabled');
jQuery("#c").html('').fadeOut();
},
error: function(jqXHR, textStatus, errorThrown) {
_this.hideLoading();
swal.fire({
title: 'Errore',
html: 'Non è stato possibile inserire il commento.',
icon: 'error',
timer: 4000
});
debug.log('POST XHR ERROR: ' + textStatus);
jQuery(el).prop('disabled', false).removeClass('btn-disabled');
jQuery("#c").html('').fadeOut();
}
});
});
};
App.prototype.replyToComment = function(el) {
this.setComment(jQuery(el).closest('.comment'));
};
App.prototype.reportComment = function(el) {
_this = this;
var nickname = '';
const comment = jQuery(el).closest('.comment');
if (typeof jQuery(comment).attr('data-nickname') !== undefined) {
nickname = jQuery(comment).attr('data-nickname');
}
var p = {
'id_commento': jQuery(comment).attr('data-commentid')
};
Swal.fire({
title: 'Segnala commento',
input: 'checkbox',
inputPlaceholder: 'Desidero segnalare il commento come inappropriato',
showCancelButton: true,
confirmButtonText: 'Segnala',
cancelButtonText: 'Annulla',
reverseButtons: true,
allowOutsideClick: true,
allowEscapeKey: true,
inputValidator: (result) => {
return !result && "È necessario confermare la segnalazione";
}
}).then((result) => {
if (result.value) {
_this.showLoading();
var token = this.myTio.fbAuth.currentUser.getIdToken();
token.then(function(jwt) {
p.token = jwt;
p.action = 'report';
jQuery.ajax({
url: '/ext/mytio/',
type: 'POST',
dataType: "json",
data: p,
success: function(data, textStatus, jqXHR) {
_this.hideLoading();
var errorTitle = "Errore";
var errorMessage = "Errore durante l'invio della segnalazione.";
var errorTimer = 5000;
if (data && data.message) {
if (data.message == 'SUCCESS') {
Swal.fire({
title: "Segnalazione",
html: "La segnalazione è stata inviata alla redazione.",
icon: "success",
timer: 5000,
backdrop: true
});
return;
}
if (data.messageText) {
errorMessage = data.messageText;
}
if (data.message == "PROFILE_NOT_COMPLETED") {
errorMessage = errorMessage + 'Clicca qui per completare il profilo. ';
errorTitle = "Attenzione";
errorTimer = 20000;
}
}
Swal.fire({
title: errorTitle,
html: errorMessage,
icon: "error",
timer: errorTimer,
backdrop: true
});
},
error: function(jqXHR, textStatus, errorThrown) {
_this.hideLoading();
Swal.fire({
title: "Errore",
html: "Errore durante l'invio della segnalazione.",
icon: "error",
timer: 5000,
backdrop: true
});
}
});
});
}
});
};
App.prototype.adBlockDetail = function(el, evt) {
var id;
if (typeof jQuery(el).attr('data-id') !== undefined) {
id = jQuery(el).attr('data-id');
}
jQuery('.adblockList li').removeClass('active');
jQuery(el).addClass('active');
jQuery('.adblock_detail').hide();
jQuery('#' + id + '_detail').show();
};
App.prototype.initBiglietteria = function() {
if (jQuery('.slick.biglietteria').length) {
if (!jQuery('.slick.biglietteria').hasClass("slick-initialized")) {
var initSlide = Math.floor((Math.random() * jQuery('.slick.biglietteria').find('.slide').length));
jQuery('.slick.biglietteria').slick({ initialSlide: initSlide, dots: true, infinite: true, arrows: false, autoplay: true });
}
}
};
App.prototype.disabledDiv = 'Questo contenuto è stato bloccato dalle vostre impostazioni sulla privacy. Modificare le impostazioni per accedere a questo tipo di contenuti.
Modifica Impostazioni Cookies ';
App.prototype.disableSocials = function() {
if (!this.checkGDPR('socials')) {
jQuery('.native_socials').remove();
jQuery('.script_obj').addClass('disabled');
jQuery('.script_obj').html(this.disabledDiv);
}
};
App.prototype.disableFunctions = function() {
if (!this.checkGDPR('functions')) {
$("#content_frame").replaceWith('' + this.disabledDiv + '
');
$('[data-video-type="video/youtube"]').replaceWith('' + this.disabledDiv + '
');
}
};
function OptanonWrapper() {
if (typeof OneTrust === 'undefined') {
return;
}
if (!OneTrust.IsAlertBoxClosed()) {
document.querySelector('html').classList.toggle('noscroll', true);
return;
}
document.querySelector('html').classList.toggle('noscroll', false);
if (!app.checkMyTioInit()) {
return;
}
if (app.checkOneTrust('analytics')) {
app.checkUserID();
app.googleAnalyticsInit();
app.mediaPulseCall(app.m.server.section_name, app.m.server.sub_section_name);
}
if (!app.checkOneTrust('functions')) {
app.disableFunctions();
}
if (!app.checkOneTrust('socials')) {
app.disableSocials();
}
app.tioAnalyticsCall();
if (app.checkBotUa()) {
return;
}
if (app.myTio.checkPermissions('mytioabo')) {
return;
}
if (!app.checkOneTrust('all')) {
app.showOneTrustMytio('');
return;
}
if (window.__tcfapi) {
__tcfapi('addEventListener', 2, function(tcData, success) {
if (success && (tcData.eventStatus === 'tcloaded' || tcData.eventStatus === 'cmpuishown' || tcData.eventStatus === 'useractioncomplete')) {
OptanonCheckTcData(tcData)
}
});
}
return;
}
function OptanonCheckTcData(tcData) {
app.adsLog(tcData);
let check_publisher_consents = true;
if (Object.keys(tcData.publisher.consents).length == 0) {
check_publisher_consents = false;
} else {
Object.keys(tcData.publisher.consents).forEach(key => {
if (key == 1) {
return;
}
if (!tcData.publisher.consents[key]) {
check_publisher_consents = false;
}
});
}
app.adsLog('check_publisher_consents', check_publisher_consents);
if (!check_publisher_consents) {
app.showOneTrustMytio('check_publisher_consents');
return;
}
let check_purpose_consent = true;
if (Object.keys(tcData.purpose.consents).length == 0) {
check_purpose_consent = false;
} else {
Object.keys(tcData.purpose.consents).forEach(key => {
if (key == 1) {
return;
}
if (!tcData.purpose.consents[key]) {
check_purpose_consent = false;
}
});
}
app.adsLog('check_purpose_consent', check_purpose_consent);
if (!check_purpose_consent) {
app.showOneTrustMytio('check_purpose_consent');
return;
}
let specialFeatureOptins = true;
if (Object.keys(tcData.specialFeatureOptins).length < 2) {
specialFeatureOptins = false;
} else {
Object.keys(tcData.specialFeatureOptins).forEach(key => {
if (!tcData.specialFeatureOptins[key]) {
specialFeatureOptins = false;
}
});
}
app.adsLog('specialFeatureOptins', specialFeatureOptins);
if (!specialFeatureOptins) {
app.showOneTrustMytio('specialFeatureOptins');
return;
}
let count_vendor_consent = 0;
Object.values(tcData.vendor.consents).forEach(val => {
if (val) {
count_vendor_consent++;
}
});
app.adsLog('count_vendor_consent', count_vendor_consent);
/**
* Questo numero è basato sui miei test su quanti ci sono se è accetta tutto, e quanti se li togli tutti dal pannello, da verificare se funziona ovunque
*/
let min_vendor_consent = 680;
if (count_vendor_consent < min_vendor_consent) {
app.showOneTrustMytio('count_vendor_consent');
return;
}
if (app.oneTrustAlertLoaded) {
app.oneTrustAlertLoaded = false;
swal.close();
}
if (app.m.device.adblock) {
app.adblockMsg();
return;
}
app.startAdsTypes();
}
App.prototype.hideReactions = function(el, evt) {
jQuery('.reactionListTouchExit').hide();
jQuery('.reactionsList').hide();
}
App.prototype.reactionStatus = 'init';
App.prototype.loadReactions = function(el, evt) {
if (jQuery('[data-field=current]').length > 0) {
var current = jQuery('[data-field=current]').html()
if (current == 'disabled') {
jQuery('.reactions').hide();
}
}
var reactions_json = [];
if (jQuery('.reactions_json').length > 0) {
try {
reactions_json = JSON.parse(jQuery('.reactions_json').html());
} catch (e) { }
}
var reactions_user_json = [];
if (jQuery('.reactions_user_json').length > 0) {
try {
reactions_user_json = JSON.parse(jQuery('.reactions_user_json').html());
} catch (e) { }
}
var currentReaction = '';
if (reactions_user_json.length > 0) {
jQuery('.mainReaction .reactionIconMedium').removeClass().addClass('reactionIconMedium').addClass(reactions_user_json[0]['name']).attr('data-type', reactions_user_json[0]['name']);
currentReaction = reactions_user_json[0]['name'];
jQuery('.reactionIconSmall.' + currentReaction).addClass('active');
jQuery('.reactionIconMedium.' + currentReaction).addClass('active');
jQuery('.reactionIconBig.' + currentReaction).addClass('active');
jQuery('.nReactions.' + currentReaction).addClass('active');
jQuery('.totReactions').addClass('active');
}
if (this.reactionStatus == 'init') {
this.reactionStatus = 'start';
if (this.m.config.type == 'web') {
jQuery('.mainReaction .reactionIconMedium').on('click', function(evt) {
app.setReaction(this, evt);
});
} else {
jQuery('.mainReaction .reactionIconMedium').on('click', function(evt) {
if (!jQuery('.reactionsList').is(':visible')) {
app.setReaction(jQuery('.mainReaction .reactionIconMedium'));
}
});
this.longPress(el, function() {
}, function() {
if (!jQuery('.reactionsList').is(':visible')) {
jQuery('.reactionListTouchExit').show();
jQuery('.reactionsList').show();
}
})
}
}
var countSmallReactions = 0;
jQuery('.smallReactions').html('');
for (var i = 0; i < reactions_json.length; i++) {
if (currentReaction == '' && i == 0) {
if (reactions_json[i]['tot'] >= 10) {
jQuery('.mainReaction .reactionIconMedium').removeClass().addClass('reactionIconMedium').addClass(reactions_json[i]['name']).attr('data-type', reactions_json[i]['name'])
currentReaction = reactions_json[i]['name'];
} else {
currentReaction = 'up';
}
}
if (currentReaction != reactions_json[i]['name'] && countSmallReactions < 3) {
jQuery('.smallReactions').prepend('
');
countSmallReactions++;
}
jQuery('.nReactions.' + reactions_json[i]['name']).html(dataFormat(reactions_json[i]['tot'], 'quotes'));
}
this.reactionStatus = 'ready';
}
App.prototype.setReaction = function(el, evt) {
if (this.reactionStatus == 'procesing') {
return;
}
if (this.scrolling) {
return;
}
if (!this.enabledAnalytics()) {
_this.notify({
content: 'Reazione articolo: stastitiche disattivate',
class: 'error',
timeout: 6
});
return;
}
if (evt) {
evt.preventDefault();
evt.stopPropagation();
}
if (typeof jQuery(el).attr('data-type') === 'undefined') {
return;
}
this.reactionStatus = 'procesing';
if (jQuery('.reactions_user_json').length > 0) {
try {
reactions_user_json = JSON.parse(jQuery('.reactions_user_json').html());
} catch (e) { }
}
var type = jQuery(el).attr('data-type');
if (jQuery(el).hasClass('active')) {
type = 'none';
}
u = _this.m.config.analyticsUrl + "/ext/api.php?output=thumbs&type=" + type + "&uid=" + this.m.device.analyticsUserID + "&id=" + this.m.server.content_id;
jQuery.get(u, function(type) {
return function(data) {
if (data && data.result && data.result == 'OK') {
jQuery('.reactions .active').removeClass('active');
jQuery('.nReactions').html('');
var reactions_json = [];
try {
reactions_json = JSON.parse(jQuery('.reactions_json').html());
} catch (e) { }
var old_reactions_user_json = [];
try {
old_reactions_user_json = JSON.parse(jQuery('.reactions_user_json').html());
} catch (e) { }
var totReactions = parseInt(jQuery('.totReactions').html(), 10)
var reactions_user_json = [];
var checkReactionAdd = false;
if (type == 'none') {
totReactions = totReactions - 1;
} else {
if (old_reactions_user_json.length == 0) {
totReactions = totReactions + 1;
}
var reactions_user_json = [{
name: type,
tot: 1
}];
checkReactionAdd = true;
}
var checkReactionRemove = false;
for (var i = 0; i < reactions_json.length; i++) {
if (reactions_json[i].name == type) {
reactions_json[i].tot = parseInt(reactions_json[i].tot, 10) + 1;
reactions_user_json[0].tot = parseInt(reactions_json[i].tot, 10) + 1;
checkReactionAdd = false;
}
if (old_reactions_user_json.length > 0) {
if (reactions_json[i].name == old_reactions_user_json[0].name) {
reactions_json[i].tot = parseInt(reactions_json[i].tot, 10) - 1;
if (reactions_json[i].tot == 0) {
checkReactionRemove = i;
}
}
}
}
if (checkReactionRemove) {
reactions_json.splice(checkReactionRemove, 1);
}
if (checkReactionAdd) {
reactions_json.push(reactions_user_json[0]);
}
jQuery('.reactions_user_json').html(JSON.stringify(reactions_user_json));
jQuery('.reactions_json').html(JSON.stringify(reactions_json));
jQuery('.totReactions').html(totReactions);
app.loadReactions();
_this.notify({
content: 'Reazione registrata',
class: 'success',
timeout: 5
});
return;
}
app.reactionStatus = 'error';
_this.notify({
content: 'Errore, riprova tra un attimo',
class: 'error',
timeout: 5
});
}
}(type));
}
App.prototype.forgetMyTioAboReminder = function() {
swal.close();
this.setStorage('mytio_abo_reminder', '-1');
}
App.prototype.openMyTioAboReminder = function() {
const checkDays = 14, // giorni da controllare
mindays = 5, // giorni minimi da mostrare
minValue = 2, // valore minimo per mostrare
maxDisabledDays = 90; // giorni massimi per non mostrare
let loyal_accesslog = new Map();
try {
loyal_accesslog = this.getStorage('lacsl')
loyal_accesslog = loyal_accesslog ? new Map(JSON.parse(loyal_accesslog.base64Decode())) : new Map();
} catch {
loyal_accesslog = new Map();
}
const currentDay = new Date().toISOString().split('T')[0].replaceAll('-', '');
loyal_accesslog.set(currentDay, loyal_accesslog.get(currentDay) ? loyal_accesslog.get(currentDay) + 1 : 1);
this.setStorage('lacsl', JSON.stringify(Array.from((loyal_accesslog))).base64Encode());
const maxDay = new Date(new Date().setDate(new Date().getDate() - checkDays)).toISOString().split('T')[0].replaceAll('-', '');
for (let [day, value] of loyal_accesslog) {
if (day == currentDay) {
continue;
}
if (day < maxDay || value <= minValue) {
//se il giorno è più vecchio di 14 giorni o se il valore è minore di 2 cancella
loyal_accesslog.delete(day);
}
}
if (loyal_accesslog.size < mindays) {
//se rimangono meno di 5 giorni non mostrare
return;
}
const mytio_abo_reminder = this.getStorage('mytio_abo_reminder');
const dayInMs = 1000 * 60 * 60 * 24;
if (mytio_abo_reminder &&
(
mytio_abo_reminder == '-1' ||
Date.now() - mytio_abo_reminder < (maxDisabledDays * dayInMs)
)
) {
// Già mostrato o mostrato meno di 90 giorni fa
return;
}
/*
Swal.fire({
'title': 'Sei stanco di vedere i Banner ?',
'html': 'Abbonati a Tio.ch e non li vedrai piùNon ricordarmelo più ',
'imageUrl': 'https://www.mytio.ch/img/logo-mytio.png',
'imageHeight': 100,
'showCancelButton': true,
'confirmButtonText': 'Abbonati',
'cancelButtonText': 'Non adesso',
'reverseButtons': true,
'allowOutsideClick': false,
'allowEscapeKey': false,
}).then((result) => {
this.setStorage('mytio_abo_reminder', Date.now());
if (result.value) {
window.location.href = 'https://mytio.ch/mytioabo';
return;
}
});
*/
}