user-upload
3,547
回編集
(コードの修正) |
(一部で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); | |||
} | } | ||
}); | }); |