var conf={ init:function(){ this.path=servConf.path; this.MSIE=(document.all && document.all.item &&(!window.opera)); this.canvasSVG=$('canvasSVG'); this.canvasSVGText=$('canvasSVGText'); this.canvas=$('canvas'); this.oldTab=$('ctrl0'); this.pathBg=this.path+'Fon2/'; this.bgCont=$('bgCont'); this.bg=$('bg'); this.textList=$('textList'); this.textForm={ 'str':$('str'), 'color':$('color'), 'font':$('fontFam'), 'size':$('size') } this.faceFalse=$('noImage'); this.faceTrue=$('changeImage'); this.textFalse=$('noText'); this.textTrue=$('changeText'); this.indicator=$('indicator'); this.formUpload=$('sendImage'); }, angle:1, angleText:1, k:0.01, correction:1, canvasW:500, canvasH:500, bkOpacity:0.5, SVGTextD:0.058 } /* angle - шаг для поворота картинки angleText - шаг для поворота текста k:0.05 - коэффициент шага увеличения для картинки correction - шаг для коррекции яркости/контраста canvasW:500 - ширина видимой области canvasH:600 - высота видимой области */п»ї window.onload=initCollage; var svgNS = "http://www.w3.org/2000/svg"; var xlinkNS='http://www.w3.org/1999/xlink'; var collage; var controlTab; function backgr(parent){ this.img=new Image(); this.parent=parent; this.bgCont=conf.bgCont; this.bg=conf.bg; } backgr.prototype.changeTransp=function(transp){ // alert(transp); if (transp)this.transp=transp==1?false:true; else{ if (this.transp) this.transp=false; else this.transp=true; } if (this.transp){ this.bgCont.className='transp'; }else{ this.bgCont.className='notTransp'; } } backgr.prototype.loadImage=function(name){ this.parent.indicateOn(); this.transp=true; this.file=name; this.src=conf.pathBg+name; this.img.onload=this.changeImage; this.img.parent=this; this.img.src=this.src; } backgr.prototype.changeImage=function(e){ thisObj=this.parent; thisObj.parent.indicateOff(); thisObj.bg.style.backgroundImage='url('+thisObj.src+')'; thisObj.bg.style.height=this.height+'px' thisObj.bg.style.width=this.width+'px' thisObj.bgCont.style.height=this.height+'px' thisObj.bgCont.style.width=this.width+'px' if(!conf.MSIE){ conf.canvasSVG.setAttribute('height',this.height+'px'); conf.canvasSVG.setAttribute('width',this.width+'px'); conf.canvasSVGText.setAttribute('height',this.height+'px'); conf.canvasSVGText.setAttribute('width',this.width+'px'); } conf.canvas.style.height=this.height+'px'; conf.canvas.style.width=this.width+'px'; var x=this.width0?this.colorCor+=conf.correction:this.colorCor-=conf.correction; if (!conf.MSIE) this.loadImage(); else ; } face.prototype.setBrightness=function(a){ a>0?this.brightness+=conf.correction:this.brightness-=conf.correction; if (!conf.MSIE) this.loadImage(); else{ var lev=(this.brightness/255)*0.5; this.pict.blacklevel=lev; } } face.prototype.setContrast=function(a){ a>0?this.contrast-=conf.correction:this.contrast+=conf.correction; if (!conf.MSIE) this.loadImage(); else{ var lev=(1-this.contrast/100); lev=lev*lev; this.pict.gain=lev; } } face.prototype.zoom=function(a){ a>0?this.k+=conf.k:this.k-=conf.k; this.setZoom(); } face.prototype.rotate=function(a){ a>0?this.angle+=conf.angle:this.angle-=conf.angle; this.setState(); } var d; DaDstart=function(e){ e=e?e:window.event; // alert(e.target.id) // if(e.target) // if (e.target==conf.canvas) return; document.documentElement.style.cursor='move'; d=e; if(e.target)e.target.ownerDocument.defaultView.getSelection().removeAllRanges(); var thisObj=this; this.oldX=this.x; this.oldY=this.y; this.startX=e.screenX; this.startY=e.screenY; if(this.dad)myRemoveEventListener(document,'mousemove',this.dad,false); myAddEventListener(document,'mousemove',this.dad=function(e){DaD.call(thisObj,e)},false); // $('a').innerHTML=this.startX; if(e.target)e.target.ownerDocument.defaultView.getSelection().removeAllRanges(); document.ondragstart=function(){window.event.returnValue = false;} document.onselectstart=function(){window.event.returnValue = false;} // document.focus(); } var b; DaD=function(e){ e=e?e:window.event; if(conf.MSIE) if(e.button!=1) {this.dadStop();return;} this.x=this.oldX+(e.screenX-this.startX); this.y=this.oldY+(e.screenY-this.startY); this.setState(); if(e.target)e.target.ownerDocument.defaultView.getSelection().removeAllRanges(); } DaDstop=function(){ if (this.dad)myRemoveEventListener(document,'mousemove',this.dad,false); this.dad=null; document.ondragstart=null; document.onselectstart=null; document.documentElement.style.cursor='default'; } function Collage(){ var thisObj=this; this.textMan=new TextMan(this); this.face=new face(this); this.backgr=new backgr(this); this.bgImg=new Image(); this.bgImg.onload=function(){thisObj.bgImgOnLoad()} this.form=conf.formUpload; } var __a; Collage.prototype.createImage=function(){ this.form.innerHTML=''; var inp; var colAtributes={}; if(this.face.file) colAtributes={ 'faceAngle': this.face.angle, 'faceX': this.face.x, 'faceY': this.face.y, 'faceK': this.face.k, 'faceContrast': this.face.contrast, 'faceBrightness': this.face.brightness, 'faceFile': this.face.file}; colAtributes.flag=1; if(this.backgr.file)colAtributes['bg']=this.backgr.file; var n=0; var curText; var textAttr=['x','y','str','color','size','font','angle']; for (var i in this.textMan.texts) { curText=this.textMan.texts[i]; if (curText){ for (var key in textAttr) colAtributes['text'+n+'_'+textAttr[key]]=curText[textAttr[key]]; n++; } } colAtributes['textN']=n; __a=colAtributes; for (var attr in colAtributes){ inp=document.createElement('input'); inp.type='hidden'; inp.name=attr; //alert(colAtributes[attr]); inp.value=colAtributes[attr]; this.form.appendChild(inp); } this.form.action='createImage.php?n='+servConf.hashN+'&t='+(new Date()-0); this.form.submit(); } Collage.prototype.indicateOff=function(ctrl){ conf.indicator.style.display='none'; } Collage.prototype.indicateOn=function(ctrl){ conf.indicator.style.display='block'; } Collage.prototype.changeCtrl=function(ctrl){ if(this.ctrl)this.removeDaD(this.ctrl); this.ctrl=ctrl; if(ctrl)this.setDaD(this.ctrl); } var c; //myAddEventListener(document,'mousemove',function(e){e=e?e:window.event;b=e},false); Collage.prototype.setDaD=function(obj){ var thisObj=obj; c=obj; myAddEventListener(conf.canvas,'mousedown',thisObj.dadStart=function(e){ // alert(''); if (thisObj.DaDstart) thisObj.DaDstart(); DaDstart.call(thisObj,e)},false); myAddEventListener(document,'mouseup',thisObj.dadStop=function(e){ if (thisObj.DaDstop) thisObj.DaDstop(); DaDstop.call(thisObj,e)},false); } Collage.prototype.removeDaD=function(obj){ // alert('remove'); if (obj.dadStart) myRemoveEventListener(conf.canvas,'mousedown',obj.dadStart,false); if (obj.dadStop) myRemoveEventListener(conf.canvas,'mouseup',obj.dadStop,false); } Collage.prototype.bgTransperency=function(transp){ this.backgr.changeTransp(transp); } Collage.prototype.changeFace=function(name){ this.face.init(name); } Collage.prototype.changeFon=function(newBg){ this.backgr.loadImage(newBg); } function Text(parent,id){ this.parent=parent; var text; this.x=Math.round(conf.canvasW/4); this.y=Math.round(conf.canvasH/4); this.str='Новый текст'; this.color='#ff0000'; this.size='40'; this.font='Times New Roman'; this.angle=0; if(conf.MSIE){ shape=this.shape=document.createElement('v:shape'); shape.style.position='absolute'; shape.style.width='1px'; shape.style.height='1px'; shape.style.zIndex='10'; // shape.stroked = "False"; shape.path="m 0,0 l -10,0 x e"; shape.style.antialias='true'; var path=document.createElement('v:path') path.textpathok="true"; this.shape.appendChild(path); var stroke=document.createElement('v:stroke') stroke.opacity=0; this.shape.appendChild(stroke); var textpath=this.textpath=document.createElement('v:textpath'); textpath.style.textDecoration='none'; textpath.style.setAttribute('v-text-align','left'); textpath.fitshape = "false"; textpath.on = "True"; this.textpath=this.shape.appendChild(textpath); textpath.style.fontStyle='normal'; textpath.style.fontWeight='normal'; this.setState(); }else{ textEl=this.textEl=document.createElementNS(svgNS,'text'); textEl.setAttribute('dominant-baseline',"middle"); textEl.style.position='absolute'; textEl.style.fontStyle='normal'; textEl.style.fontWeight='normal'; } this.setState(); this.setColor(); this.setSize(); this.setFont(); this.setText(); if(conf.MSIE) this.shape=conf.canvas.appendChild(this.shape); else this.textEl=conf.canvasSVGText.appendChild(this.textEl); } Text.prototype.setText=function(value){ if(arguments[0]) this.str=arguments[0]; if(conf.MSIE) this.textpath.string = this.str; else this.textEl.textContent=this.str; } Text.prototype.setColor=function(value){ if(arguments[0]) this.color=arguments[0]; if(conf.MSIE) this.shape.fillcolor=this.color; else this.textEl.setAttribute('fill',this.color); } Text.prototype.setSize=function(obj){ if(arguments[0]) this.size=arguments[0]; if(conf.MSIE) this.textpath.style.fontSize=this.size+'px'; else this.textEl.style.fontSize=this.size+'px'; } Text.prototype.setFont=function(obj){ if(arguments[0]) this.font=arguments[0]; if(conf.MSIE) this.textpath.style.fontFamily=this.font; else this.textEl.style.fontFamily=this.font; } Text.prototype.setState=function(){ if(conf.MSIE){ this.shape.style.left=this.x+'px'; this.shape.style.top=this.y+'px'; this.shape.style.rotation=this.angle; }else{ var d=this.size*conf.SVGTextD; this.textEl.setAttribute("transform",'translate('+this.x+','+(this.y-d)+') rotate('+this.angle+',0,'+d+')'); } } Text.prototype.setAngle=function(a){ var da=a>0?conf.angleText:-conf.angleText; this.angle+=da; this.setState(); } Text.prototype.DaDstart=function(){ //alert(''); if(conf.MSIE) this.shape.style.antialias='true'; } Text.prototype.DaDstop=function(){ if(conf.MSIE) this.shape.style.antialias='true'; } Text.prototype.dispose=function(){ if(conf.MSIE) conf.canvas.removeChild(this.shape); else conf.canvasSVGText.removeChild(this.textEl); } Text.prototype.setDaD=function(obj){ var thisObj=obj; c=obj; myAddEventListener(conf.canvas,'mousedown',thisObj.dadStart=function(e){ if (thisObj.DaDstart) thisObj.DaDstart(); DaDstart.call(thisObj,e)},false); myAddEventListener(document,'mouseup',thisObj.dadStop=function(e){ if (thisObj.DaDstop) thisObj.DaDstop(); DaDstop.call(thisObj,e)},false); } function TextMan(parent){ this.parent=parent; this.texts=[]; this.list=[]; // this.addText(); // this.selText=0; this.cont=conf.textList; this.cur=0; // this.addText(); // this.addText(); // this.selectElem.call(this.list[0]); } var _a; TextMan.prototype.checkEmpty=function(){ var empty=true; for (var key in this.list) if (this.list[key]) {empty=false;break;} if (!empty){ conf.textFalse.style.display='none'; conf.textTrue.style.display='block'; return false; }else{ conf.textFalse.style.display='block'; conf.textTrue.style.display='none'; return true; } } TextMan.prototype.initForm=function(){ var thisEl; for (var key in conf.textForm){ thisEl=this.texts[this.cur]; conf.textForm[key].value=thisEl[key]; //alert(key+' '+thisEl[key]); } } TextMan.prototype.selectElem=function(id){ var thisObj=this.parent; if(thisObj.list[thisObj.cur])this.parent.list[thisObj.cur].className='textElement notSelect'; this.className='textElement select'; thisObj.cur=this.id; thisObj.initForm(); thisObj.parent.changeCtrl(thisObj.texts[thisObj.cur]); } TextMan.prototype.newElement=function(id){ var elem=document.createElement('div'); elem.className='textElement notSelect'; elem.innerHTML='Текст в„–'+(id+1); elem.id=id; elem.parent=this; elem.onclick=this.selectElem; return elem; } TextMan.prototype.removeText=function(){ if(!this.texts[this.cur]) return; this.texts[this.cur].dispose(); this.texts[this.cur]=null; this.cont.removeChild(this.list[this.cur]); this.list[this.cur]=null; var cur=this.list[0]; for (var i=this.cur;i>=0;i--) if(this.list[i]) {cur=this.list[i];break} if (cur==null)for (var i=this.cur;i