MediaWiki:GalleryCaptions/code.js

$(function {   var $galleries;    if (window.wgEnableMediaGalleryExt) {        $galleries = $('div.media-gallery-wrapper');    } else {        $galleries = $('div.wikia-gallery');    }//if new gallery    if (!$galleries.length) return;    $(window).on('lightboxOpened', function { //w8. not loaded yet setTimeout(function {           var $lb = $('#LightboxModal');            if (!$lb.length) return;            $lb.find('#LightboxCarouselContainer .carousel li').each(function(i, v) { var $v = $(v); if($v.hasClass('more-items')) { return false; } else { var $img = $v.find('img'); var imgName = $img.attr('src').replace(/.*\/(.*?)\/revision\/.*/, '$1'); var caption; if (window.wgEnableMediaGalleryExt) { $.each($galleries, function(i, v) {                           var data = $(v).data('model');                            if (!data) return;                            $.each(data, function(i, v) { var imgname = v.thumbUrl.replace(/.*\/(.*?)\/revision\/.*/, '$1'); if (imgname === imgName) { caption = v.caption; return false; }                           });//each data                            if (caption) return false;                        });//each galleries } else { caption = $galleries.find('.lightbox img[data-image-key="' + imgName + '"]').closest('.wikia-gallery-item').find('.lightbox-caption').text; //2nd chck. needed when $(el).data('name') !== $(el).attr('data-name') if (!caption) { $galleries.find('img').each(function(i, v) {                               var $v = $(v);                                if ($v.data('imageKey') === imgName) {                                    caption = $v.closest('.wikia-gallery-item').find('.lightbox-caption').text;                                    return false;                                }//if imgname                            });//each img }                   }//if new gallery //sanitize caption = (caption || ).replace(/(<([^>]+)>)/ig, ); $img.attr('title', caption); }//if });//each li       }, 1000);//timeout });//lightboxOpened });