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

編集の要約なし
折り畳みボックス用JSを外部から読み込む形に変更
 
284行目: 284行目:
});
});


/* 折り畳みボックス用のJS */
// 折り畳みボックス用JSを読み込み
function expandableBoxFunc() {
mw.loader.load( 'https://wiki.signal-st.com/MediaWiki:ExpandableBox.js?action=raw&ctype=text/javascript' );
    // 'custom-template-expandable-box' クラスを持つ要素をすべて取得
    var expandableBoxes = document.querySelectorAll('.custom-template-expandable-box');
    console.log("あああああああ: " + expandableBoxes);
 
    expandableBoxes.forEach(function(box) {
        var header = box.querySelector('.custom-template-expandable-box-header');
        var contents = box.querySelector('.custom-template-expandable-box-contents');
        var toggleLabel = box.querySelector('.custom-template-expandable-box-toggle-label');
 
        // contents と toggleLabel が存在するか確認
        if (!contents || !toggleLabel) {
            return; // 必要な要素がなければスキップ
        }
 
        // `opened` パラメータの状態を読み取る
        var isOpenedInitially = box.getAttribute('data-opened') === 'True';
 
        // 初期状態の設定
        if (isOpenedInitially) {
            contents.style.display = 'block';
            toggleLabel.textContent = '[非表示]';
        } else {
            contents.style.display = 'none';
            toggleLabel.textContent = '[表示]';
        }
 
        // ヘッダーがクリックされたときのイベントリスナーを設定
        if (header) {
            header.addEventListener('click', function() {
                if (contents.style.display === 'none') {
                    // 非表示なら表示にする
                    contents.style.display = 'block'; // または 'initial'
                    toggleLabel.textContent = '[非表示]';
                } else {
                    // 表示なら非表示にする
                    contents.style.display = 'none';
                    toggleLabel.textContent = '[表示]';
                }
            });
        }
    });
}
 
expandableBoxFunc();