"use strict"; var IncitationRegistrationController = function ($el) { this.$el = $el; this.path = window.location.pathname; this.listen(); this.show(); this.pathExclude(); this.killCriteoCookie(); }; IncitationRegistrationController.prototype = { listen: function () { this.$el.on('click', '.close-incitation', $.proxy(this.closeClickEvent, this)); this.$el.on('click', '.register', $.proxy(this.registerClickEvent, this)); $(document).on('mouseout', $.proxy(this.windowsOutEvent, this)); $(document).on('push-to-register-evt', $.proxy(this.registerClickEvent, this)); }, windowsOutEvent: function (e) { if (e.clientY < 0 && !this.hasCookie('registration-modal')) { var from = e.relatedTarget || e.toElement; if (!from || from.nodeName == "HTML") { this.registerClickEvent(e); $(document).off('mouseout', this.windowsOutEvent); } } }, closeClickEvent: function (e) { this.$el.slideUp(); this.createCookie(); }, registerClickEvent: function (e) { e.preventDefault(); if ($('.modals').length === 0) { $('body').append('
'); } $('.modals').load('/moncompte/Registration/Modal', function () { $('#registration-modal').modal(); }); }, createCookie: function () { document.cookie = "incitation-inscription=1; path=/"; }, show: function () { if (this.pathAllowed() && !this.hasCookie('ASPXAUTH') && !this.hasCookie('login') && !this.hasCookie('incitation-inscription')) { this.$el.slideDown(); } else { $(document).off('mouseout', this.windowsOutEvent); } }, pathAllowed: function () { return this.path !== '/' && this.path.indexOf('moncompte') === -1 && this.path.indexOf('inscription') === -1; }, hasCookie: function (name) { return this.getCookie(name).length > 0; }, getCookie: function (cname) { var name = cname + "="; var ca = document.cookie.split(';'); for (var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0) == ' ') { c = c.substring(1); } if (c.indexOf(name) == 0) { return c.substring(name.length, c.length); } } return ""; }, pathExclude: function () { var str = this.path; if (str.match(/sonatural.*/) || str.match(/vente-privee.*/) || str.match(/vvf-villages.*/) || str.match(/partenariat.*/)) { this.closeClickEvent(); } }, killCriteoCookie: function () { var str = this.path; if (!str.match(/inscription*/)) { createCookie('PwCriteoInscription', '', -1); createCookie('MyTrackCriteo', '', -1); } } };