var PictureCroppers=Array(); function addEvent( obj,evt,act ) { evtFunc=obj[evt]; if(obj[evt] ) { if( typeof(obj[evt])=='function') { var i=obj[evt].toString().indexOf("{"); obj[evt]=new Function("e",obj[evt].toString().substr(i)+act); } else { obj[evt]=new Function("e",act); } } else { obj[evt]=new Function("e",act); } } function PictureCropper( src,fieldName,onChange,selectedBoxColor,dragBoxColor) { if( !selectedBoxColor) { selectedBoxColor="#ff0000"; } if( !dragBoxColor) { dragBoxColor="#ffff00"; } this.num=PictureCroppers.length; this.src=src; this.onChange=onChange; this.fieldName=fieldName; this.selectedBoxColor=selectedBoxColor; this.dragBoxColor=dragBoxColor; PictureCroppers[this.num]=this; var inst="PictureCroppers["+this.num+"]"; document.write(''); document.write(''); document.write(''); document.write(''); document.write('
'); document.write(''); document.write('Cropping Picture'); document.write('
'); this.x1=0; this.y1=0; this.x2=1; this.y2=1; this.croppingPicture=new HTMLLayer('PictureCropper_croppingPicture'+this.num); this.croppingBox=new HTMLLayer('PictureCropper_croppingBox'+this.num); this.cropCorner1=new Point(0,0); this.cropCorner2=new Point(1,1); this.cropCornerNew=-1; this.cropperCalibrate1=-1; this.cropperCalibrate2=-1; this.setCrop(0,0,1,1,false); addEvent( document,"onmouseup","eval('"+inst+".mouseUp(e)');" ) addEvent( document,"onmousemove","eval('"+inst+".mouseMove2(e)');" ) // page.obj.onmousemove = croperMove2; // page.obj.onmouseup = croperUp; } PicCrop=PictureCropper.prototype; PicCrop.mouseMove=function( e ) { if(this.cropCornerNew!=-1) { var point=getMouseClickPosition( e,this.croppingPicture); point.x=Math.min(Math.max(0,point.x),this.croppingPicture.getWidth()); point.y=Math.min(Math.max(0,point.y),this.croppingPicture.getHeight()); if( this.cropperCalibrate1==-1 ) { this.cropperCalibrate1=point; } var point1=new Point(Math.min(point.x,this.cropCornerNew.x),Math.min(point.y,this.cropCornerNew.y)); var point2=new Point(Math.max(point.x,this.cropCornerNew.x),Math.max(point.y,this.cropCornerNew.y)); this.croppingBox.style.display=''; this.croppingBox.style.width=Math.max(Math.round(point2.x-point1.x),1)+'px'; this.croppingBox.style.height=Math.max(Math.round(point2.y-point1.y),1)+'px'; this.croppingBox.style.marginLeft=point1.x+"px"; this.croppingBox.style.marginTop=point1.y+"px"; this.croppingBox.style.borderColor=this.dragBoxColor; } return true; } PicCrop.mouseMove2=function( e ) { if(this.cropCornerNew!=-1) { var point=getMouseClickPosition( e,this.croppingPicture); if( this.cropperCalibrate1!=-1 && this.cropperCalibrate2==-1) { this.cropperCalibrate2=this.cropperCalibrate1; this.cropperCalibrate2.x-=point.x; this.cropperCalibrate2.y-=point.y; } if( this.cropperCalibrate1!=-1 ) { point.x+=this.cropperCalibrate2.x; point.y+=this.cropperCalibrate2.y; } point.x=Math.min(Math.max(0,point.x),this.croppingPicture.getWidth()); point.y=Math.min(Math.max(0,point.y),this.croppingPicture.getHeight()); var point1=new Point(Math.min(point.x,this.cropCornerNew.x),Math.min(point.y,this.cropCornerNew.y)); var point2=new Point(Math.max(point.x,this.cropCornerNew.x),Math.max(point.y,this.cropCornerNew.y)); this.croppingBox.style.display=''; this.croppingBox.style.width=Math.max(Math.round(point2.x-point1.x),1)+'px'; this.croppingBox.style.height=Math.max(Math.round(point2.y-point1.y),1)+'px'; this.croppingBox.style.marginLeft=point1.x+"px"; this.croppingBox.style.marginTop=point1.y+"px"; this.croppingBox.style.borderColor=this.dragBoxColor; } return false; } PicCrop.mouseDown=function( e ) { var point=getMouseClickPosition( e,this.croppingPicture); point.x=Math.min(Math.max(0,point.x),this.croppingPicture.getWidth()); point.y=Math.min(Math.max(0,point.y),this.croppingPicture.getHeight()); this.croppingBox.style.width='4px'; this.croppingBox.style.height='4px'; this.croppingBox.style.display=''; this.croppingBox.style.marginLeft=point.x+"px"; this.croppingBox.style.marginTop=point.y+"px"; this.croppingBox.style.borderColor=this.dragBoxColor; this.croppingBox.style.borderWidth='1px'; this.cropCornerNew=point; } PicCrop.mouseUp=function( e ) { if( this.cropCornerNew != -1 ) { var point=getMouseClickPosition( e,this.croppingPicture); point.x=Math.min(Math.max(0,point.x),this.croppingPicture.getWidth()); point.y=Math.min(Math.max(0,point.y),this.croppingPicture.getHeight()); this.cropCorner1=new Point(Math.min(point.x,this.cropCornerNew.x),Math.min(point.y,this.cropCornerNew.y)); this.cropCorner2=new Point(Math.max(point.x,this.cropCornerNew.x),Math.max(point.y,this.cropCornerNew.y)); var w=this.croppingPicture.getWidth(); var h=this.croppingPicture.getHeight(); this.cropCorner1.x/=w; this.cropCorner2.x/=w; this.cropCorner1.y/=h; this.cropCorner2.y/=h; this.setCrop(this.cropCorner1.x,this.cropCorner1.y,this.cropCorner2.x,this.cropCorner2.y,true); this.cropCornerNew=-1; } } PicCrop.setCrop=function(x1,y1,x2,y2,notify) { //pictureX1=Math.min(x1,x2); //pictureY1=Math.min(y1,y2); //pictureX2=Math.max(x1,x2); //pictureY2=Math.max(y1,y2); //updatePicture(); this.x1=Math.min(x1,x2); this.y1=Math.min(y1,y2); this.x2=Math.max(x1,x2); this.y2=Math.max(y1,y2); var w=this.croppingPicture.getWidth(); var h=this.croppingPicture.getHeight(); this.croppingBox.style.display=(this.x1==0&&this.y1==0&&this.x2==1&&this.y2==1)?'none':''; this.croppingBox.style.borderColor='#ff0000'; this.croppingBox.style.width=Math.max(Math.round((this.x2-this.x1)*w),1)+'px'; this.croppingBox.style.height=Math.max(Math.round((this.y2-this.y1)*h),1)+'px'; this.croppingBox.style.marginLeft=(this.x1*w)+"px"; this.croppingBox.style.marginTop=(this.y1*h)+"px"; // croppingBox.style.left=croppingPicture.getLeft()+Math.round(x1*w); // croppingBox.style.top=(x1==0&&y1==0&&x2==1&&y2==1)?-10000:croppingPicture.getTop()+Math.round(y1*h); //updateMatWidth(); if( notify && this.onChange ) { eval(this.onChange+"("+this.x1+","+this.y1+","+this.x2+","+this.y2+");"); } } function croperMove( e ) { if(cropCornerNew!=-1) { var point=getMouseClickPosition( e,croppingPicture); point.x=Math.min(Math.max(0,point.x),croppingPicture.getWidth()); point.y=Math.min(Math.max(0,point.y),croppingPicture.getHeight()); if( cropperCalibrate1==-1 ) { cropperCalibrate1=point; } var point1=new Point(Math.min(point.x,cropCornerNew.x),Math.min(point.y,cropCornerNew.y)); var point2=new Point(Math.max(point.x,cropCornerNew.x),Math.max(point.y,cropCornerNew.y)); croppingBox.style.display=''; croppingBox.style.width=Math.max(Math.round(point2.x-point1.x),1)+'px'; croppingBox.style.height=Math.max(Math.round(point2.y-point1.y),1)+'px'; croppingBox.style.marginLeft=point1.x+"px"; croppingBox.style.marginTop=point1.y+"px"; croppingBox.style.borderColor=selectedBoxColor; } return true; } function setPictureCrop(x1,y1,x2,y2) { //pictureX1=Math.min(x1,x2); //pictureY1=Math.min(y1,y2); //pictureX2=Math.max(x1,x2); //pictureY2=Math.max(y1,y2); //updatePicture(); //updateMatWidth(); alert(x1); }