111 lines
3.3 KiB
JavaScript
111 lines
3.3 KiB
JavaScript
/**
|
|
* app/js/main.js
|
|
*
|
|
* This file is for 'access anywhere' javascript.
|
|
*
|
|
* @version 3.0
|
|
* @author Joey Kimsey <Joey@thetempusproject.com>
|
|
* @link https://TheTempusProject.com
|
|
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
|
|
*/
|
|
/**
|
|
* Automatically selects/de-selects all check boxes associated with that field
|
|
**/
|
|
function checkAll(ele) {
|
|
var checkboxes = document.getElementsByTagName( 'input' );
|
|
if (ele.checked) {
|
|
test = true;
|
|
} else {
|
|
test = false;
|
|
}
|
|
for ( var i = 0; i < checkboxes.length; i++ ) {
|
|
if ( checkboxes[i].type == 'checkbox' ) {
|
|
if ( checkboxes[i].name == ele.value ) {
|
|
checkboxes[i].checked = test;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
function copyAll( ele ) {
|
|
var eleName = '#' + ele;
|
|
var text = $( eleName ).text();
|
|
text = text.replaceAll( "''", "\n" ).trim();
|
|
text = text.substring( 1, text.length - 1 );
|
|
navigator.clipboard.writeText( text );
|
|
console.log( '#' + ele );
|
|
}
|
|
|
|
function insertTag( box, tag ) {
|
|
var Field = document.getElementById( box );
|
|
var currentPos = cursorPos( Field );
|
|
var val = Field.value;
|
|
var before = val.substring( 0, currentPos );
|
|
var after = val.substring( currentPos, val.length );
|
|
Field.value = before + '(' + tag + ')' + after;
|
|
}
|
|
|
|
function cursorPos( el ) {
|
|
if ( el.selectionStart ) {
|
|
return el.selectionStart;
|
|
} else if ( document.selection ) {
|
|
el.focus();
|
|
var r = document.selection.createRange();
|
|
if ( r == null ) {
|
|
return 0;
|
|
}
|
|
var re = el.createTextRange(),
|
|
rc = re.duplicate();
|
|
re.moveToBookmark( r.getBookmark() );
|
|
rc.setEndPoint( 'EndToStart', re );
|
|
return rc.text.length;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
function getRandomInt(min, max) {
|
|
const minCeiled = Math.ceil(min);
|
|
const maxFloored = Math.floor(max);
|
|
return Math.floor(Math.random() * (maxFloored - minCeiled) + minCeiled);
|
|
}
|
|
|
|
$(document).ready(function() {
|
|
$('select').each(function() {
|
|
var selectedValue = $(this).attr('value');
|
|
if (selectedValue) {
|
|
$(this).removeAttr('value');
|
|
$(this).find('option').each(function() {
|
|
if ($(this).attr('value') === selectedValue) {
|
|
$(this).prop('selected', true);
|
|
}
|
|
});
|
|
}
|
|
});
|
|
});
|
|
|
|
// with the dynamic footer, you need to adjust the content padding to make sure the footer doesn't overlap the content
|
|
window.onload = function () {
|
|
function updateFooterPadding() {
|
|
var footer = document.querySelector('footer');
|
|
var container = document.querySelector('.container-fluid.top-pad');
|
|
if ( ! container ) {
|
|
return;
|
|
}
|
|
// footer has no height but its children do!
|
|
var footerHeight = Array.from(footer.children).reduce((totalHeight, child) => {
|
|
return totalHeight + child.offsetHeight;
|
|
}, 0);
|
|
|
|
footerHeight += 20; // Add 20px for padding
|
|
|
|
// console.error(footerHeight);
|
|
|
|
container.style.setProperty('--footer-height', footerHeight + 'px');
|
|
}
|
|
|
|
// Update padding on initial load
|
|
updateFooterPadding();
|
|
|
|
// Update padding on window resize
|
|
window.addEventListener('resize', updateFooterPadding);
|
|
}; |