미디어위키:Common.js

풋케위키, 대한민국 대표 축구위키 FootballK WIKI-
Elofwind (토론 | 기여)님의 2012년 3월 10일 (토) 09:32 판 (숨기기/펼치기 관련 js 수정)
둘러보기로 이동 검색으로 이동

참고: 설정을 저장한 후에 바뀐 점을 확인하기 위해서는 브라우저의 캐시를 새로 고쳐야 합니다.

  • 파이어폭스 / 사파리: Shift 키를 누르면서 새로 고침을 클릭하거나, Ctrl-F5 또는 Ctrl-R을 입력 (Mac에서는 ⌘-R)
  • 구글 크롬: Ctrl-Shift-R키를 입력 (Mac에서는 ⌘-Shift-R)
  • 인터넷 익스플로러: Ctrl 키를 누르면서 새로 고침을 클릭하거나, Ctrl-F5를 입력.
  • 오페라: 메뉴 → 설정(맥의 경우 오페라 → 환경 설정)으로 이동한 다음 개인 정보 보호 및 보안 → 검색 데이터 지우기 → 캐시한 영상 및 파일을 누름.
/**
 * 이 스크립트는 위키백과 전체에 적용됩니다. 고칠 때는 주의해주세요.
 * [[위키백과:위키프로젝트 시스템]] 참고
 *
 * 스크립트를 넣을 때는 충분한 설명, 출처를 넣어주세요! 이후 관리가 어려워집니다.
 **/

/*
[[en:MediaWiki:Common.js]]에서.
관리자일 경우 [[MediaWiki:Sysop.js]]를 불러오는 기능입니다.
*/
if ( wgUserGroups ) {
  for ( var g = 0; g < wgUserGroups.length; ++g ) {
    if ( wgUserGroups[g] == "sysop" ) {
      importStylesheet("MediaWiki:Sysop.css");
      addOnloadHook( function() {
        if ( !window.disableSysopJS ) {
          importScript("MediaWiki:Sysop.js");
        }
      } );
    }
  }
}

/* from en: */
var hasClass = (function () {
    var reCache = {};
    return function (element, className) {
        return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);
    };
})();

/* ([[위키백과:관리자 요청/2007년 5월#스크립트 추가 요청]]) */
/** Collapsible tables *********************************************************
 *
 *  Description: Allows tables to be collapsed, showing only the header. See
 *               [[Wikipedia:NavFrame]].
 *  Maintainers: [[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;

    if ( Button.firstChild.data == collapseCaption ) {
        for ( var i = 1; i < Rows.length; i++ ) {
            Rows[i].style.display = "none";
        }
        Button.firstChild.data = expandCaption;
    } else {
        for ( var 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 = new Object();
    var Tables = document.getElementsByTagName( "table" );

    for ( var i = 0; i < Tables.length; i++ ) {
        if ( hasClass( Tables[i], "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", "#" );
            addHandler( ButtonLink,  "click", new Function( "evt", "collapseTable(" + tableIndex + " ); return killEvt( evt );") );
            ButtonLink.appendChild( ButtonText );

            Button.appendChild( document.createTextNode( "[" ) );
            Button.appendChild( ButtonLink );
            Button.appendChild( document.createTextNode( "]" ) );

            Header.insertBefore( Button, Header.firstChild );
            tableIndex++;
        }
    }

    for ( var i = 0;  i < tableIndex; i++ ) {
        if ( hasClass( NavigationBoxes[i], "collapsed" ) || ( tableIndex >= autoCollapse && hasClass( NavigationBoxes[i], "autocollapse" ) ) ) {
            collapseTable( i );
        } 
        else if ( hasClass( NavigationBoxes[i], "innercollapse" ) ) {
            var element = NavigationBoxes[i];
            while (element = element.parentNode) {
                if ( hasClass( element, "outercollapse" ) ) {
                    collapseTable ( i );
                    break;
                }
            }
        }
    }
}

$( createCollapseButtons );


/* ([[위키백과:관리자 요청/2007년 5월#스크립트 추가 요청]]) */
/** Dynamic Navigation Bars (experimental) *************************************
 *
 *  Description: See [[Wikipedia:NavFrame]].
 *  Maintainers: UNMAINTAINED
 */

