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

一部でautocollapseが正しくない問題の修正、&withCSS=で追加CSSを読み込むコード
(コードの修正)
(一部で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($table, key, e) {
function toggleCollapsible(key, e) {
     if ($table.hasClass('collapsed')) {
     if (this.hasClass('collapsed')) {
         expandCollapsible($table, $(this));
         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 {
         collapseCollapsible($table, $(this));
         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 collapseCollapsible($table, $toggle, duration) {
function makeCollapsibleBoxes($content) {
    $toggle.text(expandCaption);
     $content.find('table.collapsible').each(function() {
    $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),
         var $table = $(this),
             collapse = $table.data('collapse');
             collapse = $table.data('collapse');
         if (collapse === 'plain') return;
         if ($table.hasClass('made-collapsible') || collapse == 'plain') return;
         $table.addClass('made-collapsible');
         $table.addClass('made-collapsible');


         var $toggle = $('<a href="#">' + collapseCaption + '</a>'),
         var $button = $('<span class="collapseButton">[<a href="#"></a>]</span>');
            $button = $('<span class="collapseButton"></span>');
        $button.append('[').append($toggle).append(']');
         $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, $toggle, $table, key));
             $table.$toggle.on('click', $.proxy(toggleCollapsible, $table, key));
         } else {
         } else {
             $toggle.on('click', $.proxy(toggleCollapsible, $toggle, $table, null));
             $table.$toggle.on('click', $.proxy(toggleCollapsible, $table, null));
         }
         }


         if (collapse === 'collapsed' || (collapse === 'autocollapse' && $tables.length > 1)) {
         if (collapse == 'collapsed' || (collapse == 'autocollapse' &&
             collapseCollapsible($table, $toggle, 0);
                                        $table.siblings('table.collapsible').length > 0)) {
             $table.addClass('collapsed').find('> tbody > tr:not(:first)').hide();
            $table.$toggle.text(expandCaption);
        } else {
            $table.$toggle.text(collapseCaption);
         }
         }
     });
     });
user-upload
3,547

回編集