利用者:青子守歌/tag/EnhancedCollapsibleElements0/EnhancedCollapsibleElements.js
表示
< 利用者:青子守歌
お知らせ: 保存した後、ブラウザのキャッシュをクリアしてページを再読み込みする必要があります。
多くの Windows や Linux のブラウザ
- Ctrl を押しながら F5 を押す。
Mac における Safari
Mac における Chrome や Firefox
- ⌘ Cmd と ⇧ Shift を押しながら R を押す。
詳細についてはWikipedia:キャッシュを消すをご覧ください。
<source lang="javascript">
/************************************************************************/
// ja> = ECE : 強化型折りたたみ可能要素 =
// > NavFrameのように折りたたみ可能な要素を利用可能にする
// > ;作者: 青子守歌
// > ;URL: http://ja-two.iwiki.icu/wiki/User:aokomoriuta
// >
// > == 使い方 ==
// > # ボタンを置きたい場所に、{{利用者:青子守歌/EnhancedCollapsibleElements.js/ボタンテンプレート}}をおく(詳細はテンプレートの説明を参照)。
// > # 折りたたみをしたい要素に、テンプレートで指定した条件を付与する。
// > 使用例については、[[利用者:青子守歌/EnhancedCollapsibleElements.js/ボタンテンプレート使用例]]を参照。
// > 説明書が、[[利用者:青子守歌/EnhancedCollapsibleElements.js/説明書]]にあります。
// >
// > == ライセンス ==
// > このスクリプトは、複数ライセンスで利用可能です。
// > 選択可能なライセンスは次の通り:
// > * クリエイティブ・コモンズ 表示-継承 3.0 非移植
// > * クリエイティブ・コモンズ 表示-非営利 3.0 非移植
// > * GNU一般公衆利用許諾書 バージョン3.0以降
/************************************************************************/
// en> = ECE: Enhanced Collapsible Elements =
// > This script enables collapsible elements like NavFrame.
// > ;author: 青子守歌
// > ;URL: http://ja-two.iwiki.icu/wiki/User:aokomoriuta
// >
// > == Usage ==
// > # Insert {{利用者:青子守歌/EnhancedCollapsibleElements.js/ボタンテンプレート}} to you want to put the button (See the template's description for more information).
// > # Give the condition to all elements you want to collapse.
// > Usage examples are available at [[利用者:青子守歌/EnhancedCollapsibleElements.js/使用例]].
// > Documentation is available at [[利用者:青子守歌/EnhancedCollapsibleElements.js/説明書]].
// >
// > == License ==
// > This script is multi-licensed.
// > You can select the license of your choice from as following:
// > * Creative Commons Attribution-ShareAlike 3.0 Unported
// > * Creative Commons Attribution-Noncommercial 3.0 Unported
// > * GNU General Public License v3.0 or later
/************************************************************************/
$(function(){jQuery(document).ready(function($)
{
// スタイルシート読み込み
importStylesheetURI("http://ja-two.iwiki.icu//w/index.php?action=raw&ctype=text/css&title=%E5%88%A9%E7%94%A8%E8%80%85%3A%E9%9D%92%E5%AD%90%E5%AE%88%E6%AD%8C%2FEnhancedCollapsibleElements.css");
// 全ECEボタンについて
$("span.ece-button").each(function()
{
// ボタンを取得
$this = $(this);
// 対象ID、折りたたみ&展開ラベル、状態、本体を取得
var targettext = $this.find("span.ece-target").text();
var etext = $this.find("span.ece-etext").text();
var ctext = $this.find("span.ece-ctext").text();
var state = $this.find("span.ece-state").text();
var $body = $this.find("span.ece-body");
// 本体がなかったら
if($body.length == 0)
{
// 新しく作成し、追加
$body = $(document.createElement("span")).addClass("ece-body");
$(this).append($body);
}
// 情報が取得出来たら
if((targettext.length != 0)&&(etext.length != 0)&&(ctext.length != 0)&&(state.length != 0))
{
// ボタンを作成
var $button = $(document.createElement("a"));
// クリック時に
$button.click(function()
{
// 表示・非表示を逆転
state = (state == "e") ? "c" : "e";
// 折りたたみ状態に応じてラベルを変更
$button.text((state == "e") ? ctext : etext)
// 対象の要素について
$("#bodyContent").find(targettext).each(function()
{
// 表示と非表示を実行、
$(this)[(state == "e") ? "show" : "hide"]();
});
});
// 折りたたみ状態を逆転して、クリック
state = (state == "e") ? "c" : "e";
$button.click();
// 本体の中身をボタンに置き換え
$body.empty();
$body.append($button);
}
});
});});
</source>