User:Mattflaschen/Compare link.js

/**

* Convert the "Compare selected versions" button to a link

* (Based on w:en:User:Superm401/Compare_link.js)

* @source: http://www.mediawiki.org/wiki/Snippets/Compare_link

* @rev: 2

* @see: bugzilla:16165

*

* Copyright 2006-2013 Matthew Flaschen (User:Superm401), User:Helder.wiki

*

* 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 Snippets/Compare_link:

* You agree to dual-license your contributions under both the

* GFDL (http://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.

*

*/

function fixCompare() {

var $histForm = $('#mw-history-compare'),

$diffList = $('#pagehistory'),

$buttons = $histForm.find('input.historysubmit'),

buttonText, $compareLink;

if ( $buttons.length === 0 ) {

// Only one version, so do nothing

return;

}

buttonText = $buttons

.remove()

.first().val();

$compareLink = $('', {

'class': 'compare-link',

'text': buttonText

});

$histForm

.prepend($compareLink)

.append($compareLink.clone());

var updateCompare = function(){

var $radio = $histForm.find('input[type=radio]:checked'),

genLink = mw.config.get('wgScript')

+ '?title=' + mw.util.wikiUrlencode( mw.config.get( 'wgPageName' ) )

+ '&diff=' + $radio.eq(0).val()

+ '&oldid=' + $radio.eq(1).val();

$('.compare-link').each(function() {

$(this).attr('href', genLink);

});

};

updateCompare();

$diffList.change(updateCompare);

}

if ( mw.config.get('wgAction') === 'history' ) {

mw.util.addCSS( '.compare-link { border-radius:5px; color:black; text-decoration:none; border-width:1px 2px 2px 1px; border-style:solid; border-color:#DDDDDD #BBBBBB #BBBBBB #DDDDDD; padding:0.2em 1em; background-color:#EEEEEE; white-space:nowrap; } .compare-link:active{ border-width:0.1em; margin:0.1em; }' );

$(fixCompare);

}