Personal tools

Sponsorname

Your company could advertise here

www.fla-consulting.eu

MediaWiki:Common.js

From GxPlex

Revision as of 15:40, 22 June 2026 by Gxplex admin (talk | contribs) (feat: VoteNY toggle button – restore star view after voting)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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 ) );