MediaWiki:Vector.js
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 */
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);
});
});