「MediaWiki:Common.js」の版間の差分

提供:エケペディア
ナビゲーションに移動 検索に移動
(コードの修正)
(fix editintro)
 
(3人の利用者による、間の21版が非表示)
1行目: 1行目:
/* ここにあるすべてのJavaScriptは、すべてのページ読み込みですべての利用者に対して読み込まれます */
/* <nowiki> ここにあるすべてのJavaScriptは、すべてのページ読み込みですべての利用者に対して読み込まれます */


/*[[テンプレート:折り畳みボックス]]*/
/* URLのwithCSSパラメータで、追加のスタイルシートを読み込む
使われていないので無効化 有効化する場合依存関係に注意
https://www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL
var extraCSS = mw.util.getParamValue('withCSS');
if (extraCSS && extraCSS.match(/\.css$/)) {
mw.loader.load(mw.config.get('wgServer') + mw.config.get('wgScript') +
              '?action=raw&ctype=text/css&title=' +
              mw.util.wikiUrlencode(extraCSS), 'text/css');
}
*/
/* ソート順を改善(長音符は非対応) */
mw.config.set('tableSorterCollation', {
'ア':'あ', 'ァ':'あ', 'ぁ':'あ',  'イ':'い', 'ィ':'い', 'ぃ':'い',  'ウ':'う', 'ゥ':'う', 'ぅ':'う',
'エ':'え', 'ェ':'え', 'ぇ':'え',  'オ':'お', 'ォ':'お', 'ぉ':'お',
'カ':'か', 'ガ':'か', 'が':'か',  'キ':'き', 'ギ':'き', 'ぎ':'き',  'ク':'く', 'グ':'く', 'ぐ':'く',
'ケ':'け', 'ゲ':'け', 'げ':'け',  'コ':'こ', 'ゴ':'こ', 'ご':'こ',
'サ':'さ', 'ザ':'さ', 'ざ':'さ',  'シ':'し', 'ジ':'し', 'じ':'し',  'ス':'す', 'ズ':'す', 'ず':'す',
'セ':'せ', 'ゼ':'せ', 'ぜ':'せ',  'ソ':'そ', 'ゾ':'そ', 'ぞ':'そ',
'タ':'た', 'ダ':'た', 'だ':'た',  'チ':'ち', 'ヂ':'ち', 'ぢ':'ち',
'ツ':'つ', 'ヅ':'つ', 'ッ':'つ', 'づ':'つ', 'っ':'つ',
'テ':'て', 'デ':'て', 'で':'て',  'ト':'と', 'ド':'と', 'ど':'と',
'ナ':'な',  'ニ':'に',  'ヌ':'ぬ',  'ネ':'ね',  'ノ':'の',
'ハ':'は', 'バ':'は', 'パ':'は', 'ば':'は', 'ぱ':'は',
'ヒ':'ひ', 'ビ':'ひ', 'ピ':'ひ', 'び':'ひ', 'ぴ':'ひ',
'フ':'ふ', 'ブ':'ふ', 'プ':'ふ', 'ぶ':'ふ', 'ぷ':'ふ',
'ヘ':'へ', 'ベ':'へ', 'ペ':'へ', 'べ':'へ', 'ぺ':'へ',
'ホ':'ほ', 'ボ':'ほ', 'ポ':'ほ', 'ぼ':'ほ', 'ぽ':'ほ',
'マ':'ま',  'ミ':'み',  'ム':'む',  'メ':'め',  'モ':'も',
'ヤ':'や', 'ャ':'や', 'ゃ':'や',  'ユ':'ゆ', 'ュ':'ゆ', 'ゅ':'ゆ',  'ヨ':'よ', 'ョ':'よ', 'ょ':'よ',
'ラ':'ら',  'リ':'り',  'ル':'る',  'レ':'れ',  'ロ':'ろ',
'ワ':'わ',  'ヲ':'を',  'ン':'ん',  ' ':'', ' ':'',
});
 
/* [[テンプレート:折り畳みボックス]] */
var collapseCaption = '隠す';
var collapseCaption = '隠す';
var expandCaption = '表示';
var expandCaption = '表示';


function toggleCollapsible($table, key, e) {
function toggleCollapsible(key, e) {
    if ($table.hasClass('collapsed')) {
e.preventDefault();
        expandCollapsible($table, $(this));
if (this.hasClass('collapsed')) {
        if (key) $.cookie(key, 'uncollapsed', { path: '/', expires: 90 });
this.removeClass('collapsed').find('> tbody > tr:not(:first)').fadeIn();
    } else {
this.$toggle.text(collapseCaption);
        collapseCollapsible($table, $(this));
if (key) $.cookie(key, 'uncollapsed', { path: '/', expires: 90 });
        if (key) $.cookie(key, 'collapsed', { path: '/', expires: 90 });
} else {
    }
this.addClass('collapsed').find('> tbody > tr:not(:first)').fadeOut();
    e.preventDefault();
this.$toggle.text(expandCaption);
if (key) $.cookie(key, 'collapsed', { path: '/', expires: 90 });
}
}
}


