MediaWiki:ExternalLinkWarning.js

// // Shows a warning dialog when an external link is clicked. // Comments handling code was taken from https://dev.fandom.com/wiki/AjaxCommentDelete // @author Aspallar if (!window.ExternalLinkWarningLoaded) {

window.ExternalLinkWarningLoaded = true;

(function ($) {       /*global mw, ArticleComments*/        /*jshint -W003 */ // used before deinition

'use strict';

var titleText; var messageTemplate; var continueText; var cancelText;

function externalLinkClick(event) { /*jshint -W040 */ // allow old school jquery this var linkhref = $(this).attr('href'); event.preventDefault; var message = $(' ').html(messageTemplate.replace('$1', mw.html.escape(linkhref))); $.showCustomModal(titleText, message, {               id: 'form-external-link-confirm',                width: 350,                buttons: [                    {                        message: continueText,                        defaultButton: true,                        handler: function  {                            window.location = linkhref;                        }                    },                    {                        message: cancelText,                        handler: function  {                            $('#form-external-link-confirm').closeModal;                        }                    }                ]            }); }

function preload { titleText = 'External Link'; messageTemplate = 'You are following a link to $1, a site that is not part of FANDOM. Are you sure you wish to do this?'; continueText = 'Continue'; cancelText = 'Cancel'; mw.loader.using('mediawiki.api').then(function {               var api = new mw.Api;                api.get({ action: 'query', meta: 'allmessages', ammessages: 'Custom-ExternalLinkWarning', }).done(function(data) { if (data.error === undefined && data.query.allmessages[0].missing === undefined) { var texts = data.query.allmessages[0]['*'].split('|'); if (texts.length >= 1 && texts[0].length > 0) titleText = mw.html.escape(texts[0]); if (texts.length >= 2 && texts[1].length > 0) messageTemplate = mw.html.escape(texts[1]); if (texts.length >= 3 && texts[2].length > 0) continueText = mw.html.escape(texts[2]); if (texts.length >= 4 && texts[3].length > 0) cancelText = mw.html.escape(texts[3]); }               });            });        }

function setClickHandlers(content) { content.find('a.external').click(externalLinkClick); content.find('.article-comments-pagination-link').click(commentsPageSwitch); }

function commentsPageSwitch { var interval = setInterval(function {               if(!ArticleComments.$commentsList.hasClass('loading')) {                    clearInterval(interval);                    setClickHandlers(ArticleComments.$wrapper);                }            }, 500); }

preload; mw.hook('wikipage.content').add(setClickHandlers);

}(jQuery)); } //