Javascript/jQuery

팝업 하루동안 안보기

728x90
반응형
    function setCookieMobile48 (name, value, expiredays) {
        var todayDate = new Date();
        todayDate.setDate(todayDate.getDate() + expiredays);
        document.cookie = name + "=" + escape(value) + "; path=/; expires=" + todayDate.toGMTString() + ";"
    }

    function getCookieMobile48 () {
        var cookiedata = document.cookie;
        if (cookiedata.indexOf("todayCookie48=done") < 0) {
            $("#popup48").show(0);
            $("#pop_black_bg").show(0);
        } else {
            $("#popup48").hide(0);
            $("#pop_black_bg").hide();
        }
    }
    
    
    $(function () {
        getCookieMobile48 ();

        $(".popup-close .close48").click(function () {
            $("#popup48").hide();
            $("#pop_black_bg").hide();
        });

        $(".popup-close .today48").click(function () {
            setCookieMobile48 ("todayCookie48", "done",1);
            $("#popup48").hide();
            $("#pop_black_bg").hide();
        });
    });
	
	/*쿠키삭제*/
	function delPopupCookie(id) {
		var nowcookie = getPopupCookie('popview');
		setPopupCookie('popview', '[' + id + ']' + nowcookie, 0);
	}
	
	/*쿠키세팅*/
	function setPopupCookie(name, value, expiredays) {
		var todayDate = new Date();
		todayDate.setDate(todayDate.getDate() + expiredays);
		document.cookie = name + "=" + escape(value) + "; path=/; expires=" + todayDate.toGMTString() + ";"
	}
	
	/*쿠키추출*/
	function getPopupCookie(name) {
		var nameOfCookie = name + "=";
		var x = 0;
		while (x <= document.cookie.length) {
			var y = (x + nameOfCookie.length);
			if (document.cookie.substring(x, y) == nameOfCookie) {
				if ((endOfCookie = document.cookie.indexOf(";", y)) == -1) endOfCookie = document.cookie.length;
				return unescape(document.cookie.substring(y, endOfCookie));
			}
			x = document.cookie.indexOf(" ", x) + 1;
			if (x == 0) break;
		}
		return "";
	}
	
	/*객체얻기*/
	function getElm(id) {
		return document.getElementById(id);
	}
	
	/*일반 닫기 동작*/
	function hideLayerPopup(uid) {
		getElm('pop-layer-' + uid).style.display = 'none';
		getElm('_hidden_layer_').style.display = 'none';
		$('body').removeClass('scrollOff').off('scroll touchmove mousewheel');
	}
	
	/*하루 동안 닫기 동작*/
	function todayNoShow(uid) {
		var nowcookie = getPopupCookie('popview');
		setPopupCookie('popview', '[' + uid + ']' + nowcookie, 1);
		
		getElm('pop-layer-' + uid).style.display = 'none';
		getElm('_hidden_layer_').style.display = 'none';
		$('body').removeClass('scrollOff').off('scroll touchmove mousewheel');
	}
	
	/*숨기기체크*/
	if (getPopupCookie('popview').indexOf('[20160801]') == -1) {
		getElm('pop-layer-20160801').style.display = 'block';
		getElm('_hidden_layer_').style.display = 'block';
	}
	
	/*숨겨진 팝업 쿠키를 초기화 할때 사용 - 스크립트가 아래 존재하기에 새로고침을 두번 해야 적용됨*/
	/*delPopupCookie('20160801');*/
	
	/*팝업 켜져있을 시 배경 스크롤 제어*/
	$(function() {
		if (($('#_hidden_layer_').css('display') == 'block') && ($('#pop-layer-20160801').css('display') == 'block')) {
			$('body').addClass('scrollOff').on('scroll touchmove mousewheel', function(e) {
				e.preventDefault();
			});
		} else {
			$('body').removeClass('scrollOff').off('scroll touchmove mousewheel');
		}
	})
728x90
반응형