"use strict"; var IncitationNewslettersBannerController = function ($el) { this.$el = $el; //this.excludedPages = ['/moncompte/Account/', '/moncompte/inscription-code-promo', '/client', '/transfert', '/commande', '/produit/creatif', '/albums', '/paiement', '/produit/objet-photo/creation/', '/finalisation-creation/', '/produit/tirage/InterfaceTirageClassique']; this.listen(); this.listenToCookie(); }; IncitationNewslettersBannerController.prototype = { listen: function () { this.$el.on('click', '.close-incitation', $.proxy(this.closeClickEvent, this)); this.$el.on('click', '.subscribe', $.proxy(this.subscribeClickEvent, this)); }, listenToCookie: function () { //check cookie incitation var oRegex = new RegExp("(?:; )?" + "incitationNl" + "=([^;]*);?"); var incitation; if (oRegex.test(document.cookie)) { incitation = decodeURIComponent(RegExp["$1"]); } if ((typeof (incitation) === 'undefined') || (incitation != 'true')) { this.showBanner(); } }, showBanner: function () { if (this.canDisplayBanner()) { var $elt = this.$el; $.ajax({ type: "GET", url: "/moncompte/Newsletter/GetIncitation", dataType: "json", success: function (data) { if (data === false) { $elt.slideDown('slow'); }; } }); } }, canDisplayBanner: function () { return !_.some(this.excludedPages, function (page) { return window.location.pathname.startsWith(page); }); }, closeClickEvent: function (e) { this.$el.slideUp('slow'); this.createCookie(); }, createCookie: function () { var dateCookies = new Date(); //date du cookie sur 1 semaine. dateCookies.setTime(dateCookies.getTime() + (7 * 24 * 3600 * 1000)); document.cookie = 'incitationNl=true;expires=' + dateCookies + '; path=/'; }, subscribeClickEvent: function (e) { this.subscribe(); }, subscribe: function () { var self = this; this.createCookie(); $.post('/moncompte/MyAccount/Newsletters', { Newsletter: true, NewsletterPromotions: true, NewsletterPartners: false }) .done(function () { self.$el.html('Nous vous confirmons votre inscription à la newsletter Photoweb. Merci !'); self.$el.css("background-color", "#00CCDD"); $.ajax("//www.photoweb.fr/statistiques/annonceur.asp?partenaire=157&operation=4212&code=V6A4N3"); setTimeout(function () { self.$el.slideUp('slow'); }, 7000); }) .fail(function () { document.cookie = 'incitationNl=false;'; self.$el.slideUp('slow'); }) } };