MediaWiki:Common.js: Difference between revisions

From lotico
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
/* Any JavaScript here will be loaded for all users on every page load. */


// Open links with class "popup-link" in a popup window
$(document).ready(function() {
( function () {
     // Detect all links generated by the template
     function attachPopups(context) {
    $('a').once('popup-link').each(function() {
        $(context).find('a.popup-link').once('popup-link').on('click', function(e) {
        var href = $(this).attr('href');
            e.preventDefault();
            var specs = $(this).data('popup-specs') || 'width=600,height=400,scrollbars=yes,resizable=yes';
            window.open(this.href, 'popupWindow', specs);
        });
    }


    // Run on initial page load and on future content
        // Add your URL filter or class check if needed
    mw.hook('wikipage.content').add(attachPopups);
        // Example: only popup for external links
}() );
        if (href && href.startsWith('http')) {
            $(this).on('click', function(e) {
                e.preventDefault();
                window.open(this.href, 'popupWindow', 'width=600,height=400,scrollbars=yes,resizable=yes');
            });
        }
    });
});

Revision as of 20:35, 6 September 2025

/* Any JavaScript here will be loaded for all users on every page load. */

$(document).ready(function() {
    // Detect all links generated by the template
    $('a').once('popup-link').each(function() {
        var href = $(this).attr('href');

        // Add your URL filter or class check if needed
        // Example: only popup for external links
        if (href && href.startsWith('http')) {
            $(this).on('click', function(e) {
                e.preventDefault();
                window.open(this.href, 'popupWindow', 'width=600,height=400,scrollbars=yes,resizable=yes');
            });
        }
    });
});