Index: openacs-4/packages/acs-templating/tcl/head-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-templating/tcl/head-procs.tcl,v diff -u -r1.45.2.32 -r1.45.2.33 --- openacs-4/packages/acs-templating/tcl/head-procs.tcl 7 Sep 2022 16:33:39 -0000 1.45.2.32 +++ openacs-4/packages/acs-templating/tcl/head-procs.tcl 5 Oct 2022 14:04:29 -0000 1.45.2.33 @@ -974,6 +974,48 @@ return $footer } +ad_proc -private template::register_double_click_handler {} { +} { + template::add_body_script -script [ns_trim { + function oacs_reenable_double_click_handler(target) { + if ( target.dataset.oacsClicked == 'true') { + target.dataset.oacsClicked = false; + target.disabled = false; + target.classList.remove("disabled"); + console.log("re-enable click handler"); + } + }; + for (e of document.getElementsByClassName('prevent-double-click')) { + if (!e.dataset.oacsDoubleClickHandlerRegistered) { + e.addEventListener('click', function(event) { + let target = event.target || event.srcElement; + if ( target.dataset.oacsClicked == 'true') { + event.stopPropagation(); + event.preventDefault(); + console.log("blocked double-click"); + return false; + } else { + target.dataset.oacsClicked = true; + target.classList.add("disabled"); + let timeout = target.dataset.oacsTimeout || 1000; + console.log('reactivate in ' + timeout); + setTimeout(function() {oacs_reenable_double_click_handler(target);}, timeout); + setTimeout(function() {target.disabled = true;}); + return true; + } + }, true); + // In case the page has changed before the button was reenabled + // and the user uses the brower's back button, we have to establish + // a clickable state. + e.addEventListener('focus', function(event) { + oacs_reenable_double_click_handler(event.target || event.srcElement); + }); + e.dataset.oacsDoubleClickHandlerRegistered = true; + } + }; + }] +} + ad_proc template::get_body_event_handlers { } { @@ -982,6 +1024,7 @@ after having processed its content. } { + template::register_double_click_handler # # Concatenate the JavaScript event handlers for the body tag #