Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions apps/autocomplete/static/autocomplete/js/autocomplete.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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
Expand All @@ -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;
}

Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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.
Expand All @@ -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');
Expand Down
65 changes: 20 additions & 45 deletions apps/bookings/static/js/htmx_dialog.js
Original file line number Diff line number Diff line change
@@ -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 = "";
});
});
8 changes: 3 additions & 5 deletions apps/labman_utils/static/js/obfuscatre_htmlfield.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
28 changes: 28 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -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",
}
}
];
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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"
}
Expand Down