{% load static %}

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>{{ page_title }}</title>
    <link rel="stylesheet" href="https://magicbox.bk.tencent.com/static_api/v3/assets/bootstrap-3.3.4/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://magicbox.bk.tencent.com/static_api/v3/assets/artDialog-6.0.4/css/ui-dialog.css">
    <script type="text/javascript" src="{% url 'version_log:javascript-catalog' %}"></script>
    <script src="https://magicbox.bk.tencent.com/static_api/v3/assets/js/jquery-1.10.2.min.js"></script>
    <script src="https://magicbox.bk.tencent.com/static_api/v3/assets/bootstrap-3.3.4/js/bootstrap.min.js"></script>
    <script src="https://magicbox.bk.tencent.com/static_api/v3/assets/artDialog-6.0.4/dist/dialog-min.js"></script>
    <script>
        function show_modal() {
            load_modal_frame("{% url 'version_log:block' %}");
        }

        function load_modal_frame(url) {
            $.ajax({
                url: url,
                type: "GET",
                dataType: "html",
                success: function(data) {
                    var d = dialog({
                        height: 600,
                        width: 1105,
                        title: gettext('版本日志'),
                        content: data,
                    });
                    d.showModal();
                }
            })
        }

        // 获取指定的Cookie
        function getCookie(name) {
            var value = "; " + document.cookie;
            var parts = value.split("; " + name + "=");
            if (parts.length === 2) return parts.pop().split(";").shift();
        }

        // 如果存在Cookie SHOW_VERSION_LOG值为True，则弹出版本日志弹窗
        if (getCookie("SHOW_VERSION_LOG") === "True") {
            $(document).ready(function () {
                show_modal()
                // 清除Cookie避免重复弹窗
                document.cookie = "SHOW_VERSION_LOG=; path=/; expire=Thu, 01 Jan 1970 00:00:01 GMT;"
            })
        }
    </script>
</head>
<body>
</body>
    <script type="text/javascript">
        $(function () {
            show_modal();
            // waiting for modal loading
            setTimeout(() => {
                $('.ui-dialog-close').click(function () {
                    history.back(-1)
                });
            }, 500);
        });
    </script>
</html>