MediaWiki:CompareLink.js

/** * Convert the "Compare selected versions" button to a link * (Based on wikipedia:User:Mattflaschen/Compare_link.js) * @source: https://www.mediawiki.org/wiki/Snippets/Compare_link * @rev: 2-wikia1 * @see: mw:bugzilla:16165 * * Copyright 2006-2013 Matthew Flaschen (mw:User:Mattflaschen), mw:User:He7d3r * Tidied + tweaked for Wikia support by wikicities:c:dev:User:OneTwoThreeFall * * In addition to the GFDL and CC-BY-SA: * * This function (compare link) is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This function is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * A copy of the GPL is available at https://www.gnu.org/licenses/gpl-2.0.txt. * * By modifying MediaWiki:CompareLink.js: * You agree to dual-license your contributions under both the * GFDL (https://en.wikipedia.org/wiki/WP:GFDL) and version 2 of the GPL * (https://www.gnu.org/licenses/gpl-2.0.txt) or any later version * of the GPL published by the FSF. * */

/*jslint browser */ /*global jQuery, mediaWiki */

(function ($, mw) {   'use strict';    var $histForm = $('#mw-history-compare');

function updateCompare { var $radio = $histForm.find('input[type=radio]:checked'); var genLink = mw.util.getUrl + '?diff=' + $radio.eq(0).val + '&oldid=' + $radio.eq(1).val; $('.compare-link').attr('href', genLink); }

function fixCompare { var $buttons = $histForm.find('input.historysubmit'); if (!$buttons.length) { // buttons already replaced, or don't exist return; }       var $compareLink = $('', {            'accesskey': $buttons.first.attr('accesskey'),            'class': 'compare-link button',            'text': $buttons.first.val,            'title': $buttons.first.attr('title')        }); $buttons .after($compareLink) .hide; updateCompare; $('#pagehistory').change(updateCompare); }

if (mw.config.get('wgAction') === 'history') { $(fixCompare); } }(jQuery, mediaWiki));