diff --git a/apps/autocomplete/static/autocomplete/js/autocomplete.js b/apps/autocomplete/static/autocomplete/js/autocomplete.js index a60aa21..0dafabe 100644 --- a/apps/autocomplete/static/autocomplete/js/autocomplete.js +++ b/apps/autocomplete/static/autocomplete/js/autocomplete.js @@ -1,9 +1,13 @@ +/* exported phac_aspc_autocomplete_trigger_change, phac_aspc_autocomplete_blur_handler, + phac_aspc_autocomplete_item_click_handler, phac_aspc_autocomplete_focus_handler, + phac_aspc_autocomplete_click_handler, phac_aspc_autocomplete_keyup_handler, + phac_aspc_autocomplete_keydown_handler, SingleAutocompleteHelper, MultiAutocompleteHelper */ function phac_aspc_autocomplete_trigger_change(container_id) { setTimeout(() => { const container = document.getElementById(container_id); const el = container.querySelector('.textinput'); el.dispatchEvent(new Event('change', { bubbles: true })); - }, 0) + }, 0); } function phac_aspc_autocomplete_clear_focus(container, activate_ring) { @@ -32,7 +36,7 @@ function phac_aspc_autocomplete_hide_results(container) { results.classList.remove('show'); } -phac_aspc_autocomplete_blur_skip = {} +var phac_aspc_autocomplete_blur_skip = {}; function phac_aspc_autocomplete_blur_handler(event, name, sync = false, item = false) { // Handler responsible for blur events // Will remove the results when focus is no longer on the component, and update @@ -47,7 +51,7 @@ function phac_aspc_autocomplete_blur_handler(event, name, sync = false, item = f // Reset the component's state phac_aspc_autocomplete_closed[id] = false; if (phac_aspc_autocomplete_keyup_debounce[id]) { - clearTimeout(phac_aspc_autocomplete_keyup_debounce[id]) + clearTimeout(phac_aspc_autocomplete_keyup_debounce[id]); phac_aspc_autocomplete_keyup_debounce[id] = false; } @@ -132,7 +136,7 @@ function phac_aspc_autocomplete_set_initial_value(container, reset = false) { } } -phac_aspc_autocomplete_closed = {}; +var phac_aspc_autocomplete_closed = {}; function phac_aspc_autocomplete_click_handler(event) { if (event.target.classList.contains('item')) return true; const container = event.target.closest('.phac-aspc-form-autocomplete'); @@ -173,12 +177,12 @@ function phac_aspc_autocomplete_keyup_handler(event) { const v = elem.value; debounce[id] = setTimeout(() => { - if (!phac_aspc_autocomplete_closed[id] && v != value[id]) { + if (!phac_aspc_autocomplete_closed[id] && v !== value[id]) { elem.dispatchEvent(new Event('phac_aspc_autocomplete_trigger')); } else if ( phac_aspc_autocomplete_closed[id] && - v != value[id] && - v == '' + v !== value[id] && + v === '' ) { phac_aspc_autocomplete_closed[id] = false; } @@ -225,21 +229,21 @@ function phac_aspc_autocomplete_keydown_handler(event) { } if (counter > 0) return fallback; return null; - } + }; const switchFocus = (element, container) => { phac_aspc_autocomplete_clear_focus(container); const el = container.querySelector('.textinput'); el.setAttribute('aria-activedescendant', element.getAttribute('id')); element.classList.add('has-focus'); - element.scrollIntoView({ block: 'nearest' }) - } + element.scrollIntoView({ block: 'nearest' }); + }; const selectFocusedItem = (container) => { const item = container.querySelector('.has-focus'); if (item) { item.dispatchEvent(new Event('click')); } return item; - } + }; const focusWhenResultsShown = (container, timeout, up) => { // This function uses polling to wait for the results to be shown before // moving focus. @@ -266,13 +270,13 @@ function phac_aspc_autocomplete_keydown_handler(event) { const next = whereTo(container, true, false); if (next) switchFocus(next, container); } - } + }; const getPageSize = (container) => { const r1 = container.getBoundingClientRect(); const r2 = container.querySelector('.item').getBoundingClientRect(); return Math.floor((r1.bottom - r1.top) / (r2.bottom - r2.top)); - } + }; const container = event.target.closest('.phac-aspc-form-autocomplete'); const results = container.querySelector('.results'); diff --git a/apps/bookings/static/js/htmx_dialog.js b/apps/bookings/static/js/htmx_dialog.js index 96564b3..80dda1a 100644 --- a/apps/bookings/static/js/htmx_dialog.js +++ b/apps/bookings/static/js/htmx_dialog.js @@ -1,66 +1,41 @@ "use strict"; window.addEventListener("DOMContentLoaded", function() { - const elem=document.querySelector("#modal"); + const elem = document.querySelector("#modal"); - const defaultWidgetOptions = { - icons: { - time: 'bi-clock', - date: 'bi-calendar', - up: 'bi-chevron-up', - down: 'bi-chevron-down', - previous: 'bi-chevron-left', - next: 'bi-chevron-right', - today: 'bi-record-circle', - clear: 'bi-trash', - close: 'bi-x-lg' - } - } - function getConfig(inputElement) { - let /** @type {WidgetInputConfig} */ config; - try { - config = JSON.parse(inputElement.dataset.dbdpConfig); - } - catch (err) { throw Error("Invalid input config") } - const optionKeyName = inputElement.name.replace(/^(.*-)?/, "dbdpOptions_") - config.options = { ...defaultWidgetOptions, ...window.dbdpOptions, ...window[optionKeyName], ...config.options }; - config.events = { ...window.dbdpEvents, ...window[optionKeyName.replace("dbdpOptions_", "dbdpEvents_")] }; - return config; - } htmx.on("htmx:afterSwap", (e) => { // Response targeting #dialog => show the modal - if (e.detail.target.id == "dialog") { - var modal = bootstrap.Modal.getOrCreateInstance(elem) - modal.show() - + if (e.detail.target.id === "dialog") { + var modal = bootstrap.Modal.getOrCreateInstance(elem); + modal.show(); if (document.querySelector("#user__textinput")) { - htmx.trigger("#user__textinput","focus"); - htmx.trigger("#user__textinput","mousedown"); + htmx.trigger("#user__textinput", "focus"); + htmx.trigger("#user__textinput", "mousedown"); } var frm = document.querySelector("#booking"); if (frm) { frm.addEventListener('keypress', function (event) { if (event.keyCode === 13) { event.preventDefault(); - htmx.trigger("#submit_booking","focus"); - htmx.trigger("#booking","submit"); + htmx.trigger("#submit_booking", "focus"); + htmx.trigger("#booking", "submit"); } }); } } }); - htmx.on("htmx:beforeSwap", (e) => { - // Empty response targeting #dialog => hide the modal - if (e.detail.target.id == "dialog" && e.detail.xhr.status==204) { - var modal = bootstrap.Modal.getOrCreateInstance(elem) - modal.hide() - e.detail.shouldSwap = false - } - }); + htmx.on("htmx:beforeSwap", (e) => { + // Empty response targeting #dialog => hide the modal + if (e.detail.target.id === "dialog" && e.detail.xhr.status === 204) { + var modal = bootstrap.Modal.getOrCreateInstance(elem); + modal.hide(); + e.detail.shouldSwap = false; + } + }); - // Remove dialog content after hiding - htmx.on("hidden.bs.modal", () => { - document.getElementById("dialog").innerHTML = "" - }); + // Remove dialog content after hiding + htmx.on("hidden.bs.modal", () => { + document.getElementById("dialog").innerHTML = ""; + }); }); diff --git a/apps/labman_utils/static/js/obfuscatre_htmlfield.js b/apps/labman_utils/static/js/obfuscatre_htmlfield.js index 7d3e837..9100c6d 100644 --- a/apps/labman_utils/static/js/obfuscatre_htmlfield.js +++ b/apps/labman_utils/static/js/obfuscatre_htmlfield.js @@ -25,17 +25,15 @@ $(document).ready(function() { var base64EncodedText = base64Encode(originalText); var rot13Text = rot13(base64EncodedText); $(this).val(rot13Text); - $(this).attr({"encoded":"True"}) - console.log("Original text"+originalText); - console.log("New text:"+$(this).val()); + $(this).attr({"encoded": "true"}); return false; }); } // Intercept form submission - $('form').on('submit', function(event) { + $('form').on('submit', function() { setTimeout(function() { obfuscateHtmlContent(); - },0); + }, 0); }); }); diff --git a/eslint.config.mjs b/eslint.config.mjs new file mode 100644 index 0000000..094b2e3 --- /dev/null +++ b/eslint.config.mjs @@ -0,0 +1,28 @@ +export default [ + { + languageOptions: { + ecmaVersion: 2021, + sourceType: "script", + globals: { + window: "readonly", + document: "readonly", + console: "readonly", + htmx: "readonly", + bootstrap: "readonly", + requestAnimationFrame: "readonly", + setTimeout: "readonly", + clearTimeout: "readonly", + Event: "readonly", + btoa: "readonly", + $: "readonly", + } + }, + rules: { + "no-unused-vars": "warn", + "no-undef": "warn", + "semi": "warn", + "eqeqeq": "warn", + "no-console": "warn", + } + } +]; diff --git a/package.json b/package.json index 2b5889e..cbcbba7 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ }, "scripts": { "lint:css": "stylelint \"static/css/**/*.css\" \"apps/**/static/**/*.css\"", + "lint:js": "eslint \"apps/**/static/**/*.js\"", "test": "echo \"Error: no test specified\" && exit 1" }, "repository": { @@ -23,6 +24,7 @@ }, "homepage": "https://github.com/gb119/labman#readme", "devDependencies": { + "eslint": "^10.0.2", "stylelint": "^17.4.0", "stylelint-config-standard": "^40.0.0" }