MediaWiki:Common.js
From GxPlex
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (â-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (â-Shift-R on a Mac)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/* VoteNY: restore star view after voting */
( function ( $, mw ) {
'use strict';
$( function () {
if ( mw.config.get( 'wgNamespaceNumber' ) !== 0 ) {
return;
}
// Capture star HTML before the vote request fires
$( 'body' ).on( 'click', '.vote-rating-star', function () {
var id = $( this ).data( 'vote-id' );
var $c = $( '#rating_' + id );
if ( !$c.data( 'gplx-stars-html' ) ) {
$c.data( 'gplx-stars-html', $c.html() );
}
} );
// Watch each rating container; inject toggle button when score replaces stars
$( '[id^="rating_"]' ).each( function () {
var el = this;
new MutationObserver( function () {
var $el = $( el );
if (
$el.data( 'gplx-stars-html' ) &&
!$el.find( '.vote-rating-star' ).length &&
!$el.find( '.gplx-vote-toggle' ).length
) {
$el.append(
$( '<button>' )
.addClass( 'gplx-vote-toggle' )
.text( 'Show rating' )
.on( 'click', function () {
var html = $el.data( 'gplx-stars-html' );
$el.removeData( 'gplx-stars-html' );
$el.html( html );
} )
);
}
} ).observe( el, { childList: true } );
} );
} );
}( jQuery, mediaWiki ) );