「MediaWiki:Common.js」の版間の差分
ナビゲーションに移動
検索に移動
(コードの修正) |
(一部でautocollapseが正しくない問題の修正、&withCSS=で追加CSSを読み込むコード) |
||
1行目: | 1行目: | ||
/* ここにあるすべてのJavaScriptは、すべてのページ読み込みですべての利用者に対して読み込まれます */ | /* ここにあるすべてのJavaScriptは、すべてのページ読み込みですべての利用者に対して読み込まれます */ | ||
/* URLのwithCSSパラメータで、追加のスタイルシートを読み込む */ | |||
var extraCSS = mw.util.getParamValue('withCSS'); | |||
if (extraCSS && extraCSS.match(/\.css$/)) importStylesheet(extraCSS); | |||
/*[[テンプレート:折り畳みボックス]]*/ | /*[[テンプレート:折り畳みボックス]]*/ | ||
5行目: | 9行目: | ||
var expandCaption = '表示'; | var expandCaption = '表示'; | ||
function toggleCollapsible( | function toggleCollapsible(key, e) { | ||
if ( | 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 }); | if (key) $.cookie(key, 'uncollapsed', { path: '/', expires: 90 }); | ||
} else { | } else { | ||
this.addClass('collapsed').find('> tbody > tr:not(:first)').fadeOut(); | |||
this.$toggle.text(expandCaption); | |||
if (key) $.cookie(key, 'collapsed', { path: '/', expires: 90 }); | if (key) $.cookie(key, 'collapsed', { path: '/', expires: 90 }); | ||
} | } | ||
16行目: | 22行目: | ||
} | } | ||
function makeCollapsibleBoxes($content) { | |||
$content.find('table.collapsible').each(function() { | |||
function makeCollapsibleBoxes($ | |||
var $table = $(this), | var $table = $(this), | ||
collapse = $table.data('collapse'); | collapse = $table.data('collapse'); | ||
if (collapse | if ($table.hasClass('made-collapsible') || collapse == 'plain') return; | ||
$table.addClass('made-collapsible'); | $table.addClass('made-collapsible'); | ||
var $ | var $button = $('<span class="collapseButton">[<a href="#"></a>]</span>'); | ||
$table.find('tr:first > td:first').prepend($button); | $table.find('tr:first > td:first').prepend($button); | ||
$table.$toggle = $button.children(); | |||
if (/^cookie-(.+)$/.test(collapse)) { | if (/^cookie-(.+)$/.test(collapse)) { | ||
var key = 'collapse-' + RegExp.$1; | var key = 'collapse-' + RegExp.$1; | ||
collapse = $.cookie(key) || 'autocollapse'; | collapse = $.cookie(key) || 'autocollapse'; | ||
$toggle.on('click', $.proxy(toggleCollapsible | $table.$toggle.on('click', $.proxy(toggleCollapsible, $table, key)); | ||
} else { | } else { | ||
$toggle.on('click', $.proxy(toggleCollapsible | $table.$toggle.on('click', $.proxy(toggleCollapsible, $table, null)); | ||
} | } | ||
if (collapse | if (collapse == 'collapsed' || (collapse == 'autocollapse' && | ||
$table.siblings('table.collapsible').length > 0)) { | |||
$table.addClass('collapsed').find('> tbody > tr:not(:first)').hide(); | |||
$table.$toggle.text(expandCaption); | |||
} else { | |||
$table.$toggle.text(collapseCaption); | |||
} | } | ||
}); | }); |
2014年3月4日 (火) 22:31時点における版
/* ここにあるすべてのJavaScriptは、すべてのページ読み込みですべての利用者に対して読み込まれます */
/* URLのwithCSSパラメータで、追加のスタイルシートを読み込む */
var extraCSS = mw.util.getParamValue('withCSS');
if (extraCSS && extraCSS.match(/\.css$/)) importStylesheet(extraCSS);
/*[[テンプレート:折り畳みボックス]]*/
var collapseCaption = '隠す';
var expandCaption = '表示';
function toggleCollapsible(key, e) {
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 });
}
e.preventDefault();
}
function makeCollapsibleBoxes($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 = $('<span class="collapseButton">[<a href="#"></a>]</span>');
$table.find('tr:first > td:first').prepend($button);
$table.$toggle = $button.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));
}
if (collapse == 'collapsed' || (collapse == 'autocollapse' &&
$table.siblings('table.collapsible').length > 0)) {
$table.addClass('collapsed').find('> tbody > tr:not(:first)').hide();
$table.$toggle.text(expandCaption);
} else {
$table.$toggle.text(collapseCaption);
}
});
}
mw.hook('wikipage.content').add(makeCollapsibleBoxes);
/*旧エケペディアへの言語間リンクで「_」を「%20」に変換する*/
$('#p-lang a[lang=akb49]').attr('href', function(i, href) { return href.replace('_', '%20', 'g'); });
/*非autoconfirmedユーザーの「ページを保存」ボタンをロックし、「プレビューを表示」ボタンへ誘導する*/
if (mw.config.get('wgAction') === 'edit' && mw.config.get('wgNamespaceNumber') === 0 &&
$.inArray('autoconfirmed', mw.config.get('wgUserGroups')) < 0) {
$('#wpSave').attr('disabled', 'disabled').val('投稿前にプレビューで確認してください');
$('#wpPreview').css('font-weight', 'bold');
}