MediaWiki:Vector.js

From Forklift Certified Video Games
Revision as of 13:00, 21 January 2026 by Admin (talk | contribs) (Created page with "All JavaScript here will be loaded for users of the Vector skin: function addGalleryRow() { const container = document.getElementById('gallery-builder'); const row = container.firstElementChild.cloneNode(true); row.querySelectorAll('input').forEach(i => i.value = ''); container.appendChild(row); } mw.hook('pf.formSubmit').add(function () { let gallery = '<gallery>\n'; document.querySelectorAll('.gallery-row').forEach(row => { cons...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/* All JavaScript here will be loaded for users of the Vector skin */

function addGalleryRow() {
    const container = document.getElementById('gallery-builder');
    const row = container.firstElementChild.cloneNode(true);

    row.querySelectorAll('input').forEach(i => i.value = '');
    container.appendChild(row);
}

mw.hook('pf.formSubmit').add(function () {
    let gallery = '<gallery>\n';

    document.querySelectorAll('.gallery-row').forEach(row => {
        const image = row.querySelector('[name="gallery_image[]"]').value;
        const caption = row.querySelector('[name="gallery_caption[]"]').value;

        if (image) {
            gallery += 'File:' + image.replace(/^File:/, '') +
                       (caption ? '|' + caption : '') + '\n';
        }
    });

    gallery += '</gallery>';

    document.querySelector('[name="gallery"]').value = gallery;
});