From 5c89f1655289c1fe140a075bbaadd39146d2e631 Mon Sep 17 00:00:00 2001 From: Leo Koppelkamm Date: Thu, 14 Apr 2011 16:06:02 +0000 Subject: [PATCH] Followup to r86047: Rewrite the radio-button updater & move everything to action.history. Also move to fixCompare version by Helder, since HTMLdiff is scrapped --- resources/Resources.php | 9 +- .../mediawiki.action.history.js | 78 ++++++++- skins/common/history.js | 159 ------------------ 3 files changed, 75 insertions(+), 171 deletions(-) delete mode 100644 skins/common/history.js diff --git a/resources/Resources.php b/resources/Resources.php index dc1c799e63..c2253cd14e 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -403,7 +403,7 @@ return array( ), 'mediawiki.action.history' => array( 'scripts' => 'resources/mediawiki.action/mediawiki.action.history.js', - 'dependencies' => 'mediawiki.legacy.history', + 'dependencies' => 'jquery.ui.button', 'group' => 'mediawiki.action.history', ), 'mediawiki.action.edit' => array( @@ -545,13 +545,6 @@ return array( 'localBasePath' => "{$GLOBALS['IP']}/skins", 'dependencies' => 'mediawiki.legacy.wikibits', ), - 'mediawiki.legacy.history' => array( - 'scripts' => 'common/history.js', - 'group' => 'mediawiki.action.history', - 'remoteBasePath' => $GLOBALS['wgStylePath'], - 'localBasePath' => "{$GLOBALS['IP']}/skins", - 'dependencies' => array( 'mediawiki.legacy.wikibits', 'jquery.ui.button' ), - ), 'mediawiki.legacy.IEFixes' => array( 'scripts' => 'common/IEFixes.js', 'remoteBasePath' => $GLOBALS['wgStylePath'], diff --git a/resources/mediawiki.action/mediawiki.action.history.js b/resources/mediawiki.action/mediawiki.action.history.js index acf4e290cd..616e7947f9 100644 --- a/resources/mediawiki.action/mediawiki.action.history.js +++ b/resources/mediawiki.action/mediawiki.action.history.js @@ -2,8 +2,78 @@ * JavaScript for History action */ jQuery( function( $ ) { - // Replaces histrowinit - $( '#pagehistory li input[name="diff"], #pagehistory li input[name="oldid"]' ).click( diffcheck ); - diffcheck(); - window.fixCompare(); + var $lis = $( 'ul#pagehistory li' ); + var updateDiffRadios = function() { + var diffLi = false, // the li where the diff radio is checked + oldLi = false; // the li where the oldid radio is checked + + if ( !$lis.length ) { + return true; + } + $lis.removeClass( 'selected' ); + $lis.each( function() { + var $this = $(this); + var $inputs = $this.find( 'input[type=radio]' ); + if ( $inputs.length !== 2 ) { + return true; + } + + // this row has a checked radio button + if ( $inputs.get(0).checked ) { + oldLi = $this; + $this.addClass( 'selected' ); + $inputs.eq(0).css( 'visibility', 'visible' ); + $inputs.eq(1).css( 'visibility', 'hidden' ); + } else if ( $inputs.get(1).checked ) { + diffLi = $this; + $this.addClass( 'selected' ); + $inputs.eq(0).css( 'visibility', 'hidden' ); + $inputs.eq(1).css( 'visibility', 'visible' ); + } else { + // no radio is checked in this row + if ( diffLi && oldLi ) { + // We're below the selected radios + $inputs.eq(0).css( 'visibility', 'visible' ); + $inputs.eq(1).css( 'visibility', 'hidden' ); + } else if ( diffLi ) { + // We're between the selected radios + $inputs.eq(0).css( 'visibility', 'visible' ); + $inputs.eq(1).css( 'visibility', 'visible' ); + } else { + // We're above the selected radios + $inputs.eq(1).css( 'visibility', 'visible' ); + $inputs.eq(0).css( 'visibility', 'hidden' ); + } + } + }); + return true; + }; + + var fixCompare = function () { + var $histForm = $( '#mw-history-compare' ), + $diffList = $( '#pagehistory' ), + buttonText = $histForm.find( 'input.historysubmit' ).remove().first().val(), + $compareLink = $( '', { + 'class': 'compare-link', + 'text': buttonText + }).button(); + $histForm.prepend( $compareLink ) + .append( $compareLink.clone() ); + function updateCompare() { + var $radio = $histForm.find( 'input[type=radio]:checked' ); + var 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 ); + }; + + $( '#pagehistory li input[name="diff"], #pagehistory li input[name="oldid"]' ).click( function() { updateDiffRadios(); } ); + fixCompare(); + updateDiffRadios(); }); \ No newline at end of file diff --git a/skins/common/history.js b/skins/common/history.js deleted file mode 100644 index 98db46e44c..0000000000 --- a/skins/common/history.js +++ /dev/null @@ -1,159 +0,0 @@ -window.historyRadios = function( parent ) { - var inputs = parent.getElementsByTagName( 'input' ); - var radios = [], - i = 0; - for ( i = 0; i < inputs.length; i++ ) { - if ( inputs[i].name == 'diff' || inputs[i].name == 'oldid' ) { - radios[radios.length] = inputs[i]; - } - } - return radios; -}; - -// check selection and tweak visibility/class onclick -window.diffcheck = function() { - var dli = false, // the li where the diff radio is checked - oli = false, // the li where the oldid radio is checked - i = 0; - var hf = document.getElementById( 'pagehistory' ); - if ( !hf ) { - return true; - } - var lis = hf.getElementsByTagName( 'li' ); - for ( i = 0; i < lis.length; i++ ) { - var inputs = historyRadios( lis[i] ); - if ( inputs[1] && inputs[0] ) { - if ( inputs[1].checked || inputs[0].checked ) { // this row has a checked radio button - if ( inputs[1].checked && inputs[0].checked && inputs[0].value == inputs[1].value ) { - return false; - } - if ( oli ) { // it's the second checked radio - if ( inputs[1].checked ) { - if ( typeof oli.className != 'undefined' ) { - oli.classNameOriginal = oli.className.replace( 'selected', '' ); - } else { - oli.classNameOriginal = ''; - } - - oli.className = 'selected ' + oli.classNameOriginal; - return false; - } - } else if ( inputs[0].checked ) { - return false; - } - if ( inputs[0].checked ) { - dli = lis[i]; - } - if ( !oli ) { - inputs[0].style.visibility = 'hidden'; - } - if ( dli ) { - inputs[1].style.visibility = 'hidden'; - } - if ( (typeof lis[i].className) != 'undefined') { - lis[i].classNameOriginal = lis[i].className.replace( 'selected', '' ); - } else { - lis[i].classNameOriginal = ''; - } - - lis[i].className = 'selected ' + lis[i].classNameOriginal; - oli = lis[i]; - } else { // no radio is checked in this row - if ( !oli ) { - inputs[0].style.visibility = 'hidden'; - } else { - inputs[0].style.visibility = 'visible'; - } - if ( dli ) { - inputs[1].style.visibility = 'hidden'; - } else { - inputs[1].style.visibility = 'visible'; - } - if ( typeof lis[i].classNameOriginal != 'undefined' ) { - lis[i].className = lis[i].classNameOriginal; - } - } - } - } - return true; -}; - -//update the compare link as you select radio buttons -window.updateCompare = function () { - var hf = compareLink.$form.get(0); - var oldInd = -1; - var i = 0; - while(oldInd == -1 & i" + this.value + "").button(); - compareLink.$form.before($linkTop); - $linkEnd = $linkTop.clone(); - compareLink.$form.append($linkEnd); - - if(this.name == "htmldiff") { - compareLink.htmlTop = $linkTop; - compareLink.htmlEnd = $linkEnd; - } else { - compareLink.wikiTop = $linkTop; - compareLink.wikiEnd = $linkEnd; - } - }); - $buttons.hide(); - - $("#pagehistory").change(function() {window.updateCompare()}); -}; - -- 2.20.1