文章详细页实现全局DOM加载
This commit is contained in:
@@ -1,57 +1,9 @@
|
||||
/**
|
||||
* Mobile FixedInput + autoheight for comment respond (legacy parity).
|
||||
* Autoheight for comment textarea (legacy parity).
|
||||
*/
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
function $(sel, root) {
|
||||
return (root || document).querySelector(sel);
|
||||
}
|
||||
|
||||
function FixedInput(el, action) {
|
||||
if (!el) return;
|
||||
if (!el.dataset.fixedBound) {
|
||||
el.addEventListener('click', function (e) {
|
||||
if (e.target && e.target.closest && e.target.closest('.fixed-body')) {
|
||||
FixedInput(el, 'hide');
|
||||
}
|
||||
});
|
||||
el.dataset.fixedBound = '1';
|
||||
}
|
||||
if (action === 'show') {
|
||||
el.classList.add('show');
|
||||
window.setTimeout(function () {
|
||||
var field = el.querySelector('textarea, input');
|
||||
if (field) field.focus();
|
||||
}, 100);
|
||||
return;
|
||||
}
|
||||
if (action === 'hide') {
|
||||
var cancel = el.querySelector('#cancel-comment-reply-link');
|
||||
if (cancel) cancel.click();
|
||||
el.querySelectorAll('input,textarea').forEach(function (n) {
|
||||
try { n.blur(); } catch (e) {}
|
||||
});
|
||||
el.querySelectorAll('.dropup.open, .open').forEach(function (n) {
|
||||
n.classList.remove('open');
|
||||
});
|
||||
el.classList.remove('show');
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener('click', function (e) {
|
||||
var trigger = e.target && e.target.closest ? e.target.closest('[fixed-input]') : null;
|
||||
if (!trigger) return;
|
||||
e.preventDefault();
|
||||
var targetSel = trigger.getAttribute('fixed-input') || '#respond';
|
||||
var panel = document.querySelector(targetSel);
|
||||
var comments = document.getElementById('comments');
|
||||
if (comments && comments.scrollIntoView) {
|
||||
comments.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
||||
}
|
||||
FixedInput(panel, 'show');
|
||||
});
|
||||
|
||||
// Autoheight textareas.
|
||||
function bindAutoheight(ta) {
|
||||
if (!ta || ta.dataset.autoheightBound) return;
|
||||
@@ -73,18 +25,8 @@
|
||||
|
||||
document.addEventListener('DOMContentLoaded', scan);
|
||||
if (window.AksrtFrontend && typeof window.AksrtFrontend.register === 'function') {
|
||||
window.AksrtFrontend.register('aksrt-comment-fixed-input', function (root) {
|
||||
window.AksrtFrontend.register('aksrt-comment-fixed-input', function () {
|
||||
scan();
|
||||
// Expose for submit hide.
|
||||
root = root || document;
|
||||
var respond = root.querySelector ? root.querySelector('#respond') : document.getElementById('respond');
|
||||
if (respond) {
|
||||
respond.aksrtFixedInput = function (action) {
|
||||
FixedInput(respond, action);
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
window.AksrtFixedInput = FixedInput;
|
||||
})();
|
||||
|
||||
@@ -108,8 +108,6 @@
|
||||
if (textarea) textarea.value = '';
|
||||
editingId = 0;
|
||||
cancel.style.display = 'none';
|
||||
if (window.AksrtFixedInput) window.AksrtFixedInput(r, 'hide');
|
||||
else if (r) r.classList.remove('show');
|
||||
return false;
|
||||
};
|
||||
}
|
||||
@@ -154,12 +152,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
if (window.AksrtFixedInput) {
|
||||
window.AksrtFixedInput(respond, 'show');
|
||||
} else {
|
||||
respond.classList.add('show');
|
||||
}
|
||||
|
||||
if (comm && comm.scrollIntoView) {
|
||||
comm.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
||||
}
|
||||
|
||||
@@ -232,8 +232,6 @@
|
||||
restoreRespondPosition();
|
||||
setLoading(false);
|
||||
notyf(json.message || '评论已更新', 'success');
|
||||
var respondEl = document.getElementById('respond');
|
||||
if (respondEl && window.AksrtFixedInput) window.AksrtFixedInput(respondEl, 'hide');
|
||||
return;
|
||||
}
|
||||
if (json && json.success && json.html) {
|
||||
@@ -265,14 +263,6 @@
|
||||
// Move respond back to original position
|
||||
restoreRespondPosition();
|
||||
|
||||
// Hide mobile FixedInput after successful submit.
|
||||
var respondEl = document.getElementById('respond');
|
||||
if (respondEl && window.AksrtFixedInput) {
|
||||
window.AksrtFixedInput(respondEl, 'hide');
|
||||
} else if (respondEl) {
|
||||
respondEl.classList.remove('show');
|
||||
}
|
||||
|
||||
// If editing via moveForm, clear edit field.
|
||||
var editField = form.querySelector('[name="edit_comment_ID"]');
|
||||
if (editField) editField.remove();
|
||||
|
||||
Reference in New Issue
Block a user