「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($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);
         }
         }
     });
     });

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');
}