[gimp-web] content, themes: redirect to "thank you" page after downloading starts.



commit 2bb6c549e7ffb831b1911f81d337cb127300df9b
Author: Jehan <jehan girinstud io>
Date:   Wed Nov 3 14:05:36 2021 +0100

    content, themes: redirect to "thank you" page after downloading starts.
    
    This is using javascript, but so that we don't touch the actual static
    HTML page, i.e. that if javascript is disabled, it will just still work
    normally (we just won't have thank-you redirect).

 content/js/downloads.js                 | 32 ++++++++++++++++++++++++++++++++
 themes/newgimp/templates/downloads.html |  1 +
 2 files changed, 33 insertions(+)
---
diff --git a/content/js/downloads.js b/content/js/downloads.js
new file mode 100644
index 00000000..bbb43122
--- /dev/null
+++ b/content/js/downloads.js
@@ -0,0 +1,32 @@
+/*  gimp-web: GIMP official website
+ *  Copyright (C) 2021 Jehan
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU Affero General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU Affero General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Affero General Public License
+ *  along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ */
+
+var buttons = document.getElementsByClassName('win-button');
+
+for (var i = 0, len = buttons.length | 0; i < len; i= i + 1) {
+    buttons[i].onclick = function(e) {
+        /* Prevent default click behavior, otherwise we can't redirect.
+         * Thus we must also explicitly start the download in a new tab.
+         * This will still work even if javascript is disabled.
+         */
+        e.preventDefault();
+        window.open(this.getElementsByTagName("a")[0].href);
+
+        window.location="/downloads/thanks.html";
+        window.focus();
+    };
+}
diff --git a/themes/newgimp/templates/downloads.html b/themes/newgimp/templates/downloads.html
index b91aefaa..3534437c 100644
--- a/themes/newgimp/templates/downloads.html
+++ b/themes/newgimp/templates/downloads.html
@@ -482,5 +482,6 @@
     <script src='/js/platform.js'></script>
     <script src='/js/platform-display.js'></script>
 
+    <script src='/js/downloads.js'></script>
 
 {% endblock data %}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]