|
|
| 1번째 줄: |
1번째 줄: |
| /* 주석 말풍선
| | var isMobile = navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i); |
| * from [[en:MediaWiki:Gadget-ReferenceTooltips.js]]
| | var drawer, origin, content; |
| */
| | function showDrawer(id, name, orgId) { |
| // See [[mw:Reference Tooltips]] | | origin.attr("href", id); |
|
| | origin.attr("data-origin", orgId.replace(/\./g, "\\.")); |
| window.pg || $(document).ready( function($) {
| | origin.text(name); |
|
| | content.html($(id.replace(/\./g, "\\.") + " > .reference-text").html()); |
| // Make sure we are in article, project, or help namespace
| | drawer.addClass("visible"); |
| if ( mw.config.get( 'wgCanonicalNamespace' ) === '' || mw.config.get( 'wgCanonicalNamespace' ) === 'Project' || mw.config.get( 'wgCanonicalNamespace' ) === 'Help' ) {
| | } |
| function toggleRT(o){
| | |
| mw.loader.using("jquery.cookie",function(){
| | function getSettings(key, type) { |
| $.cookie("RTsettings",o+"|"+ settings[1] + "|" + settings[2], {path:"/",expires:90});
| | if ("localStorage" in window) { |
| location.reload();
| | if (type === "boolean") { |
| })
| | return (window.localStorage[key] === "true"); |
| }
| | } else { |
| var settings = document.cookie.split("RTsettings=")[1];
| | return window.localStorage[key]; |
| settings = settings ? settings.split(";")[0].split("%7C") : [1, 200, +("ontouchstart" in document.documentElement)];
| | } |
| if( settings[0] == 0 ) {
| | } else { |
| var footer = $("#footer-places, #f-list");
| | var value = "; " + document.cookie; |
| if( footer.length === 0 ) {
| | var parts = value.split("; " + key + "="); |
| footer = $("#footer li").parent();
| | if (parts.length == 2) { |
| }
| | if (type === "boolean") { |
| footer.append($("<li>").append($("<a>").text("주석 말풍선 켜기").attr("href","javascript:(function(){})()").click(function(){toggleRT(1)})));
| | return (parts.pop().split(";").shift() === "true"); |
| return;
| | } else { |
| }
| | return parts.pop().split(";").shift(); |
| var isTouchscreen = +settings[2],
| | } |
| timerLength = isTouchscreen ? 0 : +settings[1],
| | } |
| settingsMenu;
| | } |
| $(".reference").each( function() {
| | } |
| var tooltipNode, hideTimer, showTimer;
| | |
| function findRef( h ){
| | function setSettings(key, value) { |
| h = h.firstChild.getAttribute("href"); h = h && h.split("#"); h = h && h[1];
| | if ("localStorage" in window) { |
| h = h && document.getElementById( h );
| | window.localStorage[key] = value; |
| h = h && h.nodeName == "LI" && h;
| | } else { |
| return h;
| | var now = new Date(); |
| }
| | var time = now.getTime(); |
| function hide( refLink ){
| | var expireTime = time + (10 * 365 * 24 * 24); |
| if( tooltipNode && tooltipNode.parentNode == document.body ) {
| | now.setTime(expireTime); |
| hideTimer = setTimeout( function() {
| | document.cookie = key + "=" + value + ";expires=" + now.toGMTString() +";path=/"; |
| $(tooltipNode).animate({opacity: 0}, 100, function(){ document.body.removeChild( tooltipNode ) })
| | } |
| }, isTouchscreen ? 16 : 100)
| | } |
| } else {
| | |
| var h = findRef( refLink );
| | function initSettings() { |
| h && (h.style.border = "");
| | if (document.getElementById("reference-settings")) { |
| }
| | $("#reference-settings").show(); |
| }
| | return; |
| function show(){
| | } |
| if( !tooltipNode.parentNode || tooltipNode.parentNode.nodeType === 11 ){
| | var setbox = $("<form>").attr("id", "reference-settings").append( |
| document.body.appendChild( tooltipNode );
| | $("<div>").addClass("content").append( |
| }
| | $("<label>").append( |
| $(tooltipNode).stop().animate({opacity: 1}, 100)
| | $("<input>").attr({"type": "checkbox", "name": "showRefOnHover", "checked": getSettings("showRefOnHover", "boolean")}), |
| clearTimeout( hideTimer );
| | "갖다 대서 주석을 띄웁니다." |
| }
| | ) |
| function openSettingsMenu(){
| | ), |
| if( settingsMenu ) {
| | $("<div>").addClass("foot").append( |
| settingsMenu.dialog( "open" );
| | $("<input>").attr({"type": "button", "value": "취소"}).click(function() { |
| } else {
| | $("#reference-settings").hide(); |
| settingsMenu = $("<form>").append(
| | }), |
| $("<button>").css("width","100%").text("주석 말풍선 끄기").button().click(function(){toggleRT(0)}),
| | $("<input>").addClass("save-settings").attr({"type": "submit", "value": "저장"}) |
| "<br>",
| | ) |
| $("<small>").text("주석 말풍선 기능을 끄면, 이 기능을 문서 아래에 있는 링크를 통해 다시 켤 수 있습니다."),
| | ).submit(function(e) { |
| "<hr>",
| | e.preventDefault(); |
| $("<label>").text("말풍선을 띄울 때까지 걸릴 시간 (밀리초 단위): ").append($("<input>").attr({"type":"number","value":settings[1],step:50,min:0,max:5000})),
| | setSettings("showRefOnHover", $(this).find("[name=showRefOnHover]").is(":checked")); |
| "<br>",
| | location.reload(); |
| $("<span>").text("말풍선을 띄울 방법:"),
| | }); |
| $("<label>").append(
| | $(document.body).append(setbox); |
| $("<input>").attr({"type":"radio", "name":"RTActivate", "checked":settings[2]==0&&"checked", "disabled":"ontouchstart" in document.documentElement&&"disabled"}),
| | } |
| "갖다 대기"
| | |
| ),
| | function showTooltip(elem) { |
| $("<label>").append(
| | showDrawer(elem.parentNode.getAttribute("href"), elem.textContent, elem.parentNode.parentNode.getAttribute("id")); |
| $("<input>").attr({"type":"radio", "name":"RTActivate", "checked":settings[2]==1&&"checked"}),
| | drawer.show(); |
| "클릭하기"
| | drawer.css({ top: ($(elem).offset().top - drawer.outerHeight()), left: $(elem).offset().left }); |
| )
| | drawer.stop().animate({opacity: 1}, 100); |
| ).submit(function(e){e.preventDefault()}).dialog({modal:true,width:500,title:"주석 말풍선 설정",buttons:{"설정 저장하기":function(){
| | } |
| var a = this.getElementsByTagName("input"),
| | |
| b = +a[0].value;
| | function hideTooltip() { |
| $.cookie("RTsettings","1|"+ (b > -1 && b < 5001 ? b : settings[1]) + (a[1].checked ? "|0" : "|1"), {path:"/",expires:90});
| | drawer.removeClass("visible"); |
| location.reload();
| | drawer.animate({opacity: 0}, 100, function() { $(this).hide(); }); |
| }}});
| | } |
| }
| | |
| }
| | $(document).ready(function($) { |
| $(this)[ isTouchscreen ? 'click' : 'hover' ](function( e ){
| | if (getSettings("showRefOnHover") === undefined) { |
| var _this = this;
| | setSettings("showRefOnHover", true); |
| if( isTouchscreen ) {
| | } |
| e.preventDefault();
| | if (isMobile) { |
| (tooltipNode && tooltipNode.parentNode == document.body) || setTimeout( function(){
| | $(document.body).addClass("mode-drawer"); |
| $( document.body ).bind("click touchstart", function( e ) {
| | } else { |
| e = e || event;
| | $(document.body).addClass("mode-tooltip"); |
| e = e.target || e.srcElement;
| | } |
| for( ; e && e.className!="referencetooltip"; )
| | /* create drawer */ |
| e = e.parentNode;
| | drawer = $("<div>").attr("id", "reference-drawer"); |
| if( !e ){
| | origin = $("<a>").attr("id", "reference-origin").click(function() { |
| clearTimeout( showTimer );
| | $('html, body').animate({scrollTop: ($($(this).attr("href")).offset().top - 60)}, 400); |
| hide( _this );
| | }); |
| $(document.body).unbind("click touchstart", arguments.callee)
| | content = $("<span>").attr("id", "reference-drawer-text"); |
| }
| | var settingsIcon = $("<span>").addClass("settings-icon").click(function() { |
| })
| | initSettings(); |
| }, 0);
| | }); |
| }
| | var closeDrawer = $("<span>").addClass("close-icon").click(function() { |
| showTimer && clearTimeout( showTimer );
| | drawer.removeClass("visible"); |
| showTimer = setTimeout( function() {
| | }); |
| var h = findRef( _this );
| | drawer.append(settingsIcon); |
| if( !h ){return};
| | drawer.append(closeDrawer); |
| if( !isTouchscreen && ( window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0 ) + $(window).height() > $( h ).offset().top + h.offsetHeight ) {
| | drawer.append(origin); |
| h.style.border = "#080086 2px solid";
| | drawer.append(content); |
| return;
| | $(document.body).append(drawer); |
| }
| | |
| if(!tooltipNode){
| | $(document).click(function(e) { |
| tooltipNode = document.createElement("ul");
| | if (!$(e.target).closest("#reference-drawer").length) { |
| tooltipNode.className = "referencetooltip";
| | if (!isMobile) { |
| var c = tooltipNode.appendChild( h.cloneNode( true ) );
| | hideTooltip(); |
| try {
| | } else { |
| if( c.firstChild.nodeName != "A" ) {
| | drawer.removeClass("visible"); |
| 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 == " " );
| | } |
| }
| | }).scroll(function(e) { |
| }
| | if ("ontouchstart" in window && isMobile) { |
| } catch (e) { mw.log(e) }
| | drawer.removeClass("visible"); |
| c.removeChild( c.firstChild );
| | } |
| $( tooltipNode.firstChild.insertBefore( document.createElement( "span" ), tooltipNode.firstChild.firstChild ) ).addClass("RTsettings").attr("title", "말풍선").click(function(){
| | }); |
| mw.loader.using(["jquery.cookie","jquery.ui.dialog"], openSettingsMenu);
| | $(".reference a").each(function() { |
| })
| | var span = document.createElement("span"); |
| tooltipNode.appendChild( document.createElement( "li" ) );
| | span.className = "reference-hooker"; |
| isTouchscreen || $(tooltipNode).hover(show, hide);
| | span.appendChild(this.childNodes[0]); |
| }
| | this.appendChild(span); |
| show();
| | }); |
| var o = $(_this).offset(), oH = tooltipNode.offsetHeight;
| | if (getSettings("showRefOnHover", "boolean") && !isMobile) { |
| $(tooltipNode).css({top: o.top - oH, left: o.left - 7 });
| | drawer.hover(function(e) { |
| if( tooltipNode.offsetHeight > oH ) { // is it squished against the right side of the page?
| | showTooltip($("#" + origin.attr("data-origin") + " .reference-hooker").get(0)); |
| $(tooltipNode).css({left:'auto',right:0});
| | }, function(e) { |
| tooltipNode.lastChild.style.marginLeft = (o.left - tooltipNode.offsetLeft) + "px";
| | hideTooltip(); |
| }
| | }); |
| if( o.top < tooltipNode.offsetHeight ) { // is it above the top of the page?
| | $(".reference-hooker").hover(function(e) { |
| $(tooltipNode).addClass("RTflipped").css({top: o.top + 12});
| | showTooltip(this); |
| } else if( tooltipNode.className === "referencetooltip RTflipped" ) { // cancel previous
| | }, function(e) { |
| $(tooltipNode).removeClass("RTflipped");
| | hideTooltip(); |
| }
| | }); |
| }, timerLength);
| | } |
| }, isTouchscreen ? undefined : function(){clearTimeout(showTimer); hide(this); } )
| | $(".reference-hooker").click(function(e) { |
|
| | if (isMobile) { |
| } );
| | e.preventDefault(); |
|
| | e.stopPropagation(); |
| }
| | showDrawer(this.parentNode.getAttribute("href"), this.textContent, this.parentNode.parentNode.getAttribute("id")); |
|
| | drawer.addClass("visible"); |
| } ); | | } else if (!getSettings("showRefOnHover", "boolean")) { |
| | e.preventDefault(); |
| | e.stopPropagation(); |
| | showTooltip(this); |
| | } |
| | }); |
| | }); |