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

편집 요약 없음
편집 요약 없음
36번째 줄: 36번째 줄:
e.stopPropagation();
e.stopPropagation();
showDrawer(this.parentNode.href.split("#")[1], this.textContent);
showDrawer(this.parentNode.href.split("#")[1], this.textContent);
drawer.css({ top: ($(this).offset().top - drawer.offsetHeight), left: $(this).offset().left });
drawer.css({ top: ($(this).offset().top - drawer.outerHeight()), left: $(this).offset().left });
});
});
});
});

2015년 6월 3일 (수) 16:56 판

function showDrawer(id, name) {
	var drawer = document.getElementById("reference-drawer");
	drawer.children[0].href = "#" + id;
	drawer.children[0].setAttribute("data-target", id);
	drawer.children[0].textContent = name;
	drawer.children[1].innerHTML = $("#" + id + " > .reference-text").html();
	drawer.className = "visible";
}

$(document).ready(function($) {
	/* create drawer */
	var drawer = $("<div></div>").attr("id", "reference-drawer");
	var origin = $("<a></a>").attr("id", "reference-origin").click(function() { $('html, body').animate({ scrollTop: ($("#" + $(this).attr("data-target")).offset().top - 60) }, 400); });
	var 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) {
			$("#reference-drawer").removeClass("visible");
		}
	}).scroll(function(e) {
		if ("ontouchstart" in window) {
			$("#reference-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);
		drawer.css({ top: ($(this).offset().top - drawer.outerHeight()), left: $(this).offset().left });
	});
});