// set up the words in your language
var NavigationBarHide = '[' + collapseCaption + ']';
var NavigationBarShow = '[' + expandCaption + ']';

// shows and hides content and picture (if available) of navigation bars
// Parameters:
//     indexNavigationBar: the index of navigation bar to be toggled
window.toggleNavigationBar = function(indexNavigationBar){
    var NavToggle = document.getElementById("NavToggle" + indexNavigationBar);
    var NavFrame = document.getElementById("NavFrame" + indexNavigationBar);

    if (!NavFrame || !NavToggle) {
        return false;
    }

    // if shown now
    if (NavToggle.firstChild.data == NavigationBarHide) {
        for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
            if (hasClass(NavChild, 'NavContent') || hasClass(NavChild, 'NavPic')) {
                NavChild.style.display = 'none';
            }
        }
    NavToggle.firstChild.data = NavigationBarShow;

    // if hidden now
    } else if (NavToggle.firstChild.data == NavigationBarShow) {
        for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
            if (hasClass(NavChild, 'NavContent') || hasClass(NavChild, 'NavPic')) {
                NavChild.style.display = 'block';
            }
        }
        NavToggle.firstChild.data = NavigationBarHide;
    }
}

// adds show/hide-button to navigation bars
function createNavigationBarToggleButton(){
    var indexNavigationBar = 0;
    // iterate over all < div >-elements 
    var divs = document.getElementsByTagName("div");
    for (var i = 0; NavFrame = divs[i]; i++) {
        // if found a navigation bar
        if (hasClass(NavFrame, "NavFrame")) {

            indexNavigationBar++;
            var NavToggle = document.createElement("a");
            NavToggle.className = 'NavToggle';
            NavToggle.setAttribute('id', 'NavToggle' + indexNavigationBar);
            NavToggle.setAttribute('href', 'javascript:toggleNavigationBar(' + indexNavigationBar + ');');

            var isCollapsed = hasClass( NavFrame, "collapsed" );
            /*
             * Check if any children are already hidden.  This loop is here for backwards compatibility:
             * the old way of making NavFrames start out collapsed was to manually add style="display:none"
             * to all the NavPic/NavContent elements.  Since this was bad for accessibility (no way to make
             * the content visible without JavaScript support), the new recommended way is to add the class
             * "collapsed" to the NavFrame itself, just like with collapsible tables.
             */
            for (var NavChild = NavFrame.firstChild; NavChild != null && !isCollapsed; NavChild = NavChild.nextSibling) {
                if ( hasClass( NavChild, 'NavPic' ) || hasClass( NavChild, 'NavContent' ) ) {
                    if ( NavChild.style.display == 'none' ) {
                        isCollapsed = true;
                    }
                }
            }
            if (isCollapsed) {
                for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
                    if ( hasClass( NavChild, 'NavPic' ) || hasClass( NavChild, 'NavContent' ) ) {
                        NavChild.style.display = 'none';
                    }
                }
            }
            var NavToggleText = document.createTextNode(isCollapsed ? NavigationBarShow : NavigationBarHide);
            NavToggle.appendChild(NavToggleText);

            // Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked)
            for(var j=0; j < NavFrame.childNodes.length; j++) {
                if (hasClass(NavFrame.childNodes[j], "NavHead")) {
                    NavToggle.style.color = NavFrame.childNodes[j].style.color;
                    NavFrame.childNodes[j].appendChild(NavToggle);
                }
            }
            NavFrame.setAttribute('id', 'NavFrame' + indexNavigationBar);
        }
    }
}

$( createNavigationBarToggleButton );
 


/* ([[위키백과:관리자 요청/2007년 5월#스크립트 추가 요청]]) */
/** "Technical restrictions" title fix *****************************************
  *
  *  Description:
  *  Maintainers: [[User:Interiot]], [[User:Mets501]]
  */
 
