본문으로 이동

미디어위키토론:Common.js

문서 내용이 다른 언어로는 지원되지 않습니다.
위키백과, 우리 모두의 백과사전.
Priviet (토론 | 기여)님의 2013년 11월 12일 (화) 16:37 판

마지막 의견: 11년 전 (Priviet님) - 주제: 틀 숨김 기능 버그 수정요청

보안 서버용 스크립트

{{보호 문서 편집 요청}}

 /* 보안 서버 링크 스크립트
  * 보안 서버에 있을 때 일반 링크를 보안 서버 링크로 변경하여 일반 서버 접속으로 전환되는 것을 최소화
  */
if (wgServer == "https://secure.wikimedia.org") importScriptURI('https://secure.wikimedia.org/wikipedia/en/w/index.php?title=MediaWiki:Common.js/secure.js&action=raw&ctype=text/javascript');

보안 서버에서 간혹 일반 서버 접속으로 바뀌는 경우가 있습니다. 외부 링크 형식으로 된 위키백과 내 링크나 인터위키 링크를 클릭하면 일반 서버 접속으로 바뀌게 됩니다. 보안 서버에 있을 때는 보안 서버 연결을 항상 유지시키기 위해 위 스크립트의 추가를 요청합니다. Kwj2772 (msg) 2011년 1월 8일 (토) 23:00 (KST)답변

완료 - IRTC1015 (토론) 2011년 1월 9일 (일) 23:06 (KST)답변

틀 숨김 기능 버그 수정요청

위키백과:사랑방 (일반)/2013년 제45주#숨김 틀에 이상..?의 오류에 대해서 bug 56824의 답변을 올립니다.

The problem is the use of addHandler() in the createCollapseButtons function in

[1]

This function is now deprecated. There is an updated version of what looks like the same function in [2] that should work.

이 지시에 따라 수정하면 버그가 해결된다고 하는군요. 수정부탁드립니다. -Привет(토론) 2013년 11월 10일 (일) 22:22 (KST) 구체적인 수정안은 다음과 같습니다.답변

/* ([[위키백과:관리자 요청/2007년 5월#스크립트 추가 요청]]) */
/** Collapsible tables *********************************************************
 *
 *  Description: Allows tables to be collapsed, showing only the header. See
 *               [[:en:Wikipedia:NavFrame]].
 *  Maintainers: [[:en:User:R. Koot]]
 */
var autoCollapse = 2;
var collapseCaption = '숨기기';
var expandCaption = '보이기';
 
window.collapseTable = function ( tableIndex ) {
    var Button = document.getElementById( 'collapseButton' + tableIndex );
    var Table = document.getElementById( 'collapsibleTable' + tableIndex );
 
    if ( !Table || !Button ) {
        return false;
    }
 
    var Rows = Table.rows;
    var i;
 
    if ( Button.firstChild.data === collapseCaption ) {
        for ( i = 1; i < Rows.length; i++ ) {
            Rows[i].style.display = 'none';
        }
        Button.firstChild.data = expandCaption;
    } else {
        for ( i = 1; i < Rows.length; i++ ) {
            Rows[i].style.display = Rows[0].style.display;
        }
        Button.firstChild.data = collapseCaption;
    }
};
 
function createCollapseButtons() {
    var tableIndex = 0;
    var NavigationBoxes = {};
    var Tables = document.getElementsByTagName( 'table' );
    var i;
 
    function handleButtonLink( index, e ) {
        window.collapseTable( index );
        e.preventDefault();
    }
 
    for ( i = 0; i < Tables.length; i++ ) {
        if ( $( Tables[i] ).hasClass( 'collapsible' ) ) {
 
            /* only add button and increment count if there is a header row to work with */
            var HeaderRow = Tables[i].getElementsByTagName( 'tr' )[0];
            if ( !HeaderRow ) continue;
            var Header = HeaderRow.getElementsByTagName( 'th' )[0];
            if ( !Header ) continue;
 
            NavigationBoxes[ tableIndex ] = Tables[i];
            Tables[i].setAttribute( 'id', 'collapsibleTable' + tableIndex );
 
            var Button     = document.createElement( 'span' );
            var ButtonLink = document.createElement( 'a' );
            var ButtonText = document.createTextNode( collapseCaption );
 
            Button.className = 'collapseButton';  /* Styles are declared in Common.css */
 
            ButtonLink.style.color = Header.style.color;
            ButtonLink.setAttribute( 'id', 'collapseButton' + tableIndex );
            ButtonLink.setAttribute( 'href', '#' );
            $( ButtonLink ).on( 'click', $.proxy( handleButtonLink, ButtonLink, tableIndex ) );
            ButtonLink.appendChild( ButtonText );
 
            Button.appendChild( document.createTextNode( '[' ) );
            Button.appendChild( ButtonLink );
            Button.appendChild( document.createTextNode( ']' ) );
 
            Header.insertBefore( Button, Header.firstChild );
            tableIndex++;
        }
    }
 
    for ( i = 0;  i < tableIndex; i++ ) {
        if ( $( NavigationBoxes[i] ).hasClass( 'collapsed' ) || ( tableIndex >= autoCollapse && $( NavigationBoxes[i] ).hasClass( 'autocollapse' ) ) ) {
            window.collapseTable( i );
        } 
        else if ( $( NavigationBoxes[i] ).hasClass ( 'innercollapse' ) ) {
            var element = NavigationBoxes[i];
            while ((element = element.parentNode)) {
                if ( $( element ).hasClass( 'outercollapse' ) ) {
                    window.collapseTable ( i );
                    break;
                }
            }
        }
    }
}
 
mw.hook( 'wikipage.content' ).add( createCollapseButtons );

-Привет(토론) 2013년 11월 12일 (화) 16:37 (KST)답변