미디어위키:Gadget-ReferenceTooltips-ko.js: 두 판 사이의 차이

편집 요약 없음
편집 요약 없음
1번째 줄: 1번째 줄:
var ref_tags = $("[id^=cite_ref]");
var drawer, origin, content;
$(ref_tags).each(function(index ,iter)
function showDrawer(id, name) {
{
origin.attr("href", "#" + id);
var a = $(iter).children("a")[0];
origin.attr("data-target", id);
var ref_text = $($(a).attr("href")).children(".reference-text")[0];
origin.text(name);
var ref_text = $(ref_text).html();
content.html($("#" + id + " > .reference-text").html());
var baloon = document.createElement("div");
drawer.addClass("visible");
var arrow = document.createElement("div");
}
var inner = document.createElement("div");


baloon.className = "tooltip bottom fade";
$(document).ready(function($) {
arrow.className = "tooltip-arrow";
/* create drawer */
inner.className = "tooltip-inner";
drawer = $("<div></div>").attr("id", "reference-drawer");
$(inner).html(ref_text);
origin = $("<a></a>")
 
.attr("id", "reference-origin")
$(baloon).append(arrow);
.click(function() {
$(baloon).append(inner);
$('html, body').animate({scrollTop: ($("#" + $(this).attr("data-target")).offset().top - 60)}, 400);
});
content = $("<span></span>").attr("id", "reference-drawer-text");
drawer.append(origin);
drawer.append(content);
$(document.body).append(drawer);
iter.tooltip = baloon;
$(document).click(function(e) {
 
if (!$(event.target).closest("#reference-drawer").length) {
$(iter).hover(
if ($(window).width() < 768) {
function(e)
drawer.removeClass("visible");
{
} else {
$('body').after(baloon);
drawer.animate({opacity: 0}, 100, function() { $(this).css({visibility: "hidden", width: 0, height: 0}); });
var baloonWidth = $(baloon).width()/2;
}
var iterWidth = $(iter).width()/2;
}
var where_top = $(iter).offset().top+15;
}).scroll(function(e) {
var where_left = $(iter).offset().left+iterWidth-baloonWidth;
if ("ontouchstart" in window && !$(window).width() < 768) {
 
drawer.removeClass("visible");
$(baloon).css("top",where_top);
}
$(baloon).css("left",where_left);
});
 
$(".reference a").each(function() {
var bal = this.tooltip;
var span = document.createElement("span");
baloon.className = "tooltip bottom fade in";
span.className = "reference-hooker";
},
span.appendChild(this.childNodes[0]);
function(e)
this.appendChild(span);
{
});
var bal = this.tooltip;
$(".reference-hooker").click(function(e) {
baloon.className = "tooltip bottom fade";
e.preventDefault();
$(baloon).delay(250).queue(function() { $(this).remove(); });
e.stopPropagation();
showDrawer(this.parentNode.href.split("#")[1], this.textContent);
if ($(window).width() < 768) {
drawer.addClass("visible");
} else {
drawer.css({visibility: "visible", width: "auto", height: "auto"});
drawer.css({ top: ($(this).offset().top - drawer.outerHeight()), left: $(this).offset().left });
drawer.stop().animate({opacity: 1}, 100);
}
}
);
});
});
});

2015년 6월 4일 (목) 00:20 판

var drawer, origin, content;
function showDrawer(id, name) {
	origin.attr("href", "#" + id);
	origin.attr("data-target", id);
	origin.text(name);
	content.html($("#" + id + " > .reference-text").html());
	drawer.addClass("visible");
}

$(document).ready(function($) {
	/* create drawer */
	drawer = $("<div></div>").attr("id", "reference-drawer");
	origin = $("<a></a>")
	.attr("id", "reference-origin")
	.click(function() {
		$('html, body').animate({scrollTop: ($("#" + $(this).attr("data-target")).offset().top - 60)}, 400);
	});
	content = $("<span></span>").attr("id", "reference-drawer-text");
	drawer.append(origin);
	drawer.append(content);
	$(document.body).append(drawer);
	
	$(document).click(function(e) {
		if (!$(event.target).closest("#reference-drawer").length) {
			if ($(window).width() < 768) {
				drawer.removeClass("visible");
			} else {
				drawer.animate({opacity: 0}, 100, function() { $(this).css({visibility: "hidden", width: 0, height: 0}); });
			}
		}
	}).scroll(function(e) {
		if ("ontouchstart" in window && !$(window).width() < 768) {
			drawer.removeClass("visible");
		}
	});
	$(".reference a").each(function() {
		var span = document.createElement("span");
		span.className = "reference-hooker";
		span.appendChild(this.childNodes[0]);
		this.appendChild(span);
	});
	$(".reference-hooker").click(function(e) {
		e.preventDefault();
		e.stopPropagation();
		showDrawer(this.parentNode.href.split("#")[1], this.textContent);
		if ($(window).width() < 768) {
			drawer.addClass("visible");
		} else {
			drawer.css({visibility: "visible", width: "auto", height: "auto"});
			drawer.css({ top: ($(this).offset().top - drawer.outerHeight()), left: $(this).offset().left });
			drawer.stop().animate({opacity: 1}, 100);
		}
	});
});