「MediaWiki:Common.js」の版間の差分
ナビゲーションに移動
検索に移動
(折り畳みボックス用のスクリプト) |
(cookieのキー名を変更。+旧エケペディアへの言語間リンクを修正するコード) |
||
43行目: | 43行目: | ||
$table.find('tr:first > td:first').prepend($button); | $table.find('tr:first > td:first').prepend($button); | ||
if ( | if (/^cookie-(.+)$/.test(collapse)) { | ||
var key = ' | var key = 'collapse-' + RegExp.$1; | ||
collapse = $.cookie(key) || 'autocollapse'; | collapse = $.cookie(key) || 'autocollapse'; | ||
$toggle.on('click', $.proxy(toggleCollapsible, $toggle, $table, key)); | $toggle.on('click', $.proxy(toggleCollapsible, $toggle, $table, key)); | ||
56行目: | 56行目: | ||
}); | }); | ||
} | } | ||
makeCollapsibleBoxes | mw.hook('wikipage.content').add(makeCollapsibleBoxes); | ||
/*旧エケペディアへの言語間リンクで「_」を「%20」に変換する*/ | |||
$('#p-lang a[lang=akb49]').attr('href', function(i, href) { return href.replace('_', '%20', 'g'); }); |
2014年2月21日 (金) 18:23時点における版
/* ここにあるすべてのJavaScriptは、すべてのページ読み込みですべての利用者に対して読み込まれます */
/*[[テンプレート:折り畳みボックス]]*/
var collapseCaption = '隠す';
var expandCaption = '表示';
function toggleCollapsible($table, key, e) {
if ($table.hasClass('collapsed')) {
expandCollapsible($table, $(this));
if (key) $.cookie(key, 'uncollapsed', { path: '/', expires: 90 });
} else {
collapseCollapsible($table, $(this));
if (key) $.cookie(key, 'collapsed', { path: '/', expires: 90 });
}
e.preventDefault();
}
function collapseCollapsible($table, $toggle, duration) {
$toggle.text(expandCaption);
$table.addClass('collapsed').find('> tbody > tr:not(:first)').fadeOut(duration);
}
function expandCollapsible($table, $toggle, duration) {
$toggle.text(collapseCaption);
$table.removeClass('collapsed').find('> tbody > tr:not(:first)').fadeIn(duration);
}
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)) {
collapseCollapsible($table, $toggle, 0);
}
});
}
mw.hook('wikipage.content').add(makeCollapsibleBoxes);
/*旧エケペディアへの言語間リンクで「_」を「%20」に変換する*/
$('#p-lang a[lang=akb49]').attr('href', function(i, href) { return href.replace('_', '%20', 'g'); });