MediaWiki:Vector.js: Difference between revisions

From Forklift Certified Video Games
Jump to navigation Jump to search
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 () {
mw.loader.using(['jquery'], function () {
     $('#addGalleryRowBtn').on('click', function () {
 
    function addGalleryRow() {
        var $builder = $('#gallery-builder');
        var $lastRow = $builder.find('.gallery-row').last();
        var $newRow = $lastRow.clone(true, true);
 
        // Clear inputs
        $newRow.find('input[type="text"]').val('');
        $newRow.find('input[type="hidden"]').val('');
 
        // Remove image preview if present
        $newRow.find('.pfImagePreview').remove();
 
        $builder.append($newRow);
    }
 
     $('#addGalleryRowBtn').on('click', function (e) {
        e.preventDefault();
         addGalleryRow();
         addGalleryRow();
     });
     });
    // On form submit, build the gallery wikitext
    $('form').on('submit', function () {
        var galleryText = "<gallery>\n";
        var images = $('input[name="gallery_image[]"]');
        var captions = $('input[name="gallery_caption[]"]');
        images.each(function (index) {
            var image = $(this).val();
            var caption = captions.eq(index).val();
            if (image) {
                galleryText += image;
                if (caption) {
                    galleryText += "|" + caption;
                }
                galleryText += "\n";
            }
        });
        galleryText += "</gallery>";
        $('input[name="gallery"]').val(galleryText);
    });
});
});
function addGalleryRow() {
    alert('Button works!');
}

Revision as of 20:18, 21 January 2026

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

mw.loader.using(['jquery'], function () {

    function addGalleryRow() {
        var $builder = $('#gallery-builder');
        var $lastRow = $builder.find('.gallery-row').last();
        var $newRow = $lastRow.clone(true, true);

        // Clear inputs
        $newRow.find('input[type="text"]').val('');
        $newRow.find('input[type="hidden"]').val('');

        // Remove image preview if present
        $newRow.find('.pfImagePreview').remove();

        $builder.append($newRow);
    }

    $('#addGalleryRowBtn').on('click', function (e) {
        e.preventDefault();
        addGalleryRow();
    });

    // On form submit, build the gallery wikitext
    $('form').on('submit', function () {
        var galleryText = "<gallery>\n";

        var images = $('input[name="gallery_image[]"]');
        var captions = $('input[name="gallery_caption[]"]');

        images.each(function (index) {
            var image = $(this).val();
            var caption = captions.eq(index).val();

            if (image) {
                galleryText += image;
                if (caption) {
                    galleryText += "|" + caption;
                }
                galleryText += "\n";
            }
        });

        galleryText += "</gallery>";

        $('input[name="gallery"]').val(galleryText);
    });

});