review code pattern consistency

This commit is contained in:
Thanakorn S
2026-05-20 13:07:57 +07:00
parent 7396db6ffc
commit 91f8bb854f
20 changed files with 93 additions and 58 deletions
+19 -10
View File
@@ -351,8 +351,8 @@
// Reset UI
$('#tbl_body').html('<tr><td colspan="9" class="text-center py-4 text-muted">Loading…</td></tr>');
$('#lazy_sentinel').hide();
$('#lazy_loader').hide();
$('#lazy_done').hide();
$('#lazy_loader').show();
$('#result_summary').text('');
// Reset stats
@@ -404,6 +404,7 @@
}
is_loading = true;
$('#lazy_loader').show();
var sku = sku_queue[sku_index];
return ajax_request({
@@ -427,21 +428,29 @@
return;
}
// If sentinel is still within the viewport (or above it),
// the table hasn't filled the window yet — keep loading immediately.
// If sentinel is still within the viewport keep loading immediately.
// Otherwise hide the spinner and wait for the IntersectionObserver to
// fire when the user scrolls close to the sentinel.
if (sentinel_is_visible()) {
load_next_sku();
} else {
$('#lazy_loader').hide();
}
},
onError: function() {
is_loading = false;
$('#lazy_loader').hide();
}
});
}
// ── Returns true if the sentinel is visible in the current viewport ───
// ── Returns true if the sentinel is within one window-height of the fold ─
function sentinel_is_visible() {
var el = document.getElementById('lazy_sentinel');
var rect = el.getBoundingClientRect();
return rect.top <= (window.innerHeight || document.documentElement.clientHeight);
var vh = window.innerHeight || document.documentElement.clientHeight;
return rect.top <= vh * 2;
}
@@ -614,10 +623,10 @@
observer.observe(document.getElementById('lazy_sentinel'));
// ── Helpers ───────────────────────────────────────────────────────────
function fmt(n) {
return format_number(n, 2);
}
// ── Helpers ───────────────────────────────────────────────────────────
function fmt(n) {
return format_number(n, 2);
}
// ── Export ───────────────────────────────────────────────────────────
@@ -697,4 +706,4 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf-autotable/3.8.2/jspdf.plugin.autotable.min.js"></script>
</body>
</html>
</html>