// For pages that have something like Template:Lowercase, replace the title, but only if it is cut-and-pasteable as a valid wikilink.
//        (for instance [[iPod]]'s title is updated.  <nowiki>But [[C#]] is not an equivalent wikilink, so [[C Sharp]] doesn't have its main title changed)</nowiki>
//
// The function looks for a banner like this: <nowiki>
// <div id="RealTitleBanner">    <!-- div that gets hidden -->
//   <span id="RealTitle">title</span>
// </div>
// </nowiki>An element with id=DisableRealTitle disables the function.
var disableRealTitle = 0;                // users can disable this by making this true from their monobook.js
if (wgIsArticle) {                        // don't display the RealTitle when editing, since it is apparently inconsistent (doesn't show when editing sections, doesn't show when not previewing)
     addOnloadHook(function() {
        try {
                var realTitleBanner = document.getElementById("RealTitleBanner");
                if (realTitleBanner && !document.getElementById("DisableRealTitle") && !disableRealTitle) {
                        var realTitle = document.getElementById("RealTitle");
                        if (realTitle) {
                                var realTitleHTML = realTitle.innerHTML;
                                realTitleText = pickUpText(realTitle);
 
                                var isPasteable = 0;
                                //var containsHTML = /</.test(realTitleHTML);        // contains ANY HTML
                                var containsTooMuchHTML = /</.test( realTitleHTML.replace(/<\/?(sub|sup|small|big)>/gi, "") ); // contains HTML that will be ignored when cut-n-pasted as a wikilink
                                // calculate whether the title is pasteable
                                var verifyTitle = realTitleText.replace(/^ +/, "");                // trim left spaces
                                verifyTitle = verifyTitle.charAt(0).toUpperCase() + verifyTitle.substring(1, verifyTitle.length);        // uppercase first character
 
                                // if the namespace prefix is there, remove it on our verification copy.  If it isn't there, add it to the original realValue copy.
                                if (wgNamespaceNumber != 0) {
                                        if (wgCanonicalNamespace == verifyTitle.substr(0, wgCanonicalNamespace.length).replace(/ /g, "_") && verifyTitle.charAt(wgCanonicalNamespace.length) == ":") {
                                                verifyTitle = verifyTitle.substr(wgCanonicalNamespace.length + 1);
                                        } else {
                                                realTitleText = wgCanonicalNamespace.replace(/_/g, " ") + ":" + realTitleText;
                                                realTitleHTML = wgCanonicalNamespace.replace(/_/g, " ") + ":" + realTitleHTML;
                                        }
                                }
 
                                // verify whether wgTitle matches
                                verifyTitle = verifyTitle.replace(/^ +/, "").replace(/ +$/, "");                // trim left and right spaces
                                verifyTitle = verifyTitle.replace(/_/g, " ");                // underscores to spaces
                                verifyTitle = verifyTitle.charAt(0).toUpperCase() + verifyTitle.substring(1, verifyTitle.length);        // uppercase first character
                                isPasteable = (verifyTitle == wgTitle);
 
                                var h1 = document.getElementsByTagName("h1")[0];
                                if (h1 && isPasteable) {
                                        h1.innerHTML = containsTooMuchHTML ? realTitleText : realTitleHTML;
                                        if (!containsTooMuchHTML)
                                                realTitleBanner.style.display = "none";
                                }
                                document.title = realTitleText + " - Wikipedia, the free encyclopedia";
                        }
                }
        } catch (e) {
                /* Something went wrong. */
        }
     });
}
 
 
// similar to innerHTML, but only returns the text portions of the insides, excludes HTML
function pickUpText(aParentElement) {
   var str = "";
 
   function pickUpTextInternal(aElement) {
     var child = aElement.firstChild;
     while (child) {
       if (child.nodeType == 1)                // ELEMENT_NODE 
         pickUpTextInternal(child);
       else if (child.nodeType == 3)        // TEXT_NODE
         str += child.nodeValue;
 
       child = child.nextSibling;
     }
   }
 
   pickUpTextInternal(aParentElement);
 
   return str;
}

// [[위키백과:사랑방/2007년 10월#미리 보기 강제 실시]] 참고
// 소스: 프랑스어 위키백과
/**
  * Force IP to preview before saving changes.
  * Copyright Marc Mongenet, 2006
  */
function forcePreview() {
  if (wgUserName != null || wgAction != "edit") return;
  saveButton = document.getElementById("wpSave");
  if (!saveButton) return;
  saveButton.disabled = true;
  saveButton.value = "저장 (미리 보기 후)";
  saveButton.style.fontWeight = "normal";
  document.getElementById("wpPreview").style.fontWeight = "bold";
}
addOnloadHook(forcePreview);

