topical media & game development
professional-javascript-13-zdragdroplib.js / js
//JavaScript zEvents Library v1.0 by Nicholas C. Zakas, http://www.nczonline.net
function zEvent(){this.type=null;this.target=null;this.relatedTarget=null;this.cancelable=false;this.timeStamp=null;this.returnValue=true;};zEvent.prototype.initEvent=function(b){this.type=b;this.timeStamp=(new Date()).getTime();};zEvent.prototype.preventDefault=function(){if(this.cancelable){this.returnValue=false;}};function zEventTarget(){this.eventhandlers=new Object();};zEventTarget.prototype.addEventListener=function(z){if(typeof this.eventhandlers[a]=new Array;};this.eventhandlers[z);};zEventTarget.prototype.dispatchEvent=function(d.target=this;if(typeof this.eventhandlers[d.type].length;i++){this.eventhandlers[d);}};return a,a]!="undefined"){var a].length;i++){if(this.eventhandlers[z){a][i]);}};this.eventhandlers[e;}};
//JavaScript zDragDrop Library v1.0 by Nicholas C. Zakas, http://www.nczonline.net
function zDrag(){};zDrag.current=null;zDrag.dragging=false;zDrag.isDragging=function(){return this.dragging;};zDrag.setCurrent=function(a;this.dragging=true;};zDrag.getCurrent=function(){return this.current;};zDrag.clearCurrent=function(){this.current=null;this.dragging=false;};function zDraggable(z){zEventTarget.call(this);this.construct(z);this.diffX=0;this.diffY=0;this.targets=[];};zDraggable.prototype=new zEventTarget;zDraggable.DRAG_X=1;zDraggable.DRAG_Y=2;zDraggable.prototype.addDropTarget=function(e);};zDraggable.prototype.construct=function(z){this.element=z;var g=function(){var h.initDragDropEvent("dragstart",true);if(h)){var f.diffX=f.element.offsetLeft;i.clientY-f.attachEventHandlers();zDrag.setCurrent(g,false);}else if(this.element.attachEvent){this.element.attachEvent("onmousedown",f=this;this.tempMouseMove=function(){var j=f.diffX;var i.clientY-f.constraints&zDraggable.DRAG_X){j;};if(f.element.style.top=l=new zDragDropEvent();f.dispatchEvent(f.tempMouseUp=function(){var e=i.clientX,e!=null){var m.initDragDropEvent("drop",false,e.dispatchEvent(n=new zDragDropEvent();f.dispatchEvent(f.detachEventHandlers();};if(document.body.addEventListener){document.body.addEventListener("mousemove",this.tempMouseMove,false);document.body.addEventListener("mouseup",this.tempMouseUp,false);}else if(document.body.attachEvent){document.body.attachEvent("onmousemove",this.tempMouseMove);document.body.attachEvent("onmouseup",this.tempMouseUp);}else{throw new Error("zDrag doesn't support this browser.");}};zDraggable.prototype.detachEventHandlers=function(){if(document.body.removeEventListener){document.body.removeEventListener("mousemove",this.tempMouseMove,false);document.body.removeEventListener("mouseup",this.tempMouseUp,false);}else if(document.body.detachEvent){document.body.detachEvent("onmousemove",this.tempMouseMove);document.body.detachEvent("onmouseup",this.tempMouseUp);}else{throw new Error("zDrag doesn't support this browser.");}};zDraggable.prototype.getDropTarget=function(iX,iY){for(var i=0;i<this.targets.length;i++){if(this.targets[i].isOver(iX,iY)){return this.targets[i];}};return null;};zDraggable.prototype.moveTo=function(iX,iY){this.element.style.left=iX+"px";this.element.style.top=iY+"px";};zDraggable.prototype.getLeft=function(){return this.element.offsetLeft;};zDraggable.prototype.getTop=function(){return this.element.offsetTop;};function zDragDropEvent(){zEvent.call(this);};zDragDropEvent.prototype=new zEvent();zDragDropEvent.prototype.initDragDropEvent=function(q,p,r;};function zDropTarget(b);};zDropTarget.prototype=new zEventTarget;zDropTarget.prototype.construct=function(b;};zDropTarget.prototype.isOver=function(iX,iY){var t=u=this.element.offsetTop;var u+this.element.offsetHeight;return(iX>=t&&iY>=v);};zDropTarget.prototype.getLeft=function(){return this.element.offsetLeft;};zDropTarget.prototype.getTop=function(){return this.element.offsetTop;};zDropTarget.prototype.getHeight=function(){return this.element.offsetHeight;};zDropTarget.prototype.getWidth=function(){return this.element.offsetWidth;};
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.