[MediaWiki-commits] [Gerrit] History: Simplify checkboxes script on History pages - change (mediawiki/core)
jenkins-bot has submitted this change and it was merged. Change subject: History: Simplify checkboxes script on History pages .. History: Simplify checkboxes script on History pages This should reduce the amount of variables constructed and also switches to a class based implementation, which allows us to do the same with fewer calls touching the DOM. Not supported by IE6. Bug: 51561 Change-Id: I4596b3667f990ef1d8c7ca753e1d80fe285d5614 --- M resources/Resources.php A resources/src/mediawiki.action/mediawiki.action.history.css M resources/src/mediawiki.action/mediawiki.action.history.js 3 files changed, 23 insertions(+), 33 deletions(-) Approvals: Bartosz DziewoĆski: Looks good to me, approved jenkins-bot: Verified diff --git a/resources/Resources.php b/resources/Resources.php index ac83302..ea7d397 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -1024,6 +1024,7 @@ ), 'mediawiki.action.history' = array( 'scripts' = 'resources/src/mediawiki.action/mediawiki.action.history.js', + 'styles' = 'resources/src/mediawiki.action/mediawiki.action.history.css', 'group' = 'mediawiki.action.history', ), 'mediawiki.action.history.diff' = array( diff --git a/resources/src/mediawiki.action/mediawiki.action.history.css b/resources/src/mediawiki.action/mediawiki.action.history.css new file mode 100644 index 000..603a965 --- /dev/null +++ b/resources/src/mediawiki.action/mediawiki.action.history.css @@ -0,0 +1,4 @@ +#pagehistory li.before input[name=oldid], +#pagehistory li.after input[name=diff] { + visibility: hidden; +} diff --git a/resources/src/mediawiki.action/mediawiki.action.history.js b/resources/src/mediawiki.action/mediawiki.action.history.js index 8aa5a1f..ac48c59 100644 --- a/resources/src/mediawiki.action/mediawiki.action.history.js +++ b/resources/src/mediawiki.action/mediawiki.action.history.js @@ -12,54 +12,39 @@ * @param e {jQuery.Event} */ function updateDiffRadios() { - var diffLi = false, // the li where the diff radio is checked - oldLi = false; // the li where the oldid radio is checked + var nextState = 'before', + $li, + $inputs, + $oldidRadio, + $diffRadio; if ( !$lis.length ) { return true; } $lis - .removeClass( 'selected' ) .each( function () { - var $li = $( this ), - $inputs = $li.find( 'input[type=radio]' ), - $oldidRadio = $inputs.filter( '[name=oldid]' ).eq( 0 ), - $diffRadio = $inputs.filter( '[name=diff]' ).eq( 0 ); + $li = $( this ); + $inputs = $li.find( 'input[type=radio]' ); + $oldidRadio = $inputs.filter( '[name=oldid]' ).eq( 0 ); + $diffRadio = $inputs.filter( '[name=diff]' ).eq( 0 ); + + $li.removeClass( 'selected between before after' ); if ( !$oldidRadio.length || !$diffRadio.length ) { return true; } if ( $oldidRadio.prop( 'checked' ) ) { - oldLi = true; - $li.addClass( 'selected' ); - $oldidRadio.css( 'visibility', 'visible' ); - $diffRadio.css( 'visibility', 'hidden' ); - + $li.addClass( 'selected after' ); + nextState = 'after'; } else if ( $diffRadio.prop( 'checked' ) ) { - diffLi = true; - $li.addClass( 'selected' ); - $oldidRadio.css( 'visibility', 'hidden' ); - $diffRadio.css( 'visibility', 'visible' ); - - // This list item has neither checked + $li.addClass( 'selected ' + nextState ); + nextState = 'between'; } else { - // We're below the selected radios - if ( diffLi oldLi ) { - $oldidRadio.css( 'visibility', 'visible' ); - $diffRadio.css( 'visibility', 'hidden' ); - - // We're between the selected radios - } else if ( diffLi ) { - $diffRadio.css( 'visibility', 'visible' ); -
[MediaWiki-commits] [Gerrit] History: Simplify checkboxes script on History pages - change (mediawiki/core)
TheDJ has uploaded a new change for review. https://gerrit.wikimedia.org/r/133709 Change subject: History: Simplify checkboxes script on History pages .. History: Simplify checkboxes script on History pages This should reduce the amount of variables constructed and also switches to a class based implementation, which allows us to do the same with fewer calls touching the DOM. Bug: 51561 Change-Id: I4596b3667f990ef1d8c7ca753e1d80fe285d5614 --- M resources/Resources.php A resources/src/mediawiki.action/mediawiki.action.history.css M resources/src/mediawiki.action/mediawiki.action.history.js 3 files changed, 24 insertions(+), 33 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/09/133709/1 diff --git a/resources/Resources.php b/resources/Resources.php index c2112ae..01eb02e 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -971,6 +971,7 @@ ), 'mediawiki.action.history' = array( 'scripts' = 'resources/src/mediawiki.action/mediawiki.action.history.js', + 'styles' = 'resources/src/mediawiki.action/mediawiki.action.history.css', 'group' = 'mediawiki.action.history', ), 'mediawiki.action.history.diff' = array( diff --git a/resources/src/mediawiki.action/mediawiki.action.history.css b/resources/src/mediawiki.action/mediawiki.action.history.css new file mode 100644 index 000..841fadc --- /dev/null +++ b/resources/src/mediawiki.action/mediawiki.action.history.css @@ -0,0 +1,6 @@ +#pagehistory li.before input[name=oldid] { + visibility: hidden; +} +#pagehistory li.after input[name=diff] { + visibility: hidden; +} diff --git a/resources/src/mediawiki.action/mediawiki.action.history.js b/resources/src/mediawiki.action/mediawiki.action.history.js index 8aa5a1f..6a2a841 100644 --- a/resources/src/mediawiki.action/mediawiki.action.history.js +++ b/resources/src/mediawiki.action/mediawiki.action.history.js @@ -12,54 +12,38 @@ * @param e {jQuery.Event} */ function updateDiffRadios() { - var diffLi = false, // the li where the diff radio is checked - oldLi = false; // the li where the oldid radio is checked + var state = 'before', + $li, + $inputs, + $oldidRadio, + $diffRadio; if ( !$lis.length ) { return true; } $lis - .removeClass( 'selected' ) .each( function () { - var $li = $( this ), - $inputs = $li.find( 'input[type=radio]' ), - $oldidRadio = $inputs.filter( '[name=oldid]' ).eq( 0 ), - $diffRadio = $inputs.filter( '[name=diff]' ).eq( 0 ); + $li = $( this ), + $inputs = $li.find( 'input[type=radio]' ), + $oldidRadio = $inputs.filter( '[name=oldid]' ).eq( 0 ), + $diffRadio = $inputs.filter( '[name=diff]' ).eq( 0 ); + + $li.removeClass( 'selected between before after' ); if ( !$oldidRadio.length || !$diffRadio.length ) { return true; } if ( $oldidRadio.prop( 'checked' ) ) { - oldLi = true; - $li.addClass( 'selected' ); - $oldidRadio.css( 'visibility', 'visible' ); - $diffRadio.css( 'visibility', 'hidden' ); - + $li.addClass( 'selected after' ); + state = 'after'; } else if ( $diffRadio.prop( 'checked' ) ) { - diffLi = true; - $li.addClass( 'selected' ); - $oldidRadio.css( 'visibility', 'hidden' ); - $diffRadio.css( 'visibility', 'visible' ); - - // This list item has neither checked + $li.addClass( 'selected before' ); + state = 'between'; } else { - // We're below the selected radios - if ( diffLi oldLi ) { - $oldidRadio.css( 'visibility', 'visible' ); - $diffRadio.css( 'visibility', 'hidden' ); - - // We're between the selected radios - } else if ( diffLi ) { - $diffRadio.css( 'visibility', 'visible' ); -