-1

我正在尝试做这样的事情:http ://en.wikipedia.org/wiki/Bible 在右边你会看到一个带有“显示”按钮的信息框:

在此处输入图像描述

到目前为止,我按照本指南所做的工作:http: //trog.qgl.org/20140923/setting-up-infobox-templates-in-mediawiki-v1-23/

  1. 下载并安装 Scribuntu

  2. 从这个地方复制 css: https ://en.wikipedia.org/w/index.php?title=MediaWiki:Common.css&action= edit 到我的 Common.css

  3. 导出的信息框模板

  4. 导入的信息框模板

  5. 创建了信息框模板并且它有效,但是我不能让我的标题可折叠。

我用谷歌搜索并找到了这个页面http://dev.wikia.com/wiki/CollapsibleInfobox但没有信息框模板(可折叠)。

有人可以帮我吗?

4

2 回答 2

1

通过向信息框添加类解决了我的问题:

{{Infobox
 | abovestyle = background:#cfc;
 | above = Infobox
 | image = [[File:Parents.jpg|300px]]

 |header1 = Header 1
 |rowclass1 = class1 header hidden

 |label2 = 111
 |data2 = test1
 |rowclass2 = class1

 |header3 = Header 3
 |rowclass3  = class3 header hidden

 |label4 = 
 |data4  = data 4
 |rowclass4 = class3
}}

然后我将此 jQuery 代码添加到我的 Common.js 中:

    $('<a class="infoboxtoggle" href="#">+/-</a>').appendTo(
      $('.infobox tr.header').filter(function(){ return $(this).attr('class').split(" ").length > 1 }).find("th")
    );

    $(".infobox tr.header").each(function(){
      var $this = $(this);

      if( $this.hasClass("hidden") ){
        var firstclass = $this.attr("class").split(" ")[0];
        $this.siblings("." + firstclass).addClass("hidden");
      }
   });

    $('a.infoboxtoggle').click (
      function (infoboxtoggle)
      {
        var parent  = $(this).parent ();
        var grandparent  = parent.parent ();
        var firstclass  = grandparent.attr ('class').split(" ")[0];

        infoboxtoggle.preventDefault();
        grandparent.siblings ('.' + firstclass).has ('td').toggleClass ('hidden');
      }
    );

然后添加了一些css:

a.infoboxtoggle { float: right; } /* positions the +/- */
.hidden { display: none; } /* hides hidden rows */
tr.header.hidden { display: table-row; } /* does _not_ hide headers */

然后它起作用了:

在此处输入图像描述

当您按下 +/- 时,它会展开隐藏的行。

于 2014-10-03T11:48:34.690 回答
-2

你看过http://www.mediawiki.org/wiki/Manual:Collapsible_elements吗?它解释了如何使任何元素可折叠。

于 2014-10-03T11:35:24.727 回答