All pastes #155308 Raw Edit

Anonymous

public java v1 · immutable
#155308 ·published 2006-08-30 23:41 UTC
rendered paste body
var BlackSheep = new Object();BlackSheep.ElementPosition = function(obj) {	var curleft = curtop = 0;	if (obj.offsetParent) {		curleft = obj.offsetLeft		curtop = obj.offsetTop		while (obj = obj.offsetParent) {			curleft += obj.offsetLeft			curtop += obj.offsetTop		}	}		this.left = curleft;	this.top = curtop;}BlackSheep.EventMousePosition = function( e ) {	var posx = 0;	var posy = 0;	if (!e) var e = window.event;	if (e.pageX || e.pageY) 	{		posx = e.pageX;		posy = e.pageY;	}	else if (e.clientX || e.clientY) 	{		posx = e.clientX + document.body.scrollLeft			+ document.documentElement.scrollLeft;		posy = e.clientY + document.body.scrollTop			+ document.documentElement.scrollTop;	}	// posx and posy contain the mouse position relative to the document	// Do something with this information		this.x = posx;	this.y = posy;}BlackSheep.ObjectCallback = function( target, funcName ) {	if( !target ) {		throw "Invalid target";	}		if( !target[funcName] ) {		throw "Target does not have method '" + funcName + "'";	}		this.target = target;	this.funcName = funcName;}BlackSheep.ObjectCallback.prototype.run = function( arg ) {	this.target[this.funcName]( arg );}BlackSheep.addObjectEventListener = function( target, event, callback, bubble ) {	var sCallback = callback;	if( !target ) {		throw "Invalid Target";	}		if( !target.addEventListener ) {		throw "Target is not a DOM Object";	}		target.addEventListener( event, function(e){sCallback.run(e);}, bubble );}BlackSheep.setObjectTimeout = function( callback, delay ) {	return window.setTimeout( BlackSheep.objectTimeoutCallback, delay, callback );}BlackSheep.objectTimeoutCallback = function( callback ) {	callback.run();}/***** Popup Dialog Code ******/BlackSheep.PopupDialogInfo = function() {	this.closeable = true;	this.moveable = false;	this.title = "";	this.anchorElement = false;	this.startOpen = false;}BlackSheep.PopupDialog = function( info ) {	this.anchorElement = info.anchorElement;	this.title = info.title; 		this.div = document.createElement( 'div' );	this.div.className = 'popup_dialog';	this.div.style.visibility = 'hidden';	this.div.style.position = 'absolute';	this.div.style.left = '0px';	this.div.style.top = '0px';		var h1 = document.createElement( 'h1' );	h1.appendChild( document.createTextNode(this.title) );	this.div.appendChild( h1 );		if( info.closeable ) {		var closelink = document.createElement( 'a' );		closelink.href = 'javascript: void(0);';		closelink.controllerObj = this;		closelink.addEventListener( 'click', function(){this.controllerObj.close();}, false );		var closeimg = document.createElement( 'img' );		closeimg.src = '/images/icons/48x48/actions/fileclose.png';		closeimg.alt = 'X';		closelink.appendChild( closeimg );		h1.appendChild( closelink );	}		this.contentDiv = document.createElement( 'div' );	this.contentDiv.className = 'popup_content';		this.div.appendChild( this.contentDiv );	document.body.appendChild( this.div );		this.stateIsOpen = false;		if( info.startOpen ) {		this.open();	}}BlackSheep.PopupDialog.prototype.open = function() {	var pos = new BlackSheep.ElementPosition( this.anchorElement );	this.div.style.left = pos.left + 'px';	this.div.style.top = pos.top + 'px';	this.div.style.visibility = 'visible';	this.stateIsOpen = true;}BlackSheep.PopupDialog.prototype.close = function() {	this.div.style.visibility = 'hidden';	this.stateIsOpen = false;}BlackSheep.PopupDialog.prototype.content = function() {	return this.contentDiv;}BlackSheep.PopupDialog.prototype.isOpen = function() {	return this.stateIsOpen;}/**** END POPUP DIALOG ********//***** CONTEXT MENU CODE *******/BlackSheep.ContextMenuInfo = function() {	this.mouseOutDelay = 1000;	this.callback = false;}BlackSheep.ContextMenu = function( info ) {	this.mouseOutDelay = info.mouseOutDelay;	this.anchorElement = info.anchorElement;		new BlackSheep.ObjectCallback(this,"onAnchorClick");	alert( "Did It!" );	BlackSheep.addObjectEventListener( this.anchorElement, 'click', new BlackSheep.ObjectCallback(this,"onAnchorClick"), false );	this.ul = document.createElement( 'ul' );	this.ul.className = 'context_menu';	this.ul.style.visibility = 'hidden';	this.ul.style.position = 'absolute';	this.ul.style.left = '0px';	this.ul.style.top = '0px';		this.ul.contextMenuController = this;	this.ul.addEventListener( 'mouseout', function(){this.contextMenuController.onMouseOut()}, false );	this.ul.addEventListener( 'mouseover', function(){this.contextMenuController.onMouseOver()}, false );		this.statusMouseIsOver = false;		document.body.appendChild( this.ul );}BlackSheep.ContextMenu.prototype.open = function( x, y ) {	this.ul.style.left = x + 'px';	this.ul.style.top = y + 'px';	this.ul.style.visibility = 'visible';	this.stateIsOpen = true;}BlackSheep.ContextMenu.prototype.close = function() {	this.ul.style.visibility = 'hidden';	this.stateIsOpen = false;}BlackSheep.ContextMenu.prototype.isOpen = function() {	return this.stateIsOpen;}BlackSheep.ContextMenu.prototype.add = function( data ) {	var li = document.createElement( 'li' );	var a = document.createElement( 'a' );	a.href = 'javascript: void(0);';	a.appendChild( document.createTextNode(data) );	a.addEventListener( 'focus', function(){this.blur();}, false );	li.appendChild( a );	this.ul.appendChild( li );}BlackSheep.ContextMenu.prototype.onMouseOver = function(e) {	this.statusMouseIsOver = true;}BlackSheep.ContextMenu.prototype.onMouseOut = function(e) {	this.statusMouseIsOver = false;		if( this.stage2TimeoutId ) {		window.clearTimeout( this.stage2TimeoutId );		this.stage2TimeoutId = false;	}	this.stage2TimeoutId = BlackSheep.setObjectTimeout( new BlackSheep.ObjectCallback(this,"mouseOutStage2"), this.mouseOutDelay );}BlackSheep.ContextMenu.prototype.isMouseOver = function() {	if( this.stage2TimeoutId ) {		window.clearTimeout( this.stage2TimeoutId );		this.stage2TimeoutId = false;	}		return this.statusMouseIsOver;}BlackSheep.ContextMenu.prototype.mouseOutStage2 = function() {	if( !this.isMouseOver() ) {		this.close();	}}BlackSheep.ContextMenu.prototype.onAnchorClick = function( event ) {	var mousePos = new BlackSheep.EventMousePosition( event );	window.status = mousePos.x + ", " + mousePos.y;	this.open( mousePos.x, mousePos.y );}