leo-huovi commited on
Commit
ef57812
1 Parent(s): f0205ed

Papukaija-animaation observerin korjaus

Browse files
Files changed (1) hide show
  1. templates/index.html +24 -18
templates/index.html CHANGED
@@ -13,32 +13,38 @@
13
  var formData = {
14
  translation_request: $('#message').val()
15
  };
 
 
 
 
 
 
 
16
  // send the POST request using AJAX
17
  $.ajax({
18
  type: 'POST',
19
  url: '/submit',
20
  data: formData,
21
  success: function (response) {
22
- // Create a new observer instance
23
- var observer = new MutationObserver(function () {
24
- // Revert the changes to .image
25
- $(".image").attr("src", "{{ url_for('static', filename='papukaija.png') }}")
26
- $(".image").removeClass("bounce");
27
- // Disconnect the observer after reverting the changes
28
- observer.disconnect();
29
- });
30
-
31
- // Configure the observer to watch for changes in the #result element
32
- observer.observe(document.getElementById("result"), { childList: true });
33
-
34
- // Display the response in the result div
35
- $('#result').text(response);
36
-
37
- // Add animation class to the image
38
- $(".image").attr("src", "{{ url_for('static', filename='papukaija_miettii.png') }}")
39
- $(".image").addClass("bounce");
40
  }
41
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  </script>
43
  </head>
44
  <body>
 
13
  var formData = {
14
  translation_request: $('#message').val()
15
  };
16
+
17
+
18
+ // Add animation class to the image
19
+ $(".image").attr("src", "{{ url_for('static', filename='papukaija_miettii.png') }}")
20
+ $(".image").addClass("bounce");
21
+
22
+
23
  // send the POST request using AJAX
24
  $.ajax({
25
  type: 'POST',
26
  url: '/submit',
27
  data: formData,
28
  success: function (response) {
29
+ $('#result').text(response); // display the response in the result div
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  }
31
  });
32
+
33
+ var observer = new MutationObserver(function () {
34
+ // Revert the changes to .image
35
+ $(".image").attr("src", "{{ url_for('static', filename='papukaija.png') }}")
36
+ $(".image").removeClass("bounce");
37
+ // Disconnect the observer after reverting the changes
38
+ observer.disconnect();
39
+ });
40
+
41
+ // Configure the observer to watch for changes in the #result element
42
+ observer.observe(document.getElementById("result"), {childList: true});
43
+
44
+ // Display the response in the result div
45
+ $('#result').text(response);
46
+
47
+ }
48
  </script>
49
  </head>
50
  <body>