This commit introduces a new JavaScript function to open a document editing popup, enhancing user interaction with documentation links. The CSS has been updated to improve the layout and styling of the documentation panel, including adjustments to padding and font sizes for better readability. Additionally, new PHP functions have been added to generate edit links for documentation, integrating them into the header actions for improved accessibility. The version code has been incremented to 4.72.641.
188 lines
5.6 KiB
JavaScript
188 lines
5.6 KiB
JavaScript
/**
|
|
* MS1 — Module documentation overlay (navigation + ouverture/fermeture).
|
|
*/
|
|
(function () {
|
|
'use strict';
|
|
|
|
function findOverlayForTrigger(trigger) {
|
|
var anchor = trigger.getAttribute('data-doc-anchor');
|
|
if (!anchor) {
|
|
return null;
|
|
}
|
|
var overlays = document.querySelectorAll('.ms1-doc-overlay[data-doc-anchor="' + anchor + '"]');
|
|
return overlays.length ? overlays[0] : null;
|
|
}
|
|
|
|
function getMeta(overlay) {
|
|
var anchor = overlay.getAttribute('data-doc-anchor');
|
|
var script = document.querySelector('script.ms1-doc-meta[data-doc-anchor="' + anchor + '"]');
|
|
if (!script) {
|
|
return [];
|
|
}
|
|
try {
|
|
return JSON.parse(script.textContent || '[]');
|
|
} catch (e) {
|
|
return [];
|
|
}
|
|
}
|
|
|
|
function setPage(overlay, index) {
|
|
var pages = overlay.querySelectorAll('.ms1-doc-page');
|
|
var dots = overlay.querySelectorAll('.ms1-doc-dot');
|
|
var meta = getMeta(overlay);
|
|
var total = pages.length;
|
|
|
|
if (total === 0) {
|
|
return;
|
|
}
|
|
|
|
if (index < 0) {
|
|
index = 0;
|
|
}
|
|
if (index >= total) {
|
|
index = total - 1;
|
|
}
|
|
|
|
pages.forEach(function (page, i) {
|
|
if (i === index) {
|
|
page.removeAttribute('hidden');
|
|
} else {
|
|
page.setAttribute('hidden', 'hidden');
|
|
}
|
|
});
|
|
|
|
dots.forEach(function (dot, i) {
|
|
if (i === index) {
|
|
dot.classList.add('is-active');
|
|
} else {
|
|
dot.classList.remove('is-active');
|
|
}
|
|
});
|
|
|
|
var titleEl = overlay.querySelector('.ms1-doc-title');
|
|
var subtitleEl = overlay.querySelector('.ms1-doc-subtitle');
|
|
var currentEl = overlay.querySelector('.ms1-doc-counter-current');
|
|
var prevBtn = overlay.querySelector('.ms1-doc-prev');
|
|
var nextBtn = overlay.querySelector('.ms1-doc-next');
|
|
|
|
if (meta[index]) {
|
|
if (titleEl) {
|
|
titleEl.textContent = meta[index].titre || '';
|
|
}
|
|
if (subtitleEl) {
|
|
subtitleEl.textContent = meta[index].sous_titre || '';
|
|
}
|
|
}
|
|
|
|
if (currentEl) {
|
|
currentEl.textContent = String(index + 1);
|
|
}
|
|
|
|
if (prevBtn) {
|
|
prevBtn.disabled = index <= 0;
|
|
}
|
|
if (nextBtn) {
|
|
nextBtn.disabled = index >= total - 1;
|
|
}
|
|
|
|
overlay.setAttribute('data-doc-current-index', String(index));
|
|
}
|
|
|
|
function openOverlay(overlay) {
|
|
overlay.removeAttribute('hidden');
|
|
document.body.classList.add('ms1-doc-open');
|
|
var idx = parseInt(overlay.getAttribute('data-doc-current-index') || '0', 10);
|
|
setPage(overlay, idx);
|
|
}
|
|
|
|
function closeOverlay(overlay) {
|
|
overlay.setAttribute('hidden', 'hidden');
|
|
if (!document.querySelector('.ms1-doc-overlay:not([hidden])')) {
|
|
document.body.classList.remove('ms1-doc-open');
|
|
}
|
|
}
|
|
|
|
function getCurrentIndex(overlay) {
|
|
return parseInt(overlay.getAttribute('data-doc-current-index') || '0', 10);
|
|
}
|
|
|
|
function openDocEditPopup(url) {
|
|
var w = window.open(
|
|
url,
|
|
'ms1DocEdit' + Date.now(),
|
|
'width=1120,height=820,scrollbars=yes,resizable=yes'
|
|
);
|
|
if (w) {
|
|
var timer = setInterval(function () {
|
|
if (w.closed) {
|
|
clearInterval(timer);
|
|
window.location.reload();
|
|
}
|
|
}, 400);
|
|
}
|
|
}
|
|
|
|
document.addEventListener('click', function (e) {
|
|
var docEditLink = e.target.closest('a.ms1-doc-edit-link');
|
|
if (docEditLink && docEditLink.href) {
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
openDocEditPopup(docEditLink.href);
|
|
return;
|
|
}
|
|
|
|
var trigger = e.target.closest('.ms1-doc-trigger, .btn-doc-trigger');
|
|
if (trigger) {
|
|
e.preventDefault();
|
|
var overlay = findOverlayForTrigger(trigger);
|
|
if (overlay) {
|
|
openOverlay(overlay);
|
|
}
|
|
return;
|
|
}
|
|
|
|
var closeEl = e.target.closest('[data-ms1-doc-close]');
|
|
if (closeEl) {
|
|
var overlayClose = closeEl.closest('.ms1-doc-overlay');
|
|
if (overlayClose) {
|
|
closeOverlay(overlayClose);
|
|
}
|
|
return;
|
|
}
|
|
|
|
var dot = e.target.closest('.ms1-doc-dot');
|
|
if (dot) {
|
|
var overlayDot = dot.closest('.ms1-doc-overlay');
|
|
if (overlayDot) {
|
|
setPage(overlayDot, parseInt(dot.getAttribute('data-doc-page-index') || '0', 10));
|
|
}
|
|
return;
|
|
}
|
|
|
|
if (e.target.closest('[data-ms1-doc-prev]')) {
|
|
var overlayPrev = e.target.closest('.ms1-doc-overlay');
|
|
if (overlayPrev) {
|
|
setPage(overlayPrev, getCurrentIndex(overlayPrev) - 1);
|
|
}
|
|
return;
|
|
}
|
|
|
|
if (e.target.closest('[data-ms1-doc-next]')) {
|
|
var overlayNext = e.target.closest('.ms1-doc-overlay');
|
|
if (overlayNext) {
|
|
setPage(overlayNext, getCurrentIndex(overlayNext) + 1);
|
|
}
|
|
}
|
|
});
|
|
|
|
document.addEventListener('keydown', function (e) {
|
|
if (e.key !== 'Escape') {
|
|
return;
|
|
}
|
|
var open = document.querySelector('.ms1-doc-overlay:not([hidden])');
|
|
if (open) {
|
|
closeOverlay(open);
|
|
}
|
|
});
|
|
})();
|