All pastes #499577 Raw Edit

Someone

public text v1 · immutable
#499577 ·published 2007-05-21 03:36 UTC
rendered paste body
// much code to create this was borrowed and implemented from code that was/is featured on quirksmode.com

// The infomation on that website has been invaluable for a lot of purposes. thanks!



document.writeln('<div id="context_menu" style="display:none; position: absolute;">');

	document.writeln('<a href="javascript:history.go(-1)" class="context_menu_item">Back</a>');

	document.writeln('<a href="javascript:history.go(1)" class="context_menu_item">Forward</a>');

	document.writeln('<a href="javascript:window.location.reload()" class="context_menu_item">Reload</a>');

	document.writeln('<hr />'); // --- sepeator ---

	document.writeln('<a href="view-source:' + document.location.href + '" class="context_menu_item">View Source</a>');

	document.writeln('<a href="javascript:disablemenu()" onclick="disablemenu()" class="context_menu_item">Disable this Menu</a>');

document.writeln('</div>');



document.writeln('<style type="text/css" rel="stylesheet">');

	document.writeln('#context_menu {');

		document.writeln('background-color: #d4d0c8;');

		document.writeln('color: #333333;');

		document.writeln('padding: 3px;');

		document.writeln('text-align:left;');

		document.writeln('font-size: .7em;');

		document.writeln('z-index: 10000;');

		document.writeln('border: 2px solid #999999;');

		document.writeln('width: 150px;');

		document.writeln('opacity: .825;');

	document.writeln('}');

	document.writeln('#context_menu hr {');

		document.writeln('color: #999999;');

		document.writeln('background-color: #999999;');

		document.writeln('height: 1px;');

		document.writeln('border: 0;');

	document.writeln('}');

	document.writeln('#context_menu a {');

		document.writeln('display: block;');

		document.writeln('border: 1px solid #d4d0c8;');

		document.writeln('text-decoration: none;');

		document.writeln('color: #333333;');

		document.writeln('padding-left: 13px;');

		document.writeln('padding-top: 2px;');

		document.writeln('padding-bottom: 2px;');

	document.writeln('}');

	document.writeln('#context_menu a:hover {');

		document.writeln('border: 1px solid #666666;');

		document.writeln('background-color: #999999;');

		document.writeln('color: #ffffff;');

	document.writeln('}');

document.writeln('</style>');



document.oncontextmenu=checkMouseDown;

var use_my_menu = 1;



function disablemenu() {

	document.getElementById('context_menu').style.display = "none";

	use_my_menu = 0;

}



function killEvents(e) {

	if (!e) { var e = window.event; e.cancelBubble = true; }

	if (e.stopPropagation) { e.stopPropagation(); }

}



var menuVisible = 0;



function checkMouseDown(e) {

	if (!use_my_menu) { return true; }

	var rightclick, leftclick;

	if (!e) { var e = window.event; }

	if (e.which) { rightclick = (e.which == 3); }

	else if (e.button) { rightclick = (e.button == 2); }

	if (e.which) { leftclick = (e.which == 1); }

	else if (e.button) { leftclick = (e.button == 1); }

	var theTarget = (window.event) ? e.srcElement : e.target;

	menuVisible = (document.getElementById('context_menu').style.display == "");

	if (rightclick) {

		document.getElementById('context_menu').style.display = "";

		var posx = 0;

		var posy = 0;

		if (!e) { var e = window.event; }

		if (e.pageX || e.pageY) {

			posx = e.pageX;

			posy = e.pageY;

			document.getElementById('context_menu').style.left = posx+"px";

			document.getElementById('context_menu').style.top = posy+"px";

		}

		else if (e.clientX || e.clientY) {

			posx = e.clientX + document.body.scrollLeft;

			posy = e.clientY + document.body.scrollTop;

			document.getElementById('context_menu').left = posx;

			document.getElementById('context_menu').top = posy;

		}

		killEvents(e);

		return false;

	}

	

	else if (leftclick && menuVisible) {

		if (theTarget.className != 'context_menu_item') { document.getElementById('context_menu').style.display = "none"; }

		killEvents(e);

		return true;

	}

	else if (leftclick && !menuVisible) {

		killEvents(e);

		return true;

	}

	else { return false; }

	return false;

}



if (parseInt(navigator.appVersion)>3) {

	document.onmousedown = checkMouseDown;

	if (navigator.appName=="Netscape") { document.captureEvents(Event.MOUSEDOWN); }

}