function collapseCollapsible($table, $toggle, duration) {
mw.hook('wikipage.content').add(function($content) {
    $toggle.text(expandCaption);
/* 折り畳みボックス */
    $table.addClass('collapsed').find('> tbody > tr:not(:first)').fadeOut(duration);
$content.find('table.collapsible').each(function() {
}
var $table = $(this),
collapse = $table.data('collapse');
if ($table.hasClass('made-collapsible') || collapse == 'plain') return;
$table.addClass('made-collapsible');
 
var $button = $table.find('tr:first > td:first > .collapseButton');
$table.$toggle = $button.append('[<a href="#"></a>]').children();
/*
if (/^cookie-(.+)$/.test(collapse)) {
var key = 'collapse-' + RegExp.$1;
collapse = $.cookie(key) || 'autocollapse';
$table.$toggle.on('click', $.proxy(toggleCollapsible, $table, key));
} else {
$table.$toggle.on('click', $.proxy(toggleCollapsible, $table, null));
}
*/
$table.$toggle.on('click', $.proxy(toggleCollapsible, $table, null));
 
if (collapse == 'collapsed' || (collapse == 'autocollapse' &&
                            $table.siblings('table.collapsible').length)) {
$table.addClass('collapsed').find('> tbody > tr:not(:first)').hide();
$table.$toggle.text(expandCaption);
} else {
$table.$toggle.text(collapseCaption);
}
});


function expandCollapsible($table, $toggle, duration) {
/* タブ */
    $toggle.text(collapseCaption);
$content.find('.tab-list').each(function() {
    $table.removeClass('collapsed').find('> tbody > tr:not(:first)').fadeIn(duration);
var $tabList = $(this),
}
$tabs = $tabList.find('> ul > li'),
$tabContent = $tabList.nextAll('.tab-content');
$tabs.bind('click', function() {
var $tab = $(this),
index = $tab.data('tab') - 1;
$tabs.removeClass('current-tab');
$tab.addClass('current-tab');
$tabContent.not($tabContent.eq(index).toggle()).hide();
});
});
});


function makeCollapsibleBoxes($root) {
    var $tables = $root.find('table').filter(function() {
        var $table = $(this);
        makeCollapsibleBoxes($table);
        return $table.hasClass('collapsible') && !$table.hasClass('made-collapsible');
    });
    $tables.each(function() {
        var $table = $(this),
            collapse = $table.data('collapse');
        if (collapse === 'plain') return;
        $table.addClass('made-collapsible');


        var $toggle = $('<a href="#">' + collapseCaption + '</a>'),
            $button = $('<span class="collapseButton"></span>');
        $button.append('[').append($toggle).append(']');
        $table.find('tr:first > td:first').prepend($button);


        if (/^cookie-(.+)$/.test(collapse)) {
            var key = 'collapse-' + RegExp.$1;
            collapse = $.cookie(key) || 'autocollapse';
            $toggle.on('click', $.proxy(toggleCollapsible, $toggle, $table, key));
        } else {
            $toggle.on('click', $.proxy(toggleCollapsible, $toggle, $table, null));
        }


        if (collapse === 'collapsed' || (collapse === 'autocollapse' && $tables.length > 1)) {
/* 非autoconfirmedユーザーの「ページを保存」ボタンをロックし、「プレビューを表示」ボタンへ誘導する */
            collapseCollapsible($table, $toggle, 0);
if (mw.config.get('wgAction') === 'edit' &&
        }
    $.inArray('autoconfirmed', mw.config.get('wgUserGroups')) < 0) {
    });
$('#wpSave').attr('disabled', 'disabled').val('投稿前にプレビューで確認してください');
$('#wpPreview').css('font-weight', 'bold');
}
}
mw.hook('wikipage.content').add(makeCollapsibleBoxes);




/*旧エケペディアへの言語間リンクで「_」を「%20」に変換する*/
/* 要約欄でエンターキーを押した際に投稿されないようにする */
$('#p-lang a[lang=akb49]').attr('href', function(i, href) { return href.replace('_', '%20', 'g'); });
jQuery(document).ready(function($) {
if (typeof summaryEnterRejectDisable === 'undefined' || summaryEnterRejectDisable == false) {
$('#wpSummary').keypress(function(e) {
if (e.keyCode == 13) {
e.preventDefault();
}
});
 
$('#wpSave').css('font-weight', 'normal');
}
});


