Personal tools

MediaWiki:Common.js: Difference between revisions

From GxPlex

Jump to: navigation, search
fix: use post-vote display HTML for star toggle instead of pre-vote snapshot
Deploy ANG-2026-0011
Tag: Replaced
 
(19 intermediate revisions by the same user not shown)
Line 1: Line 1:
/* VoteNY: restore star view after voting */
/* The site scripts live in the Cavendish skin since 16.11.2026 (ANG-2026-0011):
( function ( $, mw ) {
* mediawiki/skins/Cavendish/resources/gxplex/*.js, registered as ResourceLoader
'use strict';
* modules in skin.json and loaded by config/GxPlexHooks.php (section 9).
 
*
$( function () {
* Keep this page short. While it is longer than 2000 bytes, the skin modules stay
if ( mw.config.get( 'wgNamespaceNumber' ) !== 0 ) {
* off, because the hook assumes the old code is still here. */
return;
}
 
$( document ).ajaxComplete( function ( event, xhr, settings ) {
var params;
try {
params = new URLSearchParams( settings.data );
} catch ( e ) {
return;
}
if (
params.get( 'action' ) !== 'voteny' ||
params.get( 'type' ) !== 'stars' ||
params.get( 'what' ) !== 'multi'
) {
return;
}
 
var data;
try {
data = JSON.parse( xhr.responseText );
} catch ( e ) {
return;
}
 
var displayHtml = data && data.voteny && data.voteny.display;
var pageId = params.get( 'pageId' );
if ( !displayHtml || !pageId ) {
return;
}
 
var $el = $( '#rating_' + pageId );
$el.data( 'gplx-stars-html', displayHtml );
 
if ( !$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 () {
$el.html( $el.data( 'gplx-stars-html' ) );
$el.removeData( 'gplx-stars-html' );
} )
);
}
} );
} );
 
}( jQuery, mediaWiki ) );

Latest revision as of 12:33, 19 November 2026

/* The site scripts live in the Cavendish skin since 16.11.2026 (ANG-2026-0011):
 * mediawiki/skins/Cavendish/resources/gxplex/*.js, registered as ResourceLoader
 * modules in skin.json and loaded by config/GxPlexHooks.php (section 9).
 *
 * Keep this page short. While it is longer than 2000 bytes, the skin modules stay
 * off, because the hook assumes the old code is still here. */