MediaWiki:Vector.js: Difference between revisions

From Forklift Certified Video Games
Jump to navigation Jump to search
Admin
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...")
 
Line 1: Line 1:
/* All JavaScript here will be loaded for users of the Vector skin */
/* All JavaScript here will be loaded for users of the Vector skin */
mw.loader.using('jquery', function () {
    $('#addGalleryRowBtn').on('click', function () {
        addGalleryRow();
    });
});


function addGalleryRow() {
function addGalleryRow() {
     const container = document.getElementById('gallery-builder');
     alert('Button works!');
    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;
});

Revision as of 20:11, 21 January 2026

/* All JavaScript here will be loaded for users of the Vector skin */

mw.loader.using('jquery', function () {
    $('#addGalleryRowBtn').on('click', function () {
        addGalleryRow();
    });
});

function addGalleryRow() {
    alert('Button works!');
}