"미디어위키:Common.js"의 두 판 사이의 차이

누리위키, 온 누리의 백과사전
잔글
잔글 (testing2)
296번째 줄: 296번째 줄:
 
     mw.loader.load('https://secure.wikimedia.org/wikipedia/en/w/index.php?title=MediaWiki:Common.js/secure.js&action=raw&ctype=text/javascript');
 
     mw.loader.load('https://secure.wikimedia.org/wikipedia/en/w/index.php?title=MediaWiki:Common.js/secure.js&action=raw&ctype=text/javascript');
 
}
 
}
 +
 +
// Reference Tooltips by Yair_rand (Wikipedia)
 +
// lines for RTsettings button & ref box highlight are replaced.
 +
window.pg || $(document).ready(function ($) {
 +
 +
// Make sure we are in article, project, or help namespace
 +
if (wgCanonicalNamespace === '' || wgCanonicalNamespace === 'Project' || wgCanonicalNamespace === 'Help') {
 +
function toggleRT(o) {
 +
mw.loader.using("jquery.cookie", function () {
 +
$.cookie("RTsettings", o + "|" + settings[1] + "|" + settings[2], {
 +
path: "/",
 +
expires: 90
 +
});
 +
location.reload();
 +
})
 +
}
 +
var settings = document.cookie.split("RTsettings=")[1];
 +
settings = settings ? settings.split(";")[0].split("%7C") : [1, 200, +("ontouchstart" in document.documentElement)];
 +
var isTouchscreen = +settings[2],
 +
timerLength = isTouchscreen ? 0 : +settings[1],
 +
settingsMenu,
 +
R;
 +
$(".reference").each(R = function () {
 +
var tooltipNode, hideTimer, showTimer, checkFlip = false;
 +
 +
function findRef(h) {
 +
h = h.firstChild;
 +
h = h && h.getAttribute && h.getAttribute("href");
 +
h = h && h.split("#");
 +
h = h && h[1];
 +
h = h && document.getElementById(h);
 +
h = h && h.nodeName == "LI" && h;
 +
return h;
 +
}
 +
 +
function hide(refLink) {
 +
if (tooltipNode && tooltipNode.parentNode == document.body) {
 +
hideTimer = setTimeout(function () {
 +
$(tooltipNode).animate({
 +
opacity: 0
 +
}, 100, function () {
 +
document.body.removeChild(tooltipNode)
 +
})
 +
}, isTouchscreen ? 16 : 100)
 +
} else {
 +
$(findRef(refLink)).removeClass("RTTarget");
 +
}
 +
}
 +
 +
function show() {
 +
if (!tooltipNode.parentNode || tooltipNode.parentNode.nodeType === 11) {
 +
document.body.appendChild(tooltipNode);
 +
checkFlip = true;
 +
}
 +
$(tooltipNode).stop().animate({
 +
opacity: 1
 +
}, 100)
 +
clearTimeout(hideTimer);
 +
}
 +
 +
$(this)[isTouchscreen ? 'click' : 'hover'](function (e) {
 +
var _this = this;
 +
if (isTouchscreen) {
 +
e.preventDefault();
 +
(tooltipNode && tooltipNode.parentNode == document.body) || setTimeout(function () {
 +
$(document.body).on("click touchstart", function (e) {
 +
e = e || event;
 +
e = e.target || e.srcElement;
 +
for (; e && !$(e).hasClass("referencetooltip");)
 +
e = e.parentNode;
 +
if (!e) {
 +
clearTimeout(showTimer);
 +
hide(_this);
 +
$(document.body).off("click touchstart", arguments.callee)
 +
}
 +
})
 +
}, 0);
 +
}
 +
hideTimer && clearTimeout(hideTimer);
 +
showTimer && clearTimeout(showTimer);
 +
showTimer = setTimeout(function () {
 +
var h = findRef(_this);
 +
if (!h) {
 +
return
 +
};
 +
// Hightlight the reference when the ref is entirely on the screen.
 +
// if (!isTouchscreen && (window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0) + $(window).height() > $(h).offset().top +
 +
// h.offsetHeight) {
 +
// $(h).addClass("RTTarget");
 +
// return;
 +
// }
 +
if (!tooltipNode) {
 +
tooltipNode = document.createElement("ul");
 +
tooltipNode.className = "referencetooltip";
 +
var c = tooltipNode.appendChild(h.cloneNode(true));
 +
$(".reference", c).each(R);
 +
try {
 +
if (c.firstChild.nodeName != "A") {
 +
while (c.childNodes[1].nodeName == "A" && c.childNodes[1].getAttribute("href").indexOf("#cite_ref-") !== -1) {
 +
do {
 +
c.removeChild(c.childNodes[1])
 +
} while (c.childNodes[1].nodeValue == " ");
 +
}
 +
}
 +
} catch (e) {
 +
mw.log(e)
 +
}
 +
c.removeChild(c.firstChild);
 +
tooltipNode.appendChild(document.createElement("li"));
 +
isTouchscreen || $(tooltipNode).hover(show, hide);
 +
}
 +
show();
 +
var o = $(_this).offset(),
 +
oH = tooltipNode.offsetHeight;
 +
$(tooltipNode).css({
 +
top: o.top - oH,
 +
left: o.left - 7
 +
});
 +
if (tooltipNode.offsetHeight > oH) { // is it squished against the right side of the page?
 +
$(tooltipNode).css({
 +
left: 'auto',
 +
right: 0
 +
});
 +
tooltipNode.lastChild.style.marginLeft = (o.left - tooltipNode.offsetLeft) + "px";
 +
}
 +
if (checkFlip) {
 +
if (o.top < tooltipNode.offsetHeight + (window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0)) { // is part of it above the top of the screen?
 +
$(tooltipNode).addClass("RTflipped").css({
 +
top: o.top + 12
 +
});
 +
} else if (tooltipNode.className === "referencetooltip RTflipped") { // cancel previous
 +
$(tooltipNode).removeClass("RTflipped");
 +
}
 +
checkFlip = false;
 +
}
 +
}, timerLength);
 +
}, isTouchscreen ? undefined : function () {
 +
clearTimeout(showTimer);
 +
hide(this);
 +
})
 +
});
 +
}
 +
});

