Content deleted Content added
No edit summary |
Amorymeltzer (talk | contribs) m Remove legacy globals per phab:T72470 (via WP:JWB) |
||
(24 intermediate revisions by one other user not shown) | |||
Line 1:
/** "Technical restrictions" title fix *****************************************
// The function looks for a banner like that:▼
*
// <div id="RealTitleBanner">Div that is hidden▼
* Description:
// <span id="RealTitle">title</span>▼
* Maintainers: [[User:Interiot]], [[User:Mets501]]
// </div>▼
*/
// An element with id=DisableRealTitle disables the function.▼
addOnloadHook(function() {▼
// For pages that have something like Template:Lowercase, replace the title, but only if it is cut-and-pasteable as a valid wikilink.
try {▼
// (for instance [[iPod]]'s title is updated. <nowiki>But [[C#]] is not an equivalent wikilink, so [[C Sharp]] doesn't have its main title changed)</nowiki>
var realTitleBanner = document.getElementById("RealTitleBanner");▼
//
if (realTitleBanner && !document.getElementById("DisableRealTitle")) {▼
var realTitle = document.getElementById("RealTitle");▼
if (realTitle) {▼
▲ // <span id="RealTitle">title</span>
▲ // </div>
var isPasteable = 0;▼
▲ // </nowiki>An element with id=DisableRealTitle disables the function.
var disableRealTitle = 0; // users can disable this by making this true from their monobook.js
// calculate whether the title is pasteable▼
if (mw.config.get('wgIsArticle')) { // don't display the RealTitle when editing, since it is apparently inconsistent (doesn't show when editing sections, doesn't show when not previewing)
var verifyTitle = realTitle.replace(/^ +/, ""); // trim left spaces▼
▲ addOnloadHook(function() {
verifyTitle = verifyTitle.charAt(0).toUpperCase() + verifyTitle.substring(1, verifyTitle.length); // uppercase first character▼
▲ var realTitleBanner = document.getElementById("RealTitleBanner");
// if the namespace prefix is there, remove it on our verification copy. If it isn't there, add it to the original realValue copy.▼
▲ if (realTitleBanner && !document.getElementById("DisableRealTitle")) {
if (wgNamespaceNumber != 0) {▼
▲ var realTitle = document.getElementById("RealTitle");
if (wgCanonicalNamespace == verifyTitle.substr(0, wgCanonicalNamespace.length).replace(/ /g, "_") && verifyTitle.charAt(wgCanonicalNamespace.length) == ":") {▼
▲ if (realTitle) {
verifyTitle = verifyTitle.substr(wgCanonicalNamespace.length + 1);▼
var realTitleHTML = realTitle.innerHTML;
} else {▼
realTitle = wgCanonicalNamespace.replace(/_/g, " ") + ":" + realTitle;▼
}▼
▲ var isPasteable = 0;
}▼
//var containsHTML = /</.test(realTitleHTML); // contains ANY HTML
var containsTooMuchHTML = /</.test( realTitleHTML.replace(/<\/?(sub|sup|small|big)>/gi, "") ); // contains HTML that will be ignored when cut-n-pasted as a wikilink
// verify whether wgTitle matches▼
▲ // calculate whether the title is pasteable
verifyTitle = verifyTitle.replace(/^_+/, "").replace(/_+$/, ""); // trim left and right spaces▼
var verifyTitle =
verifyTitle = verifyTitle.charAt(0).toUpperCase() + verifyTitle.substring(1, verifyTitle.length); // uppercase first character
isPasteable = (verifyTitle == wgTitle);▼
▲ // if the namespace prefix is there, remove it on our verification copy. If it isn't there, add it to the original realValue copy.
▲ if (mw.config.get('wgNamespaceNumber') != 0) {
var h1 = document.getElementsByTagName("h1")[0];▼
▲ if (mw.config.get('wgCanonicalNamespace') == verifyTitle.substr(0, mw.config.get('wgCanonicalNamespace').length).replace(/ /g, "_") && verifyTitle.charAt(mw.config.get('wgCanonicalNamespace').length) == ":") {
if (h1 && isPasteable) {▼
▲ verifyTitle = verifyTitle.substr(mw.config.get('wgCanonicalNamespace').length + 1);
▲ h1.innerHTML = realTitle;
▲ } else {
realTitleBanner.style.display = "none";▼
▲
}▼
realTitleHTML = mw.config.get('wgCanonicalNamespace').replace(/_/g, " ") + ":" + realTitleHTML;
document.title = realTitle + " - Wikipedia, the free encyclopedia";▼
}
}
} catch (e) {▼
▲ // verify whether wgTitle matches
/* Something went wrong. */▼
▲ }
});▼
▲ verifyTitle = verifyTitle.charAt(0).toUpperCase() + verifyTitle.substring(1, verifyTitle.length); // uppercase first character
▲ isPasteable = (verifyTitle == mw.config.get('wgTitle'));
▲ var h1 = document.getElementsByTagName("h1")[0];
▲ if (h1 && isPasteable) {
h1.innerHTML = containsTooMuchHTML ? realTitleText : realTitleHTML;
if (!containsTooMuchHTML)
▲ realTitleBanner.style.display = "none";
▲ }
▲ }
▲ /* Something went wrong. */
▲ });
}
|