/** * app/js/main.js * * This file is for 'access anywhere' javascript. * * @version 3.0 * @author Joey Kimsey * @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 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); } function copyElementText( id ) { const inputElement = document.getElementById( id ); const textToCopy = inputElement.value; if (navigator.clipboard && navigator.clipboard.writeText) { navigator.clipboard.writeText(textToCopy) .then(() => alert('Copied to clipboard!')) .catch((err) => console.error('Failed to copy: ', err)); } else { // Fallback for older browsers inputElement.select(); try { document.execCommand('copy'); alert('Copied to clipboard!'); } catch (err) { console.error('Failed to copy: ', err); } } } $(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 document.addEventListener('DOMContentLoaded', function () { const toggleButton = document.getElementById('dark-mode-toggle'); const enableButton = document.getElementById('dark-mode-toggle-button'); const darkModeStylesheet = document.getElementById('dark-mode-stylesheet'); // Check if dark mode is saved in localStorage if (localStorage.getItem('darkMode') === 'enabled') { darkModeStylesheet.disabled = false; toggleButton.checked = true; if ( enableButton ) { enableButton.innerText = 'Disable Now'; } } document.querySelectorAll('.table-striped').forEach((table) => { if (localStorage.getItem('darkMode') === 'enabled') { table.classList.add('table-dark'); } else { table.classList.add('table-light') } }); if ( enableButton ) { enableButton.addEventListener('click', function () { if (darkModeStylesheet.disabled) { darkModeStylesheet.disabled = false; localStorage.setItem('darkMode', 'enabled'); enableButton.innerText = 'Disable Now'; } else { darkModeStylesheet.disabled = true; localStorage.setItem('darkMode', 'disabled'); enableButton.innerText = 'Enable Now'; } }); } toggleButton.addEventListener('click', function () { if (darkModeStylesheet.disabled) { darkModeStylesheet.disabled = false; localStorage.setItem('darkMode', 'enabled'); } else { darkModeStylesheet.disabled = true; localStorage.setItem('darkMode', 'disabled'); } document.querySelectorAll('.table-striped').forEach((table) => { if (localStorage.getItem('darkMode') === 'enabled') { table.classList.add('table-dark'); table.classList.remove('table-light'); } else { table.classList.add('table-light'); table.classList.remove('table-dark'); } }); }); }); document.addEventListener('DOMContentLoaded', () => { // Initialize Masonry const masonryContainer = document.querySelector('[data-masonry]'); const masonryInstance = new Masonry(masonryContainer, { // horizontalOrder: false, // Maintains natural order in DOM columnHeight: '.accordion', // columnWidth: '.card', // Use the card width as the column reference percentPosition: true }); // const sortContainer = document.getElementById('bookmarkSort'); // Sortable.create(masonryContainer, { // // animation: 150, // Smooth animations // sort: true, // ghostClass: 'bg-primary', // onEnd: () => { // // Trigger Masonry layout after drag-and-drop // masonryInstance.layout(); // } // }); // Function to trigger layout after any accordion change const updateMasonryLayout = () => masonryInstance.layout(); // Listen for all accordion collapse/expand events masonryContainer.addEventListener('hidden.bs.collapse', updateMasonryLayout); masonryContainer.addEventListener('shown.bs.collapse', updateMasonryLayout); // Observe dynamic content changes (e.g., rows added/removed) const observer = new MutationObserver(() => { updateMasonryLayout(); }); // Observe all cards for changes in the DOM document.querySelectorAll('.card').forEach((card) => { observer.observe(card, { childList: true, subtree: true }); }); jQuery(function($) { var panelList = $('#bookmarkSort'); panelList.sortable({ // Only make the .panel-heading child elements support dragging. // Omit this to make then entire
  • ...
  • draggable. handle: '.card', update: function() { console.error( 'update' ); $('.bookmark-card', panelList).each(function(index, elem) { var $listItem = $(elem), newIndex = $listItem.index(); masonryInstance.layout(); console.error( $listItem ); console.error( index ); console.error( newIndex ); // Persist the new indices. }); } }); }); });