Skip to main content

max / makenotwork

2.6 KB · 61 lines History Blame Raw
1 /*
2 * actions-partials.js
3 *
4 * Delegated event handlers extracted from inline on* attributes and
5 * href="javascript:" links in templates/partials/*.html, for CSP compliance
6 * (lets script-src drop 'unsafe-inline'). The delegated dispatcher lives in
7 * static/the core module; it looks these up by name as globals and invokes them with
8 * `this` bound to the dispatching element and args from data-arg/data-arg2.
9 *
10 * Each function preserves the original inline behavior verbatim.
11 */
12
13 // No-op verb: lets an element use data-stop/data-prevent modifiers without
14 // running any action (former onclick="event.stopPropagation();").
15 window.noop = function () {};
16
17 // link_row.html
18 window.onMoveLink = function (dir) { moveLink(this, parseInt(dir, 10)); };
19 window.onEditLink = function () { editLink(this); };
20 window.onSaveLink = function () { saveLink(this); };
21 window.onCancelLink = function () { cancelLink(this); };
22
23 // git_nav.html
24 window.navToValue = function () { if (this.value) window.location.href = this.value; };
25
26 // insertion_list.html
27 window.insertionsStartUpload = function () { MNW.insertions.startUpload(); };
28 window.onInsertionFileSelected = function () { MNW.insertions.handleFileSelected(this); };
29 window.onInsertionRename = function (id) { MNW.insertions.rename(id, this.dataset.title); };
30
31 // promo_codes_list.html and item_license_keys.html (copy to clipboard)
32 window.copyText = function () { navigator.clipboard.writeText(this.dataset.copy); };
33
34 // promo_codes_list.html (toggle inline edit row)
35 window.togglePromoEditRow = function () { this.closest('tr').nextElementSibling.classList.toggle('hidden'); };
36
37 // tag_suggestions.html
38 window.onAddTagSuggestion = function (id) { addTagById(id); this.remove(); };
39
40 // discover_results.html
41 window.onOpenCollectionPicker = function () { openCollectionPicker(this.dataset.itemId, this); };
42
43 // item_edit_row.html
44 window.onPriceInput = function () { this.nextElementSibling.value = Math.round(parseFloat(this.value || 0) * 100); };
45
46 // placement_list.html
47 window.onPlacementPositionChange = function () { MNW.insertions.toggleOffsetInput(this.value); };
48 window.onAddPlacement = function (id) { MNW.insertions.addPlacement(id); };
49
50 // toast.html
51 window.dismissToast = function () { this.parentElement.remove(); };
52
53 // slug_status.html
54 window.applySlugSuggestion = function () {
55 var i = this.closest('.form-group').querySelector('input[name=slug]');
56 if (i) { i.value = this.dataset.slug; i.dispatchEvent(new Event('keyup', { bubbles: true })); }
57 };
58
59 // tip_button.html
60 window.toggleTipForm = function () { this.nextElementSibling.classList.toggle('hidden'); };
61