MediaWiki:Common.js: Difference between revisions
From Taylor Wiki
No edit summary |
No edit summary |
||
| Line 10: | Line 10: | ||
'wgCategories' | 'wgCategories' | ||
]); | ]); | ||
// Only run on standard page views (skip edit forms, history, special pages) | // Only run on standard page views (skip edit forms, history, special pages) | ||
if ( !conf || conf.wgAction !== 'view' || conf.wgNamespaceNumber < 0 ) { | if ( !conf || conf.wgAction !== 'view' || conf.wgNamespaceNumber < 0 ) { | ||
return; | return; | ||
} | } | ||
var mainPageTitle = conf.wgMainPageTitle || 'Main Page'; | var mainPageTitle = conf.wgMainPageTitle || 'Main Page'; | ||
var homeUrl = mw.util.getUrl( mainPageTitle ); | var homeUrl = mw.util.getUrl( mainPageTitle ); | ||
var isHome = conf.wgIsMainPage || ( conf.wgPageName === mainPageTitle.replace( / /g, '_' ) ); | var isHome = conf.wgIsMainPage || ( conf.wgPageName === mainPageTitle.replace( / /g, '_' ) ); | ||
if ( isHome ) { | if ( isHome ) { | ||
return; | return; | ||
} | } | ||
var currentTitle = conf.wgTitle.replace( /_/g, ' ' ); | var currentTitle = conf.wgTitle.replace( /_/g, ' ' ); | ||
var categories = conf.wgCategories || []; | var categories = conf.wgCategories || []; | ||
// Top-level hub categories | // Top-level hub categories | ||
var TOP_SECTIONS = [ | var TOP_SECTIONS = [ | ||
| Line 36: | Line 31: | ||
'Family' | 'Family' | ||
]; | ]; | ||
var topSection = null; | var topSection = null; | ||
var subSection = null; | var subSection = null; | ||
// 1. Find the top-level section if present | // 1. Find the top-level section if present | ||
for ( var i = 0; i < TOP_SECTIONS.length; i++ ) { | for ( var i = 0; i < TOP_SECTIONS.length; i++ ) { | ||
| Line 53: | Line 46: | ||
} | } | ||
} | } | ||
// 2. Find any secondary category (like "Lamson") that isn't the top section | // 2. Find any secondary category (like "Lamson") that isn't the top section | ||
for ( var k = 0; k < categories.length; k++ ) { | for ( var k = 0; k < categories.length; k++ ) { | ||
| Line 62: | Line 54: | ||
} | } | ||
} | } | ||
// Prevent duplicates if viewing the section or collection page itself | // Prevent duplicates if viewing the section or collection page itself | ||
if ( topSection && currentTitle.toLowerCase() === topSection.toLowerCase() ) { | if ( topSection && currentTitle.toLowerCase() === topSection.toLowerCase() ) { | ||
| Line 70: | Line 61: | ||
subSection = null; | subSection = null; | ||
} | } | ||
// Build the breadcrumb bar | // Build the breadcrumb bar | ||
var $nav = $( '<div class="mw-dynamic-breadcrumbs" aria-label="Breadcrumb navigation"></div>' ); | var $nav = $( '<div class="mw-dynamic-breadcrumbs" aria-label="Breadcrumb navigation"></div>' ); | ||
// 1. Home / Main Page | // 1. Home / Main Page | ||
$nav.append( $( '<a>' ).addClass( 'crumb-link' ).attr( 'href', homeUrl ).text( 'Main Page' ) ); | $nav.append( $( '<a>' ).addClass( 'crumb-link' ).attr( 'href', homeUrl ).text( 'Main Page' ) ); | ||
// 2. Top-level Section (e.g. Letters) | // 2. Top-level Section (e.g. Letters) | ||
if ( topSection ) { | if ( topSection ) { | ||
| Line 82: | Line 70: | ||
$nav.append( $( '<a>' ).addClass( 'crumb-link' ).attr( 'href', mw.util.getUrl( topSection ) ).text( topSection ) ); | $nav.append( $( '<a>' ).addClass( 'crumb-link' ).attr( 'href', mw.util.getUrl( topSection ) ).text( topSection ) ); | ||
} | } | ||
// 3. Sub-level Collection / Person (e.g. Lamson) | // 3. Sub-level Collection / Person (e.g. Lamson) | ||
if ( subSection ) { | if ( subSection ) { | ||
| Line 88: | Line 75: | ||
$nav.append( $( '<a>' ).addClass( 'crumb-link' ).attr( 'href', mw.util.getUrl( subSection ) ).text( subSection ) ); | $nav.append( $( '<a>' ).addClass( 'crumb-link' ).attr( 'href', mw.util.getUrl( subSection ) ).text( subSection ) ); | ||
} | } | ||
// 4. Current File or Article Title | // 4. Current File or Article Title | ||
$nav.append( $( '<span>' ).addClass( 'crumb-sep' ).text( '›' ) ); | $nav.append( $( '<span>' ).addClass( 'crumb-sep' ).text( '›' ) ); | ||
$nav.append( $( '<span>' ).addClass( 'crumb-current' ).text( currentTitle ) ); | $nav.append( $( '<span>' ).addClass( 'crumb-current' ).text( currentTitle ) ); | ||
// Inject above title in Timeless skin | // Inject above title in Timeless skin | ||
$( function () { | $( function () { | ||
| Line 103: | Line 88: | ||
} ); | } ); | ||
}() ); | }() ); | ||
/* Open optimal reading resolution preview instead of tiny thumb or original massive scan */ | /* Open optimal reading resolution preview instead of tiny thumb or original massive scan */ | ||
$( function() { | $( function() { | ||
| Line 108: | Line 94: | ||
var $previewLink = $( '.fullImageLink a' ); | var $previewLink = $( '.fullImageLink a' ); | ||
var $resLinks = $( '.mw-filepage-resolutioninfo a' ); | var $resLinks = $( '.mw-filepage-resolutioninfo a' ); | ||
if ( $previewLink.length && $resLinks.length ) { | if ( $previewLink.length && $resLinks.length ) { | ||
var bestHref = null; | var bestHref = null; | ||
var bestWidth = 0; | var bestWidth = 0; | ||
$resLinks.each( function() { | $resLinks.each( function() { | ||
var text = $( this ).text(); // e.g. "1,504 × 2,048 pixels" | var text = $( this ).text(); // e.g. "1,504 × 2,048 pixels" | ||
| Line 125: | Line 109: | ||
} | } | ||
} ); | } ); | ||
// If found a great size, or fall back to the largest available intermediate | // If found a great size, or fall back to the largest available intermediate | ||
if ( !bestHref && $resLinks.length ) { | if ( !bestHref && $resLinks.length ) { | ||
bestHref = $resLinks.last().attr( 'href' ); | bestHref = $resLinks.last().attr( 'href' ); | ||
} | } | ||
if ( bestHref ) { | if ( bestHref ) { | ||
$previewLink.attr( 'href', bestHref ); | $previewLink.attr( 'href', bestHref ); | ||
| Line 137: | Line 119: | ||
} | } | ||
} ); | } ); | ||
/* Inject Universal GEWAME Umbrella Header */ | /* Inject Universal GEWAME Umbrella Header */ | ||
$( function () { | $( function () { | ||
| Line 144: | Line 127: | ||
var isLoggedIn = document.cookie.indexOf( 'gewame_logged_in=1' ) !== -1; | var isLoggedIn = document.cookie.indexOf( 'gewame_logged_in=1' ) !== -1; | ||
var currentUrl = encodeURIComponent( window.location.href ); | |||
var authLink = isLoggedIn | var authLink = isLoggedIn | ||
? '<a href="https://gewame.com/sso-logout.php" class="gw-nav-link">Logout</a>' | ? '<a href="https://gewame.com/sso-logout.php?redirect_to=' + currentUrl + '" class="gw-nav-link">Logout</a>' | ||
: '<a href="https://gewame.com/wp-login.php" class="gw-nav-link">Login</a>'; | : '<a href="https://gewame.com/wp-login.php?action=register" class="gw-nav-link">Register</a>' + | ||
'<a href="https://gewame.com/wp-login.php?redirect_to=' + currentUrl + '" class="gw-nav-link">Login</a>'; | |||
var headerHtml = | var headerHtml = | ||
'<div id="gewame-universal-bar">' + | '<div id="gewame-universal-bar">' + | ||
'<div class="gw-bar-inner">' + | '<div class="gw-bar-inner">' + | ||
'<a href="https://gewame.com/" class="gw-brand">' + | '<a href="https://gewame.com/" class="gw-brand" title="GEWAME — The Taylor Archive">' + | ||
'<span class="gw-brand-title">GEWAME</span>' + | '<span class="gw-brand-title">GEWAME</span>' + | ||
'<span class="gw-brand-sep">|</span>' + | '<span class="gw-brand-sep">|</span>' + | ||
| Line 157: | Line 143: | ||
'</a>' + | '</a>' + | ||
'<nav class="gw-nav">' + | '<nav class="gw-nav">' + | ||
'<a href="https://gewame.com/wiki/" class="gw-nav-link gw-active">Wiki</a>' + | '<a href="https://gewame.com/wiki/" class="gw-nav-link gw-active">Wiki</a>' + | ||
'<a href="https://gewame.com/tree/" class="gw-nav-link">Family Tree</a>' + | '<a href="https://gewame.com/tree/" class="gw-nav-link">Family Tree</a>' + | ||
Revision as of 20:10, 1 October 2026
/* Multi-Tier Category Breadcrumbs (Home › Section › Collection/Topic › Page/File) */
( function () {
var conf = mw.config.get([
'wgAction',
'wgNamespaceNumber',
'wgPageName',
'wgTitle',
'wgIsMainPage',
'wgMainPageTitle',
'wgCategories'
]);
// Only run on standard page views (skip edit forms, history, special pages)
if ( !conf || conf.wgAction !== 'view' || conf.wgNamespaceNumber < 0 ) {
return;
}
var mainPageTitle = conf.wgMainPageTitle || 'Main Page';
var homeUrl = mw.util.getUrl( mainPageTitle );
var isHome = conf.wgIsMainPage || ( conf.wgPageName === mainPageTitle.replace( / /g, '_' ) );
if ( isHome ) {
return;
}
var currentTitle = conf.wgTitle.replace( /_/g, ' ' );
var categories = conf.wgCategories || [];
// Top-level hub categories
var TOP_SECTIONS = [
'Letters',
'Instruments',
'Photographs',
'Documents',
'Biographies',
'Family'
];
var topSection = null;
var subSection = null;
// 1. Find the top-level section if present
for ( var i = 0; i < TOP_SECTIONS.length; i++ ) {
var sec = TOP_SECTIONS[i];
for ( var c = 0; c < categories.length; c++ ) {
if ( categories[c].toLowerCase() === sec.toLowerCase() ) {
topSection = sec;
break;
}
}
if ( topSection ) {
break;
}
}
// 2. Find any secondary category (like "Lamson") that isn't the top section
for ( var k = 0; k < categories.length; k++ ) {
var catName = categories[k].replace( /_/g, ' ' );
if ( !topSection || catName.toLowerCase() !== topSection.toLowerCase() ) {
subSection = catName;
break;
}
}
// Prevent duplicates if viewing the section or collection page itself
if ( topSection && currentTitle.toLowerCase() === topSection.toLowerCase() ) {
topSection = null;
}
if ( subSection && currentTitle.toLowerCase() === subSection.toLowerCase() ) {
subSection = null;
}
// Build the breadcrumb bar
var $nav = $( '<div class="mw-dynamic-breadcrumbs" aria-label="Breadcrumb navigation"></div>' );
// 1. Home / Main Page
$nav.append( $( '<a>' ).addClass( 'crumb-link' ).attr( 'href', homeUrl ).text( 'Main Page' ) );
// 2. Top-level Section (e.g. Letters)
if ( topSection ) {
$nav.append( $( '<span>' ).addClass( 'crumb-sep' ).text( '›' ) );
$nav.append( $( '<a>' ).addClass( 'crumb-link' ).attr( 'href', mw.util.getUrl( topSection ) ).text( topSection ) );
}
// 3. Sub-level Collection / Person (e.g. Lamson)
if ( subSection ) {
$nav.append( $( '<span>' ).addClass( 'crumb-sep' ).text( '›' ) );
$nav.append( $( '<a>' ).addClass( 'crumb-link' ).attr( 'href', mw.util.getUrl( subSection ) ).text( subSection ) );
}
// 4. Current File or Article Title
$nav.append( $( '<span>' ).addClass( 'crumb-sep' ).text( '›' ) );
$nav.append( $( '<span>' ).addClass( 'crumb-current' ).text( currentTitle ) );
// Inject above title in Timeless skin
$( function () {
var $heading = $( '#firstHeading' );
if ( $heading.length ) {
$nav.insertBefore( $heading );
} else {
$( '#mw-content-text' ).prepend( $nav );
}
} );
}() );
/* Open optimal reading resolution preview instead of tiny thumb or original massive scan */
$( function() {
if ( mw.config.get( 'wgNamespaceNumber' ) === 6 ) { // File namespace
var $previewLink = $( '.fullImageLink a' );
var $resLinks = $( '.mw-filepage-resolutioninfo a' );
if ( $previewLink.length && $resLinks.length ) {
var bestHref = null;
var bestWidth = 0;
$resLinks.each( function() {
var text = $( this ).text(); // e.g. "1,504 × 2,048 pixels"
var match = text.replace(/,/g, '').match(/(\d+)\s*×/);
if ( match ) {
var w = parseInt( match[1], 10 );
// Look for the largest intermediate preview up to ~1800px wide
if ( w > bestWidth && w <= 1800 ) {
bestWidth = w;
bestHref = $( this ).attr( 'href' );
}
}
} );
// If found a great size, or fall back to the largest available intermediate
if ( !bestHref && $resLinks.length ) {
bestHref = $resLinks.last().attr( 'href' );
}
if ( bestHref ) {
$previewLink.attr( 'href', bestHref );
}
}
}
} );
/* Inject Universal GEWAME Umbrella Header */
$( function () {
if ( $( '#gewame-universal-bar' ).length ) {
return;
}
var isLoggedIn = document.cookie.indexOf( 'gewame_logged_in=1' ) !== -1;
var currentUrl = encodeURIComponent( window.location.href );
var authLink = isLoggedIn
? '<a href="https://gewame.com/sso-logout.php?redirect_to=' + currentUrl + '" class="gw-nav-link">Logout</a>'
: '<a href="https://gewame.com/wp-login.php?action=register" class="gw-nav-link">Register</a>' +
'<a href="https://gewame.com/wp-login.php?redirect_to=' + currentUrl + '" class="gw-nav-link">Login</a>';
var headerHtml =
'<div id="gewame-universal-bar">' +
'<div class="gw-bar-inner">' +
'<a href="https://gewame.com/" class="gw-brand" title="GEWAME — The Taylor Archive">' +
'<span class="gw-brand-title">GEWAME</span>' +
'<span class="gw-brand-sep">|</span>' +
'<span class="gw-brand-sub">The Taylor Archive</span>' +
'</a>' +
'<nav class="gw-nav">' +
'<a href="https://gewame.com/wiki/" class="gw-nav-link gw-active">Wiki</a>' +
'<a href="https://gewame.com/tree/" class="gw-nav-link">Family Tree</a>' +
'<a href="https://gewame.com/forum/" class="gw-nav-link">Forum</a>' +
authLink +
'</nav>' +
'</div>' +
'</div>';
$( 'body' ).prepend( headerHtml );
} );