function UserNotifications() { "use strict" var self = this; self.totalScrollHeight = 0; self.topNotif = 0; self.offSss = false; self._tipTimeout = false; self.notifBoxHtml; self.audio = 1; self.undelivN = 0; self.HTTP_ENDPOINT = "/checkN.php"; self.startIntervals(); } UserNotifications.prototype.startIntervals = function () { "use strict" var self = this; var intervals = BidooCnf.intervals.user.notifications; self.pingNotification(); setInterval(self.bidping.bind(self, getBidsBonus()), intervals.bidping); setInterval(self.updateNotificationsDateTime.bind(self), intervals.updateNotificationsDateTime); setInterval(self.pingNotification.bind(self), intervals.pingNotification); setInterval(self.updateAuctionsWon.bind(self), intervals.auctionsWon); // [GR] for update badge number for auctions won to pay by user } UserNotifications.prototype.updateNotificationsDateTime = function () { "use strict" var self = this; moment.locale('it'); self.getCorrectNotifSelector().find("abbr").each(function () { var abbrTime = parseInt($(this).data("utime"), 10); var newTime = parseInt((new Date()).getTime() / 1000, 10); var moment_abbr_time = moment(abbrTime, "X"); var shouldBeFromNow = (newTime - abbrTime) < 21600; $(this).data("alt", moment().format()); $(this).text(shouldBeFromNow ? moment_abbr_time.fromNow() : moment_abbr_time.calendar()); }); }; UserNotifications.prototype.updateAuctionsWon = function () { // [GR] for update badge number for auctions won to pay by user "use strict" $.get("/check_auctions_won.php", function (data) { if (self.offSss) { window.location.reload(); return; } $(".navbar-fixed-bottom #bottomAuctionsWonToPay").html(data); $(".myBidooDesk #bottomAuctionsWonToPay").html(data); $(".myBidooMobile #bottomAuctionsWonToPay").html(data); $("#testataAuctionsWonToPay").html(data); if (parseInt(data) > 0) { $("#bottomAuctionsWonToPay").css("visibility", "visible"); $("#testataAuctionsWonToPay").css("visibility", "visible"); } else { $("#bottomAuctionsWonToPay").css("visibility", "hidden"); $("#testataAuctionsWonToPay").css("visibility", "hidden"); } }); } UserNotifications.prototype.bidping = function (bonus) { "use strict" var self = this; $.get("/bidping.php", function (data) { if (self.offSss) { window.location.reload(); return; } var progressValue = data[0] + "/" + data[1]; $("#seven_7").html(progressValue); $(".bid-challenge [data-spot=0]") .html(progressValue) .parent() .attr("data-progress", progressValue); $(".leader-btn .progress-bar-success").css("width", ((data[0] / data[1]) * 100.00).toFixed(2) + "%"); if (data[0] >= data[1] && data[2] < data[1]) { $('.bid-challenge .img-lock-open').hide(); $('.bid-challenge .img-lock').show(); $('#auctionBidBottomBar .wrap-progress').hide(); $('#auctionBidBottomBar .wrap-button-get-bonus').show(); } if (data[0] >= data[1] && (typeof getCookie('won') == "undefined")) { var expireWonDate = new Date(); expireWonDate.setTime(getTimeFrames()); self.wonChallenge(data[0], bonus); setValueCookie("won", 1, expireWonDate); } }).fail(function (jqXHR, textStatus, error) { if (jqXHR.status == 403) { self.offSss = true; $(".btn.leader-btn[data-target=#leader]") .html(getSessionExpired(true)) .attr('data-toggle', null) .attr('data-target', null) .off("click").on({ click: showLogin }); } }); self.bidPingProduct(); } UserNotifications.prototype.bidPingProduct = function () { "use strict" $.get("/bidping_product.php", function (data) { if (self.offSss) { window.location.reload(); return; } $(".bid-challenge-product").html(data); }); } UserNotifications.prototype.getCallTipMsg = function (credits, bonus) { "use strict" var html = [ "
", "
", "", "
", "
", "Complimenti!", "
Hai Vinto " + credits + " Aste di Puntate
", "
", "
" ]; return html.join(""); } UserNotifications.prototype.callTip = function (credits, bonus, callback) { "use strict" var self = this; var tooltipReach = $(".tooltip.reach"); $(".leader-btn") .tooltip('destroy').tooltip({ html: true, placement: 'top', title: self.getCallTipMsg(credits, bonus), trigger: 'manual', animation: false, template: '' }) .tooltip("show"); tooltipReach.removeClass("bounceOutDown"); if (self._tipTimeout) clearTimeout(self._tipTimeout); self._tipTimeout = setTimeout(function () { callback(); }, 10000); } UserNotifications.prototype.wonChallenge = function (nAuctions, bonus) { "use strict" var self = this; var selector = $(".leader-btn > div.bid-challenge"); if (!selector.hasClass("achieved")) { self.callTip(nAuctions, bonus); } } UserNotifications.prototype.pingNotification = function () { "use strict" var self = this; $.get(self.HTTP_ENDPOINT, {_t: 1}, function (r) { if (r.count > 0) { $(".bubble_desktop, .bubble_mobile, .toggle_bar_mobile").html(r.count).show(); if ($("#notifBox").is(":visible") || $("#notifBoxMobile").is(":visible")) { self.loadNotification(true); } if (typeof r.undeliv != "undefined" && (Object.keys(r.undeliv).length > 0 && self.undelivN != Object.keys(r.undeliv).length)) { var audioCookie = getCookie('audioN'); if (self.audio && ("undefined" == typeof audioCookie || audioCookie < r.count)) { self .playSound(r.audio) .then(setCookieMinutes.bind(null, 'audioN', r.count, 5)) .catch(function () { $(document) .off('touchstart click') .on('touchstart click', function () { self.playSound(r.audio); $(document).off('touchstart click'); }); }); } self.undelivN = Object.keys(r.undeliv).length; } } else { delCookie('audioN'); $(".bubble_desktop, .bubble_mobile").hide(); } }); } UserNotifications.prototype.playSound = function (audioSrc) { "use strict" var audio = $("#push"); if (audio.length) audio.remove(); var aSound = document.createElement('audio'); aSound.id = 'push'; aSound.setAttribute('src', audioSrc + "?chk=" + (new Date()).getTime()); return aSound.play(); } UserNotifications.prototype.toggleAudio = function (audioSetting) { "use strict" var self = this; var isNotArgPassed = "undefined" == typeof audioSetting; var snd = self.getCorrectNotifSelector().find(".sAudio"); var snData = !!(isNotArgPassed ? parseInt(snd.attr("data-audio")) : audioSetting); snd.attr("data-audio", (!snData | 0)) .toggleClass("disabled glyphicon-volume-off", !snData) .toggleClass("enabled glyphicon-volume-up", snData); if (isNotArgPassed) $.get(self.HTTP_ENDPOINT, {_s: (snData | 0)}); } UserNotifications.prototype.loadSettings = function (shouldSetCheckOptions) { "use strict" var self = this; $.get(self.HTTP_ENDPOINT, {_load: 0}, function (settings) { self.audio = settings.audio; self.toggleAudio(self.audio); if (shouldSetCheckOptions) { $("#ticketMail").prop("checked", !!+settings["1"]); $("#creditMail").prop("checked", !!+settings["2"]); $("#packageMail").prop("checked", !!+settings["3"]); } }); } UserNotifications.prototype.cleanData = function (dirtyString) { "use strict" dirtyString = dirtyString.replace(/&/g, "&"); dirtyString = dirtyString.replace(/>/g, ">"); dirtyString = dirtyString.replace(/</g, "<"); dirtyString = dirtyString.replace(/"/g, "\""); dirtyString = dirtyString.replace("", "

"); dirtyString = dirtyString.replace("", "

"); dirtyString = dirtyString.replace("data-href", "data-mobile-fullscreen='true' data-no-padding-modal-body='true' data-href"); dirtyString = dirtyString.replace("//it.bidoo.com", ""); return dirtyString; } UserNotifications.prototype.getNotificationItem = function (data) { "use strict" var self = this; var flag = parseInt(data.readFlag, 10); var classNotif = 2 == flag ? "class='read wrap-notif'" : (1 == flag ? "class='deliv wrap-notif'" : ""); var item = [ "
  • ", "
    "+self.cleanData(data.content)+"
    ", "
    ", "
    ", "
  • " ]; return item.join(""); } UserNotifications.prototype.getEmptyNotifications = function () { "use strict" var notif = [ '
  • ', '

    Non hai alcuna notifica.

    ', '
  • ' ]; return notif.join(""); } UserNotifications.prototype._renderN = function (data, more) { "use strict" var self = this; var list = []; var selector = this.getCorrectNotifSelector().find("ul"); if (data.length) { $.each(data, function (i, item) { if ("object" == typeof item) { selector.append(self.getNotificationItem(item)); if (parseInt(item.readFlag, 10) < 2 && item.type != '1') { list.push(item.id); } } }); self.updateNotificationsDateTime(); } else { if (more === undefined || more === false) { selector.append(self.getEmptyNotifications()); } } return list; } UserNotifications.prototype._renderFoot = function (shouldLoadMore, paging) { "use strict" var loader = [ "", "Vedi altre", "" ].join(""); var footer = [ "
    ", shouldLoadMore ? loader : "", "
    " ]; return footer.join(""); } UserNotifications.prototype.loadMore = function (id) { "use strict" var self = this; $.get(self.HTTP_ENDPOINT, {f: id, m: 5}, function (r) { var selector = self.getCorrectNotifSelector(); var listNotif = selector.find("ul"); selector.find(".whatelse").remove(); if (Object.keys(r.elements).length > 0) { var list = self._renderN(r.elements, true); var welse = self._renderFoot(r.shexc, r.elements[Object.keys(r.elements).length - 1].id); listNotif.append(welse); if (listNotif.height() <= selector.find("#notifBoxContainer").height()) { //selector.find("#more").find("a").click(); } } if (typeof list != "undefined" && list.length > 0) { self.sendReadReq(list); } self.loadCustomScrollbar(); return false; }); return false; } $("body").click(function (event) { window.elementSelected = event.target.classList[0]; if ($('.bidooBell').hasClass('active')) { $('.bidooBell').removeClass('active'); } else { $('.bidooBell').addClass('active'); } }); UserNotifications.prototype.loadNotification = function (forceFetchNotif) { "use strict" var self = this; var isMobile = $(window).width() <= 991; var selector = self.getCorrectNotifSelector(); self.topNotif = 0; if (selector.is(":visible") && !forceFetchNotif) { stopBodyScroll(false); if (window.elementSelected == "bidooBell") { selector.hide(); $("#tickNotif").hide(); } if (isMobile) { $('#notifBoxMobile').hide(); $('#menuModal #btn-1 span').addClass('fa-plus'); $('#menuModal #btn-1 span').removeClass('fa-minus'); $('#menuModal #submenu1').css('display', 'none'); } self.totalScrollHeight = 0; } else { selector.empty().show(); if (isMobile) self.hideModalHeaderNotifications(true); self.composeNotificationsUI(isMobile, function (jqXHR, textStatus, errorThrown) { var isError = jqXHR && textStatus && errorThrown; if (!isError) { self.loadCustomScrollbar(); $("#notifBox").show(); // [GR] ADD if (isMobile) { var titleSelector = selector.find(".nTitle"); var realHeightNotificationShade = (titleSelector.height() + parseInt(titleSelector.css("padding-top"))); var heightNotifDialog = ($(window).height() - realHeightNotificationShade); selector.find("#notifBoxContainer").css("height", "auto"); selector.find("#more").find("a").click(); } } $("#tickNotif").show(); }); } return false; } UserNotifications.prototype.getNotificationsStructure = function (mobile, isFirstLoadNotifications, isSettings) { "use strict" var arrow_left = [ '', '', '' ].join(""); var structure = [ '
    ', mobile || isSettings ? arrow_left : "", '

    ' + (isSettings ? "Impostazioni" : "Notifiche") + '

    ', '', '', '
    ', '
    ', isFirstLoadNotifications ? "" : "", '', '
    ' ] return structure.join(""); } UserNotifications.prototype.composeNotificationsUI = function (mobile, callback) { "use strict" var self = this; var selector = self.getCorrectNotifSelector(); selector.html(self.getNotificationsStructure(mobile, true)); $.get(self.HTTP_ENDPOINT, function (r) { $(".bubble_desktop, .bubble_mobile, .toggle_bar_mobile").hide(); self.delivReadReq(); var mobile = $(window).width() <= 991; var selectorList = selector.find("ul"); selector.find(".loader-notifications").remove(); if (r !== null) { var list = self._renderN(r.elements); if (Object.keys(r.elements).length > 0) { var footer = self._renderFoot(r.shexc, r.elements[Object.keys(r.elements).length - 1].id); selectorList.append(footer); } if (typeof list != "undefined" && list.length > 0) { self.sendReadReq(list); } self.loadSettings(); } else { selectorList.html(getSessionExpired()); } callback(); }).fail(callback); } UserNotifications.prototype.sendReadReq = function (list) { "use strict" var self = this; if (typeof list !== undefined && list.length > 0) { $.get(self.HTTP_ENDPOINT, {_r: 1, l: list.join(',')}); } } UserNotifications.prototype.delivReadReq = function () { "use strict" $.get(this.HTTP_ENDPOINT, {_d: 1}); } UserNotifications.prototype.getSettings = function () { "use strict" var html = [ '
    ', '
    ', '
    Notifiche Email
    ', '
    ', '', '
    ', '
    ', '', '
    ', '
    ', '', '
    ', 'Salva Impostazioni', '
    ', '
    ' ]; return html.join(""); } UserNotifications.prototype.showSettingNotification = function () { "use strict" var self = this; var selector = self.getCorrectNotifSelector(); if (selector.length) { self.notifBoxHtml = selector.html(); selector.html(self.getNotificationsStructure(true, false, true)) .find("#notifBoxContainer") .append(self.getSettings()); self.loadSettings(true); document.querySelector('#notifBoxMobile #notifBoxContainer .not').remove(); } } UserNotifications.prototype.back = function () { "use strict" var self = this; var selector = self.getCorrectNotifSelector(); if ($(window).width() <= 991 && !selector.find(".settingBox").length) { self.hideModalHeaderNotifications(false); backMobile(); return; } selector.html(self.notifBoxHtml); self.loadCustomScrollbar(true); } UserNotifications.prototype.toggleSettings = function () { "use strict" var self = this; var selector = self.getCorrectNotifSelector(); if (!selector.is(":visible")) { selector.show(); self.loadNotification(); } else { self.showSettingNotification(); } return true; } UserNotifications.prototype.saveSettings = function () { "use strict" var self = this; var mail = +$("#ticketMail").is(":checked"); var pack = +$("#packageMail").is(":checked"); var accr = +$("#creditMail").is(":checked"); var data = [ 'm', mail, 'p', pack, 'a', accr ]; $.get(self.HTTP_ENDPOINT, {_set: data.join("|")}, function () { self.back(); }); } UserNotifications.prototype.loadCustomScrollbar = function (forceReload) { "use strict" var self = this; var notif_box_selector = self.getCorrectNotifSelector().find("#notifBoxContainer"); if ($(window).width() <= 991) { notif_box_selector.off("scroll").scroll(function () { if ($(this).scrollTop() + $(this).innerHeight() >= $(this)[0].scrollHeight) { self.topNotif = $(this).scrollTop(); //notif_box_selector.find("#more").find("a").click(); } }); notif_box_selector.scrollTop(self.topNotif); } else if (forceReload || !notif_box_selector.hasClass("mCustomScrollbar")) { if (forceReload) { var list = notif_box_selector.find("ul").clone(); notif_box_selector.empty().append(list); self.totalScrollHeight = 0; } notif_box_selector.mCustomScrollbar({ documentTouchScroll: true, contentTouchScroll: 1, callbacks: { onTotalScroll: function () { var more_notif_selector = notif_box_selector.find("#more"); if (more_notif_selector.is(":visible") && more_notif_selector.children().length) { // more_notif_selector.find("a").click(); self.totalScrollHeight += 5 * 70; } }, onInit: function () { if (self.totalScrollHeight != 0) { notif_box_selector.mCustomScrollbar("scrollTo", self.totalScrollHeight, { scrollInertia: 0 }); } } } }); } notif_box_selector .off("mouseover") .mouseover(true, stopBodyScroll) .off("mouseout") .mouseout(false, stopBodyScroll); bindModalCall("#notifBoxContainer", true); } UserNotifications.prototype.getCorrectNotifSelector = function () { "use strict" var notifMobile = $("#notifBoxMobile"); return $(window).width() <= 991 ? notifMobile : $("#notifBox"); } UserNotifications.prototype.hideModalHeaderNotifications = function (shouldHide) { "use strict" var self = this; self.getCorrectNotifSelector().parent() .parent() .find(".modal-header") .toggleClass("hidden", shouldHide); } UserNotifications.prototype.closeAll = function () { "use strict" var self = this; var selector = self.getCorrectNotifSelector(); if (!selector.is(":visible")) return; if (selector.find(".settingBox").is(":visible")) self.back(); self.back(); } function bidping() { "use strict" if (BidooCnf.modules.exist(UserNotifications)) BidooCnf.instances.user.notifications.bidping(getBidsBonus()); } $(document).ready(function () { "use strict" BidooCnf.modules.notifications = UserNotifications; BidooCnf.instances.user.notifications = new UserNotifications(); });