MediaWiki:Common.js: Difference between revisions
Ttenbergen (talk | contribs) No edit summary |
Ttenbergen (talk | contribs) make page titles into links |
||
| Line 207: | Line 207: | ||
} ); | } ); | ||
} | } | ||
/** | |||
* Wrap #firstHeading in a link to itself. | |||
* Works with Vector 2022 navigation reloads. | |||
*/ | |||
function wrapHeadingInLink() { | |||
var pageName = mw.config.get('wgPageName'); | |||
if (!pageName) return; | |||
var $heading = $('#firstHeading'); | |||
if (!$heading.length || $heading.find('a').length) return; | |||
var pageUrl = mw.util.getUrl(pageName); | |||
var headingText = $heading.text().trim(); | |||
$heading.empty().append( | |||
$('<a>') | |||
.attr('href', pageUrl) | |||
.attr('title', 'Right-click to copy link') | |||
.css({ | |||
textDecoration: 'none', | |||
color: 'inherit' | |||
}) | |||
.text(headingText) | |||
); | |||
} | |||
function setupHeadingWatcher() { | |||
wrapHeadingInLink(); | |||
// Re-run when navigation completes | |||
if (window.mw && typeof mw.trackSubscribe === 'function') { | |||
// MW 1.39+ (used by Vector 2022) navigation tracker | |||
mw.trackSubscribe('mw.page.ready', wrapHeadingInLink); | |||
} else { | |||
// Fallback for older setups | |||
window.addEventListener('popstate', wrapHeadingInLink); | |||
} | |||
} | |||
// Load dependencies and run | |||
mw.loader.using(['mediawiki.util']).then(setupHeadingWatcher); | |||