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

折り畳みボックスをオーバーレイ表示させる実験コード
(MediaWiki:Common.jsの一部機能をモバイル版へ移植)
 
(折り畳みボックスをオーバーレイ表示させる実験コード)
1行目: 1行目:
/* ここにあるすべてのJavaScriptは携帯機器版サイトの利用者に影響します */
/* ここにあるすべてのJavaScriptは携帯機器版サイトの利用者に影響します */
/*試験的コードを有効にする*/
var beta = mw.util.getParamValue('beta'), enableTestCode;
if (beta == 'on') {
    $.cookie('enable-test-code', 'on', { path: '/', expires: 30 });
    enableTestCode = true;
} else if (beta == 'off') {
    $.cookie('enable-test-code', null);
} else {
    enableTestCode = $.cookie('enable-test-code') == 'on';
}


/*[[テンプレート:折り畳みボックス]]*/
/*[[テンプレート:折り畳みボックス]]*/
52行目: 63行目:
     $lastContentBlock.children('table.collapsible').insertAfter($lastContentBlock);
     $lastContentBlock.children('table.collapsible').insertAfter($lastContentBlock);


     makeCollapsibleBoxes(mw.util.$content);
     if (!enableTestCode) makeCollapsibleBoxes(mw.util.$content);


     /*旧エケペディアへの言語間リンクで「_」を「%20」に変換する*/
     /*旧エケペディアへの言語間リンクで「_」を「%20」に変換する*/
59行目: 70行目:
     });
     });
});
});
if (enableTestCode) {
/*[[テンプレート:折り畳みボックス]]をOverlayで表示*/
mw.loader.using('mobile.stable.common', function() {
    var CollapsibleBoxOverlay = mw.mobileFrontend.require('Overlay').extend({
        className: 'collapsible-box-overlay mw-mf-overlay',
        initialize: function(options) {
            var title = options.table.find('> tbody > tr > td.navbox-title').html(),
                content = '';
            options.heading = '<h2>' + title + '</h2>';
            options.table.find('> tbody > tr > td.navbox-list').each(function() {
                var $list = $(this),
                    $group = $list.prev('.navbox-group');
                content += $list.html();
            });
            options.content = content;
            this._super(options);
        },
        postRender: function(options) {
            var self = this;
            this._super(options);
            this.$('table.collapsible').each(function() {
                var $table = $(this);
                $table.on('click', function(e) {
                    e.preventDefault();
                    new CollapsibleBoxOverlay({ table: $table, parent: self }).show();
                });
            });
        }
    });
    mw.hook('wikipage.content').add(function() {
        mw.util.$content.find('table.collapsible').each(function() {
            var $table = $(this);
            $table.find('> tbody > tr:not(:first)').hide();
            $table.on('click', function(e) {
                e.preventDefault();
                new CollapsibleBoxOverlay({ table: $table }).show();
            });
        });
    });
});
}
user-upload
3,547

回編集