Wrap a wait before the DOM is loaded before loading anything calling anything in app.js

This commit is contained in:
johnnyq
2025-03-23 18:08:14 -04:00
parent 53713a0318
commit df8a755462

779
js/app.js
View File

@@ -1,21 +1,157 @@
//Prevents resubmit on forms $(document).ready(function() {
if(window.history.replaceState){ //Prevents resubmit on forms
window.history.replaceState(null, null, window.location.href); if(window.history.replaceState){
} window.history.replaceState(null, null, window.location.href);
}
// Slide alert up after 4 secs // Slide alert up after 4 secs
$("#alert").fadeTo(5000, 500).slideUp(500, function(){ $("#alert").fadeTo(5000, 500).slideUp(500, function(){
$("#alert").slideUp(500); $("#alert").slideUp(500);
}); });
// Initialize Select2 Elements // Initialize Select2 Elements
$('.select2').select2({ $('.select2').select2({
theme: 'bootstrap4', theme: 'bootstrap4',
}); });
// Initialize TinyMCE // Initialize TinyMCE
tinymce.init({ tinymce.init({
selector: '.tinymce', selector: '.tinymce',
browser_spellcheck: true,
contextmenu: false,
resize: true,
min_height: 300,
max_height: 600,
promotion: false,
branding: false,
menubar: false,
statusbar: false,
toolbar: [
{ name: 'styles', items: [ 'styles' ] },
{ name: 'formatting', items: [ 'bold', 'italic', 'forecolor' ] },
{ name: 'link', items: [ 'link'] },
{ name: 'lists', items: [ 'bullist', 'numlist' ] },
{ name: 'alignment', items: [ 'alignleft', 'aligncenter', 'alignright', 'alignjustify' ] },
{ name: 'indentation', items: [ 'outdent', 'indent' ] },
{ name: 'table', items: [ 'table' ] },
{ name: 'extra', items: [ 'code', 'fullscreen' ] }
],
mobile: {
menubar: false,
plugins: 'autosave lists autolink',
toolbar: 'bold italic styles'
},
convert_urls: false,
plugins: 'link image lists table code codesample fullscreen autoresize',
license_key: 'gpl'
});
// Initialize TinyMCE
tinymce.init({
selector: '.tinymceAI',
browser_spellcheck: true,
contextmenu: false,
resize: true,
min_height: 300,
max_height: 600,
promotion: false,
branding: false,
menubar: false,
statusbar: false,
toolbar: [
{ name: 'styles', items: [ 'styles' ] },
{ name: 'formatting', items: [ 'bold', 'italic', 'forecolor' ] },
{ name: 'link', items: [ 'link'] },
{ name: 'lists', items: [ 'bullist', 'numlist' ] },
{ name: 'alignment', items: [ 'alignleft', 'aligncenter', 'alignright', 'alignjustify' ] },
{ name: 'indentation', items: [ 'outdent', 'indent' ] },
{ name: 'table', items: [ 'table' ] },
{ name: 'extra', items: [ 'code', 'fullscreen' ] },
{ name: 'ai', items: [ 'reword', 'undo', 'redo' ] }
],
mobile: {
menubar: false,
plugins: 'autosave lists autolink',
toolbar: 'bold italic styles'
},
convert_urls: false,
plugins: 'link image lists table code codesample fullscreen autoresize',
license_key: 'gpl',
setup: function(editor) {
var rewordButtonApi;
editor.ui.registry.addButton('reword', {
icon: 'ai',
tooltip: 'Reword Text',
onAction: function() {
var content = editor.getContent();
// Disable the Reword button
rewordButtonApi.setEnabled(false);
// Show the progress indicator
editor.setProgressState(true);
fetch('post.php?ai_reword', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ text: content }),
})
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(data => {
editor.undoManager.transact(function() {
editor.setContent(data.rewordedText || 'Error: Could not reword the text.');
});
// Hide the progress indicator
editor.setProgressState(false);
// Re-enable the Reword button
rewordButtonApi.setEnabled(true);
// Optional: Show a success notification
editor.notificationManager.open({
text: 'Text reworded successfully!',
type: 'success',
timeout: 3000
});
})
.catch(error => {
console.error('Error:', error);
// Hide the progress indicator
editor.setProgressState(false);
// Re-enable the Reword button
rewordButtonApi.setEnabled(true);
// Show an error notification
editor.notificationManager.open({
text: 'An error occurred while rewording the text.',
type: 'error',
timeout: 5000
});
});
},
onSetup: function(buttonApi) {
rewordButtonApi = buttonApi;
return function() {
// Cleanup when the editor is destroyed (if necessary)
};
}
});
}
});
tinymce.init({
selector: '.tinymceTicket', // Your selector
browser_spellcheck: true, browser_spellcheck: true,
contextmenu: false, contextmenu: false,
resize: true, resize: true,
@@ -27,27 +163,45 @@ tinymce.init({
statusbar: false, statusbar: false,
toolbar: [ toolbar: [
{ name: 'styles', items: [ 'styles' ] }, { name: 'styles', items: [ 'styles' ] },
{ name: 'formatting', items: [ 'bold', 'italic', 'forecolor' ] }, { name: 'formatting', items: [ 'bold', 'italic', 'forecolor'] },
{ name: 'link', items: [ 'link'] }, { name: 'link', items: [ 'link'] },
{ name: 'lists', items: [ 'bullist', 'numlist' ] }, { name: 'lists', items: [ 'bullist', 'numlist' ] },
{ name: 'alignment', items: [ 'alignleft', 'aligncenter', 'alignright', 'alignjustify' ] },
{ name: 'indentation', items: [ 'outdent', 'indent' ] }, { name: 'indentation', items: [ 'outdent', 'indent' ] },
{ name: 'table', items: [ 'table' ] }, { name: 'custom', items: ['redactButton'] } // Add custom button to toolbar
{ name: 'extra', items: [ 'code', 'fullscreen' ] }
], ],
mobile: { mobile: {
menubar: false, menubar: false,
plugins: 'autosave lists autolink', plugins: 'autosave lists autolink',
toolbar: 'bold italic styles' toolbar: 'bold italic styles'
}, },
convert_urls: false, convert_urls: false,
plugins: 'link image lists table code codesample fullscreen autoresize', plugins: 'link image lists table code fullscreen autoresize',
license_key: 'gpl' license_key: 'gpl',
}); setup: function(editor) {
// Add custom toolbar button with Font Awesome icon
editor.ui.registry.addButton('redactButton', {
icon: 'permanent-pen',
tooltip: 'Redact', // Tooltip text for the button
onAction: function() {
var selectedText = editor.selection.getContent({ format: 'text' });
// Initialize TinyMCE if (selectedText) {
tinymce.init({ // Replace the selected text with [REDACTED] in bold red
selector: '.tinymceAI', var newContent = '<span style="font-weight: bold; color: red;">[REDACTED]</span>';
// Replace selected content with the new content
editor.selection.setContent(newContent);
} else {
alert('Please select a word to redact');
}
}
});
}
});
// Initialize TinyMCE AI
tinymce.init({
selector: '.tinymceTicketAI',
browser_spellcheck: true, browser_spellcheck: true,
contextmenu: false, contextmenu: false,
resize: true, resize: true,
@@ -58,396 +212,247 @@ tinymce.init({
menubar: false, menubar: false,
statusbar: false, statusbar: false,
toolbar: [ toolbar: [
{ name: 'styles', items: [ 'styles' ] }, { name: 'styles', items: ['styles'] },
{ name: 'formatting', items: [ 'bold', 'italic', 'forecolor' ] }, { name: 'formatting', items: ['bold', 'italic', 'forecolor'] },
{ name: 'link', items: [ 'link'] }, { name: 'link', items: ['link'] },
{ name: 'lists', items: [ 'bullist', 'numlist' ] }, { name: 'lists', items: ['bullist', 'numlist'] },
{ name: 'alignment', items: [ 'alignleft', 'aligncenter', 'alignright', 'alignjustify' ] }, { name: 'indentation', items: ['outdent', 'indent'] },
{ name: 'indentation', items: [ 'outdent', 'indent' ] }, { name: 'ai', items: ['reword', 'undo', 'redo'] },
{ name: 'table', items: [ 'table' ] }, { name: 'custom', items: ['redactButton'] } // Add custom redact button to toolbar
{ name: 'extra', items: [ 'code', 'fullscreen' ] },
{ name: 'ai', items: [ 'reword', 'undo', 'redo' ] }
], ],
mobile: { mobile: {
menubar: false, menubar: false,
plugins: 'autosave lists autolink', toolbar: 'bold italic styles'
toolbar: 'bold italic styles'
}, },
convert_urls: false, convert_urls: false,
plugins: 'link image lists table code codesample fullscreen autoresize', plugins: 'link image lists table code codesample fullscreen autoresize',
license_key: 'gpl', license_key: 'gpl',
setup: function(editor) { setup: function(editor) {
var rewordButtonApi; var rewordButtonApi;
editor.ui.registry.addButton('reword', { // Define the Reword button (AI-related button)
icon: 'ai', editor.ui.registry.addButton('reword', {
tooltip: 'Reword Text', icon: 'ai', // Example icon for AI rewording
onAction: function() { tooltip: 'Reword Text',
var content = editor.getContent(); onAction: function() {
var content = editor.getContent();
// Disable the Reword button // Disable the Reword button
rewordButtonApi.setEnabled(false); rewordButtonApi.setEnabled(false);
// Show the progress indicator // Show the progress indicator
editor.setProgressState(true); editor.setProgressState(true);
fetch('post.php?ai_reword', { fetch('post.php?ai_reword', {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
},
body: JSON.stringify({ text: content }),
})
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(data => {
editor.undoManager.transact(function() {
editor.setContent(data.rewordedText || 'Error: Could not reword the text.');
});
// Hide the progress indicator
editor.setProgressState(false);
// Re-enable the Reword button
rewordButtonApi.setEnabled(true);
// Optional: Show a success notification
editor.notificationManager.open({
text: 'Text reworded successfully!',
type: 'success',
timeout: 3000
});
})
.catch(error => {
console.error('Error:', error);
// Hide the progress indicator
editor.setProgressState(false);
// Re-enable the Reword button
rewordButtonApi.setEnabled(true);
// Show an error notification
editor.notificationManager.open({
text: 'An error occurred while rewording the text.',
type: 'error',
timeout: 5000
});
});
}, },
onSetup: function(buttonApi) { body: JSON.stringify({ text: content }),
rewordButtonApi = buttonApi; })
return function() { .then(response => {
// Cleanup when the editor is destroyed (if necessary) if (!response.ok) {
}; throw new Error('Network response was not ok');
} }
}); return response.json();
} })
}); .then(data => {
editor.undoManager.transact(function() {
editor.setContent(data.rewordedText || 'Error: Could not reword the text.');
});
tinymce.init({ // Hide the progress indicator
selector: '.tinymceTicket', // Your selector editor.setProgressState(false);
browser_spellcheck: true,
contextmenu: false,
resize: true,
min_height: 300,
max_height: 600,
promotion: false,
branding: false,
menubar: false,
statusbar: false,
toolbar: [
{ name: 'styles', items: [ 'styles' ] },
{ name: 'formatting', items: [ 'bold', 'italic', 'forecolor'] },
{ name: 'link', items: [ 'link'] },
{ name: 'lists', items: [ 'bullist', 'numlist' ] },
{ name: 'indentation', items: [ 'outdent', 'indent' ] },
{ name: 'custom', items: ['redactButton'] } // Add custom button to toolbar
],
mobile: {
menubar: false,
plugins: 'autosave lists autolink',
toolbar: 'bold italic styles'
},
convert_urls: false,
plugins: 'link image lists table code fullscreen autoresize',
license_key: 'gpl',
setup: function(editor) {
// Add custom toolbar button with Font Awesome icon
editor.ui.registry.addButton('redactButton', {
icon: 'permanent-pen',
tooltip: 'Redact', // Tooltip text for the button
onAction: function() {
var selectedText = editor.selection.getContent({ format: 'text' });
if (selectedText) { // Re-enable the Reword button
// Replace the selected text with [REDACTED] in bold red rewordButtonApi.setEnabled(true);
var newContent = '<span style="font-weight: bold; color: red;">[REDACTED]</span>';
// Optional: Show a success notification
// Replace selected content with the new content editor.notificationManager.open({
editor.selection.setContent(newContent); text: 'Text reworded successfully!',
} else { type: 'success',
alert('Please select a word to redact'); timeout: 3000
});
})
.catch(error => {
console.error('Error:', error);
// Hide the progress indicator
editor.setProgressState(false);
// Re-enable the Reword button
rewordButtonApi.setEnabled(true);
// Show an error notification
editor.notificationManager.open({
text: 'An error occurred while rewording the text.',
type: 'error',
timeout: 5000
});
});
},
onSetup: function(buttonApi) {
rewordButtonApi = buttonApi;
return function() {
// Cleanup when the editor is destroyed (if necessary)
};
} }
} });
});
}
});
// Initialize TinyMCE AI // Add the Redact button
tinymce.init({ editor.ui.registry.addButton('redactButton', {
selector: '.tinymceTicketAI', icon: 'permanent-pen',
browser_spellcheck: true, tooltip: 'Redact Text', // Tooltip text for the button
contextmenu: false, onAction: function() {
resize: true, var selectedText = editor.selection.getContent({ format: 'text' });
min_height: 300,
max_height: 600,
promotion: false,
branding: false,
menubar: false,
statusbar: false,
toolbar: [
{ name: 'styles', items: ['styles'] },
{ name: 'formatting', items: ['bold', 'italic', 'forecolor'] },
{ name: 'link', items: ['link'] },
{ name: 'lists', items: ['bullist', 'numlist'] },
{ name: 'indentation', items: ['outdent', 'indent'] },
{ name: 'ai', items: ['reword', 'undo', 'redo'] },
{ name: 'custom', items: ['redactButton'] } // Add custom redact button to toolbar
],
mobile: {
menubar: false,
toolbar: 'bold italic styles'
},
convert_urls: false,
plugins: 'link image lists table code codesample fullscreen autoresize',
license_key: 'gpl',
setup: function(editor) {
var rewordButtonApi;
// Define the Reword button (AI-related button) if (selectedText) {
editor.ui.registry.addButton('reword', { // Replace the selected text with [REDACTED] in bold red
icon: 'ai', // Example icon for AI rewording var newContent = '<span style="font-weight: bold; color: red;">[REDACTED]</span>';
tooltip: 'Reword Text',
onAction: function() { // Replace selected content with the new content
var content = editor.getContent(); editor.selection.setContent(newContent);
} else {
// Disable the Reword button alert('Please select a word to redact');
rewordButtonApi.setEnabled(false);
// Show the progress indicator
editor.setProgressState(true);
fetch('post.php?ai_reword', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ text: content }),
})
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
} }
return response.json();
})
.then(data => {
editor.undoManager.transact(function() {
editor.setContent(data.rewordedText || 'Error: Could not reword the text.');
});
// Hide the progress indicator
editor.setProgressState(false);
// Re-enable the Reword button
rewordButtonApi.setEnabled(true);
// Optional: Show a success notification
editor.notificationManager.open({
text: 'Text reworded successfully!',
type: 'success',
timeout: 3000
});
})
.catch(error => {
console.error('Error:', error);
// Hide the progress indicator
editor.setProgressState(false);
// Re-enable the Reword button
rewordButtonApi.setEnabled(true);
// Show an error notification
editor.notificationManager.open({
text: 'An error occurred while rewording the text.',
type: 'error',
timeout: 5000
});
});
},
onSetup: function(buttonApi) {
rewordButtonApi = buttonApi;
return function() {
// Cleanup when the editor is destroyed (if necessary)
};
}
});
// Add the Redact button
editor.ui.registry.addButton('redactButton', {
icon: 'permanent-pen',
tooltip: 'Redact Text', // Tooltip text for the button
onAction: function() {
var selectedText = editor.selection.getContent({ format: 'text' });
if (selectedText) {
// Replace the selected text with [REDACTED] in bold red
var newContent = '<span style="font-weight: bold; color: red;">[REDACTED]</span>';
// Replace selected content with the new content
editor.selection.setContent(newContent);
} else {
alert('Please select a word to redact');
} }
} });
}); }
} });
});
// Initialize TinyMCE editor with only a redact button // Initialize TinyMCE editor with only a redact button
tinymce.init({ tinymce.init({
selector: '.tinymceTicketRedact', selector: '.tinymceTicketRedact',
browser_spellcheck: false, browser_spellcheck: false,
contextmenu: false,
resize: true,
min_height: 300,
max_height: 500,
promotion: false,
branding: false,
menubar: false,
statusbar: false,
license_key: 'gpl',
readonly: true,
toolbar: '',
});
tinymce.init({
selector: '.tinymceRedact', // Your selector
browser_spellcheck: true,
contextmenu: false, contextmenu: false,
resize: true, resize: true,
min_height: 300, min_height: 300,
max_height: 500, max_height: 600,
promotion: false, promotion: false,
branding: false, branding: false,
menubar: false, menubar: false,
statusbar: false, statusbar: false,
toolbar: 'redactButton', // Only the redact button in the toolbar
mobile: {
menubar: false,
plugins: 'autosave lists autolink',
toolbar: 'redactButton' // Only the redact button on mobile
},
convert_urls: false,
plugins: 'link image lists table code fullscreen autoresize',
license_key: 'gpl', license_key: 'gpl',
readonly: true, setup: function(editor) {
toolbar: '', // Disable all text input and backspace/delete actions
}); editor.on('keydown', function(e) {
// Prevent all key events (including backspace and delete)
e.preventDefault();
});
tinymce.init({ // Add custom toolbar button with Font Awesome icon and label
selector: '.tinymceRedact', // Your selector editor.ui.registry.addButton('redactButton', {
browser_spellcheck: true, icon: 'permanent-pen',
contextmenu: false, tooltip: 'Redact', // Tooltip text for the button
resize: true, text: 'REDACT', // Add the text next to the icon
min_height: 300, onAction: function() {
max_height: 600, var selectedText = editor.selection.getContent({ format: 'text' });
promotion: false,
branding: false,
menubar: false,
statusbar: false,
toolbar: 'redactButton', // Only the redact button in the toolbar
mobile: {
menubar: false,
plugins: 'autosave lists autolink',
toolbar: 'redactButton' // Only the redact button on mobile
},
convert_urls: false,
plugins: 'link image lists table code fullscreen autoresize',
license_key: 'gpl',
setup: function(editor) {
// Disable all text input and backspace/delete actions
editor.on('keydown', function(e) {
// Prevent all key events (including backspace and delete)
e.preventDefault();
});
// Add custom toolbar button with Font Awesome icon and label if (selectedText) {
editor.ui.registry.addButton('redactButton', { // Replace the selected text with [REDACTED] in bold red
icon: 'permanent-pen', var newContent = '<span style="font-weight: bold; color: red;">[REDACTED]</span>';
tooltip: 'Redact', // Tooltip text for the button
text: 'REDACT', // Add the text next to the icon // Replace selected content with the new content
onAction: function() { editor.selection.setContent(newContent);
var selectedText = editor.selection.getContent({ format: 'text' }); } else {
alert('Please select a word to redact');
if (selectedText) { }
// Replace the selected text with [REDACTED] in bold red
var newContent = '<span style="font-weight: bold; color: red;">[REDACTED]</span>';
// Replace selected content with the new content
editor.selection.setContent(newContent);
} else {
alert('Please select a word to redact');
} }
} });
}); }
}
});
// DateTime
$('.datetimepicker').datetimepicker({
});
// Data Input Mask
$('[data-mask]').inputmask();
// ClipboardJS
//Fix to allow Clipboard Copying within Bootstrap Modals
//For use in Bootstrap Modals or with any other library that changes the focus you'll want to set the focused element as the container value.
$.fn.modal.Constructor.prototype._enforceFocus = function() {};
// Tooltip
$('button').tooltip({
trigger: 'click',
placement: 'bottom'
});
function setTooltip(btn, message) {
$(btn).tooltip('hide')
.attr('data-original-title', message)
.tooltip('show');
}
function hideTooltip(btn) {
setTimeout(function() {
$(btn).tooltip('hide');
}, 1000);
}
// Clipboard
var clipboard = new ClipboardJS('.clipboardjs');
clipboard.on('success', function(e) {
setTooltip(e.trigger, 'Copied!');
hideTooltip(e.trigger);
});
clipboard.on('error', function(e) {
setTooltip(e.trigger, 'Failed!');
hideTooltip(e.trigger);
});
// Enable Popovers
$(function () {
$('[data-toggle="popover"]').popover()
});
// Data Tables
new DataTable('.dataTables');
// Initialize International Phone Input
const inputs = document.querySelectorAll('input[type="tel"]');
// Loop through all the selected inputs and initialize intlTelInput on each one
inputs.forEach(input => {
window.intlTelInput(input, {
initialCountry: "us",
strictMode: true,
loadUtils: () => import("../plugins/intl-tel-input/js/utils.js") // for formatting/placeholders etc
}); });
// DateTime
$('.datetimepicker').datetimepicker({
});
// Data Input Mask
$('[data-mask]').inputmask();
// ClipboardJS
//Fix to allow Clipboard Copying within Bootstrap Modals
//For use in Bootstrap Modals or with any other library that changes the focus you'll want to set the focused element as the container value.
$.fn.modal.Constructor.prototype._enforceFocus = function() {};
// Tooltip
$('button').tooltip({
trigger: 'click',
placement: 'bottom'
});
function setTooltip(btn, message) {
$(btn).tooltip('hide')
.attr('data-original-title', message)
.tooltip('show');
}
function hideTooltip(btn) {
setTimeout(function() {
$(btn).tooltip('hide');
}, 1000);
}
// Clipboard
var clipboard = new ClipboardJS('.clipboardjs');
clipboard.on('success', function(e) {
setTooltip(e.trigger, 'Copied!');
hideTooltip(e.trigger);
});
clipboard.on('error', function(e) {
setTooltip(e.trigger, 'Failed!');
hideTooltip(e.trigger);
});
// Enable Popovers
$(function () {
$('[data-toggle="popover"]').popover()
});
// Data Tables
new DataTable('.dataTables');
// Initialize International Phone Input
const inputs = document.querySelectorAll('input[type="tel"]');
// Loop through all the selected inputs and initialize intlTelInput on each one
inputs.forEach(input => {
window.intlTelInput(input, {
initialCountry: "us",
strictMode: true,
loadUtils: () => import("../plugins/intl-tel-input/js/utils.js") // for formatting/placeholders etc
});
});
}); });