Personal tools

MediaWiki:Common.js: Difference between revisions

From GxPlex

Jump to: navigation, search
feat: VoteNY toggle button – restore star view after voting
 
Deploy ANG-2026-0011
Tag: Replaced
 
(20 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;
}
 
// 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 ) );

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. */