Last edited 5 days ago
by WikiSysop

MediaWiki:Common.js: Difference between revisions

WikiSysop (talk | contribs)
 
WikiSysop (talk | contribs)
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
/* Any JavaScript here will be loaded for all users on every page load. */
/* ===== BlueSpice Galaxy – chatbot hero banner =====
/* ===== BlueSpice Galaxy – chatbot hero banner by Claude.ai=====
  Paste into MediaWiki:Common.js.
 
   Makes "Chat with Nova" open your existing chatbot instead of following the link.
   Makes "Chat with Nova" open your existing chatbot instead of following the link.
   Without JavaScript, the link still leads to the Help:ChatBot page as a fallback. */
   Without JavaScript, the link still leads to the Help:ChatBot page as a fallback. */
mw.hook( 'wikipage.content' ).add( function ( $content ) {
mw.hook( 'wikipage.content' ).add( function ( $content ) {
$content.find( '.bs-hero__cta a' ).each( function () {
$content.find( '.bs-hero__cta a' ).each( function () {
var link = this;
var link = this;
// bind only once, even if the hook fires several times
if ( link.dataset.bsChatBound ) {
return;
}
link.dataset.bsChatBound = '1';
link.setAttribute( 'role', 'button' );
link.setAttribute( 'role', 'button' );
link.addEventListener( 'click', function ( e ) {
link.addEventListener( 'click', function ( e ) {
// TODO: replace the selector with your chatbot's launch button
var launcher = document.getElementById( 'maximizeChat' );
var launcher = document.querySelector( '.cdx-button' );
if ( !launcher ) {
if ( launcher ) {
return; // no chat on this page: follow the link to the help page
}
e.preventDefault();
// keep this click from reaching the chat's own "click outside" handling
e.stopPropagation();
// open the chat after this click has finished
setTimeout( function () {
launcher.click();
}, 0 );
} );
 
link.addEventListener( 'keydown', function ( e ) {
if ( e.key === ' ' ) {
e.preventDefault();
e.preventDefault();
launcher.click();
link.click();
}
} );
} );
} );
 
 
/* ==========================================================================
  Galaxy Helpdesk · 404 search box
  Opens a suggested page directly instead of going to Special:Search.
  Only acts on the search box inside the 404 panel (.g404).
  ========================================================================== */
$( function () {
var $input = $( '.g404 .mw-searchInput' );
if ( !$input.length ) {
return;
}
 
mw.loader.using( 'mediawiki.util' ).then( function () {
function getContext() {
return $input.data( 'suggestions-context' );
}
 
// Find the suggestion that matches the typed text (ignoring case)
function findSuggestion( text ) {
var ctx = getContext(),
list = ( ctx && ctx.config.suggestions ) || [],
wanted = String( text ).trim().toLowerCase(),
i;
for ( i = 0; i < list.length; i++ ) {
if ( String( list[ i ] ).toLowerCase() === wanted ) {
return list[ i ];
}
}
return null;
}
 
// Mouse: point the suggestion link at the page itself before the click lands
$( document ).on( 'mousedown', '.suggestions a.mw-searchSuggest-link', function () {
var ctx = getContext();
if ( ctx && ctx.data.$container.has( this ).length && this.title ) {
this.href = mw.util.getUrl( this.title );
}
}
} );
} );
link.addEventListener( 'keydown', function ( e ) {
 
if ( e.key === ' ' ) { e.preventDefault(); link.click(); }
// Keyboard (Enter on a highlighted suggestion) or an exact title typed in:
// open the page; anything else goes to the normal search results
$input.closest( 'form' ).on( 'submit', function ( e ) {
var match = findSuggestion( $input.val() );
if ( match ) {
e.preventDefault();
location.assign( mw.util.getUrl( match ) );
}
} );
} );
} );
} );
} );
} );

Latest revision as of 16:25, 19 November 2026

/* Any JavaScript here will be loaded for all users on every page load. */
/* ===== BlueSpice Galaxy – chatbot hero banner by Claude.ai=====

   Makes "Chat with Nova" open your existing chatbot instead of following the link.
   Without JavaScript, the link still leads to the Help:ChatBot page as a fallback. */

mw.hook( 'wikipage.content' ).add( function ( $content ) {
	$content.find( '.bs-hero__cta a' ).each( function () {
		var link = this;
		// bind only once, even if the hook fires several times
		if ( link.dataset.bsChatBound ) {
			return;
		}
		link.dataset.bsChatBound = '1';
		link.setAttribute( 'role', 'button' );

		link.addEventListener( 'click', function ( e ) {
			var launcher = document.getElementById( 'maximizeChat' );
			if ( !launcher ) {
				return; // no chat on this page: follow the link to the help page
			}
			e.preventDefault();
			// keep this click from reaching the chat's own "click outside" handling
			e.stopPropagation();
			// open the chat after this click has finished
			setTimeout( function () {
				launcher.click();
			}, 0 );
		} );

		link.addEventListener( 'keydown', function ( e ) {
			if ( e.key === ' ' ) {
				e.preventDefault();
				link.click();
			}
		} );
	} );
} );


/* ==========================================================================
   Galaxy Helpdesk · 404 search box
   Opens a suggested page directly instead of going to Special:Search.
   Only acts on the search box inside the 404 panel (.g404).
   ========================================================================== */
$( function () {
	var $input = $( '.g404 .mw-searchInput' );
	if ( !$input.length ) {
		return;
	}

	mw.loader.using( 'mediawiki.util' ).then( function () {
		function getContext() {
			return $input.data( 'suggestions-context' );
		}

		// Find the suggestion that matches the typed text (ignoring case)
		function findSuggestion( text ) {
			var ctx = getContext(),
				list = ( ctx && ctx.config.suggestions ) || [],
				wanted = String( text ).trim().toLowerCase(),
				i;
			for ( i = 0; i < list.length; i++ ) {
				if ( String( list[ i ] ).toLowerCase() === wanted ) {
					return list[ i ];
				}
			}
			return null;
		}

		// Mouse: point the suggestion link at the page itself before the click lands
		$( document ).on( 'mousedown', '.suggestions a.mw-searchSuggest-link', function () {
			var ctx = getContext();
			if ( ctx && ctx.data.$container.has( this ).length && this.title ) {
				this.href = mw.util.getUrl( this.title );
			}
		} );

		// Keyboard (Enter on a highlighted suggestion) or an exact title typed in:
		// open the page; anything else goes to the normal search results
		$input.closest( 'form' ).on( 'submit', function ( e ) {
			var match = findSuggestion( $input.val() );
			if ( match ) {
				e.preventDefault();
				location.assign( mw.util.getUrl( match ) );
			}
		} );
	} );
} );