2013년 8월 16일 (금) 20:14 판

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

// Overwriting deprecated functions that have a follower that (also) accepts the same syntax:
// from [[commons:MediaWiki:Common.js]]
window.addPortletLink = mw.util.addPortletLink;
window.getParamValue = mw.util.getParamValue;

// Import more specific scripts if necessary

if( wgNamespaceNumber == 6 ) {
    importScript('MediaWiki:Common.js/file.js');
}
 
/* 관리자용 css/js 불러오기.
 * [[en:MediaWiki:Common.js]]에서.
 * 관리자일 경우 [[MediaWiki:Sysop.js]]를 불러오는 기능입니다.
 */
if ( $.inArray( 'sysop', wgUserGroups) > -1 ) {
 importStylesheet('MediaWiki:Sysop.css');
 if ( !window.disableSysopJS ) {
  $(function(){
   importScript('MediaWiki:Sysop.js');
  });
 }
}

/* from en: */
/* Test if an element has a certain class
 *
 * @deprecated:  Use $(element).hasClass() instead.
 */
 
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
 *               [[:en:Wikipedia:NavFrame]].
 *  Maintainers: [[:en:User:R. Koot]]
 */
 
var autoCollapse = 2;
var collapseCaption = "숨기기";
var expandCaption = "보이기";
 
