사용자:Senior9324/Gadget-ReferenceDrawerDev.js: 두 판 사이의 차이

편집 요약 없음
편집 요약 없음
30번째 줄: 30번째 줄:
}).scroll(function(e) {
}).scroll(function(e) {
if ("ontouchstart" in window && !$(window).width() < 768) {
if ("ontouchstart" in window && !$(window).width() < 768) {
$("#reference-drawer").animate({marginTop: 0}, 250, function() { $(this).remove(); });
$("#reference-drawer").slideUp(250, function() { $(this).remove(); });
}
}
});
});

2015년 6월 3일 (수) 18:32 판

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());
	$(document.body).append(drawer);
}

$(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).click(function(e) {
		if (!$(event.target).closest("#reference-drawer").length) {
			if ($(window).width() < 768) {
				$("#reference-drawer").slideUp(250, function() { $(this).remove(); });
			} else {
				$("#reference-drawer").animate({opacity: 0}, 100, function() { $(this).remove(); });
			}
		}
	}).scroll(function(e) {
		if ("ontouchstart" in window && !$(window).width() < 768) {
			$("#reference-drawer").slideUp(250, function() { $(this).remove(); });
		}
	});
	$(".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) {
			$("#reference-drawer").stop().slideDown(250);
		} else {
			drawer.css({ top: ($(this).offset().top - drawer.outerHeight()), left: $(this).offset().left });
			$("#reference-drawer").stop().animate({opacity: 1}, 100);
		}
	});
});