홈페이지

asp 다중팝업 변수처리

초코몽몽 2025. 3. 19. 09:48
728x90


<% 
' 팝업 데이터 배열로 정의 (teacherName, teacherMonth, teacherWidth, linkUrl, isActive, teacherYear, target)
Dim popupData(2, 6) ' 2차원 배열: 팝업 개수 x 속성 (0부터 시작)
popupData(0, 0) = "ysh"   : popupData(0, 1) = "2022" : popupData(0, 2) = "600" : popupData(0, 3) = ""                     : popupData(0, 4) = "true"  : popupData(0, 5) = "2025" : popupData(0, 6) = "_blank"
popupData(1, 0) = "ysh"   : popupData(1, 1) = "2022" : popupData(1, 2) = "600" : popupData(1, 3) = ""                     : popupData(1, 4) = "false" : popupData(1, 5) = "2025" : popupData(1, 6) = "_self"
popupData(2, 0) = "xyz3"  : popupData(2, 1) = "0306" : popupData(2, 2) = "500" : popupData(2, 3) = "https://example.com/3" : popupData(2, 4) = "false" : popupData(2, 5) = "2025" : popupData(2, 6) = "_blank"
%>

<style>
.popup_teacher {
    position: absolute;
    /*z-index: 1000;*/
}
</style>

<script language="Javascript">
<!--
function setCookie(name, value, days) {
    var expires = "";
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        expires = "; expires=" + date.toUTCString();
    }
    document.cookie = name + "=" + (value || "") + expires + "; path=/";
}

function getCookie(name) {
    var nameEQ = name + "=";
    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, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}

function closePopup(popupId) {
    document.getElementById(popupId).style.display = "none";
}

function closePopupToday(popupId, cookieName) {
    setCookie(cookieName, "done", 1);
    closePopup(popupId);
}

function closePopupWeek(popupId, cookieName) {
    setCookie(cookieName, "done", 7);
    closePopup(popupId);
}

function positionPopups() {
    var offset = 20;
    var topPosition = 50;
    var leftPosition = 50;
    var maxHeight = 0;
    
    <% 
    For i = 0 To UBound(popupData, 1)
        If popupData(i, 4) = "true" Then
    %>
        var popup_<%=popupData(i, 0)%> = document.getElementById('popup_<%=popupData(i, 0)%>');
        if (popup_<%=popupData(i, 0)%> && popup_<%=popupData(i, 0)%>.style.display !== "none") {
            popup_<%=popupData(i, 0)%>.style.top = topPosition + "px";
            popup_<%=popupData(i, 0)%>.style.left = leftPosition + "px";
            var popupHeight = popup_<%=popupData(i, 0)%>.offsetHeight;
            maxHeight = Math.max(maxHeight, popupHeight);
            leftPosition += parseInt('<%=popupData(i, 2)%>') + offset;
        }
    <% 
        End If
    Next 
    %>
}

function initPopup(popupId, cookieName) {
    if (!getCookie(cookieName)) {
        document.getElementById(popupId).style.display = "block";
    } else {
        document.getElementById(popupId).style.display = "none";
    }
    positionPopups();
}

window.onload = function() {
    <% 
    For i = 0 To UBound(popupData, 1)
        If popupData(i, 4) = "true" Then
            Response.Write "initPopup('popup_" & popupData(i, 0) & "', 'imyong_" & popupData(i, 0) & "1');" & vbCrLf
        End If
    Next 
    %>
};
-->
</script>

<form>
<% 
For i = 0 To UBound(popupData, 1)
    If popupData(i, 4) = "true" Then
        Dim teacherName, teacherMonth, teacherWidth, linkUrl, teacherYear, teacherTarget
        teacherName = popupData(i, 0)
        teacherMonth = popupData(i, 1)
        teacherWidth = popupData(i, 2)
        linkUrl = popupData(i, 3)
        teacherYear = popupData(i, 5)
        teacherTarget = popupData(i, 6)
%>
    <div id="popup_<%=teacherName%>" class="popup_teacher" style="display:none;">
        <div class="popup_teacher_wrap" style="width:<%=teacherWidth%>px;">
            <!-- 링크가 있는 경우와 없는 경우 조건문으로 처리 -->
            <% If Len(linkUrl) > 0 Then %>
                <a href="<%=linkUrl%>" target="<%=teacherTarget%>">
                    <img src="/images/teacher/<%=teacherYear%>/popup_<%=teacherName%>_<%=teacherMonth%>.png" alt="" border="0" style="width:<%=teacherWidth%>px;" />
                </a>
            <% Else %>
                <img src="/images/teacher/<%=teacherYear%>/popup_<%=teacherName%>_<%=teacherMonth%>.png" alt="" border="0" style="width:<%=teacherWidth%>px;" />
            <% End If %>
            <div class="popup_teacher_footer">
                <div>
                    <input type="checkbox" name="imyong_<%=teacherName%>1_1" value="imyong_<%=teacherName%>1_1" onClick="closePopupToday('popup_<%=teacherName%>', 'imyong_<%=teacherName%>1');">
                    <font color="#818181" size="-1">오늘 하루 열지 않기</font>
                </div>
                <div>
                    <input type="checkbox" name="imyong_<%=teacherName%>1_2" value="imyong_<%=teacherName%>1_2" onClick="closePopupWeek('popup_<%=teacherName%>', 'imyong_<%=teacherName%>1');">
                    <font color="#818181" size="-1">일주일간 열지 않기</font>
                </div>
                <div>
                    <img src="/images/teacher/2024/close_02.png" align="absmiddle" onClick="closePopup('popup_<%=teacherName%>');" style="cursor:hand">
                </div>
            </div>
        </div>
    </div>
<% 
    End If
Next 
%>
</form>