~jshsj/python_link_shortener

ref: f467640a576f01d14ee2706e27ef6a9d95492c76 python_link_shortener/templates/home.html -rw-r--r-- 4.0 KiB
f467640a — JSH initial commit 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Url Shortener</title>
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Fira+Sans:300,400">
    <style>
        body {
            font-family: "Fira Sans", sans-serif;
            font-size: 16px;
        }

        * {
            box-sizing: border-box;
        }
        .container {
            width: 80%;
            max-width: 1024px;
            margin: 0 auto;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            height: 100vh;
        }

        .shortener-wrap {
            width: 100%;
            max-width: 640px;
        }
        .form-input {
            display: flex;
            height: 60px;
            align-items: center;
            margin: 10px 0;
            position: relative;
        }

        label {
            width: 20%;
            min-width: 80px;
            font-weight: 300;
        }

        input {
            width: 80%;
            min-width: 250px;
            border: none;
            font-size: 16px;
            background: rgba(255, 175, 56, 0.8);
            padding: 8px 5px;
            display: block;
            position: relative;
            height: 40px;
        }

        input[type='submit'] {
            width: 150px;
        }

        input[type='checkbox'] {
            display: none;
        }

        #checkbox-field {
                display: block;
                height: 40px;
                width: 40px;
                background: rgba(255,175,56,0.8);
            }

        #checkbox-field.active:after {
            content: '\2714';
            position: relative;
            font-size: 40px;
            left: 5px;

            line-height: 40px;
        }

        shortened-wrap {
            width: 100%;
            margin-top: 50px;
            font-size: 18px;
        }

        a {
            text-decoration: none;
            color: rgba(255,175,56);
        }
        
        

        
    </style>
</head>
<body>
    <section class="container">
        {% if not custom_url %}
        <div class="shortener-wrap">
            <h1>URL Shortener</h1>
            <form method="post" action="">
                {{ form.csrf_token }}
                <div class="form-input">{{ form.url.label }} {{ form.url}}</div>
                <div class="form-input">{{ form.use_custom.label }} <span id="checkbox-field"></span>{{ form.use_custom(checked=False)}}</div>
                <div class="form-input" id="custom_url_field">{{ form.custom_url.label }} {{ form.custom_url}}</div>
                <input type="submit" value="URL generieren"/>
            </form>
        </div>
        {% else %}
        <div class="shortened-wrap">
            <p>Und hier ist deine URL: <a href="{{ custom_url }}">{{ custom_url }}</a></p>
            <a href="/">Noch eine!</a>
        </div>
        {% endif %}
        {% if error %}
        <p class="error">{{ error }}</p>
        {% endif %}
    </section>

    <script>
        let checkbox = document.getElementById('checkbox-field');
        let use_custom = document.getElementById('use_custom');
        let custom_url_field = document.getElementById('custom_url_field')
        let is_checked = use_custom.checked
        is_checked ? custom_url_field.style.display = 'flex' : custom_url_field.style.display = 'none'
        checkbox.addEventListener('click', function(e) {
            if (is_checked) {
                checkbox.classList.remove('active');
                use_custom.checked = false
                custom_url_field.style.display = 'none'
            } else {
                checkbox.classList.add('active')
                use_custom.checked = true
                custom_url_field.style.display = 'flex'
            }
            is_checked = !is_checked
        })

    </script>
    
</body>
</html>