/*
알찬 글에 별표 붙이는 스크립트
*/
function LinkFA() 
{
    // iterate over all <span>-elements
    for(var i=0; a = document.getElementsByTagName("span")[i]; i++) {
 
       // if found a FA span
       if(a.className == "FA") {
       var InterwikiLinks = document.getElementById( "p-lang" ).getElementsByTagName( "li" );
 
          for ( var j = 0; j < InterwikiLinks.length; j++ ) {
             if ( InterwikiLinks[j].className == "interwiki-"+a.id){
                InterwikiLinks[j].className += " FA"
                InterwikiLinks[j].title = "이 문서는 알찬 글로 선정되었습니다."
             }
          }
       }
    }
}
addOnloadHook(LinkFA);

/* 대문의 "프로젝트" 탭을 "대문"으로 바꿉니다. */

function MainPageRenameNamespaceTab() {
  try {
    var node = document.getElementById('ca-nstab-project').firstChild;
    node.innerHTML = "<span>대문</span>";
  } catch(e) {
  }
}
 
if (wgPageName == "위키백과:대문" || wgPageName == "위키백과토론:대문") {
  addOnloadHook(MainPageRenameNamespaceTab);
}
 
/***** 그림 정보 틀을 자동으로 불러옴 ********
 * Adds a link to subpages of current page
 * from commons.wikimedia.org
 *  Maintainers: [[User:Yonidebest]], [[User:Dschwen]]
 *  [[사용자:Kwj2772]]가 수정
 *  JSconfig items: bool 'loadAutoInformationTemplate'
 *                       (true=enabled (default), false=disabled)
 * JSConfig를 사용하지 않도록 수정함. --[[사용자:Klutzy|klutzy]] ([[사용자토론:Klutzy|토론]]) 2009년 9월 27일 (일) 20:33 (KST)
 ****/
if (wgCanonicalSpecialPageName == 'Upload') {
  importScript('MediaWiki:Upload.js');
}

/*
[[위키백과:사랑방/2009년 제28주#부분 편집 링크 위치 변경 제안]]
독일어 위키백과(de:Benutzer:Dbenzhuser)에서 가져와 fontSize 고침 
비활성화하려면, [[특수기능:Mypage/monobook.js]]에서 var oldEditsectionLinks = true; 을 추가해주세요.
*/
addOnloadHook(function() {
    if (typeof oldEditsectionLinks != 'undefined' && oldEditsectionLinks)   return;
    var spans = document.getElementsByTagName("span");
    for (var i=0; i<spans.length; i++) {
        var span = spans[i];
        if (span.className != "editsection")    continue;
        span.style.fontSize = "small";
        span.style.fontWeight = "normal";
        span.style.styleFloat = "none"; // IE-Fix für die folgende Zeile
        span.style.cssFloat = "none";
        span.style.marginLeft = "0px";
        span.parentNode.appendChild(document.createTextNode(" "));
        span.parentNode.appendChild(span);
    }
});


/* 인터랙티브 지도. 영어 위키백과에서 가져옴. -- [[사용자:ChongDae]] 2010년 3월 28일 (일) 02:08 (KST) */
/** WikiMiniAtlas *******************************************************
  *
  *  Description: WikiMiniAtlas is a popup click and drag world map.
  *               This script causes all of our coordinate links to display the WikiMiniAtlas popup button.
  *               The script itself is located on meta because it is used by many projects.
  *               See [[Meta:WikiMiniAtlas]] for more information. 
  *  Maintainers: [[User:Dschwen]]
  */
 
if (wgServer == "https://secure.wikimedia.org") {
    var metaBase = "https://secure.wikimedia.org/wikipedia/meta";
} else {
    var metaBase = "http://meta.wikimedia.org";
}
importScriptURI(metaBase+"/w/index.php?title=MediaWiki:Wikiminiatlas.js&action=raw&ctype=text/javascript&smaxage=21600&maxage=86400")


/* 이 자바스크립트 설정은 모든 문서, 모든 사용자에게 적용됩니다. */