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].

stephan 2023-10-24 20:27 trunk
Commit 600f171306d29f398e685bdf9713e1ff99573ecbc47ab4e2efc72107197b3238
1 file changed +23 -4
--- src/fossil.page.forumpost.js
+++ src/fossil.page.forumpost.js
@@ -1,17 +1,17 @@
11
(function(F/*the fossil object*/){
22
"use strict";
3
- /* JS code for /forumpage and friends. Requires fossil.dom
3
+ /* JS code for /forumpost and friends. Requires fossil.dom
44
and can optionally use fossil.pikchr. */
55
const P = F.page, D = F.dom;
66
77
/**
88
When the page is loaded, this handler does the following:
99
1010
- Installs expand/collapse UI elements on "long" posts and collapses
1111
them.
12
-
12
+
1313
- Any pikchr-generated SVGs get a source-toggle button added to them
1414
which activates when the mouse is over the image or it is tapped.
1515
1616
This is a harmless no-op if the current page has neither forum
1717
post constructs for (1) nor any pikchr images for (2), nor will
@@ -99,8 +99,27 @@
9999
})/*F.onPageLoad()*/;
100100
101101
if(F.pikchr){
102102
F.pikchr.addSrcView();
103103
}
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*/;
106125
})(window.fossil);
107126
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button