1. Module bundling added to reduce server calls as each file was taking ~440 ms to load on public server.\n2. JavaScript lib files refactored with OOP for use with module bundling.

This commit is contained in:
2024-09-10 19:43:02 +01:00
parent aac01e687f
commit 0c88f161c3
7678 changed files with 778712 additions and 1254 deletions

View File

@@ -1,10 +1,12 @@
import Validation from "./lib/validation";
// Date picker inputs
/*
function hookupInputDatePickers(dateInputs, notFuture, notPast, parent, addClearOption) {
if (!isEmpty(dateInputs)) {
if (!Validation.isEmpty(dateInputs)) {
let currentInput, currentDateString, currentDate, exceptionsArray;
@@ -12,13 +14,13 @@ function hookupInputDatePickers(dateInputs, notFuture, notPast, parent, addClear
currentInput = document.querySelectorAll(dateInputs[i]);
currentDateString = currentInput.val();
currentDate = (!isEmpty(currentDateString)) ? convertDDMMYYYYString2Date(currentDateString, false) : null;
currentDate = (!Validation.isEmpty(currentDateString)) ? convertDDMMYYYYString2Date(currentDateString, false) : null;
exceptionsArray = (currentDate != null) ? [currentDate] : null;
turnInputIntoDatePicker(currentInput, notFuture, notPast, exceptionsArray);
}
if (!isEmpty(parent)) {
if (!Validation.isEmpty(parent)) {
// stop user from manually typing date except backspace and delete
// which will clear the whole value to ensure we either have a whole
// date string or none
@@ -50,7 +52,7 @@ function hookupInputDatePickers(dateInputs, notFuture, notPast, parent, addClear
"clears": {
name: "Clear Date",
icon: "delete",
disabled: function(key, opt) { return isEmpty(document.querySelectorAll(opt.$trigger)); }, // if it's already empty, don't do anything
disabled: function(key, opt) { return Validation.isEmpty(document.querySelectorAll(opt.$trigger)); }, // if it's already empty, don't do anything
callback: function(itemKey, opt, rootMenu, originalEvent) { var input = document.querySelectorAll(opt.$trigger); input.val(''); input.trigger('change'); }
}
}
@@ -73,12 +75,12 @@ function turnInputIntoDatePicker(input, notFuture, notPast, exceptionValueArray)
tomorrow.setDate(today.getDate() + 1);
tomorrow.setHours(0, 0, 0, 0);
var hasExceptions = !isEmpty(exceptionValueArray);
var hasExceptions = !Validation.isEmpty(exceptionValueArray);
beforeShowDayCallBack = function(date) {
var selectedDate = date.getTime();
var fieldHasException = hasExceptions && arrayContainsItem(exceptionValueArray, date);
var fieldHasException = hasExceptions && Validation.arrayContainsItem(exceptionValueArray, date);
if (notFuture && (tomorrow < selectedDate) && fieldHasException) return [false, 'redday', 'You cannot choose a future date'];
if (notPast && (selectedDate < today) && fieldHasException) return [false, 'redday', 'You cannot choose a past date'];
@@ -101,7 +103,7 @@ function turnInputIntoDatePicker(input, notFuture, notPast, exceptionValueArray)
}
function setDatePickerDate(input, objDate) {
if (!isEmpty(objDate)) {
if (!Validation.isEmpty(objDate)) {
input.val('');
}
else {
@@ -113,7 +115,7 @@ function getDatePickerDate(input, adjust4DayLightSavings) {
var date = null;
if (!isEmpty(input)) {
if (!Validation.isEmpty(input)) {
date = input.datepicker('getDate');
if (adjust4DayLightSavings) {
@@ -128,13 +130,13 @@ function formatDateDayLightSavingsTime(date) {
// JSON.stringify removes hour delta for daylight savings
// e.g. 13/11/2023 01:00:00 goes to 13/11/2023 00:00:00
// this adds an hour so it becomes the correct time when stringified
if (!isEmpty(date)) {
if (!Validation.isEmpty(date)) {
date.setTime(date.getTime() - date.getTimezoneOffset() * 60 * 1000)
}
}
*/
function convertJSONDateString2Date(dateStr) {
if (isEmpty(dateStr)) return null;
if (Validation.isEmpty(dateStr)) return null;
if (dateStr instanceof Date) return dateStr;
return new Date(parseInt(dateStr.substr(6)));
}
@@ -142,7 +144,7 @@ function convertJSONDateString2Date(dateStr) {
function convertDDMMYYYYString2Date(dateStr, adjust4DayLightSavings) {
var date = null;
if (!isEmpty(dateStr)) {
if (!Validation.isEmpty(dateStr)) {
if (dateStr instanceof Date) {
date = dateStr;
}
@@ -154,7 +156,7 @@ function convertDDMMYYYYString2Date(dateStr, adjust4DayLightSavings) {
}
}
if (adjust4DayLightSavings && !isEmpty(date)) {
if (adjust4DayLightSavings && !Validation.isEmpty(date)) {
formatDateDayLightSavingsTime(date);
}
}
@@ -163,7 +165,7 @@ function convertDDMMYYYYString2Date(dateStr, adjust4DayLightSavings) {
}
function convertDate2DDMMYYYYString(date) {
if (isEmpty(date)) return '';
if (Validation.isEmpty(date)) return '';
try {
var dd = date.getDate();

View File

@@ -1,18 +1,21 @@
import Validation from "./lib/validation";
// Data tables
function getDataTableCellByNode(table, elRow, indexColumn) {
// normal jQuery selector won't pick up hidden columns
return document.querySelectorAll(table.DataTable().cells(elRow, indexColumn, null).nodes());
}
function outputTableElementDateInput(table, elRow, indexColumn, value) {
let currentCell = getDataTableCellByNode(table, elRow, indexColumn);
let dateTxt = '';
if (!isEmpty(value)) {
if (typeof value === 'string') value = convertJSONDateString2Date(value);
export default class Table {
getDataTableCellByNode(table, elRow, indexColumn) {
// normal jQuery selector won't pick up hidden columns
return document.querySelectorAll(table.DataTable().cells(elRow, indexColumn, null).nodes());
}
outputTableElementDateInput(table, elRow, indexColumn, value) {
let currentCell = getDataTableCellByNode(table, elRow, indexColumn);
let dateTxt = '';
if (!Validation.isEmpty(value)) {
if (typeof value === 'string') value = convertJSONDateString2Date(value);
}
}
}

View File

@@ -1,41 +1,44 @@
function removeBlankTextAreaLines(textarea) {
textarea.val(textarea.val.replace(/(?:(?:\r\n|\r|\n)\s*){2}/gm, ''));
}
import Validation from "./lib/validation";
function fitTextAreasToContent(parent) {
var textareas = parent.querySelector('textarea');
export default class TextArea {
removeBlankTextAreaLines(textarea) {
textarea.val(textarea.val.replace(/(?:(?:\r\n|\r|\n)\s*){2}/gm, ''));
}
if (!isEmpty(textareas)) {
for (var t = 0; t < textareas.length; t++) {
fitTextAreaToContent(document.querySelectorAll(textareas[t]));
fitTextAreasToContent(parent) {
var textareas = parent.querySelector('textarea');
if (!Validation.isEmpty(textareas)) {
for (var t = 0; t < textareas.length; t++) {
fitTextAreaToContent(document.querySelectorAll(textareas[t]));
}
}
}
fitTextAreaToContent(textarea) {
// Trim new text
var txtNew = textarea.val().trim();
textarea.val(txtNew);
var elTextarea = textarea[0];
// Clear style height and set rows = 1
elTextarea.style.removeProperty('height');
textarea.attr('rows', 1);
const paddingTop = parseCSSPropertyToFloat(textarea, 'padding-top');
const paddingBottom= parseCSSPropertyToFloat(textarea, 'padding-bottom');
const borderTop = parseCSSPropertyToFloat(textarea, 'border-top');
const borderBottom = parseCSSPropertyToFloat(textarea, 'border-bottom');
let heightDelta = paddingTop + paddingBottom + borderTop + borderBottom;
let heightNew = elTextarea.scrollHeight + heightDelta;
// If new height is less than 1 linem default to single line height
const heightSingleLine = parseCSSPropertyToFloat(textarea, 'line-height') + heightDelta;
if (heightNew < heightSingleLine) heightNew = heightSingleLine;
elTextarea.style.height = heightNew + 'px';
}
}
function fitTextAreaToContent(textarea) {
// Trim new text
var txtNew = textarea.val().trim();
textarea.val(txtNew);
var elTextarea = textarea[0];
// Clear style height and set rows = 1
elTextarea.style.removeProperty('height');
textarea.attr('rows', 1);
const paddingTop = parseCSSPropertyToFloat(textarea, 'padding-top');
const paddingBottom= parseCSSPropertyToFloat(textarea, 'padding-bottom');
const borderTop = parseCSSPropertyToFloat(textarea, 'border-top');
const borderBottom = parseCSSPropertyToFloat(textarea, 'border-bottom');
let heightDelta = paddingTop + paddingBottom + borderTop + borderBottom;
let heightNew = elTextarea.scrollHeight + heightDelta;
// If new height is less than 1 linem default to single line height
const heightSingleLine = parseCSSPropertyToFloat(textarea, 'line-height') + heightDelta;
if (heightNew < heightSingleLine) heightNew = heightSingleLine;
elTextarea.style.height = heightNew + 'px';
}