// 著作権 :Copyright(c) 2016 RECRUIT LIFESTYLE CO., LTD. // 会社名 :株式会社リクルートライフスタイル // ============================================= // 性別アンケートjs // ============================================= var HPB = HPB || {}; HPB.TOP = HPB.TOP || {}; HPB.TOP.genderSelect = function() { this.init(); }; HPB.TOP.genderSelect.prototype = { cookieData: null, AUTO_CLOSE_LIMIT: 7000, COOKIE_NAME: 'HPB_USER_INFO', init: function() { this.$btnClose = $('#jsiGenderSelectCloseBtn'); this.$btnLadies = $('#jsiGenderBtnLadies'); this.$btnMens = $('#jsiGenderBtnMens'); this.$genderSelect = $('#jsiGenderSelect'); if (Cookies.get('HPB_DISPLAYED_GENDER_ENQUETE') ?? null){ return; } this.autoClose(); this.bindEvent(); this.$genderSelect.removeClass('dn'); this.cookieData = JSON.parse(Cookies.get(this.COOKIE_NAME) ?? null); if (this.cookieData === null) { // クッキーがない this.cookieData = {GENDER_ENQUETE: ''}; } // アンケート表示済みとする Cookies.set('HPB_DISPLAYED_GENDER_ENQUETE', 'true', {secure: true, path: '/'}); }, bindEvent: function() { var _self = this; this.$btnLadies.on('click', function(e) { _self.closePopup(); // アンケートの回答内容を優先する _self.addCookie('F', true, e); customLinkLog('answer_ladies'); }); this.$btnMens.on('click', function(e) { _self.closePopup(); // アンケートの回答内容を優先する _self.addCookie('M', true, e); customLinkLog('answer_mens'); }); this.$btnClose.on('click', function(e) { e.preventDefault(); _self.closePopup(); // 性別切り替えスイッチの値を優先する _self.addCookie('N', false, e); customLinkLog('answer_close'); }); this.$genderSelect.on('click', function(e) { e.stopPropagation(); }); $('body').on('click.closePopup', function() { _self.closePopup(); customLinkLog('answer_ignore'); }); }, closePopup: function() { clearTimeout(this.timeoutID); this.closePopupSmooth(); }, closePopupSmooth: function() { var _self = this; $('body').off('.closePopup'); this.$genderSelect.animate({'opacity': '0'}, function() { _self.$genderSelect.addClass('dn'); }); }, autoClose: function() { var _self = this; this.timeoutID = setTimeout(function() { _self.closePopupSmooth(); customLinkLog('answer_ignore'); }, this.AUTO_CLOSE_LIMIT); }, addCookie: function(data, isSwitchReset, e) { this.cookieData.GENDER_ENQUETE = data; // アンケートの回答が性別切り替えスイッチの選択より優先される場合はスイッチの値を初期化 if (isSwitchReset && 'GENDER_SWITCH' in this.cookieData) { this.cookieData.GENDER_SWITCH = ''; } Cookies.set(this.COOKIE_NAME, JSON.stringify(this.cookieData), {expires: 180, secure: true, path: '/'}); $.ajax({ async: true, cache: false, data: { name: this.COOKIE_NAME }, dataType: "JSON", timeout: 1000, url: "/CSP/cookie/doRefreshExpiresApi", complete: function() { var href = e && $(e.target).attr("data-href"); if (href) { window.location.href = href; } } }); } }; $(window).on('load', function() { new HPB.TOP.genderSelect(); });