From 889bee93497b612a3822c17659fbab38501d6098 Mon Sep 17 00:00:00 2001 From: Josha von Gizycki Date: Wed, 3 Apr 2019 11:26:59 +0200 Subject: [PATCH] some fiddling --- resources/public/js/scripts.js | 118 +++++++++++++++++++-------------- 1 file changed, 70 insertions(+), 48 deletions(-) diff --git a/resources/public/js/scripts.js b/resources/public/js/scripts.js index d9ed66b..0bb4df3 100644 --- a/resources/public/js/scripts.js +++ b/resources/public/js/scripts.js @@ -1,59 +1,81 @@ document.addEventListener('DOMContentLoaded', function() { function label(element, value) { - if(element.hasAttribute('value')) { - if(value !== undefined) { - element.setAttribute('value', value) - } else { - return element.getAttribute('value') - } - } else { - if(value !== undefined) { - element.textContent = value - } else { - return element.textContent - } - } + if(element.hasAttribute('value')) { + if(value !== undefined) { + element.setAttribute('value', value) + } else { + return element.getAttribute('value') + } + } else { + if(value !== undefined) { + element.textContent = value + } else { + return element.textContent + } + } } function countdownDeleteButton(event) { - const btn = event.target - const countdown = btn.getAttribute('data-countdown') - - if(countdown != 1) { - event.preventDefault() - btn.classList.add('__on-countdown') - - const hasCountdown = countdown !== null - const newCountdown = hasCountdown ? countdown - 1 : 3 - - if(!hasCountdown) { - btn.setAttribute('data-label', label(btn)) - } - - label(btn, newCountdown) - btn.setAttribute('data-countdown', newCountdown) - setTimeout(countdownDeleteButton, 1000, event) - } else { - label(btn, btn.getAttribute('data-label')) - } + const btn = event.target + const countdown = btn.getAttribute('data-countdown') + + if(countdown != 1) { + event.preventDefault() + btn.classList.add('__on-countdown') + + const hasCountdown = countdown !== null + const newCountdown = hasCountdown ? countdown - 1 : 3 + + if(!hasCountdown) { + btn.setAttribute('data-label', label(btn)) + } + + label(btn, newCountdown) + btn.setAttribute('data-countdown', newCountdown) + setTimeout(countdownDeleteButton, 1000, event) + } else { + label(btn, btn.getAttribute('data-label')) + } } document.querySelectorAll('.delete-btn').forEach(function(btn) { - btn.addEventListener('click', countdownDeleteButton) + btn.addEventListener('click', countdownDeleteButton) }) -}) -$(document).ready(function() { - return; - $('table').DataTable({ - stateSave: true, - fixedHeader: true, - lengthMenu: [[25, 50, 100, -1], [25, 50, 100, "All"]], - stateSaveCallback: function(settings,data) { - localStorage.setItem('DataTables', JSON.stringify(data)) - }, - stateLoadCallback: function(settings) { - return JSON.parse(localStorage.getItem('DataTables')) - } - }) + function dynamicTables() { + const range = (x,y) => + x > y ? [] : [x, ...range(x + 1, y)]; + + const pageSize = 50 + const colsFromThead = thead => + [...thead.children[0].children].map(th => th.innerText) + const visibleRows = page => + range(page * pageSize, (page + 1) * pageSize - 1) + + document.querySelectorAll('table').forEach(function(tbl) { + const thead = tbl.tHead + const tbody = tbl.tBodies[0] + const cols = colsFromThead(thead) + const rows = [...tbl.rows] + let page = 0 + console.debug(visibleRows(1)) + }) + } + dynamicTables() }) + +/* + $(document).ready(function() { + $('table').DataTable({ + stateSave: true, + fixedHeader: true, + lengthMenu: [[25, 50, 100, -1], [25, 50, 100, "All"]], + stateSaveCallback: function(settings,data) { + localStorage.setItem('DataTables', JSON.stringify(data)) + }, + stateLoadCallback: function(settings) { + return JSON.parse(localStorage.getItem('DataTables')) + } + }) + }) +*/