Fossil SCM
Attempt to prevent forum FORM elements from a double-submit via stray double-clicks on the various submit buttons, as reported in [forum:6bd02466533aa131|forum post 6bd02466533aa131].
Commit
600f171306d29f398e685bdf9713e1ff99573ecbc47ab4e2efc72107197b3238
Parent
39bcd310e889538…
1 file changed
+23
-4
+23
-4
| --- src/fossil.page.forumpost.js | ||
| +++ src/fossil.page.forumpost.js | ||
| @@ -1,17 +1,17 @@ | ||
| 1 | 1 | (function(F/*the fossil object*/){ |
| 2 | 2 | "use strict"; |
| 3 | - /* JS code for /forumpage and friends. Requires fossil.dom | |
| 3 | + /* JS code for /forumpost and friends. Requires fossil.dom | |
| 4 | 4 | and can optionally use fossil.pikchr. */ |
| 5 | 5 | const P = F.page, D = F.dom; |
| 6 | 6 | |
| 7 | 7 | /** |
| 8 | 8 | When the page is loaded, this handler does the following: |
| 9 | 9 | |
| 10 | 10 | - Installs expand/collapse UI elements on "long" posts and collapses |
| 11 | 11 | them. |
| 12 | - | |
| 12 | + | |
| 13 | 13 | - Any pikchr-generated SVGs get a source-toggle button added to them |
| 14 | 14 | which activates when the mouse is over the image or it is tapped. |
| 15 | 15 | |
| 16 | 16 | This is a harmless no-op if the current page has neither forum |
| 17 | 17 | post constructs for (1) nor any pikchr images for (2), nor will |
| @@ -99,8 +99,27 @@ | ||
| 99 | 99 | })/*F.onPageLoad()*/; |
| 100 | 100 | |
| 101 | 101 | if(F.pikchr){ |
| 102 | 102 | F.pikchr.addSrcView(); |
| 103 | 103 | } |
| 104 | - })/*onload callback*/; | |
| 105 | - | |
| 104 | + | |
| 105 | + /* Attempt to keep stray double-clicks from double-posting. */ | |
| 106 | + const formSubmitted = function(event){ | |
| 107 | + const form = event.target; | |
| 108 | + if( form.dataset.submitted ){ | |
| 109 | + console.warn("Preventing double-submit."); | |
| 110 | + event.preventDefault(); | |
| 111 | + return; | |
| 112 | + } | |
| 113 | + form.dataset.submitted = '1'; | |
| 114 | + /** If the user is left waiting "a long time," disable the | |
| 115 | + resubmit protection. If we don't do this and they tap the | |
| 116 | + browser's cancel button while waiting, they'll be stuck with | |
| 117 | + an unsubmittable form. */ | |
| 118 | + setTimeout(()=>{delete form.dataset.submitted}, 7000); | |
| 119 | + return; | |
| 120 | + }; | |
| 121 | + document.querySelectorAll("form").forEach(function(form){ | |
| 122 | + form.addEventListener('submit',formSubmitted); | |
| 123 | + }); | |
| 124 | + })/*F.onPageLoad callback*/; | |
| 106 | 125 | })(window.fossil); |
| 107 | 126 |
| --- src/fossil.page.forumpost.js | |
| +++ src/fossil.page.forumpost.js | |
| @@ -1,17 +1,17 @@ | |
| 1 | (function(F/*the fossil object*/){ |
| 2 | "use strict"; |
| 3 | /* JS code for /forumpage and friends. Requires fossil.dom |
| 4 | and can optionally use fossil.pikchr. */ |
| 5 | const P = F.page, D = F.dom; |
| 6 | |
| 7 | /** |
| 8 | When the page is loaded, this handler does the following: |
| 9 | |
| 10 | - Installs expand/collapse UI elements on "long" posts and collapses |
| 11 | them. |
| 12 | |
| 13 | - Any pikchr-generated SVGs get a source-toggle button added to them |
| 14 | which activates when the mouse is over the image or it is tapped. |
| 15 | |
| 16 | This is a harmless no-op if the current page has neither forum |
| 17 | post constructs for (1) nor any pikchr images for (2), nor will |
| @@ -99,8 +99,27 @@ | |
| 99 | })/*F.onPageLoad()*/; |
| 100 | |
| 101 | if(F.pikchr){ |
| 102 | F.pikchr.addSrcView(); |
| 103 | } |
| 104 | })/*onload callback*/; |
| 105 | |
| 106 | })(window.fossil); |
| 107 |
| --- src/fossil.page.forumpost.js | |
| +++ src/fossil.page.forumpost.js | |
| @@ -1,17 +1,17 @@ | |
| 1 | (function(F/*the fossil object*/){ |
| 2 | "use strict"; |
| 3 | /* JS code for /forumpost and friends. Requires fossil.dom |
| 4 | and can optionally use fossil.pikchr. */ |
| 5 | const P = F.page, D = F.dom; |
| 6 | |
| 7 | /** |
| 8 | When the page is loaded, this handler does the following: |
| 9 | |
| 10 | - Installs expand/collapse UI elements on "long" posts and collapses |
| 11 | them. |
| 12 | |
| 13 | - Any pikchr-generated SVGs get a source-toggle button added to them |
| 14 | which activates when the mouse is over the image or it is tapped. |
| 15 | |
| 16 | This is a harmless no-op if the current page has neither forum |
| 17 | post constructs for (1) nor any pikchr images for (2), nor will |
| @@ -99,8 +99,27 @@ | |
| 99 | })/*F.onPageLoad()*/; |
| 100 | |
| 101 | if(F.pikchr){ |
| 102 | F.pikchr.addSrcView(); |
| 103 | } |
| 104 | |
| 105 | /* Attempt to keep stray double-clicks from double-posting. */ |
| 106 | const formSubmitted = function(event){ |
| 107 | const form = event.target; |
| 108 | if( form.dataset.submitted ){ |
| 109 | console.warn("Preventing double-submit."); |
| 110 | event.preventDefault(); |
| 111 | return; |
| 112 | } |
| 113 | form.dataset.submitted = '1'; |
| 114 | /** If the user is left waiting "a long time," disable the |
| 115 | resubmit protection. If we don't do this and they tap the |
| 116 | browser's cancel button while waiting, they'll be stuck with |
| 117 | an unsubmittable form. */ |
| 118 | setTimeout(()=>{delete form.dataset.submitted}, 7000); |
| 119 | return; |
| 120 | }; |
| 121 | document.querySelectorAll("form").forEach(function(form){ |
| 122 | form.addEventListener('submit',formSubmitted); |
| 123 | }); |
| 124 | })/*F.onPageLoad callback*/; |
| 125 | })(window.fossil); |
| 126 |