MediaWiki:Common.js

出典: フリー多機能辞典『ウィクショナリー日本語版(Wiktionary)』
ナビゲーションに移動 検索に移動

注意: 保存後、変更を確認するにはブラウザーのキャッシュを消去する必要がある場合があります。

  • Firefox / Safari: Shift を押しながら 再読み込み をクリックするか、Ctrl-F5 または Ctrl-R を押してください (Mac では ⌘-R)
  • Google Chrome: Ctrl-Shift-R を押してください (Mac では ⌘-Shift-R)
  • Internet Explorer: Ctrl を押しながら 最新の情報に更新 をクリックするか、Ctrl-F5 を押してください
  • Opera: メニュー → 設定 (Mac では Opera → 環境設定) に移動し、プライバシーとセキュリティ → 閲覧データを消去 → キャッシュされた画像およびファイル からキャッシュをクリアしてください。
/* ここに書いたスクリプトは全ての外装に反映されます */

/** "Technical restrictions" title fix *****************************************
 *
 *  Description:
 *  Maintainers:,
 */

// For pages that have something like Template:Lowercase, replace the title, but only if it is cut-and-pasteable as a valid wikilink.
//  (for instance iPod's title is updated. But [[C#]] is not an equivalent wikilink, so [[C Sharp]] doesn't have its main title changed)
// [[テンプレート:項目名の制約]]、[[テンプレート:骨簡体字]]で使用。
// The function looks for a banner like this: 
 // <div id="RealTitleBanner">   <!-- div that gets hidden -->
 //  <span id="RealTitle">title</span>
 // </div>
 // An element with id=DisableRealTitle disables the function.
var disableRealTitle = 0;				// users can disable this by making this true from their monobook.js
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)
	mw.hook( 'wikipage.content' ).add(function() {
		try {
			var realTitleBanner = document.getElementById("RealTitleBanner");
			if (realTitleBanner && !document.getElementById("DisableRealTitle") && !disableRealTitle) {
				var realTitle = document.getElementById("RealTitle");
				if (realTitle) {
					var realTitleHTML = realTitle.innerHTML;
					realTitleText = $(realTitle).text();
					
					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
					// calculate whether the title is pasteable
					var verifyTitle = realTitleText.replace(/^ +/, "");				// trim left spaces
					verifyTitle = verifyTitle.charAt(0).toUpperCase() + verifyTitle.substring(1, verifyTitle.length);		// uppercase first character
					
					// 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) {
						if (wgCanonicalNamespace == verifyTitle.substr(0, wgCanonicalNamespace.length).replace(/ /g, "_") && verifyTitle.charAt(wgCanonicalNamespace.length) == ":") {
							verifyTitle = verifyTitle.substr(wgCanonicalNamespace.length + 1);
						} else {
							realTitleText = wgCanonicalNamespace.replace(/_/g, " ") + ":" + realTitleText;
							realTitleHTML = wgCanonicalNamespace.replace(/_/g, " ") + ":" + realTitleHTML;
						}
					}
					
					// verify whether wgTitle matches
					verifyTitle = verifyTitle.replace(/^ +/, "").replace(/ +$/, "");				// trim left and right spaces
					verifyTitle = verifyTitle.replace(/_/g, " ");			// underscores to spaces
					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";
					}
					document.title = realTitleText + " - Wiktionary";
				}
			}
		} catch (e) {
			/* Something went wrong. */
		}
	});
}