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

편집 요약 없음
편집 요약 없음
1번째 줄: 1번째 줄:
var drawer;
//$(window).width()
function showDrawer(id, name) {
function showDrawer(id, name) {
var drawer = document.getElementById("reference-drawer");
drawer.first().attr("href", "#" + id);
drawer.children[0].href = "#" + id;
drawer.first().attr("data-target", id);
drawer.children[0].setAttribute("data-target", id);
drawer.first().text(name);
drawer.children[0].textContent = name;
drawer.find("#reference-drawer-text").html($("#" + id + " > .reference-text").html());
drawer.children[1].innerHTML = $("#" + id + " > .reference-text").html();
$(document.body).append(drawer);
drawer.className = "visible";
}
}


$(document).ready(function($) {
$(document).ready(function($) {
/* create drawer */
/* create drawer */
var drawer = $("<div></div>").attr("id", "reference-drawer");
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 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");
var content = $("<span></span>").attr("id", "reference-drawer-text");
drawer.append(origin);
drawer.append(origin);
drawer.append(content);
drawer.append(content);
$(document.body).append(drawer);
$(document).click(function(e) {
$(document).click(function(e) {
if (!$(event.target).closest("#reference-drawer").length) {
if (!$(event.target).closest("#reference-drawer").length) {
$("#reference-drawer").removeClass("visible");
if ($(window).width() > 768) {
$("#reference-drawer").animate({margin-top: 0}, 250, function() { $(this).remove(); });
} else {
$("#reference-drawer").animate({opacity: 0}, 250, function() { $(this).remove(); });
}
}
}
}).scroll(function(e) {
}).scroll(function(e) {
if ("ontouchstart" in window) {
if ("ontouchstart" in window && !$(window).width() > 768) {
$("#reference-drawer").removeClass("visible");
$("#reference-drawer").animate({opacity: 0}, 250, function() { $(this).remove(); });
}
}
});
});
36번째 줄: 40번째 줄:
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.outerHeight()), left: $(this).offset().left });
if ($(window).width() > 768) {
$("#reference-drawer").animate({margin-top: drawer.outerHeight() * -1}, 250);
} else {
drawer.css({ top: ($(this).offset().top - drawer.outerHeight()), left: $(this).offset().left });
$("#reference-drawer").animate({opacity: 1}, 250);
}
});
});
});
});

2015년 6월 3일 (수) 17:35 판

var drawer;
//$(window).width()
function showDrawer(id, name) {
	drawer.first().attr("href", "#" + id);
	drawer.first().attr("data-target", id);
	drawer.first().text(name);
	drawer.find("#reference-drawer-text").html($("#" + id + " > .reference-text").html());
	$(document.body).append(drawer);
}

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