Changeset 14429 for dojox/trunk/sketch

Show
Ignore:
Timestamp:
07/14/08 09:26:50 (4 months ago)
Author:
ttrenka
Message:

Fix up the code style to be more readable. Fixes #6499. !strict.

Location:
dojox/trunk/sketch
Files:
11 modified

Legend:

Unmodified
Added
Removed
  • dojox/trunk/sketch/Anchor.js

    r12204 r14429  
    2424                }; 
    2525                this.doChange=function(pt){ 
    26                         if(this.isControl) this.shape.applyTransform(pt); 
    27                         else{ 
     26                        if(this.isControl){ 
     27                                this.shape.applyTransform(pt); 
     28                        } else{ 
    2829                                an.transform.dx+=pt.dx; 
    2930                                an.transform.dy+=pt.dy; 
     
    3839 
    3940                this.enable=function(){ 
    40                         if(!an.shape) return; 
     41                        if(!an.shape){ return; } 
    4142                        an.figure._add(this); 
    4243                        rect={ x:an[id].x-size, y:an[id].y-size, width:size*2, height:size*2 }; 
     
    4950                this.disable=function(){ 
    5051                        an.figure._remove(this); 
    51                         if(an.shape) an.shape.remove(this.shape); 
     52                        if(an.shape){ an.shape.remove(this.shape); } 
    5253                        this.shape=null; 
    5354                        rect=null; 
  • dojox/trunk/sketch/Annotation.js

    r12244 r14429  
    1111//              }, 
    1212                onMouseMove: function(e,rect){ 
    13                                 if(this._cshape){  
    14                                         this._cshape.setShape(rect); 
    15                                 } else { 
    16                                         this._cshape=this.figure.surface.createRect(rect) 
    17                                                 .setStroke({color:"#999", width:1, style:"ShortDot"}) 
    18                                                 .setFill([255,255,255,0.7]); 
    19                                         this._cshape.getEventSource().setAttribute("shape-rendering","crispEdges"); 
    20                                 } 
     13                        if(this._cshape){  
     14                                this._cshape.setShape(rect); 
     15                        } else { 
     16                                this._cshape=this.figure.surface.createRect(rect) 
     17                                        .setStroke({color:"#999", width:1, style:"ShortDot"}) 
     18                                        .setFill([255,255,255,0.7]); 
     19                                this._cshape.getEventSource().setAttribute("shape-rendering","crispEdges"); 
     20                        } 
    2121                }, 
    2222                onMouseUp: function(e){ 
     
    3636                                } 
    3737                        } 
    38                         if(this._cshape) f.surface.remove(this._cshape); 
     38                        if(this._cshape){  
     39                                f.surface.remove(this._cshape);  
     40                        } 
    3941                }, 
    4042                _create: function(start,end){ 
     
    4446                        var _=f.nextKey(); 
    4547                        var a=new (this.annotation)(f, "annotation-"+_); 
    46                         a.transform={dx:start.x/f.zoomFactor, dy:start.y/f.zoomFactor}; 
    47                         a.end={ x:end.x/f.zoomFactor, y:end.y/f.zoomFactor }; 
     48                        a.transform={ 
     49                                dx:start.x/f.zoomFactor,  
     50                                dy:start.y/f.zoomFactor 
     51                        }; 
     52                        a.end={  
     53                                x:end.x/f.zoomFactor,  
     54                                y:end.y/f.zoomFactor  
     55                        }; 
    4856                        if(a.control){ 
    49                                 a.control={ x:Math.round((end.x/2)/f.zoomFactor),y:Math.round((end.y/2)/f.zoomFactor) }; 
     57                                a.control={  
     58                                        x:Math.round((end.x/2)/f.zoomFactor), 
     59                                        y:Math.round((end.y/2)/f.zoomFactor)  
     60                                }; 
    5061                        } 
    5162                        f.onBeforeCreateShape(a); 
     
    5667                } 
    5768        }); 
     69 
    5870        ta.Annotation=function(figure, id){ 
    5971                //      for editing stuff. 
     
    7183                }; 
    7284 
    73                 if(this.figure) this.figure.add(this); 
    74         }; 
     85                if(this.figure){  
     86                        this.figure.add(this);  
     87                } 
     88        }; 
     89 
    7590        var p=ta.Annotation.prototype; 
    7691        p.constructor=ta.Annotation; 
    7792        p.type=function(){ return ''; }; 
    7893        p.getType=function(){ return ta.Annotation; }; 
    79  
    8094        p.remove=function(){ 
    8195                this.figure.history.add(ta.CommandTypes.Delete, this, this.serialize()); 
     
    99113                this.figure.history.add(ta.CommandTypes.Create,this); 
    100114        } 
    101         p.onDblClick=function(event){ 
     115        p.onDblClick=function(e){ 
    102116                var l=prompt('Set new text:',this.property('label')); 
    103117                if(l!==false){ 
     
    133147        p.calculate={ 
    134148                slope:function(p1, p2){ 
    135                         if(!(p1.x-p2.x)) return 0; 
     149                        if(!(p1.x-p2.x)){ return 0; } 
    136150                        return ((p1.y-p2.y)/(p1.x-p2.x)); 
    137151                }, 
    138152                dx:function(p1, p2, dy){ 
    139153                        var s=this.slope(p1,p2); 
    140                         if(s==0) return s; 
     154                        if(s==0){ return s; } 
    141155                        return dy/s;  
    142156                }, 
    143                 dy:function(p1, p2, dx){ return this.slope(p1,p2)*dx; } 
     157                dy:function(p1, p2, dx){  
     158                        return this.slope(p1,p2)*dx;  
     159                } 
    144160        }; 
    145161        p.drawBBox=function(){ 
     
    153169                        this.boundingBox.getEventSource().setAttribute("shape-rendering","crispEdges"); 
    154170                        this.figure._add(this); 
    155                 } else this.boundingBox.setShape(r); 
     171                } else {  
     172                        this.boundingBox.setShape(r);  
     173                } 
    156174        }; 
    157175        p.setBinding=function(pt){ 
     
    165183        }; 
    166184        p.setMode=function(m){ 
    167                 if(this.mode==m) return; 
     185                if(this.mode==m){ return; } 
    168186                this.mode=m; 
    169187                var method="disable"; 
    170                 if(m==ta.Annotation.Modes.Edit) method="enable"; 
     188                if(m==ta.Annotation.Modes.Edit){ method="enable"; } 
    171189                if(method=="enable"){ 
    172190                        //      draw the bounding box 
     
    175193                } else { 
    176194                        if(this.boundingBox){ 
    177                                 if(this.shape) this.shape.remove(this.boundingBox); 
     195                                if(this.shape){ this.shape.remove(this.boundingBox); } 
    178196                                this.boundingBox=null; 
    179197                        } 
    180198                } 
    181                 for(var p in this.anchors){ this.anchors[p][method](); } 
     199                for(var p in this.anchors){  
     200                        this.anchors[p][method]();  
     201                } 
    182202        }; 
    183203//      p.writeProperties=function(){ 
     
    215235        ta.Annotation.register=function(name){ 
    216236                var cls=ta[name+'Annotation']; 
    217                 ta.registerTool(name, function(p){dojo.mixin(p,{shape: name,annotation:cls});return new ta.AnnotationTool(p)}); 
     237                ta.registerTool(name, function(p){ 
     238                        dojo.mixin(p, { 
     239                                shape: name, 
     240                                annotation:cls 
     241                        }); 
     242                        return new ta.AnnotationTool(p); 
     243                }); 
    218244        }; 
    219245})(); 
  • dojox/trunk/sketch/DoubleArrowAnnotation.js

    r12263 r14429  
    4242                var opp=this.start.y-this.control.y; 
    4343                var adj=this.start.x-this.control.x; 
    44                 if(!adj) adj=1; 
     44                if(!adj){ adj=1; } 
    4545                this.startRotation=Math.atan(opp/adj); 
     46 
    4647                opp=this.control.y-this.end.y; 
    4748                adj=this.control.x-this.end.x; 
    48                 if(!adj) adj=1; 
     49                if(!adj){ adj=1; } 
    4950                this.endRotation=Math.atan(opp/adj); 
    5051        }; 
     
    5455 
    5556                //      figure out the pull of the curve and place accordingly 
    56                 if(this.control.y<this.end.y) offset*=-1; 
    57                 else offset+=this.textYOffset; 
    58                 var ab={x:((this.control.x-this.start.x)*.5)+this.start.x, y:((this.control.y-this.start.y)*.5)+this.start.y}; 
    59                 var bc={x:((this.end.x-this.control.x)*.5)+this.control.x, y:((this.end.y-this.control.y)*.5)+this.control.y}; 
    60                 this.textPosition={x:((bc.x-ab.x)*.5)+ab.x, y:(((bc.y-ab.y)*.5)+ab.y)+offset}; 
     57                if(this.control.y<this.end.y){ offset*=-1; } 
     58                else { offset+=this.textYOffset; } 
     59                var ab={ 
     60                        x:((this.control.x-this.start.x)*.5)+this.start.x,  
     61                        y:((this.control.y-this.start.y)*.5)+this.start.y 
     62                }; 
     63                var bc={ 
     64                        x:((this.end.x-this.control.x)*.5)+this.control.x,  
     65                        y:((this.end.y-this.control.y)*.5)+this.control.y 
     66                }; 
     67                this.textPosition={ 
     68                        x:((bc.x-ab.x)*.5)+ab.x,  
     69                        y:(((bc.y-ab.y)*.5)+ab.y)+offset 
     70                }; 
    6171        }; 
    6272         
    6373        p.apply=function(obj){ 
    64                 if(!obj) return; 
    65                 if(obj.documentElement) obj=obj.documentElement; 
     74                if(!obj){ return; } 
     75                if(obj.documentElement){ obj=obj.documentElement; } 
    6676                this.readCommonAttrs(obj); 
    6777                 
    6878                for(var i=0; i<obj.childNodes.length; i++){ 
    6979                        var c=obj.childNodes[i]; 
    70                         if(c.localName=="text") this.property('label',c.childNodes.length?c.childNodes[0].nodeValue:''); 
     80                        if(c.localName=="text"){ this.property('label',c.childNodes.length?c.childNodes[0].nodeValue:''); } 
    7181                        else if(c.localName=="path"){ 
    7282                                //      the line 
     
    95105                //      rotation matrix 
    96106                var rot=this.startRotation; 
    97                 if(this.control.x<this.start.x) rot+=Math.PI; 
     107                if(this.control.x<this.start.x){ rot+=Math.PI; } 
    98108                var startRot=dojox.gfx.matrix.rotate(rot); 
    99109 
    100110                rot=this.endRotation; 
    101                 if(this.control.x>=this.end.x) rot+=Math.PI; 
     111                if(this.control.x>=this.end.x){ rot+=Math.PI; } 
    102112                var endRot=dojox.gfx.matrix.rotateAt(rot, this.end.x, this.end.y); 
    103113 
     
    105115                this.shape=this.figure.group.createGroup(); 
    106116                this.shape.getEventSource().setAttribute("id", this.id); 
    107                 if(this.transform.dx||this.transform.dy) this.shape.setTransform(this.transform); 
    108                 this.pathShape=this.shape.createPath( 
    109                                 "M"+this.start.x+" "+this.start.y+"Q"+this.control.x+" "+this.control.y+" "+this.end.x+" "+this.end.y + " l0,0" 
    110                         ).setStroke(this.property('stroke')); 
     117                if(this.transform.dx||this.transform.dy){ this.shape.setTransform(this.transform); } 
     118 
     119                this.pathShape=this.shape.createPath("M"+this.start.x+" "+this.start.y+"Q"+this.control.x+" "+this.control.y+" "+this.end.x+" "+this.end.y + " l0,0") 
     120                        .setStroke(this.property('stroke')); 
    111121                 
    112122                this.startArrowGroup=this.shape.createGroup().setTransform({ dx:this.start.x, dy:this.start.y }); 
    113123                this.startArrowGroup.applyTransform(startRot); 
    114124//              console.log('startArrow',this.property('fill')); 
    115                 this.startArrow=this.startArrowGroup.createPath("M0,0 l20,-5 -3,5 3,5 Z").setFill(this.property('fill')); 
     125                this.startArrow=this.startArrowGroup.createPath("M0,0 l20,-5 -3,5 3,5 Z") 
     126                        .setFill(this.property('fill')); 
    116127                 
    117128                this.endArrowGroup=this.shape.createGroup().setTransform(endRot); 
    118                 this.endArrow=this.endArrowGroup.createPath( 
    119                         "M" + this.end.x + "," + this.end.y + " l-20,-5 3,5 -3,5 Z" 
    120                 ).setFill(this.property('fill')); 
     129                this.endArrow=this.endArrowGroup.createPath("M" + this.end.x + "," + this.end.y + " l-20,-5 3,5 -3,5 Z") 
     130                        .setFill(this.property('fill')); 
     131 
    121132                this.labelShape=this.shape.createText({ 
    122                         x:this.textPosition.x, y:this.textPosition.y, text:this.property('label'), align:this.textAlign 
    123                 }).setFont(font).setFill(this.property('fill')); 
     133                                x:this.textPosition.x,  
     134                                y:this.textPosition.y,  
     135                                text:this.property('label'),  
     136                                align:this.textAlign 
     137                        }) 
     138                        .setFont(font) 
     139                        .setFill(this.property('fill')); 
    124140        }; 
    125141        p.destroy=function(){ 
    126                 if(!this.shape) return; 
     142                if(!this.shape){ return; } 
    127143                this.startArrowGroup.remove(this.startArrow); 
    128144                this.endArrowGroup.remove(this.endArrow); 
     
    138154                this._rot(); 
    139155                this._pos(); 
     156 
    140157                //      rotation matrix 
    141158                var rot=this.startRotation; 
    142                 if(this.control.x<this.start.x) rot+=Math.PI; 
     159                if(this.control.x<this.start.x){ rot+=Math.PI; } 
    143160                var startRot=dojox.gfx.matrix.rotate(rot); 
    144161                rot=this.endRotation; 
    145                 if(this.control.x>=this.end.x) rot+=Math.PI; 
     162                if(this.control.x>=this.end.x){ rot+=Math.PI; } 
    146163                var endRot=dojox.gfx.matrix.rotateAt(rot, this.end.x, this.end.y); 
    147164 
    148165                this.shape.setTransform(this.transform); 
    149                 this.pathShape.setShape( 
    150                                 "M"+this.start.x+" "+this.start.y+" Q"+this.control.x+" "+this.control.y+" "+this.end.x+" "+this.end.y + " l0,0" 
    151                         ).setStroke(this.property('stroke')); 
     166                this.pathShape.setShape("M"+this.start.x+" "+this.start.y+" Q"+this.control.x+" "+this.control.y+" "+this.end.x+" "+this.end.y + " l0,0") 
     167                        .setStroke(this.property('stroke')); 
    152168                this.startArrowGroup.setTransform({ dx:this.start.x, dy:this.start.y }); 
    153169                this.startArrowGroup.applyTransform(startRot); 
     
    155171                 
    156172                this.endArrowGroup.setTransform(endRot); 
    157                 this.endArrow.setShape( 
    158                         "M" + this.end.x + "," + this.end.y + " l-20,-5 3,5 -3,5 Z" 
    159                 ).setFill(this.property('fill')); 
    160                 this.labelShape.setShape({x:this.textPosition.x, y:this.textPosition.y, text:this.property('label')}).setFill(this.property('fill')); 
    161         }; 
     173                this.endArrow.setShape("M" + this.end.x + "," + this.end.y + " l-20,-5 3,5 -3,5 Z") 
     174                        .setFill(this.property('fill')); 
     175                this.labelShape.setShape({ 
     176                                x:this.textPosition.x,  
     177                                y:this.textPosition.y,  
     178                                text:this.property('label') 
     179                        }) 
     180                        .setFill(this.property('fill')); 
     181        }; 
     182 
    162183        p.getBBox=function(){ 
    163184                var x=Math.min(this.start.x, this.control.x, this.end.x); 
     
    167188                return { x:x, y:y, width:w, height:h }; 
    168189        }; 
     190 
    169191        p.serialize=function(){ 
    170192                var s=this.property('stroke'); 
  • dojox/trunk/sketch/Figure.js

    r13496 r14429  
    3535                this.isSelected=function(obj){ 
    3636                        for(var i=0; i<self.selected.length; i++){ 
    37                                 if(self.selected[i]==obj) return true; 
     37                                if(self.selected[i]==obj){ return true; } 
    3838                        } 
    3939                        return false; 
     
    6565                }; 
    6666                this.clearSelections=function(){ 
    67                         for(var i=0; i<self.selected.length; i++)  
     67                        for(var i=0; i<self.selected.length; i++){  
    6868                                self.selected[i].setMode(ta.Annotation.Modes.View); 
     69                        } 
    6970                        self.selected=[];  
    7071                }; 
     
    7778                        for(var i=0; i<self.selected.length; i++){ 
    7879                                if(self.selected[i]==o){ 
    79                                         idx=i; break; 
     80                                        idx=i;  
     81                                        break; 
    8082                                } 
    8183                        } 
     
    111113                        } else if(!o.setMode){ 
    112114                                //      skip me. 
    113                         } else self.select(o); 
    114                 }; 
     115                        } else {  
     116                                self.select(o);  
     117                        } 
     118                }; 
     119 
    115120                this._dblclick=function(e){ 
    116121                        var o=self._fromEvt(e); 
     
    123128                        var prevent=false; 
    124129                        if(e.ctrlKey){ 
    125                                         if(e.keyCode==90){ //ctrl+z 
    126                                                 self.undo(); 
    127                                                 prevent = true; 
    128                                         }else if(e.keyCode==89){ //ctrl+y 
    129                                                 self.redo(); 
    130                                                 prevent = true; 
    131                                         } 
     130                                if(e.keyCode==90){ //ctrl+z 
     131                                        self.undo(); 
     132                                        prevent = true; 
     133                                } 
     134                                else if(e.keyCode==89){ //ctrl+y 
     135                                        self.redo(); 
     136                                        prevent = true; 
     137                                } 
    132138                        } 
    133139 
     
    147153                        self._startPoint={ x:e.pageX, y:e.pageY }; 
    148154                        var win = dijit.getDocumentWindow(self.node.ownerDocument); 
     155 
    149156                        //      figure out the coordinates within the iframe 
    150157                        self._ctr=dojo._abs(self.node); 
     
    170177                }; 
    171178                this._mm=function(e){ 
    172                         if(!self._ctr) return; 
     179                        if(!self._ctr){ return; } 
    173180                        var x=e.clientX-self._ctr.x; 
    174181                        var y=e.clientY-self._ctr.y; 
     
    180187                                self._c.setBinding({dx:Math.round(dx/self.zoomFactor), dy:Math.round(dy/self.zoomFactor)}); 
    181188                                self._lp={x:x, y:y}; 
    182                         } 
    183                         else { 
     189                        } else { 
    184190                                self._end={x:dx, y:dy}; 
    185191                                var rect={ 
     
    222228        var p=ta.Figure.prototype; 
    223229        p.initUndoStack=function(){ 
    224                         this.history=new ta.UndoStack(this); 
     230                this.history=new ta.UndoStack(this); 
    225231        }; 
    226232        p.setTool=function(/*dojox.sketch._Plugin*/t){ 
     
    255261                this._cons.push(dojo.connect(this.surface.getEventSource().ownerDocument, 'onkeydown', this._keydown)); 
    256262                 
    257                 //      rect hack.  Fcuking VML> 
     263                //      rect hack.  Fcuking VML. 
    258264                this.group.createRect({ x:0, y:0, width:this.size.w, height:this.size.h }); 
    259265                this.image=this.group.createImage({ width:this.size.w, height:this.size.h, src:this.imageSrc }); 
    260266        }; 
     267 
    261268        p.destroy=function(isLoading){ 
    262                 if(!this.node){ 
    263                         return; 
    264                 } 
     269                if(!this.node){ return; } 
    265270                if(!isLoading){ 
    266                         if(this.history) this.history.destroy(); 
     271                        if(this.history){ this.history.destroy(); } 
    267272                        if(this._subscribed){ 
    268273                                dojo.unsubscribe(this._subscribed); 
     
    270275                        } 
    271276                } 
    272                 dojo.forEach(this._cons,dojo.disconnect); 
     277                dojo.forEach(this._cons, dojo.disconnect); 
    273278                this._cons=[]; 
    274279 
     
    278283                this.shapes=[]; 
    279284        }; 
     285 
    280286        p.draw=function(){ }; 
    281287        p.zoom=function(pct){ 
     
    316322        }; 
    317323        p._get=function(key){ 
    318                 if(key&&key.indexOf("bounding")>-1) key=key.replace("-boundingBox",""); 
     324                if(key&&key.indexOf("bounding")>-1){  
     325                        key=key.replace("-boundingBox",""); 
     326                } 
    319327                return this.obj[key]; 
    320328        }; 
     
    348356                        } 
    349357                } 
    350                 if(idx>-1) this.shapes.splice(idx, 1); 
     358                if(idx>-1){ this.shapes.splice(idx, 1); } 
    351359                return annotation; 
    352360        }; 
     
    363371                //      convert an existing annotation to a different kind of annotation 
    364372                var ctor=t+"Annotation"; 
    365                 if(!ta[ctor]) return; 
    366                 var type=ann.type(), id=ann.id, label=ann.label, mode=ann.mode, 
    367                         tokenId=ann.tokenId; 
     373                if(!ta[ctor]){ return; } 
     374                var type=ann.type(), id=ann.id, label=ann.label, mode=ann.mode, tokenId=ann.tokenId; 
    368375                var start, end, control, transform; 
    369376                switch(type){ 
     
    401408                        n.transform={dx:transform.dx+start.x, dy:transform.dy+start.y }; 
    402409                } else { 
    403                         if(n.transform) n.transform=transform; 
    404                         if(n.start) n.start=start; 
    405                 } 
    406                 if(n.end) n.end=end; 
    407                 if(n.control) n.control=control; 
     410