mirror of
https://github.com/itflow-org/itflow
synced 2026-09-05 22:35:12 +00:00
Fix: Six ajax modals had dead JS - DOMContentLoaded had already fired before their scripts were injected. New itflowReady() helper restores jQuery .ready() semantics. Fixes notification pagination, asset OS autocomplete, contact auth toggle, AI ticket summary, AI document template generation
This commit is contained in:
@@ -49,7 +49,7 @@ ob_start();
|
||||
</form>
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
itflowReady(function () {
|
||||
|
||||
var button = document.getElementById('generateAIContent');
|
||||
var promptField = document.getElementById('aiPrompt');
|
||||
|
||||
@@ -461,7 +461,7 @@ ob_start();
|
||||
|
||||
<!-- JSON Autocomplete / type ahead -->
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
itflowReady(function () {
|
||||
|
||||
var operatingSystems = <?= $json_os ?>;
|
||||
|
||||
|
||||
@@ -315,7 +315,7 @@ function generatePassword() {
|
||||
);
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
itflowReady(function () {
|
||||
function syncAuthForm(select) {
|
||||
var form = select.closest('.authForm');
|
||||
if (!form) {
|
||||
|
||||
@@ -351,7 +351,7 @@ function generatePassword() {
|
||||
);
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
itflowReady(function () {
|
||||
function syncAuthForm(select) {
|
||||
var form = select.closest('.authForm');
|
||||
if (!form) {
|
||||
|
||||
@@ -19,7 +19,7 @@ ob_start();
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
itflowReady(function () {
|
||||
var target = document.getElementById('summaryContent');
|
||||
if (!target) {
|
||||
return;
|
||||
|
||||
25
js/app.js
25
js/app.js
@@ -108,6 +108,25 @@ function itflowBindOnce(name, type, selector, handler) {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Run fn once the DOM is ready, the way jQuery's .ready() did.
|
||||
*
|
||||
* js/ajax_modal.js injects a modal payload's <script> tags long after
|
||||
* DOMContentLoaded has fired, so a bare
|
||||
* document.addEventListener('DOMContentLoaded', ...) inside one of them
|
||||
* registers for an event that will never come again and the body silently
|
||||
* never runs. jQuery's .ready() invoked the callback immediately when the
|
||||
* document was already parsed, which is why that pattern worked before the
|
||||
* vanilla conversion. Modal payload scripts must use this instead.
|
||||
*/
|
||||
function itflowReady(fn) {
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', fn);
|
||||
} else {
|
||||
fn();
|
||||
}
|
||||
}
|
||||
|
||||
function itflowInit() {
|
||||
// Prevents resubmit on forms
|
||||
if (window.history.replaceState) {
|
||||
@@ -636,11 +655,7 @@ function itflowInit() {
|
||||
|
||||
// modal_footer.php re-loads this file on every ajax modal open, so run now if
|
||||
// the document is already parsed, otherwise wait for it.
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', itflowInit);
|
||||
} else {
|
||||
itflowInit();
|
||||
}
|
||||
itflowReady(itflowInit);
|
||||
|
||||
/*
|
||||
* Calendar event modals - the All day switch shows or hides the time row.
|
||||
|
||||
@@ -65,7 +65,8 @@ ob_start();
|
||||
</table>
|
||||
<div class="text-center mt-2">
|
||||
<button id="prev-btn" class="btn btn-sm btn-outline-secondary me-2"><i class="fas fa-caret-left"></i></button>
|
||||
<button id="next-btn" class="btn btn-sm btn-outline-secondary"><i class="fas fa-caret-right"></i></button>
|
||||
<span id="page-indicator" class="small text-muted mx-2"></span>
|
||||
<button id="next-btn" class="btn btn-sm btn-outline-secondary ms-2"><i class="fas fa-caret-right"></i></button>
|
||||
</div>
|
||||
<?php } else { ?>
|
||||
<div class="text-center text-secondary pt-3">
|
||||
@@ -94,7 +95,7 @@ ob_start();
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
itflowReady(function () {
|
||||
var perPage = 8;
|
||||
var items = Array.from(document.querySelectorAll('.notification-item'));
|
||||
var totalItems = items.length;
|
||||
|
||||
Reference in New Issue
Block a user