mw.loader.using( [ 'mediawiki.util' ] ).done( function () {
    /* カテゴリごとにeditintroを設定する */
var CATEGORY_EDITINTRO_TABLE = {
'メンバー': 'ヘルプ:メンバーページのスタイル/editintro' ,
'元メンバー': 'ヘルプ:メンバーページのスタイル/editintro' ,
'シングル': 'ヘルプ:シングルページのスタイル/editintro' ,
};
function addEditIntro(templateName) {
    $( '.mw-editsection,#quickbar, #ca-edit' ).find( 'a' ).each( function ( i, el ) {
        el.href = $( this ).attr( 'href' ) + '&editintro=' + templateName;
    } );
};


/*非autoconfirmedユーザーの「ページを保存」ボタンをロックし、「プレビューを表示」ボタンへ誘導する*/
if (mw.config.get('wgNamespaceNumber') == 0) {
if (mw.config.get('wgAction') === 'edit' && mw.config.get('wgNamespaceNumber') === 0 &&
$(function(){
    $.inArray('autoconfirmed', mw.config.get('wgUserGroups')) < 0) {
        var catContainer = mw.config.get( 'wgCategories' );
    $('#wpSave').attr('disabled', 'disabled').val('投稿前にプレビューで確認してください');
        $.each(catContainer, function(index, value) {
    $('#wpPreview').css('font-weight', 'bold');
            if(ei = CATEGORY_EDITINTRO_TABLE[value]) {
                addEditIntro(ei);
                return;
            }
          });
});
}
}
});

2022年9月17日 (土) 14:03時点における最新版

/* <nowiki> ここにあるすべてのJavaScriptは、すべてのページ読み込みですべての利用者に対して読み込まれます */

/* URLのwithCSSパラメータで、追加のスタイルシートを読み込む
使われていないので無効化 有効化する場合依存関係に注意
https://www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL
var extraCSS = mw.util.getParamValue('withCSS');
if (extraCSS && extraCSS.match(/\.css$/)) {
	mw.loader.load(mw.config.get('wgServer') + mw.config.get('wgScript') +
	               '?action=raw&ctype=text/css&title=' +
	               mw.util.wikiUrlencode(extraCSS), 'text/css');
}
 */
/* ソート順を改善(長音符は非対応) */
mw.config.set('tableSorterCollation', {
	'ア':'あ', 'ァ':'あ', 'ぁ':'あ',  'イ':'い', 'ィ':'い', 'ぃ':'い',  'ウ':'う', 'ゥ':'う', 'ぅ':'う',
	'エ':'え', 'ェ':'え', 'ぇ':'え',  'オ':'お', 'ォ':'お', 'ぉ':'お',
	'カ':'か', 'ガ':'か', 'が':'か',  'キ':'き', 'ギ':'き', 'ぎ':'き',  'ク':'く', 'グ':'く', 'ぐ':'く',
	'ケ':'け', 'ゲ':'け', 'げ':'け',  'コ':'こ', 'ゴ':'こ', 'ご':'こ',
	'サ':'さ', 'ザ':'さ', 'ざ':'さ',  'シ':'し', 'ジ':'し', 'じ':'し',  'ス':'す', 'ズ':'す', 'ず':'す',
	'セ':'せ', 'ゼ':'せ', 'ぜ':'せ',  'ソ':'そ', 'ゾ':'そ', 'ぞ':'そ',
	'タ':'た', 'ダ':'た', 'だ':'た',  'チ':'ち', 'ヂ':'ち', 'ぢ':'ち',
	'ツ':'つ', 'ヅ':'つ', 'ッ':'つ', 'づ':'つ', 'っ':'つ',
	'テ':'て', 'デ':'て', 'で':'て',  'ト':'と', 'ド':'と', 'ど':'と',
	'ナ':'な',  'ニ':'に',  'ヌ':'ぬ',  'ネ':'ね',  'ノ':'の',
	'ハ':'は', 'バ':'は', 'パ':'は', 'ば':'は', 'ぱ':'は',
	'ヒ':'ひ', 'ビ':'ひ', 'ピ':'ひ', 'び':'ひ', 'ぴ':'ひ',
	'フ':'ふ', 'ブ':'ふ', 'プ':'ふ', 'ぶ':'ふ', 'ぷ':'ふ',
	'ヘ':'へ', 'ベ':'へ', 'ペ':'へ', 'べ':'へ', 'ぺ':'へ',
	'ホ':'ほ', 'ボ':'ほ', 'ポ':'ほ', 'ぼ':'ほ', 'ぽ':'ほ',
	'マ':'ま',  'ミ':'み',  'ム':'む',  'メ':'め',  'モ':'も',
	'ヤ':'や', 'ャ':'や', 'ゃ':'や',  'ユ':'ゆ', 'ュ':'ゆ', 'ゅ':'ゆ',  'ヨ':'よ', 'ョ':'よ', 'ょ':'よ',
	'ラ':'ら',  'リ':'り',  'ル':'る',  'レ':'れ',  'ロ':'ろ',
	'ワ':'わ',  'ヲ':'を',  'ン':'ん',  ' ':'', ' ':'',
});

