ntbaongoc commited on
Commit
b4f8557
·
1 Parent(s): e446454

Update stylesheet

Browse files
Files changed (2) hide show
  1. static/style.css +39 -2
  2. templates/index.html +39 -9
static/style.css CHANGED
@@ -31,7 +31,7 @@ textarea {
31
  width: 100%;
32
  height: 120px;
33
  padding: 0.5em;
34
- font-size: 16px;
35
  border: 1px solid #ccc;
36
  border-radius: 4px;
37
  resize: none;
@@ -54,6 +54,43 @@ input[type="submit"]:hover {
54
  }
55
 
56
  p {
57
- font-size: 18px;
58
  line-height: 1.6;
59
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  width: 100%;
32
  height: 120px;
33
  padding: 0.5em;
34
+ line-height: 1.6;
35
  border: 1px solid #ccc;
36
  border-radius: 4px;
37
  resize: none;
 
54
  }
55
 
56
  p {
 
57
  line-height: 1.6;
58
  }
59
+
60
+ #loader {
61
+ margin: 2em auto;
62
+ border: 5px solid #f3f3f3;
63
+ border-radius: 50%;
64
+ border-top: 5px solid #555;
65
+ width: 20px;
66
+ height: 20px;
67
+ -webkit-animation: spin 2s linear infinite; /* Safari */
68
+ animation: spin 2s linear infinite;
69
+ }
70
+
71
+ /* Safari */
72
+ @-webkit-keyframes spin {
73
+ 0% {
74
+ -webkit-transform: rotate(0deg);
75
+ }
76
+ 100% {
77
+ -webkit-transform: rotate(360deg);
78
+ }
79
+ }
80
+
81
+ @keyframes spin {
82
+ 0% {
83
+ transform: rotate(0deg);
84
+ }
85
+ 100% {
86
+ transform: rotate(360deg);
87
+ }
88
+ }
89
+
90
+ #result {
91
+ margin: 2em auto;
92
+ width: 60%;
93
+ max-width: 600px;
94
+ text-align: left;
95
+ color: #333;
96
+ }
templates/index.html CHANGED
@@ -2,20 +2,50 @@
2
  <html lang="en">
3
  <head>
4
  <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <link href="{{ url_for('static', filename='style.css') }}" rel="stylesheet">
7
  <title>Text Translator</title>
8
  </head>
9
  <body>
10
- <h1>English to Finnish Translator</h1>
11
- <form method="POST">
12
- <label for="text">Enter text in English:</label><br>
13
- <textarea id="text" name="text" rows="6" cols="50" required></textarea><br><br>
14
- <input type="submit" value="Translate">
15
- </form>
 
 
 
 
16
  {% if translation %}
17
- <h2>Translation:</h2>
18
- <p>{{ translation }}</p>
19
  {% endif %}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  </body>
21
  </html>
 
2
  <html lang="en">
3
  <head>
4
  <meta charset="UTF-8">
5
+ <meta content="width=device-width, initial-scale=1.0" name="viewport">
6
  <link href="{{ url_for('static', filename='style.css') }}" rel="stylesheet">
7
  <title>Text Translator</title>
8
  </head>
9
  <body>
10
+ <h1>English to Finnish Translator</h1>
11
+ <form id="translateForm">
12
+ <label for="text">Input text in English:</label><br>
13
+ <textarea cols="50" id="text" name="text" required rows="6">{{ text }}</textarea><br><br>
14
+ <input type="submit" value="Translate">
15
+ </form>
16
+
17
+ <div id="loader"></div>
18
+
19
+ <div id="result">
20
  {% if translation %}
21
+ <h2>Translated text:</h2>
22
+ <p>{{ translation }}</p>
23
  {% endif %}
24
+ </div>
25
+
26
+ <script>
27
+ document.getElementById('translateForm').addEventListener('submit', async function(evt) {
28
+ evt.preventDefault(); // Prevent page reload
29
+
30
+ const loadingElement = document.getElementById('loader');
31
+ const resultElement = document.getElementById('result');
32
+ const text = document.getElementById('text').value;
33
+
34
+ loadingElement.style.display = 'block';
35
+ resultElement.innerHTML = ''; // Clear previous result
36
+
37
+ const response = await fetch('/', {
38
+ method: 'POST',
39
+ headers: {
40
+ 'Content-Type': 'application/x-www-form-urlencoded',
41
+ },
42
+ body: new URLSearchParams({text: text}),
43
+ });
44
+
45
+ const html = await response.text();
46
+ loadingElement.style.display = 'none';
47
+ resultElement.innerHTML = new DOMParser().parseFromString(html, 'text/html').getElementById('result').innerHTML;
48
+ });
49
+ </script>
50
  </body>
51
  </html>