「MediaWiki:Gadget-exlinks.js」の版間の差分

出典: フリー教科書『ウィキブックス(Wikibooks)』
削除された内容 追加された内容
w:MediaWiki:Gadget-exlinks.js 2008年2月25日 (月) 14:57 の版より作成
 
update; copy from enwiki w:Special:PermaLink/609653720
5 行 5 行
// ** **
// ** **
// **********************************************************************
// **********************************************************************
/**
addOnloadHook(function() {
* @source mediawiki.org/wiki/Snippets/Open_external_links_in_new_window
var content = document.getElementById('content');
* @version 5
if(!content) content = document.getElementById('mw_content');
*/
if(!content) return;
mw.hook('wikipage.content').add(function($content) {
var alinks = content.getElementsByTagName('a');
// Second selector is for external links in Parsoid HTML+RDFa output (bug 65243).
var tablink, sitename;
$content.find('a.external, a[rel="mw:ExtLink"]').each(function () {
for (var i = 0, leng = alinks.length; i < leng; i++) {
// Can't use wgServer because it can be protocol relative
tablink = alinks[i];
// Use this.href property instead of this.getAttribute('href') because the property
if (tablink.className.indexOf("external") != -1 && tablink.href.indexOf(wgServer) != 0)
// is converted to a full URL (including protocol)
tablink.target = "_blank";
if (this.href.indexOf(location.protocol + '//' + location.hostname) !== 0) {
}
this.target = '_blank';
}
});
});
});

2016年3月17日 (木) 12:19時点における版

// **********************************************************************
// **                 ***WARNING GLOBAL GADGET FILE***                 **
// **             changes to this file affect many users.              **
// **           please discuss on the talk page before editing         **
// **                                                                  **
// **********************************************************************
/**
 * @source mediawiki.org/wiki/Snippets/Open_external_links_in_new_window
 * @version 5
 */
mw.hook('wikipage.content').add(function($content) {
	// Second selector is for external links in Parsoid HTML+RDFa output (bug 65243).
	$content.find('a.external, a[rel="mw:ExtLink"]').each(function () {
		// Can't use wgServer because it can be protocol relative
		// Use this.href property instead of this.getAttribute('href')  because the property
		// is converted to a full URL (including protocol)
		if (this.href.indexOf(location.protocol + '//' + location.hostname) !== 0) {
			this.target = '_blank';
		}
	});
});