Skip to main content

max / makenotwork

2.2 KB · 51 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 // link_row.html
14 window.onMoveLink = function (dir) { moveLink(this, parseInt(dir, 10)); };
15 window.onEditLink = function () { editLink(this); };
16 window.onSaveLink = function () { saveLink(this); };
17 window.onCancelLink = function () { cancelLink(this); };
18
19 // insertion_list.html
20 window.insertionsStartUpload = function () { MNW.insertions.startUpload(); };
21 window.onInsertionFileSelected = function () { MNW.insertions.handleFileSelected(this); };
22 window.onInsertionRename = function (id) { MNW.insertions.rename(id, this.dataset.title); };
23
24 // promo_codes_list.html and item_license_keys.html (copy to clipboard)
25 window.copyText = function () { navigator.clipboard.writeText(this.dataset.copy); };
26
27 // promo_codes_list.html (toggle inline edit row)
28 window.togglePromoEditRow = function () { this.closest('tr').nextElementSibling.classList.toggle('hidden'); };
29
30 // tag_suggestions.html
31 window.onAddTagSuggestion = function (id) { addTagById(id); this.remove(); };
32
33 // discover_results.html
34 window.onOpenCollectionPicker = function () { openCollectionPicker(this.dataset.itemId, this); };
35
36 // item_edit_row.html
37 window.onPriceInput = function () { this.nextElementSibling.value = Math.round(parseFloat(this.value || 0) * 100); };
38
39 // placement_list.html
40 window.onPlacementPositionChange = function () { MNW.insertions.toggleOffsetInput(this.value); };
41 window.onAddPlacement = function (id) { MNW.insertions.addPlacement(id); };
42
43 // slug_status.html
44 window.applySlugSuggestion = function () {
45 var i = this.closest('.form-group').querySelector('input[name=slug]');
46 if (i) { i.value = this.dataset.slug; i.dispatchEvent(new Event('keyup', { bubbles: true })); }
47 };
48
49 // tip_button.html
50 window.toggleTipForm = function () { this.nextElementSibling.classList.toggle('hidden'); };
51