@modernman00/shared-js-lib 1.2.7 → 1.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Login.js +32 -28
- package/ShowResponse.js +2 -49
- package/package.json +1 -1
- package/theAutoComplete.js +87 -95
package/Login.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
import { convertFormData } from './FormProcessing.js';
|
|
3
|
-
import { postFormData } from
|
|
3
|
+
import { postFormData } from './Http.js';
|
|
4
4
|
import { showLoader, clearLoader } from './Loader.js';
|
|
5
|
-
import { showError } from
|
|
5
|
+
import { showError } from './ShowResponse.js';
|
|
6
6
|
|
|
7
7
|
// block the setLoader div
|
|
8
8
|
|
|
@@ -15,29 +15,33 @@ import { showError } from "./ShowResponse.js";
|
|
|
15
15
|
* @returns {void}
|
|
16
16
|
* @throws {Error} - If there is an error with the submission
|
|
17
17
|
*/
|
|
18
|
-
export const loginSubmission = async (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
18
|
+
export const loginSubmission = async (
|
|
19
|
+
formId,
|
|
20
|
+
loginURL,
|
|
21
|
+
redirect,
|
|
22
|
+
css = null, lengthLimit = null
|
|
23
|
+
) => {
|
|
24
|
+
const formData = convertFormData(formId);
|
|
25
|
+
formData.clearError();
|
|
26
|
+
if (lengthLimit) {
|
|
27
|
+
formData.realTimeCheckLen(lengthLimit.maxLength.id, lengthLimit.maxLength.max);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
formData.emailVal();
|
|
32
|
+
formData.massValidate();
|
|
33
|
+
|
|
34
|
+
if (!formData.error.length) {
|
|
35
|
+
showLoader();
|
|
36
|
+
localStorage.setItem('redirect', redirect);
|
|
37
|
+
|
|
38
|
+
await postFormData(loginURL, formId, redirect, css);
|
|
39
|
+
} else {
|
|
40
|
+
alert('The form cannot be submitted. Please check the errors');
|
|
39
41
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
} catch (err) {
|
|
43
|
+
showError(err);
|
|
44
|
+
} finally {
|
|
45
|
+
clearLoader();
|
|
46
|
+
}
|
|
47
|
+
};
|
package/ShowResponse.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { id } from './UtilityHtml.js';
|
|
2
|
-
|
|
1
|
+
import { id, qSel } from './UtilityHtml.js';
|
|
2
|
+
|
|
3
3
|
export const showError = (e) =>
|
|
4
4
|
console.error(
|
|
5
5
|
`${e.name} at ${e.fileName}:${e.lineNumber} - ${e.message}\n${e.stack}`,
|
|
@@ -35,54 +35,7 @@ export const showNotification = (
|
|
|
35
35
|
}, timer);
|
|
36
36
|
};
|
|
37
37
|
|
|
38
|
-
/************* ✨ Windsurf Command 🌟 *************/
|
|
39
|
-
export const deleteNotification = async (elementId, yourId, famCode) => {
|
|
40
|
-
export const deleteNotification = async (elementId) => {
|
|
41
|
-
// Extract the user ID from the target ID
|
|
42
|
-
const senderId = elementId.replace('deleteNotification', 'notificationBar');
|
|
43
|
-
|
|
44
|
-
const elementData = id(elementId);
|
|
45
|
-
const data = elementData.getAttribute('data-id');
|
|
46
|
-
// change the background of the clicked element
|
|
47
|
-
const notificationHTML = id(senderId);
|
|
48
|
-
// Make sure required variables are defined before using them
|
|
49
|
-
if (typeof yourId === 'undefined' || typeof famCode === 'undefined') {
|
|
50
|
-
msgException('Required parameters (yourId or famCode) are not defined');
|
|
51
|
-
}
|
|
52
|
-
const url = `/removeNotification/${yourId}/${famCode}/${data}`;
|
|
53
|
-
const response = await axios.put(url);
|
|
54
|
-
if (response.data.message === 'Notification marked as read') {
|
|
55
|
-
// remove a html element with notificationBar after 2 mins
|
|
56
|
-
notificationHTML.remove();
|
|
57
|
-
// reduce the notification count as you have deleted the notification
|
|
58
|
-
const newValues = parseInt(
|
|
59
|
-
sessionStorage.getItem('notificationCount') - 1,
|
|
60
|
-
);
|
|
61
|
-
id('notification_count').innerHTML = newValues;
|
|
62
|
-
} else {
|
|
63
|
-
msgException('Error removing notification' + ' ' + response.data.message);
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
/******* 43b70b66-cdee-4764-a1e7-4f21be65d0d7 *******/
|
|
67
|
-
|
|
68
|
-
const url = `/removeNotification/${yourId}/${famCode}/${data}`;
|
|
69
38
|
|
|
70
|
-
try {
|
|
71
|
-
const response = await axios.put(url);
|
|
72
|
-
|
|
73
|
-
if (response.data.message === 'Notification marked as read') {
|
|
74
|
-
notificationHTML.remove();
|
|
75
|
-
const newValues = parseInt(
|
|
76
|
-
sessionStorage.getItem('notificationCount') - 1,
|
|
77
|
-
);
|
|
78
|
-
id('notification_count').innerHTML = newValues;
|
|
79
|
-
} else {
|
|
80
|
-
console.error('Error removing notification', response.data.message);
|
|
81
|
-
}
|
|
82
|
-
} catch (error) {
|
|
83
|
-
console.error('Error removing notification', error);
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
39
|
|
|
87
40
|
export const showResponse = (theId, message, status) => {
|
|
88
41
|
const responseEl = id(theId);
|
package/package.json
CHANGED
package/theAutoComplete.js
CHANGED
|
@@ -1,101 +1,93 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
} else if (e.keyCode == 38) { //up
|
|
54
|
-
/*If the arrow UP key is pressed,
|
|
55
|
-
decrease the currentFocus variable:*/
|
|
56
|
-
currentFocus--;
|
|
57
|
-
/*and and make the current item more visible:*/
|
|
58
|
-
addActive(x);
|
|
59
|
-
} else if (e.keyCode == 13) {
|
|
60
|
-
/*If the ENTER key is pressed, prevent the form from being submitted,*/
|
|
61
|
-
e.preventDefault();
|
|
62
|
-
if (currentFocus > -1) {
|
|
63
|
-
/*and simulate a click on the "active" item:*/
|
|
64
|
-
if (x) x[currentFocus].click();
|
|
65
|
-
}
|
|
1
|
+
import { id } from './UtilityHtml.js'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param {string} inputId
|
|
6
|
+
* @param {Array} arr
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Sets up an autocomplete functionality for an input element.
|
|
11
|
+
*
|
|
12
|
+
* @param {string} inputId - The ID of the input element to attach the autocomplete to.
|
|
13
|
+
* @param {Array<string>} arr - An array of strings containing the autocomplete suggestions.
|
|
14
|
+
*
|
|
15
|
+
* The function converts all strings in the array to lowercase for case-insensitive matching.
|
|
16
|
+
* It initializes the autocomplete with the given input element and array of suggestions,
|
|
17
|
+
* providing real-time suggestions based on user input. On selecting a suggestion,
|
|
18
|
+
* it populates the input element with the selected suggestion.
|
|
19
|
+
*/
|
|
20
|
+
export const autocomplete = (inputId, arr) => {
|
|
21
|
+
const whatToBuyInput = id(inputId); // Get the text input
|
|
22
|
+
if (whatToBuyInput) {
|
|
23
|
+
// Create a <ul> for autocomplete suggestions
|
|
24
|
+
const suggestionList = document.createElement("ul");
|
|
25
|
+
suggestionList.classList.add("autocomplete-suggestions");
|
|
26
|
+
suggestionList.id = "suggestions"; // For accessibility
|
|
27
|
+
whatToBuyInput.parentElement.appendChild(suggestionList); // Append to input's parent
|
|
28
|
+
|
|
29
|
+
// Function to show matching suggestions based on user input
|
|
30
|
+
const showSuggestions = (inputValue) => {
|
|
31
|
+
suggestionList.innerHTML = ""; // Clear previous suggestions
|
|
32
|
+
if (!inputValue) return; // Exit if input is empty
|
|
33
|
+
|
|
34
|
+
// Filter items that match the input (case-insensitive), limit to 8
|
|
35
|
+
const matches = arr
|
|
36
|
+
.filter(item => item.toLowerCase().includes(inputValue.toLowerCase()))
|
|
37
|
+
.slice(0, 8);
|
|
38
|
+
|
|
39
|
+
// Create <li> for each match
|
|
40
|
+
matches.forEach((item, index) => {
|
|
41
|
+
const li = document.createElement("li");
|
|
42
|
+
li.textContent = item;
|
|
43
|
+
li.setAttribute("tabindex", "0"); // Make focusable for keyboard
|
|
44
|
+
li.setAttribute("data-index", index); // Store index for navigation
|
|
45
|
+
li.addEventListener("click", () => {
|
|
46
|
+
whatToBuyInput.value = item; // Set input value on click
|
|
47
|
+
suggestionList.innerHTML = ""; // Clear suggestions
|
|
48
|
+
});
|
|
49
|
+
li.addEventListener("keypress", (e) => {
|
|
50
|
+
if (e.key === "Enter") {
|
|
51
|
+
whatToBuyInput.value = item; // Set input value on Enter
|
|
52
|
+
suggestionList.innerHTML = ""; // Clear suggestions
|
|
66
53
|
}
|
|
54
|
+
});
|
|
55
|
+
suggestionList.appendChild(li);
|
|
67
56
|
});
|
|
57
|
+
};
|
|
68
58
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
removeActive(x);
|
|
74
|
-
if (currentFocus >= x.length) currentFocus = 0;
|
|
75
|
-
if (currentFocus < 0) currentFocus = (x.length - 1);
|
|
76
|
-
/*add class "autocomplete-active":*/
|
|
77
|
-
x[currentFocus].classList.add("autocomplete-active");
|
|
78
|
-
}
|
|
59
|
+
// Show suggestions as user types
|
|
60
|
+
whatToBuyInput.addEventListener("input", (e) => {
|
|
61
|
+
showSuggestions(e.target.value);
|
|
62
|
+
});
|
|
79
63
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
}
|
|
64
|
+
// Clear suggestions on blur (with delay for click to register)
|
|
65
|
+
whatToBuyInput.addEventListener("blur", () => {
|
|
66
|
+
setTimeout(() => suggestionList.innerHTML = "", 200);
|
|
67
|
+
});
|
|
86
68
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
69
|
+
// Handle keyboard navigation for suggestions
|
|
70
|
+
whatToBuyInput.addEventListener("keydown", (e) => {
|
|
71
|
+
const suggestions = suggestionList.querySelectorAll("li");
|
|
72
|
+
if (!suggestions.length) return; // Exit if no suggestions
|
|
73
|
+
|
|
74
|
+
let focusedIndex = Array.from(suggestions).findIndex(li => li === document.activeElement);
|
|
75
|
+
if (e.key === "ArrowDown") {
|
|
76
|
+
e.preventDefault(); // Prevent cursor movement
|
|
77
|
+
focusedIndex = (focusedIndex + 1) % suggestions.length; // Loop to start
|
|
78
|
+
suggestions[focusedIndex].focus();
|
|
79
|
+
} else if (e.key === "ArrowUp") {
|
|
80
|
+
e.preventDefault();
|
|
81
|
+
focusedIndex = (focusedIndex - 1 + suggestions.length) % suggestions.length; // Loop to end
|
|
82
|
+
suggestions[focusedIndex].focus();
|
|
83
|
+
} else if (e.key === "Enter" && focusedIndex >= 0) {
|
|
84
|
+
e.preventDefault();
|
|
85
|
+
whatToBuyInput.value = suggestions[focusedIndex].textContent; // Select item
|
|
86
|
+
suggestionList.innerHTML = ""; // Clear suggestions
|
|
87
|
+
} else if (e.key === "Escape") {
|
|
88
|
+
suggestionList.innerHTML = ""; // Clear suggestions
|
|
96
89
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|