function collapseTable( 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.childNodes[0] );
            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 [[:en: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
function toggleNavigationBar(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 );


/*
알찬 글과 좋은 글에 별표 붙이는 스크립트
*/
function LinkFA() 
{
    if ( document.getElementById( "p-lang" ) ) {
        var InterwikiLinks = document.getElementById( "p-lang" ).getElementsByTagName( "li" );
 
        for ( var i = 0; i < InterwikiLinks.length; i++ ) {
            if ( document.getElementById( InterwikiLinks[i].className + "-fa" ) ) {
                InterwikiLinks[i].className += " FA"
                InterwikiLinks[i].title = "알찬 글로 선정되었습니다.";
            } else if ( document.getElementById( InterwikiLinks[i].className + "-ga" ) ) {
                InterwikiLinks[i].className += " GA"
                InterwikiLinks[i].title = "좋은 글로 선정되었습니다.";
            }
        }
    }
}
 
$( LinkFA );

/* 대문의 "프로젝트" 탭을 "대문"으로 바꿉니다.
- 영어 위키백과 common.js의 main page 스크립트를 약간 변형 */

if (wgPageName == "누리위키:대문" || wgPageName == "누리위키토론:대문") {
 $(function () {
        var nstab = document.getElementById('ca-nstab-project');
        if (nstab) {
            while (nstab.firstChild) { nstab = nstab.firstChild; }
            nstab.nodeValue = '대문';
        }
    });
}

/***** 그림 정보 틀을 자동으로 불러옴 ********
 * 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');
}

/* 인터랙티브 지도. 영어 위키백과에서 가져옴. -- [[사용자: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]]
  */
 
var metaBase = '//meta.wikimedia.org';

mw.loader.load(metaBase + '/w/index.php?title=MediaWiki:Wikiminiatlas.js&action=raw&ctype=text/javascript&smaxage=21600&maxage=86400');

/* 보안 서버 링크 스크립트
 * 보안 서버에 있을 때 일반 링크를 보안 서버 링크로 변경하여 일반 서버 접속으로 전환되는 것을 최소화
 * [[미디어위키토론:Common.js#보안 서버용 스크립트]]
 * [[사용자:IRTC1015]] 2011년 1월 9일 (일) 23:06 (KST)
 */
if (wgServer == "https://secure.wikimedia.org") {
    mw.loader.load('https://secure.wikimedia.org/wikipedia/en/w/index.php?title=MediaWiki:Common.js/secure.js&action=raw&ctype=text/javascript');
}

// Reference Tooltips by Yair_rand (Wikipedia)
// lines for RTsettings button & ref box highlight are replaced.
window.pg || $(document).ready(function ($) {

	// Make sure we are in article, project, or help namespace
	if (wgCanonicalNamespace === '' || wgCanonicalNamespace === 'Project' || wgCanonicalNamespace === 'Help') {
		function toggleRT(o) {
			mw.loader.using("jquery.cookie", function () {
				$.cookie("RTsettings", o + "|" + settings[1] + "|" + settings[2], {
					path: "/",
					expires: 90
				});
				location.reload();
			})
		}
		var settings = document.cookie.split("RTsettings=")[1];
		settings = settings ? settings.split(";")[0].split("%7C") : [1, 200, +("ontouchstart" in document.documentElement)];
		var isTouchscreen = +settings[2],
			timerLength = isTouchscreen ? 0 : +settings[1],
			settingsMenu,
			R;
		$(".reference").each(R = function () {
			var tooltipNode, hideTimer, showTimer, checkFlip = false;

			function findRef(h) {
				h = h.firstChild;
				h = h && h.getAttribute && h.getAttribute("href");
				h = h && h.split("#");
				h = h && h[1];
				h = h && document.getElementById(h);
				h = h && h.nodeName == "LI" && h;
				return h;
			}

			function hide(refLink) {
				if (tooltipNode && tooltipNode.parentNode == document.body) {
					hideTimer = setTimeout(function () {
						$(tooltipNode).animate({
							opacity: 0
						}, 100, function () {
							document.body.removeChild(tooltipNode)
						})
					}, isTouchscreen ? 16 : 100)
				} else {
					$(findRef(refLink)).removeClass("RTTarget");
				}
			}

			function show() {
				if (!tooltipNode.parentNode || tooltipNode.parentNode.nodeType === 11) {
					document.body.appendChild(tooltipNode);
					checkFlip = true;
				}
				$(tooltipNode).stop().animate({
					opacity: 1
				}, 100)
				clearTimeout(hideTimer);
			}

			$(this)[isTouchscreen ? 'click' : 'hover'](function (e) {
				var _this = this;
				if (isTouchscreen) {
					e.preventDefault();
					(tooltipNode && tooltipNode.parentNode == document.body) || setTimeout(function () {
						$(document.body).on("click touchstart", function (e) {
							e = e || event;
							e = e.target || e.srcElement;
							for (; e && !$(e).hasClass("referencetooltip");)
								e = e.parentNode;
							if (!e) {
								clearTimeout(showTimer);
								hide(_this);
								$(document.body).off("click touchstart", arguments.callee)
							}
						})
					}, 0);
				}
				hideTimer && clearTimeout(hideTimer);
				showTimer && clearTimeout(showTimer);
				showTimer = setTimeout(function () {
					var h = findRef(_this);
					if (!h) {
						return
					};
					// Hightlight the reference when the ref is entirely on the screen.
					// if (!isTouchscreen && (window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0) + $(window).height() > $(h).offset().top +
					//	h.offsetHeight) {
					//	$(h).addClass("RTTarget");
					//	return;
					// }
					if (!tooltipNode) {
						tooltipNode = document.createElement("ul");
						tooltipNode.className = "referencetooltip";
						var c = tooltipNode.appendChild(h.cloneNode(true));
						$(".reference", c).each(R);
						try {
							if (c.firstChild.nodeName != "A") {
								while (c.childNodes[1].nodeName == "A" && c.childNodes[1].getAttribute("href").indexOf("#cite_ref-") !== -1) {
									do {
										c.removeChild(c.childNodes[1])
									} while (c.childNodes[1].nodeValue == " ");
								}
							}
						} catch (e) {
							mw.log(e)
						}
						c.removeChild(c.firstChild);
						tooltipNode.appendChild(document.createElement("li"));
						isTouchscreen || $(tooltipNode).hover(show, hide);
					}
					show();
					var o = $(_this).offset(),
						oH = tooltipNode.offsetHeight;
					$(tooltipNode).css({
						top: o.top - oH,
						left: o.left - 7
					});
					if (tooltipNode.offsetHeight > oH) { // is it squished against the right side of the page?
						$(tooltipNode).css({
							left: 'auto',
							right: 0
						});
						tooltipNode.lastChild.style.marginLeft = (o.left - tooltipNode.offsetLeft) + "px";
					}
					if (checkFlip) {
						if (o.top < tooltipNode.offsetHeight + (window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0)) { // is part of it above the top of the screen?
							$(tooltipNode).addClass("RTflipped").css({
								top: o.top + 12
							});
						} else if (tooltipNode.className === "referencetooltip RTflipped") { // cancel previous
							$(tooltipNode).removeClass("RTflipped");
						}
						checkFlip = false;
					}
				}, timerLength);
			}, isTouchscreen ? undefined : function () {
				clearTimeout(showTimer);
				hide(this);
			})
		});
	}
});