-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGooFlow.js
3641 lines (3605 loc) · 173 KB
/
GooFlow.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//定义一个区域图类:
function GooFlow(bgDiv,property){
if (navigator.userAgent.indexOf("MSIE 8.0")>0||navigator.userAgent.indexOf("MSIE 7.0")>0||navigator.userAgent.indexOf("MSIE 6.0")>0)
GooFlow.prototype.useSVG="";
else GooFlow.prototype.useSVG="1";
//初始化区域图的对象
this.$id=bgDiv.attr("id");
this.$bgDiv=bgDiv;//最父框架的DIV
this.$bgDiv.addClass("GooFlow");
var width=(property.width||800)-2;
var height=(property.height||500)-2;
this.$bgDiv.css({width:width+"px",height:height+"px"});
this.$tool=null;//左侧工具栏对象
this.$head=null;//顶部标签及工具栏按钮
this.$title="newFlow_1";//流程图的名称
this.$nodeRemark={};//每一种结点或按钮的说明文字,JSON格式,key为类名,value为用户自定义文字说明
this.$nowType="cursor";//当前要绘制的对象类型
this.$lineData={};
this.$lineCount=0;
this.$nodeData={};
this.$nodeCount=0;
this.$areaData={};
this.$areaCount=0;
this.$lineDom={};
this.$nodeDom={};
this.$areaDom={};
this.$max=property.initNum||1;//计算默认ID值的起始SEQUENCE
this.$focus="";//当前被选定的结点/转换线ID,如果没选中或者工作区被清空,则为""
this.$cursor="default";//鼠标指针在工作区内的样式
this.$editable=false;//工作区是否可编辑
this.$deletedItem={};//在流程图的编辑操作中被删除掉的元素ID集合,元素ID为KEY,元素类型(node,line.area)为VALUE
var headHeight=0;
var tmp="";
if(property.haveHead){
tmp="<div class='GooFlow_head'><label title='"+(property.initLabelText||"newFlow_1")+"'>"+(property.initLabelText||"newFlow_1")+"</label>";
for(var x=0;x<property.headBtns.length;++x){
tmp+="<a href='javascript:void(0)' class='GooFlow_head_btn'><b class='ico_"+property.headBtns[x]+"'></b></a>"
}
tmp+="</div>";
this.$head=$(tmp);
this.$bgDiv.append(this.$head);
headHeight=24;
//以下是当工具栏按钮被点击时触发的事件自定义(虚函数),格式为function(),因为可直接用THIS操作对象本身,不用传参;用户可自行重定义:
this.onBtnNewClick=null;//新建流程图按钮被点中
this.onBtnOpenClick=null;//打开流程图按钮定义
this.onBtnSaveClick=null;//保存流程图按钮定义
this.onFreshClick=null;//重载流程图按钮定义
if(property.headBtns)
this.$head.on("click",{inthis:this},function(e){
if(!e)e=window.event;
var tar=e.target;
if(tar.tagName=="DIV"||tar.tagName=="SPAN") return;
else if(tar.tagName=="a") tar=tar.childNode[0];
var This=e.data.inthis;
//定义顶部操作栏按钮的事件
switch($(tar).attr("class")){
case "ico_new": if(This.onBtnNewClick!=null) This.onBtnNewClick();break;
case "ico_open": if(This.onBtnOpenClick!=null) This.onBtnOpenClick();break;
case "ico_save": if(This.onBtnSaveClick!=null) This.onBtnSaveClick();break;
case "ico_undo": This.undo();break;
case "ico_redo": This.redo();break;
case "ico_reload" :if(This.onFreshClick!=null) This.onFreshClick();break;
}
});
}
var toolWidth=0;
if(property.haveTool){
this.$bgDiv.append("<div class='GooFlow_tool'"+(property.haveHead? "":" style='margin-top:3px'")+"><div style='height:"+(height-headHeight-(property.haveHead? 7:10))+"px' class='GooFlow_tool_div'></div></div>");
this.$tool=this.$bgDiv.find(".GooFlow_tool div");
//未加代码:加入绘图工具按钮
this.$tool.append("<a href='javascript:void(0)' type='cursor' class='GooFlow_tool_btndown' id='"+this.$id+"_btn_cursor'><b class='ico_cursor'/></a><a href='javascript:void(0)' type='direct' class='GooFlow_tool_btn' id='"+this.$id+"_btn_direct'><b class='ico_direct'/></a>");
if(property.toolBtns&&property.toolBtns.length>0){
tmp="<span/>";
for(var i=0;i<property.toolBtns.length;++i){
tmp+="<a href='javascript:void(0)' type='"+property.toolBtns[i]+"' id='"+this.$id+"_btn_"+property.toolBtns[i].split(" ")[0]+"' class='GooFlow_tool_btn'><b class='ico_"+property.toolBtns[i]+"'/></a>";//加入自定义按钮
}
this.$tool.append(tmp);
}
//加入区域划分框工具开关按钮
if(property.haveGroup)
this.$tool.append("<span/><a href='javascript:void(0)' type='group' class='GooFlow_tool_btn' id='"+this.$id+"_btn_group'><b class='ico_group'/></a>");
toolWidth=31;
this.$nowType="cursor";
//绑定各个按钮的点击事件
this.$tool.on("click",{inthis:this},function(e){
if(!e)e=window.event;
var tar;
switch(e.target.tagName){
case "SPAN":return false;
case "DIV":return false;
case "B": tar=e.target.parentNode;break;
case "A": tar=e.target;
};
var type=$(tar).attr("type");
e.data.inthis.switchToolBtn(type);
return false;
});
this.$editable=true;//只有具有工具栏时可编辑
}
width=width-toolWidth-8;
height=height-headHeight-(property.haveHead? 5:8);
this.$bgDiv.append("<div class='GooFlow_work' style='width:"+(width)+"px;height:"+(height)+"px;"+(property.haveHead? "":"margin-top:3px")+"'></div>");
this.$workArea=$("<div class='GooFlow_work_inner' style='width:"+width*3+"px;height:"+height*3+"px'></div>")
.attr({"unselectable":"on","onselectstart":'return false',"onselect":'document.selection.empty()'});
this.$bgDiv.children(".GooFlow_work").append(this.$workArea);
this.$draw=null;//画矢量线条的容器
this.initDraw("draw_"+this.$id,width,height);
this.$group=null;
if(property.haveGroup)
this.initGroup(width,height);
if(this.$editable){
this.$workArea.on("click",{inthis:this},function(e){
if(!e)e=window.event;
if(!e.data.inthis.$editable)return;
var type=e.data.inthis.$nowType;
if(type=="cursor"){
var t=$(e.target);
var n=t.prop("tagName");
if(n=="svg"||(n=="DIV"&&t.prop("class").indexOf("GooFlow_work")>-1)||n=="LABEL")e.data.inthis.blurItem();
return;
}
else if(type=="direct"||type=="group")return;
var X,Y;
var ev=mousePosition(e),t=getElCoordinate(this);
X=ev.x-t.left+this.parentNode.scrollLeft-1;
Y=ev.y-t.top+this.parentNode.scrollTop-1;
e.data.inthis.addNode(e.data.inthis.$id+"_node_"+e.data.inthis.$max,{id:e.data.inthis.$id+"_node_"+e.data.inthis.$max,name:"node_"+e.data.inthis.$max,left:X,top:Y,type:e.data.inthis.$nowType});
e.data.inthis.$max++;
});
//划线时用的绑定
this.$workArea.mousemove({inthis:this},function(e){
if(e.data.inthis.$nowType!="direct") return;
var lineStart=$(this).data("lineStart");
if(!lineStart)return;
var ev=mousePosition(e),t=getElCoordinate(this);
var X,Y;
X=ev.x-t.left+this.parentNode.scrollLeft;
Y=ev.y-t.top+this.parentNode.scrollTop;
var line=document.getElementById("GooFlow_tmp_line");
if(GooFlow.prototype.useSVG!=""){
line.childNodes[0].setAttribute("d","M "+lineStart.x+" "+lineStart.y+" L "+X+" "+Y);
line.childNodes[1].setAttribute("d","M "+lineStart.x+" "+lineStart.y+" L "+X+" "+Y);
if(line.childNodes[1].getAttribute("marker-end")=="url(\"#arrow2\")")
line.childNodes[1].setAttribute("marker-end","url(#arrow3)");
else line.childNodes[1].setAttribute("marker-end","url(#arrow2)");
}
else line.points.value=lineStart.x+","+lineStart.y+" "+X+","+Y;
});
this.$workArea.mouseup({inthis:this},function(e){
if(e.data.inthis.$nowType!="direct") return;
$(this).css("cursor","auto").removeData("lineStart");
var tmp=document.getElementById("GooFlow_tmp_line");
if(tmp)e.data.inthis.$draw.removeChild(tmp);
});
//为了结点而增加的一些集体delegate绑定
this.initWorkForNode();
//对结点进行移动或者RESIZE时用来显示的遮罩层
this.$ghost=$("<div class='rs_ghost'></div>").attr({"unselectable":"on","onselectstart":'return false',"onselect":'document.selection.empty()'});
this.$bgDiv.append(this.$ghost);
this.$textArea=$("<textarea></textarea>");
this.$bgDiv.append(this.$textArea);
this.$lineMove=$("<div class='GooFlow_line_move' style='display:none'></div>");//操作折线时的移动框
this.$workArea.append(this.$lineMove);
this.$lineMove.on("mousedown",{inthis:this},function(e){
if(e.button==2)return false;
var lm=$(this);
lm.css({"background-color":"#333"});
var This=e.data.inthis;
var ev=mousePosition(e),t=getElCoordinate(This.$workArea[0]);
var X,Y;
X=ev.x-t.left+This.$workArea[0].parentNode.scrollLeft;
Y=ev.y-t.top+This.$workArea[0].parentNode.scrollTop;
var p=This.$lineMove.position();
var vX=X-p.left,vY=Y-p.top;
var isMove=false;
document.onmousemove=function(e){
if(!e)e=window.event;
var ev=mousePosition(e);
var ps=This.$lineMove.position();
X=ev.x-t.left+This.$workArea[0].parentNode.scrollLeft;
Y=ev.y-t.top+This.$workArea[0].parentNode.scrollTop;
if(This.$lineMove.data("type")=="lr"){
X=X-vX;
if(X<0) X=0;
else if(X>This.$workArea.width())
X=This.$workArea.width();
This.$lineMove.css({left:X+"px"});
}
else if(This.$lineMove.data("type")=="tb"){
Y=Y-vY;
if(Y<0) Y=0;
else if(Y>This.$workArea.height())
Y=This.$workArea.height();
This.$lineMove.css({top:Y+"px"});
}
isMove=true;
}
document.onmouseup=function(e){
if(isMove){
var p=This.$lineMove.position();
if(This.$lineMove.data("type")=="lr")
This.setLineM(This.$lineMove.data("tid"),p.left+3);
else if(This.$lineMove.data("type")=="tb")
This.setLineM(This.$lineMove.data("tid"),p.top+3);
}
This.$lineMove.css({"background-color":"transparent"});
if(This.$focus==This.$lineMove.data("tid")){
This.focusItem(This.$lineMove.data("tid"));
}
document.onmousemove=null;
document.onmouseup=null;
}
});
this.$lineOper=$("<div class='GooFlow_line_oper' style='display:none'><b class='b_l1'></b><b class='b_l2'></b><b class='b_l3'></b><b class='b_x'></b></div>");//选定线时显示的操作框
this.$workArea.append(this.$lineOper);
this.$lineOper.on("click",{inthis:this},function(e){
if(!e)e=window.event;
if(e.target.tagName!="B") return;
var This=e.data.inthis;
var id=$(this).data("tid");
switch($(e.target).attr("class")){
case "b_x":
This.delLine(id);
this.style.display="none";break;
case "b_l1":
This.setLineType(id,"lr");break;
case "b_l2":
This.setLineType(id,"tb");break;
case "b_l3":
This.setLineType(id,"sl");break;
}
});
//下面绑定当结点/线/分组块的一些操作事件,这些事件可直接通过this访问对象本身
//当操作某个单元(结点/线/分组块)被添加时,触发的方法,返回FALSE可阻止添加事件的发生
//格式function(id,type,json):id是单元的唯一标识ID,type是单元的种类,有"node","line","area"三种取值,json即addNode,addLine或addArea方法的第二个传参json.
this.onItemAdd=null;
//当操作某个单元(结点/线/分组块)被删除时,触发的方法,返回FALSE可阻止删除事件的发生
//格式function(id,type):id是单元的唯一标识ID,type是单元的种类,有"node","line","area"三种取值
this.onItemDel=null;
//当操作某个单元(结点/分组块)被移动时,触发的方法,返回FALSE可阻止移动事件的发生
//格式function(id,type,left,top):id是单元的唯一标识ID,type是单元的种类,有"node","area"两种取值,线line不支持移动,left是新的左边距坐标,top是新的顶边距坐标
this.onItemMove=null;
//当操作某个单元(结点/线/分组块)被重命名时,触发的方法,返回FALSE可阻止重命名事件的发生
//格式function(id,name,type):id是单元的唯一标识ID,type是单元的种类,有"node","line","area"三种取值,name是新的名称
this.onItemRename=null;
//当操作某个单元(结点/线)被由不选中变成选中时,触发的方法,返回FALSE可阻止选中事件的发生
//格式function(id,type):id是单元的唯一标识ID,type是单元的种类,有"node","line"两种取值,"area"不支持被选中
this.onItemFocus=null;
//当操作某个单元(结点/线)被由选中变成不选中时,触发的方法,返回FALSE可阻止取消选中事件的发生
//格式function(id,type):id是单元的唯一标识ID,type是单元的种类,有"node","line"两种取值,"area"不支持被取消选中
this.onItemBlur=null;
//当操作某个单元(结点/分组块)被重定义大小或造型时,触发的方法,返回FALSE可阻止重定大小/造型事件的发生
//格式function(id,type,width,height):id是单元的唯一标识ID,type是单元的种类,有"node","line","area"三种取值;width是新的宽度,height是新的高度
this.onItemResize=null;
//当移动某条折线中段的位置,触发的方法,返回FALSE可阻止重定大小/造型事件的发生
//格式function(id,M):id是单元的唯一标识ID,M是中段的新X(或Y)的坐标
this.onLineMove=null;
//当变换某条连接线的类型,触发的方法,返回FALSE可阻止重定大小/造型事件的发生
//格式function(id,type):id是单元的唯一标识ID,type是连接线的新类型,"sl":直线,"lr":中段可左右移动的折线,"tb":中段可上下移动的折线
this.onLineSetType=null;
//当用重色标注某个结点/转换线时触发的方法,返回FALSE可阻止重定大小/造型事件的发生
//格式function(id,type,mark):id是单元的唯一标识ID,type是单元类型("node"结点,"line"转换线),mark为布尔值,表示是要标注TRUE还是取消标注FALSE
this.onItemMark=null;
if(property.useOperStack&&this.$editable){//如果要使用堆栈记录操作并提供“撤销/重做”的功能,只在编辑状态下有效
this.$undoStack=[];
this.$redoStack=[];
this.$isUndo=0;
///////////////以下是构造撤销操作/重做操作的方法
//为了节省浏览器内存空间,undo/redo中的操作缓存栈,最多只可放40步操作;超过40步时,将自动删掉最旧的一个缓存
this.pushOper=function(funcName,paras){
var len=this.$undoStack.length;
if(this.$isUndo==1){
this.$redoStack.push([funcName,paras]);
this.$isUndo=false;
if(this.$redoStack.length>40) this.$redoStack.shift();
}else{
this.$undoStack.push([funcName,paras]);
if(this.$undoStack.length>40) this.$undoStack.shift();
if(this.$isUndo==0){
this.$redoStack.splice(0,this.$redoStack.length);
}
this.$isUndo=0;
}
};
//将外部的方法加入到GooFlow对象的事务操作堆栈中,在过后的undo/redo操作中可以进行控制,一般用于对流程图以外的附加信息进行编辑的事务撤销/重做控制;
//传参func为要执行方法对象,jsonPara为外部方法仅有的一个面向字面的JSON传参,由JSON对象带入所有要传的信息;
//提示:为了让外部方法能够被UNDO/REDO,需要在编写这些外部方法实现时,加入对该方法执行后效果回退的另一个执行方法的pushExternalOper
this.pushExternalOper=function(func,jsonPara){
this.pushOper("externalFunc",[func,jsonPara]);
};
//撤销上一步操作
this.undo=function(){
if(this.$undoStack.length==0) return;
var tmp=this.$undoStack.pop();
this.$isUndo=1;
if(tmp[0]=="externalFunc"){
tmp[1][0](tmp[1][1]);
}
else{
//传参的数量,最多支持6个.
switch(tmp[1].length){
case 0:this[tmp[0]]();break;
case 1:this[tmp[0]](tmp[1][0]);break;
case 2:this[tmp[0]](tmp[1][0],tmp[1][1]);break;
case 3:this[tmp[0]](tmp[1][0],tmp[1][1],tmp[1][2]);break;
case 4:this[tmp[0]](tmp[1][0],tmp[1][1],tmp[1][2],tmp[1][3]);break;
case 5:this[tmp[0]](tmp[1][0],tmp[1][1],tmp[1][2],tmp[1][3],tmp[1][4]);break;
case 6:this[tmp[0]](tmp[1][0],tmp[1][1],tmp[1][2],tmp[1][3],tmp[1][4],tmp[1][5]);break;
}
}
};
//重做最近一次被撤销的操作
this.redo=function(){
if(this.$redoStack.length==0) return;
var tmp=this.$redoStack.pop();
this.$isUndo=2;
if(tmp[0]=="externalFunc"){
tmp[1][0](tmp[1][1]);
}
else{
//传参的数量,最多支持6个.
switch(tmp[1].length){
case 0:this[tmp[0]]();break;
case 1:this[tmp[0]](tmp[1][0]);break;
case 2:this[tmp[0]](tmp[1][0],tmp[1][1]);break;
case 3:this[tmp[0]](tmp[1][0],tmp[1][1],tmp[1][2]);break;
case 4:this[tmp[0]](tmp[1][0],tmp[1][1],tmp[1][2],tmp[1][3]);break;
case 5:this[tmp[0]](tmp[1][0],tmp[1][1],tmp[1][2],tmp[1][3],tmp[1][4]);break;
case 6:this[tmp[0]](tmp[1][0],tmp[1][1],tmp[1][2],tmp[1][3],tmp[1][4],tmp[1][5]);break;
}
}
};
}
$(document).keydown({inthis:this},function(e){
//绑定键盘操作
var This=e.data.inthis;
if(This.$focus=="")return;
switch(e.keyCode){
case 46://删除
This.delNode(This.$focus,true);
This.delLine(This.$focus);
break;
}
});
}
}
GooFlow.prototype = {
useSVG: "",
getSvgMarker: function (id, color) {
var m = document.createElementNS("http://www.w3.org/2000/svg", "marker");
m.setAttribute("id", id);
m.setAttribute("viewBox", "0 0 6 6");
m.setAttribute("refX", 5);
m.setAttribute("refY", 3);
m.setAttribute("markerUnits", "strokeWidth");
m.setAttribute("markerWidth", 6);
m.setAttribute("markerHeight", 6);
m.setAttribute("orient", "auto");
var path = document.createElementNS("http://www.w3.org/2000/svg", "path");
path.setAttribute("d", "M 0 0 L 6 3 L 0 6 z");
path.setAttribute("fill", color);
path.setAttribute("stroke-width", 0);
m.appendChild(path);
return m;
},
initDraw: function (id, width, height) {
var elem;
if (GooFlow.prototype.useSVG != "") {
this.$draw = document.createElementNS("http://www.w3.org/2000/svg", "svg"); //可创建带有指定命名空间的元素节点
this.$workArea.prepend(this.$draw);
var defs = document.createElementNS("http://www.w3.org/2000/svg", "defs");
this.$draw.appendChild(defs);
defs.appendChild(GooFlow.prototype.getSvgMarker("arrow1", "#15428B"));
defs.appendChild(GooFlow.prototype.getSvgMarker("arrow2", "#ff3300"));
defs.appendChild(GooFlow.prototype.getSvgMarker("arrow3", "#ff3300"));
}
else {
this.$draw = document.createElement("v:group");
this.$draw.coordsize = width * 3 + "," + height * 3;
this.$workArea.prepend("<div class='GooFlow_work_vml' style='position:relative;width:" + width * 3 + "px;height:" + height * 3 + "px'></div>");
this.$workArea.children("div")[0].insertBefore(this.$draw, null);
}
this.$draw.id = id;
this.$draw.style.width = width * 3 + "px";
this.$draw.style.height = +height * 3 + "px";
//绑定连线的点击选中以及双击编辑事件
var tmpClk = null;
if (GooFlow.prototype.useSVG != "") tmpClk = "g";
else tmpClk = "PolyLine";
if (this.$editable) {
$(this.$draw).delegate(tmpClk, "click", { inthis: this }, function (e) {
e.data.inthis.focusItem(this.id, true);
});
$(this.$draw).delegate(tmpClk, "dblclick", { inthis: this }, function (e) {
var oldTxt, x, y, from, to;
var This = e.data.inthis;
if (GooFlow.prototype.useSVG != "") {
oldTxt = this.childNodes[2].textContent;
from = this.getAttribute("from").split(",");
to = this.getAttribute("to").split(",");
} else {
oldTxt = this.childNodes[1].innerHTML;
var n = this.getAttribute("fromTo").split(",");
from = [n[0], n[1]];
to = [n[2], n[3]];
}
if (This.$lineData[this.id].type == "lr") {
from[0] = This.$lineData[this.id].M;
to[0] = from[0];
}
else if (This.$lineData[this.id].type == "tb") {
from[1] = This.$lineData[this.id].M;
to[1] = from[1];
}
x = (parseInt(from[0], 10) + parseInt(to[0], 10)) / 2 - 60;
y = (parseInt(from[1], 10) + parseInt(to[1], 10)) / 2 - 12;
var t = getElCoordinate(This.$workArea[0]);
This.$textArea.val(oldTxt).css({ display: "block", width: 120, height: 14,
left: t.left + x - This.$workArea[0].parentNode.scrollLeft,
top: t.top + y - This.$workArea[0].parentNode.scrollTop
}).data("id", This.$focus).focus();
This.$workArea.parent().one("mousedown", function (e) {
if (e.button == 2) return false;
This.setName(This.$textArea.data("id"), This.$textArea.val(), "line");
This.$textArea.val("").removeData("id").hide();
});
});
}
},
initGroup: function (width, height) {
this.$group = $("<div class='GooFlow_work_group' style='width:" + width * 3 + "px;height:" + height * 3 + "px'></div>"); //存放背景区域的容器
this.$workArea.prepend(this.$group);
if (!this.$editable) return;
//区域划分框操作区的事件绑定
this.$group.on("mousedown", { inthis: this }, function (e) {//绑定RESIZE功能以及移动功能
if (e.button == 2) return false;
var This = e.data.inthis;
if (This.$nowType != "group") return;
if (This.$textArea.css("display") == "block") {
This.setName(This.$textArea.data("id"), This.$textArea.val(), "area");
This.$textArea.val("").removeData("id").hide();
return false;
};
if (!e) e = window.event;
var cursor = $(e.target).css("cursor");
var id = e.target.parentNode;
switch (cursor) {
case "nw-resize": id = id.parentNode; break;
case "w-resize": id = id.parentNode; break;
case "n-resize": id = id.parentNode; break;
case "move": break;
default: return;
}
id = id.id;
var hack = 1;
if (navigator.userAgent.indexOf("8.0") != -1) hack = 0;
var ev = mousePosition(e), t = getElCoordinate(This.$workArea[0]);
var X, Y;
X = ev.x - t.left + This.$workArea[0].parentNode.scrollLeft;
Y = ev.y - t.top + This.$workArea[0].parentNode.scrollTop;
if (cursor != "move") {
This.$ghost.css({ display: "block",
width: This.$areaData[id].width - 2 + "px", height: This.$areaData[id].height - 2 + "px",
top: This.$areaData[id].top + t.top - This.$workArea[0].parentNode.scrollTop + hack + "px",
left: This.$areaData[id].left + t.left - This.$workArea[0].parentNode.scrollLeft + hack + "px", cursor: cursor
});
var vX = (This.$areaData[id].left + This.$areaData[id].width) - X;
var vY = (This.$areaData[id].top + This.$areaData[id].height) - Y;
}
else {
var vX = X - This.$areaData[id].left;
var vY = Y - This.$areaData[id].top;
}
var isMove = false;
This.$ghost.css("cursor", cursor);
document.onmousemove = function (e) {
if (!e) e = window.event;
var ev = mousePosition(e);
if (cursor != "move") {
X = ev.x - t.left + This.$workArea[0].parentNode.scrollLeft - This.$areaData[id].left + vX;
Y = ev.y - t.top + This.$workArea[0].parentNode.scrollTop - This.$areaData[id].top + vY;
if (X < 200) X = 200;
if (Y < 100) Y = 100;
switch (cursor) {
case "nw-resize": This.$ghost.css({ width: X - 2 + "px", height: Y - 2 + "px" }); break;
case "w-resize": This.$ghost.css({ width: X - 2 + "px" }); break;
case "n-resize": This.$ghost.css({ height: Y - 2 + "px" }); break;
}
}
else {
if (This.$ghost.css("display") == "none") {
This.$ghost.css({ display: "block",
width: This.$areaData[id].width - 2 + "px", height: This.$areaData[id].height - 2 + "px",
top: This.$areaData[id].top + t.top - This.$workArea[0].parentNode.scrollTop + hack + "px",
left: This.$areaData[id].left + t.left - This.$workArea[0].parentNode.scrollLeft + hack + "px", cursor: cursor
});
}
X = ev.x - vX; Y = ev.y - vY;
if (X < t.left - This.$workArea[0].parentNode.scrollLeft)
X = t.left - This.$workArea[0].parentNode.scrollLeft;
else if (X + This.$workArea[0].parentNode.scrollLeft + This.$areaData[id].width > t.left + This.$workArea.width())
X = t.left + This.$workArea.width() - This.$workArea[0].parentNode.scrollLeft - This.$areaData[id].width;
if (Y < t.top - This.$workArea[0].parentNode.scrollTop)
Y = t.top - This.$workArea[0].parentNode.scrollTop;
else if (Y + This.$workArea[0].parentNode.scrollTop + This.$areaData[id].height > t.top + This.$workArea.height())
Y = t.top + This.$workArea.height() - This.$workArea[0].parentNode.scrollTop - This.$areaData[id].height;
This.$ghost.css({ left: X + hack + "px", top: Y + hack + "px" });
}
isMove = true;
}
document.onmouseup = function (e) {
This.$ghost.empty().hide();
document.onmousemove = null;
document.onmouseup = null;
if (!isMove) return;
if (cursor != "move")
This.resizeArea(id, This.$ghost.outerWidth(), This.$ghost.outerHeight());
else
This.moveArea(id, X + This.$workArea[0].parentNode.scrollLeft - t.left, Y + This.$workArea[0].parentNode.scrollTop - t.top);
return false;
}
});
//绑定修改文字说明功能
this.$group.on("dblclick", { inthis: this }, function (e) {
var This = e.data.inthis;
if (This.$nowType != "group") return;
if (!e) e = window.event;
if (e.target.tagName != "LABEL") return false;
var oldTxt = e.target.innerHTML;
var p = e.target.parentNode;
var x = parseInt(p.style.left, 10) + 18, y = parseInt(p.style.top, 10) + 1;
var t = getElCoordinate(This.$workArea[0]);
This.$textArea.val(oldTxt).css({ display: "block", width: 100, height: 14,
left: t.left + x - This.$workArea[0].parentNode.scrollLeft,
top: t.top + y - This.$workArea[0].parentNode.scrollTop
}).data("id", p.id).focus();
This.$workArea.parent().one("mousedown", function (e) {
if (e.button == 2) return false;
if (This.$textArea.css("display") == "block") {
This.setName(This.$textArea.data("id"), This.$textArea.val(), "area");
This.$textArea.val("").removeData("id").hide();
}
});
return false;
});
//绑定点击事件
this.$group.mouseup({ inthis: this }, function (e) {
var This = e.data.inthis;
if (This.$nowType != "group") return;
if (!e) e = window.event;
switch ($(e.target).attr("class")) {
case "rs_close": This.delArea(e.target.parentNode.parentNode.id); return false; //删除该分组区域
case "bg": return;
}
switch (e.target.tagName) {
case "LABEL": return false;
case "B": //绑定变色功能
var id = e.target.parentNode.id;
switch (This.$areaData[id].color) {
case "red": This.setAreaColor(id, "yellow"); break;
case "yellow": This.setAreaColor(id, "blue"); break;
case "blue": This.setAreaColor(id, "green"); break;
case "green": This.setAreaColor(id, "red"); break;
}
return false;
}
if (e.data.inthis.$ghost.css("display") == "none") {
var X, Y;
var ev = mousePosition(e), t = getElCoordinate(this);
X = ev.x - t.left + this.parentNode.parentNode.scrollLeft - 1;
Y = ev.y - t.top + this.parentNode.parentNode.scrollTop - 1;
var color = ["red", "yellow", "blue", "green"];
e.data.inthis.addArea(e.data.inthis.$id + "_area_" + e.data.inthis.$max, { name: "area_" + e.data.inthis.$max, left: X, top: Y, color: color[e.data.inthis.$max % 4], width: 200, height: 100 });
e.data.inthis.$max++;
return false;
}
});
},
//每一种类型结点及其按钮的说明文字
setNodeRemarks: function (remark) {
this.$tool.children("a").each(function () {
this.title = remark[$(this).attr("id").split("btn_")[1]];
});
this.$nodeRemark = remark;
},
//切换左边工具栏按钮,传参TYPE表示切换成哪种类型的按钮
switchToolBtn: function (type) {
this.$tool.children("#" + this.$id + "_btn_" + this.$nowType.split(" ")[0]).attr("class", "GooFlow_tool_btn");
if (this.$nowType == "group") {
this.$workArea.prepend(this.$group);
for (var key in this.$areaDom) this.$areaDom[key].addClass("lock").children("div:eq(1)").css("display", "none");
}
this.$nowType = type;
this.$tool.children("#" + this.$id + "_btn_" + type.split(" ")[0]).attr("class", "GooFlow_tool_btndown");
if (this.$nowType == "group") {
this.blurItem();
this.$workArea.append(this.$group);
for (var key in this.$areaDom) this.$areaDom[key].removeClass("lock").children("div:eq(1)").css("display", "");
}
if (this.$textArea.css("display") == "none") this.$textArea.removeData("id").val("").hide();
},
//增加一个流程结点,传参为一个JSON,有id,name,top,left,width,height,type(结点类型)等属性
addNode: function (id, json) {//yangyang
if (this.onItemAdd != null && !this.onItemAdd(id, "node", json)) return;
if (this.$undoStack && this.$editable) {
this.pushOper("delNode", [id]);
}
var mark = json.mark ? " item_mark" : "";
if (json.type.indexOf(" round") < 0) {
if (!json.width || json.width < 86) json.width = 86;
if (!json.height || json.height < 24) json.height = 24;
if (!json.top || json.top < 0) json.top = 0;
if (!json.left || json.left < 0) json.left = 0;
var hack = 0;
if (navigator.userAgent.indexOf("8.0") != -1) hack = 2;
this.$nodeDom[id] = $("<div class='GooFlow_item" + mark + "' id='" + id + "' style='top:" + json.top + "px;left:" + json.left + "px'><table cellspacing='1' style='width:" + (json.width - 2) + "px;height:" + (json.height - 2) + "px;'><tr><td class='ico'><b class='ico_" + json.type + "'></b></td><td>" + json.name + "</td></tr></table><div style='display:none'><div class='rs_bottom'></div><div class='rs_right'></div><div class='rs_rb'></div><div class='rs_close'></div></div></div>");
if (json.type.indexOf(" mix") > -1) this.$nodeDom[id].addClass("item_mix");
}
else {
json.width = 24; json.height = 24;
this.$nodeDom[id] = $("<div class='GooFlow_item item_round" + mark + "' id='" + id + "' style='top:" + json.top + "px;left:" + json.left + "px'><table cellspacing='0'><tr><td class='ico'><b class='ico_" + json.type + "'></b></td></tr></table><div style='display:none'><div class='rs_close'></div></div><div class='span'>" + json.name + "</div></div>");
}
var ua = navigator.userAgent.toLowerCase();
if (ua.indexOf('msie') != -1 && ua.indexOf('8.0') != -1)
this.$nodeDom[id].css("filter", "progid:DXImageTransform.Microsoft.Shadow(color=#94AAC2,direction=135,strength=2)");
this.$workArea.append(this.$nodeDom[id]);
var ss= {nodeid:id,name:json.name,left:json.left,top:json.top,type:json.type,width:json.width,height:json.height,alt:json.alt};
this.$nodeData[id] = ss; ////////////////////////////yangyang
alert(ss);
//{id:e.data.inthis.$id+"_node_"+e.data.inthis.$max,name:"node_"+e.data.inthis.$max,left:X,top:Y,type:e.data.inthis.$nowType}
++this.$nodeCount;
if (this.$editable) {
this.$nodeData[id].alt = true;
if (this.$deletedItem[id]) delete this.$deletedItem[id]; //在回退删除操作时,去掉该元素的删除记录
}
},
initWorkForNode: function () {
//绑定点击事件
this.$workArea.delegate(".GooFlow_item", "click", { inthis: this }, function (e) {
e.data.inthis.focusItem(this.id, true);
$(this).removeClass("item_mark");
});
//绑定用鼠标移动事件
this.$workArea.delegate(".ico", "mousedown", { inthis: this }, function (e) {
if (!e) e = window.event;
if (e.button == 2) return false;
var This = e.data.inthis;
if (This.$nowType == "direct") return;
var Dom = $(this).parents(".GooFlow_item");
var id = Dom.attr("id");
This.focusItem(id, true);
var hack = 1;
if (navigator.userAgent.indexOf("8.0") != -1) hack = 0;
var ev = mousePosition(e), t = getElCoordinate(This.$workArea[0]);
Dom.children("table").clone().prependTo(This.$ghost);
var X, Y;
X = ev.x - t.left + This.$workArea[0].parentNode.scrollLeft;
Y = ev.y - t.top + This.$workArea[0].parentNode.scrollTop;
var vX = X - This.$nodeData[id].left, vY = Y - This.$nodeData[id].top;
var isMove = false;
document.onmousemove = function (e) {
if (!e) e = window.event;
var ev = mousePosition(e);
if (X == ev.x - vX && Y == ev.y - vY) return false;
X = ev.x - vX; Y = ev.y - vY;
if (isMove && This.$ghost.css("display") == "none") {
This.$ghost.css({ display: "block",
width: This.$nodeData[id].width - 2 + "px", height: This.$nodeData[id].height - 2 + "px",
top: This.$nodeData[id].top + t.top - This.$workArea[0].parentNode.scrollTop + hack + "px",
left: This.$nodeData[id].left + t.left - This.$workArea[0].parentNode.scrollLeft + hack + "px", cursor: "move"
});
}
if (X < t.left - This.$workArea[0].parentNode.scrollLeft)
X = t.left - This.$workArea[0].parentNode.scrollLeft;
else if (X + This.$workArea[0].parentNode.scrollLeft + This.$nodeData[id].width > t.left + This.$workArea.width())
X = t.left + This.$workArea.width() - This.$workArea[0].parentNode.scrollLeft - This.$nodeData[id].width;
if (Y < t.top - This.$workArea[0].parentNode.scrollTop)
Y = t.top - This.$workArea[0].parentNode.scrollTop;
else if (Y + This.$workArea[0].parentNode.scrollTop + This.$nodeData[id].height > t.top + This.$workArea.height())
Y = t.top + This.$workArea.height() - This.$workArea[0].parentNode.scrollTop - This.$nodeData[id].height;
This.$ghost.css({ left: X + hack + "px", top: Y + hack + "px" });
isMove = true;
}
document.onmouseup = function (e) {
if (isMove) This.moveNode(id, X + This.$workArea[0].parentNode.scrollLeft - t.left, Y + This.$workArea[0].parentNode.scrollTop - t.top);
This.$ghost.empty().hide();
document.onmousemove = null;
document.onmouseup = null;
}
});
if (!this.$editable) return;
//绑定鼠标覆盖/移出事件
this.$workArea.delegate(".GooFlow_item", "mouseenter", { inthis: this }, function (e) {
if (e.data.inthis.$nowType != "direct") return;
$(this).addClass("item_mark");
});
this.$workArea.delegate(".GooFlow_item", "mouseleave", { inthis: this }, function (e) {
if (e.data.inthis.$nowType != "direct") return;
$(this).removeClass("item_mark");
});
//绑定连线时确定初始点
this.$workArea.delegate(".GooFlow_item", "mousedown", { inthis: this }, function (e) {
if (e.button == 2) return false;
var This = e.data.inthis;
if (This.$nowType != "direct") return;
var ev = mousePosition(e), t = getElCoordinate(This.$workArea[0]);
var X, Y;
X = ev.x - t.left + This.$workArea[0].parentNode.scrollLeft;
Y = ev.y - t.top + This.$workArea[0].parentNode.scrollTop;
This.$workArea.data("lineStart", { "x": X, "y": Y, "id": this.id }).css("cursor", "crosshair");
var line = GooFlow.prototype.drawLine("GooFlow_tmp_line", [X, Y], [X, Y], true, true);
This.$draw.appendChild(line);
});
//绑定连线时确定结束点
this.$workArea.delegate(".GooFlow_item", "mouseup", { inthis: this }, function (e) {
var This = e.data.inthis;
if (This.$nowType != "direct") return;
var lineStart = This.$workArea.data("lineStart");
if (lineStart) This.addLine(This.$id + "_line_" + This.$max, { from: lineStart.id, to: this.id, name: "" });
This.$max++;
});
//绑定双击编辑事件
this.$workArea.delegate(".GooFlow_item > .span", "dblclick", { inthis: this }, function (e) {
var oldTxt = this.innerHTML;
var This = e.data.inthis;
var id = this.parentNode.id;
var t = getElCoordinate(This.$workArea[0]);
This.$textArea.val(oldTxt).css({ display: "block", height: $(this).height(), width: 100,
left: t.left + This.$nodeData[id].left - This.$workArea[0].parentNode.scrollLeft - 24,
top: t.top + This.$nodeData[id].top - This.$workArea[0].parentNode.scrollTop + 26
})
.data("id", This.$focus).focus();
This.$workArea.parent().one("mousedown", function (e) {
if (e.button == 2) return false;
This.setName(This.$textArea.data("id"), This.$textArea.val(), "node");
This.$textArea.val("").removeData("id").hide();
});
});
this.$workArea.delegate(".ico + td", "dblclick", { inthis: this }, function (e) {
var oldTxt = this.innerHTML;
var This = e.data.inthis;
var id = $(this).parents(".GooFlow_item").attr("id");
var t = getElCoordinate(This.$workArea[0]);
This.$textArea.val(oldTxt).css({ display: "block", width: $(this).width() + 24, height: $(this).height(),
left: t.left + 24 + This.$nodeData[id].left - This.$workArea[0].parentNode.scrollLeft,
top: t.top + 2 + This.$nodeData[id].top - This.$workArea[0].parentNode.scrollTop
})
.data("id", This.$focus).focus();
This.$workArea.parent().one("mousedown", function (e) {
if (e.button == 2) return false;
This.setName(This.$textArea.data("id"), This.$textArea.val(), "node");
This.$textArea.val("").removeData("id").hide();
});
});
//绑定结点的删除功能
this.$workArea.delegate(".rs_close", "click", { inthis: this }, function (e) {
if (!e) e = window.event;
e.data.inthis.delNode(e.data.inthis.$focus);
return false;
});
//绑定结点的RESIZE功能
this.$workArea.delegate(".GooFlow_item > div > div[class!=rs_close]", "mousedown", { inthis: this }, function (e) {
if (!e) e = window.event;
if (e.button == 2) return false;
var cursor = $(this).css("cursor");
if (cursor == "pointer") { return; }
var This = e.data.inthis;
var id = This.$focus;
This.switchToolBtn("cursor");
e.cancelBubble = true;
e.stopPropagation();
var hack = 1;
if (navigator.userAgent.indexOf("8.0") != -1) hack = 0;
var ev = mousePosition(e), t = getElCoordinate(This.$workArea[0]);
This.$ghost.css({ display: "block",
width: This.$nodeData[id].width - 2 + "px", height: This.$nodeData[id].height - 2 + "px",
top: This.$nodeData[id].top + t.top - This.$workArea[0].parentNode.scrollTop + hack + "px",
left: This.$nodeData[id].left + t.left - This.$workArea[0].parentNode.scrollLeft + hack + "px", cursor: cursor
});
var X, Y;
X = ev.x - t.left + This.$workArea[0].parentNode.scrollLeft;
Y = ev.y - t.top + This.$workArea[0].parentNode.scrollTop;
var vX = (This.$nodeData[id].left + This.$nodeData[id].width) - X;
var vY = (This.$nodeData[id].top + This.$nodeData[id].height) - Y;
var isMove = false;
This.$ghost.css("cursor", cursor);
document.onmousemove = function (e) {
if (!e) e = window.event;
var ev = mousePosition(e);
X = ev.x - t.left + This.$workArea[0].parentNode.scrollLeft - This.$nodeData[id].left + vX;
Y = ev.y - t.top + This.$workArea[0].parentNode.scrollTop - This.$nodeData[id].top + vY;
if (X < 86) X = 86;
if (Y < 24) Y = 24;
isMove = true;
switch (cursor) {
case "nw-resize": This.$ghost.css({ width: X - 2 + "px", height: Y - 2 + "px" }); break;
case "w-resize": This.$ghost.css({ width: X - 2 + "px" }); break;
case "n-resize": This.$ghost.css({ height: Y - 2 + "px" }); break;
}
}
document.onmouseup = function (e) {
This.$ghost.hide();
if (!isMove) return;
if (!e) e = window.event;
This.resizeNode(id, This.$ghost.outerWidth(), This.$ghost.outerHeight());
document.onmousemove = null;
document.onmouseup = null;
}
});
},
//获取结点/连线/分组区域的详细信息
getItemInfo: function (id, type) {
switch (type) {
case "node": return this.$nodeData[id] || null;
case "line": return this.$lineData[id] || null;
case "area": return this.$areaData[id] || null;
}
},
//取消所有结点/连线被选定的状态
blurItem: function () {
if (this.$focus != "") {
var jq = $("#" + this.$focus);
if (jq.prop("tagName") == "DIV") {
if (this.onItemBlur != null && !this.onItemBlur(id, "node")) return false;
jq.removeClass("item_focus").children("div:eq(0)").css("display", "none");
}
else {
if (this.onItemBlur != null && !this.onItemBlur(id, "line")) return false;
if (GooFlow.prototype.useSVG != "") {
if (!this.$lineData[this.$focus].marked) {
jq[0].childNodes[1].setAttribute("stroke", "#5068AE");
jq[0].childNodes[1].setAttribute("marker-end", "url(#arrow1)");
}
}
else {
if (!this.$lineData[this.$focus].marked) jq[0].strokeColor = "#5068AE";
}
this.$lineMove.hide().removeData("type").removeData("tid");
if (this.$editable) this.$lineOper.hide().removeData("tid");
}
}
this.$focus = "";
return true;
},
//选定某个结点/转换线 bool:TRUE决定了要触发选中事件,FALSE则不触发选中事件,多用在程序内部调用。
focusItem: function (id, bool) {
var jq = $("#" + id);
if (jq.length == 0) return;
if (!this.blurItem()) return; //先执行"取消选中",如果返回FLASE,则也会阻止选定事件继续进行.
if (jq.prop("tagName") == "DIV") {
if (bool && this.onItemFocus != null && !this.onItemFocus(id, "node")) return;
jq.addClass("item_focus");
if (this.$editable) jq.children("div:eq(0)").css("display", "block");
this.$workArea.append(jq);
}
else {//如果是连接线
if (this.onItemFocus != null && !this.onItemFocus(id, "line")) return;
if (GooFlow.prototype.useSVG != "") {
jq[0].childNodes[1].setAttribute("stroke", "#ff3300");
jq[0].childNodes[1].setAttribute("marker-end", "url(#arrow2)");
}
else jq[0].strokeColor = "#ff3300";
if (!this.$editable) return;
var x, y, from, to;
if (GooFlow.prototype.useSVG != "") {
from = jq.attr("from").split(",");
to = jq.attr("to").split(",");
} else {
var n = jq[0].getAttribute("fromTo").split(",");
from = [n[0], n[1]];
to = [n[2], n[3]];
}
from[0] = parseInt(from[0], 10);
from[1] = parseInt(from[1], 10);
to[0] = parseInt(to[0], 10);
to[1] = parseInt(to[1], 10);
//var t=getElCoordinate(this.$workArea[0]);
if (this.$lineData[id].type == "lr") {
from[0] = this.$lineData[id].M;
to[0] = from[0];
this.$lineMove.css({
width: "5px", height: (to[1] - from[1]) * (to[1] > from[1] ? 1 : -1) + "px",
left: from[0] - 3 + "px",
top: (to[1] > from[1] ? from[1] : to[1]) + 1 + "px",
cursor: "e-resize", display: "block"
}).data({ "type": "lr", "tid": id });
}
else if (this.$lineData[id].type == "tb") {
from[1] = this.$lineData[id].M;
to[1] = from[1];
this.$lineMove.css({
width: (to[0] - from[0]) * (to[0] > from[0] ? 1 : -1) + "px", height: "5px",
left: (to[0] > from[0] ? from[0] : to[0]) + 1 + "px",
top: from[1] - 3 + "px",
cursor: "s-resize", display: "block"
}).data({ "type": "tb", "tid": id });
}
x = (from[0] + to[0]) / 2 - 35;
y = (from[1] + to[1]) / 2 + 6;
this.$lineOper.css({ display: "block", left: x + "px", top: y + "px" }).data("tid", id);
}
this.$focus = id;
this.switchToolBtn("cursor");
},
//移动结点到一个新的位置
moveNode: function (id, left, top) {
if (!this.$nodeData[id]) return;
if (this.onItemMove != null && !this.onItemMove(id, "node", left, top)) return;
if (this.$undoStack) {
var paras = [id, this.$nodeData[id].left, this.$nodeData[id].top];
this.pushOper("moveNode", paras);
}
if (left < 0) left = 0;
if (top < 0) top = 0;
$("#" + id).css({ left: left + "px", top: top + "px" });
this.$nodeData[id].left = left;
this.$nodeData[id].top = top;
//重画转换线
this.resetLines(id, this.$nodeData[id]);
if (this.$editable) {
this.$nodeData[id].alt = true;
}
},
//设置结点/连线/分组区域的文字信息
setName: function (id, name, type) {
var oldName;
if (type == "node") {//如果是结点
if (!this.$nodeData[id]) return;
if (this.$nodeData[id].name == name) return;
if (this.onItemRename != null && !this.onItemRename(id, name, "node")) return;
oldName = this.$nodeData[id].name;
this.$nodeData[id].name = name;
if (this.$nodeData[id].type.indexOf("round") > 1) {
this.$nodeDom[id].children(".span").text(name);
}
else {
this.$nodeDom[id].find("td:eq(1)").text(name);
var hack = 0;
if (navigator.userAgent.indexOf("8.0") != -1) hack = 2;
var width = this.$nodeDom[id].outerWidth();
var height = this.$nodeDom[id].outerHeight();
this.$nodeDom[id].children("table").css({ width: width - 2 + "px", height: height - 2 + "px" });
this.$nodeData[id].width = width;
this.$nodeData[id].height = height;
}
if (this.$editable) {
this.$nodeData[id].alt = true;
}
//重画转换线
this.resetLines(id, this.$nodeData[id]);
}
else if (type == "line") {//如果是线
if (!this.$lineData[id]) return;
if (this.$lineData[id].name == name) return;
if (this.onItemRename != null && !this.onItemRename(id, name, "line")) return;
oldName = this.$lineData[id].name;
this.$lineData[id].name = name;
if (GooFlow.prototype.useSVG != "") {
this.$lineDom[id].childNodes[2].textContent = name;
}
else {
this.$lineDom[id].childNodes[1].innerHTML = name;
var n = this.$lineDom[id].getAttribute("fromTo").split(",");
var x;
if (this.$lineData[id].type != "lr") {
x = (n[2] - n[0]) / 2;
}
else {
var Min = n[2] > n[0] ? n[0] : n[2];
if (Min > this.$lineData[id].M) Min = this.$lineData[id].M;
x = this.$lineData[id].M - Min;
}
if (x < 0) x = x * -1;
this.$lineDom[id].childNodes[1].style.left = x - this.$lineDom[id].childNodes[1].offsetWidth / 2 + 4 + "px";
}
if (this.$editable) {
this.$lineData[id].alt = true;
}
}
else if (type == "area") {//如果是分组区域
if (!this.$areaData[id]) return;
if (this.$areaData[id].name == name) return;
if (this.onItemRename != null && !this.onItemRename(id, name, "area")) return;
oldName = this.$areaData[id].name;
this.$areaData[id].name = name;
this.$areaDom[id].children("label").text(name);
if (this.$editable) {
this.$areaData[id].alt = true;