Skip to main content

max / makenotwork

1.6 KB · 34 lines History Blame Raw
1 // Delegated event handlers extracted from inline on* attributes in the
2 // dashboard, dashboard editor, embed, and wizard templates, moved here for CSP
3 // compliance (so script-src can drop 'unsafe-inline'). The dispatcher in
4 // the core module invokes each of these by name with `this` bound to the dispatching
5 // element and any data-arg/data-arg2 attributes passed as arguments. Bodies
6 // are preserved verbatim from the original inline handlers.
7
8 // setActiveTab is defined in the core module and takes the clicked button as its
9 // argument; the inline handlers called setActiveTab(this), so wrap it.
10 window.onSetActiveTab = function () {
11 setActiveTab(this);
12 };
13
14 // Reactivate-account form: schedule a page reload after the HTMX request.
15 window.reactivateReload = function () {
16 setTimeout(function(){ window.location.reload(); }, 500);
17 };
18
19 // Blog editor breadcrumb / cancel links: after navigating, activate the Blog tab.
20 window.blogTabNav = function () {
21 setTimeout(function(){document.getElementById('tab-blog').click()},100);
22 };
23
24 // Copy the item id to the clipboard and flash feedback on the button.
25 window.onCopyItemId = function (id) {
26 navigator.clipboard.writeText(id); this.textContent='Copied!'; setTimeout(()=>this.textContent='Copy Item ID', 1500);
27 };
28
29 // Custom page reset form: confirm before submitting. data-submit auto-prevents
30 // the native submit, so re-submit programmatically when confirmed.
31 window.confirmResetPage = function () {
32 if (confirm('Reset this page to the platform default? This clears your custom HTML and CSS.')) this.submit();
33 };
34