/* [[テンプレート:折り畳みボックス]] */
var collapseCaption = '隠す';
var expandCaption = '表示';

function toggleCollapsible(key, e) {
	e.preventDefault();
	if (this.hasClass('collapsed')) {
		this.removeClass('collapsed').find('> tbody > tr:not(:first)').fadeIn();
		this.$toggle.text(collapseCaption);
		if (key) $.cookie(key, 'uncollapsed', { path: '/', expires: 90 });
	} else {
		this.addClass('collapsed').find('> tbody > tr:not(:first)').fadeOut();
		this.$toggle.text(expandCaption);
		if (key) $.cookie(key, 'collapsed', { path: '/', expires: 90 });
	}
}

mw.hook('wikipage.content').add(function($content) {
	/* 折り畳みボックス */
	$content.find('table.collapsible').each(function() {
		var $table = $(this),
			collapse = $table.data('collapse');
		if ($table.hasClass('made-collapsible') || collapse == 'plain') return;
		$table.addClass('made-collapsible');

		var $button = $table.find('tr:first > td:first > .collapseButton');
		$table.$toggle = $button.append('[<a href="#"></a>]').children();
		/*
		if (/^cookie-(.+)$/.test(collapse)) {
			var key = 'collapse-' + RegExp.$1;
			collapse = $.cookie(key) || 'autocollapse';
			$table.$toggle.on('click', $.proxy(toggleCollapsible, $table, key));
		} else {
			$table.$toggle.on('click', $.proxy(toggleCollapsible, $table, null));
		}
		*/
		$table.$toggle.on('click', $.proxy(toggleCollapsible, $table, null));

		if (collapse == 'collapsed' || (collapse == 'autocollapse' &&
			                            $table.siblings('table.collapsible').length)) {
			$table.addClass('collapsed').find('> tbody > tr:not(:first)').hide();
			$table.$toggle.text(expandCaption);
		} else {
			$table.$toggle.text(collapseCaption);
		}
	});

	/* タブ */
	$content.find('.tab-list').each(function() {
		var $tabList = $(this),
			$tabs = $tabList.find('> ul > li'),
			$tabContent = $tabList.nextAll('.tab-content');
		$tabs.bind('click', function() {
			var $tab = $(this),
				index = $tab.data('tab') - 1;
			$tabs.removeClass('current-tab');
			$tab.addClass('current-tab');
			$tabContent.not($tabContent.eq(index).toggle()).hide();
		});
	});
});




/* 非autoconfirmedユーザーの「ページを保存」ボタンをロックし、「プレビューを表示」ボタンへ誘導する */
if (mw.config.get('wgAction') === 'edit' &&
    $.inArray('autoconfirmed', mw.config.get('wgUserGroups')) < 0) {
	$('#wpSave').attr('disabled', 'disabled').val('投稿前にプレビューで確認してください');
	$('#wpPreview').css('font-weight', 'bold');
}


/* 要約欄でエンターキーを押した際に投稿されないようにする */
jQuery(document).ready(function($) {
	if (typeof summaryEnterRejectDisable === 'undefined' || summaryEnterRejectDisable == false) {
		$('#wpSummary').keypress(function(e) {
			if (e.keyCode == 13) {
				e.preventDefault();
			}
		});

		$('#wpSave').css('font-weight', 'normal');
	}
});

mw.loader.using( [ 'mediawiki.util' ] ).done( function () {
    /* カテゴリごとにeditintroを設定する */
var CATEGORY_EDITINTRO_TABLE = {
	'メンバー': 'ヘルプ:メンバーページのスタイル/editintro' ,
	'元メンバー': 'ヘルプ:メンバーページのスタイル/editintro' ,
	'シングル': 'ヘルプ:シングルページのスタイル/editintro' ,
};
 
function addEditIntro(templateName) {
    $( '.mw-editsection,#quickbar, #ca-edit' ).find( 'a' ).each( function ( i, el ) {
        el.href = $( this ).attr( 'href' ) + '&editintro=' + templateName;
    } );
};

if (mw.config.get('wgNamespaceNumber') == 0) {
	$(function(){
        var catContainer = mw.config.get( 'wgCategories' );
        $.each(catContainer, function(index, value) {
            if(ei = CATEGORY_EDITINTRO_TABLE[value]) {
                addEditIntro(ei);
                return;
            }
          });
	});
}
});