-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjceditor.js
4588 lines (3477 loc) · 136 KB
/
jceditor.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
/**
* @fileoverview 기존의 오픈소스 웹 에디터들의 업데이트 미지원과 유료화 진행으로 인하여
* 보다 가볍고 필요한 기능 위주의 오픈 소스 에디터를 만들어 보고자 한다.
*
* @author Jang Jin Chul
* @version 1.0
*/
/**
* 에디터 모듈을 로드 한다.
*
*/
/**
* JCEDITOR 에서 이용 할 함수를 관리한다.
*
*/
var Browser = (function(){
var returnObj = {};
returnObj.type ="";
returnObj.version= "";
var browerAgent = navigator.userAgent;
var browerType = ""; // 브라우져 종류
// 브라우져 종류 설정.
if (browerAgent.indexOf("Chrome") != -1) {
browerType = "Chrome";
} else if (browerAgent.indexOf("Firefox") != -1) {
browerType = "Firefox";
} else if (browerAgent.indexOf("Safari") != -1) {
browerType = "Safari";
} else if (browerAgent.indexOf("MSIE") != -1 || browerAgent.indexOf("rv:") != -1) {
browerType = "MSIE";
}else{
browerType = "Opera";
}
returnObj.type = browerType;
var rv = -1; // Return value assumes failure.
var ua = navigator.userAgent;
var re = null;
if (browerType == "MSIE") {
if (browerAgent.indexOf("rv:") != -1) {
re = new RegExp("rv:([0-9]{1,}[\.0-9]{0,})");
}else{
re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
}
} else {
re = new RegExp(browerType + "/([0-9]{1,}[\.0-9]{0,})");
}
if (re.exec(ua) != null) {
rv = parseFloat(RegExp.$1);
}
returnObj.version = rv;
return returnObj;
})();
var $J = function (queryId, select) {
if (queryId.indexOf("#") != -1 && queryId.charAt(0) == "#") {
queryId = queryId.substr(1);
switch (select) {
case "wrap":
queryId = queryId + "-jceditor-wrap-div";
break;
case "cTable":
queryId = queryId + "-jceditor-container-table";
break;
case "dragBlock":
queryId = queryId + "-jceditor-dragBlock-div";
break;
case "dragResize":
queryId = queryId + "-jceditor-dragResize-div";
break;
case "ifrm":
queryId = queryId + "-jceditor-edit-iframe";
return {
iframe: document.getElementById(queryId),
contentWindow: function () {
return document.getElementById(queryId).contentWindow;
},
doc: function () {
return document.getElementById(queryId).contentWindow.document;
},
body: function () {
return document.getElementById(queryId).contentWindow.document.getElementsByTagName("body");
}
};
break;
default:
queryId;
break;
}
return document.getElementById(queryId);
} else if (queryId.indexOf("#") == -1) {
return document.getElementsByTagName(queryId);
}
};
var addEvent = function (editBox, eventName, func) {
if (editBox.attachEvent) {
return editBox.attachEvent(eventName, func);
} else if (window.addEventListener) {
return editBox.addEventListener(eventName.replace(/^on/i, ""), func, false);
}
};
/**
* 에디터 창을 리사이징 한다.
* @class
* @param textAreaId
* @param ifrmId
*/
var DragResize = function (textAreaId, ifrmId) {
var startPosX;
var startPosY;
var reSizeStart;
var diffPosX = 0;
var diffPosY = 0;
var self = this;
var textAreaId = textAreaId;
var ifrmId = ifrmId;
this.dragResize_mouse_down = function (event) {
event = event ? event : window.event;
event.cancelBubble = true;
startPosX = event.clientX;
startPosY = event.clientY;
reSizeStart = true;
//dragResize를 하기 위해서 iframe 위에 block 레이러를 덧씌워준다. 그렇게 하지 않으면 좌표가 사라져 drag가 되지 않음
$J("#" + textAreaId, "dragBlock").style.display = "block";
addEvent(window.document, "onmousemove", self.dragResize_mouse_move);
addEvent(window.document, "onmouseup", self.dragResize_mouse_up);
};
this.dragResize_mouse_move = function (event) {
event = event ? event : window.event;
var editBox_container_table = $J("#" + textAreaId, "cTable");
var editBox_iframe = $J("#" + ifrmId);
var editBox_textArea = $J("#" + textAreaId);
var doc = editBox_container_table.getElementsByTagName("tr")[0];
var contentHeight = 0;
if(doc.offsetHeight != 0){
contentHeight = doc.offsetHeight; // 현재 지정된 객체의 padding값을 포함한 높이.(눈에보이는 높이 그대로..
}
if (editBox_container_table && reSizeStart) {
var movePosX = parseInt(editBox_container_table.style.width.substr(0, editBox_container_table.style.width.indexOf("px"))) + event.clientX - startPosX;
var movePosY = parseInt(editBox_container_table.style.height.substr(0, editBox_container_table.style.height.indexOf("px"))) + event.clientY - startPosY;
// console.log(contentoffsetHeight);
diffPosX = movePosX;
diffPosY = movePosY;
if (movePosX > 400 && (movePosY-contentHeight) > 65) {
editBox_container_table.style.cssText += "; width: " + movePosX + "px; height: " + ((movePosY)) + "px;";
editBox_iframe.style.cssText = "; height: "+(movePosY) + "px";
editBox_textArea.style.cssText= "; height: "+(movePosY) + "px";
startPosX = event.clientX;
startPosY = event.clientY;
}
}
};
this.dragResize_mouse_up = function (event) {
reSizeStart = false;
//drag후에 iframe에 있는 내용을 편집하기 위하여 block 레이어를 없애준다.
$J("#" + textAreaId, "dragBlock").style.display = "";
addEvent(window.document, "onmousemove", null);
addEvent(window.document, "onmouseup", null);
$J("#" + textAreaId, "dragResize").onmouseout = null;
};
this.dragResize = function () {
var targetObj = $J("#" + textAreaId, "dragResize");
addEvent(targetObj, "onmousedown", self.dragResize_mouse_down);
};
};
/**
* @class
* @param textAreaId textarea 아이디
* @param width 가ㄹ크기
* @param height 높이
* @param config 설정
*
*/
var JCEditor = function(textAreaId,width,height,config){
/** TextArea Id**/
this.textAreaId = textAreaId || "";
/** iframe Id**/
this.ifrmId = textAreaId+"-jceditor-edit-iframe";
/**TextArea 객체. **/
this.taObj = null;
/**내용을 편집 하기 위한 iframe Contet.. **/
this.ifrmContent = null;
/** 아이프레임 document..**/
this.ifrmDoc = null;
/** 에디터 가로 크기 **/
this.width = width || "600px";
/** 에디터 세로 크기 **/
this.height = height || "500px";
/** 현재 자신을 가리키는 객체**/
this.self = this;
/** selection 객체를 text와 htmltext값과 함께 제공한다.**/
this.selection = null;
/** 펼처진 DropDownId 를 저장한다.**/
this.oldDropDownId=null;
/** 펼처진 DropDown객체 를 저장한다.**/
this.oldDropDownObj=null;
/** 펼처진 DropDownBtn 객체 를 저장한다.**/
this.oldDropDownBtn=null;
/** 에디터 편집창의 히스토리를 저장한다.**/
this.history = new Array();
/** 저장된 히스토리를 꺼내올 인덱스 번호.**/
this.historyPos = -1;
/** 전체 화면 모드 지정.**/
this.fullMode = false;
/** IE11 에서 포커스를 일어버리는 현상이 발생하여 선택된 부분 저장.**/
this.storedSelections = [];
this.clickTableObj;
this.currRowIndex = 0;
this.currColIndex = 0;
/** 옵션 설정 Json 방식으로 넘어온다. **/
this.config = {
hideGroup : {
groupA : false,
groupB : false,
groupC : false,
groupD : false,
groupE : false,
groupF : false,
groupG : false,
groupH : false,
group1 : false,
group2 : false,
group3 : false,
group4 : false,
group5 : false,
group6 : false,
group7 : false,
group8 : false
},
hideButton : {
FormatBlock : false,
FontFamily : false,
FontSize : false,
Bold : false,
Underline : false,
Italic : false,
Strikethrough : false,
ForeColor : false,
BackColor : false,
Justifyleft : false,
Justifycenter : false,
Justifyright : false,
Justifyfull : false,
Insertorderedlist : false,
Insertunorderedlist : false,
Outdent : false,
Indent : false,
CreateLink : false,
UnLink : false,
Htmlmode : false,
NewDocument : false,
Undo : false,
Redo : false,
Cut : false,
Copy : false,
Paste : false,
SelectAll : false,
SubScript : false,
SuperScript : false,
RemoveFormat : false,
Quotation : false,
Emoticon : false,
Scharacter : false,
Table : false,
Picture : false,
Flash : false,
Inserthorizontalrule : false,
PrintLine : false,
Preview : false,
Print : false,
FullScreen : false
},
enterMode : false,
allowScript : false,
allowScriptValidateMessage : false,
pTagMargin : {
marginTop : "15",
marginBottom : "15",
lineHeight : "1.2"
}
};
/** 전체 화면 모드일 때 이전 크기로 복원하기 위해 가로,세로 정보를 저장한다.**/
this.fullModeElOffset = {
containerWidth : 0,
containerHeight : 0,
contentWidth : 0,
contentHeight : 0
};
/**
* 에디터 생성시 글자 크기 설정하는 정보.
* @type Json
*/
this.fontSizeInfo={
"1" : "8pt",
"2" : "10pt",
"3" : "12pt",
"4" : "14pt",
"5" : "18pt",
"6" : "24pt",
"7" : "36pt"
};
this.formatblockInfo = {
"p" : "기본 문단",
"address" : "주소" ,
"h1": "제목 1",
"h2": "제목 2",
"h3": "제목 3",
"h4": "제목 4",
"h5": "제목 5",
"h6": "제목 6",
"pre" : "Formatted"
};
/**
* 에디터에서 이용할 폰트 목록
*/
this.fontFamilyInfo=["굴림", "굴림체", "돋움", "돋움체", "바탕", "바탕체", "궁서", "Arial", "Arial Black", "Comic Sans Ms", "Courier New", "Tahoma", "Verdana"];
this.toolBar = {
optionToolBar : {
groupA : ["NewDocument"],
groupB : ["Undo","Redo"],
groupC : ["Cut","Copy","Paste","SelectAll"],
groupD : ["SubScript","SuperScript","RemoveFormat"],
groupE : ["Quotation","Emoticon","Scharacter","Table","Picture","Flash","Inserthorizontalrule"],
groupF : ["CreateLink","UnLink"],
groupG : ["PrintLine","Preview","Print"],
groupH: ["FullScreen"]
},
defaultToolBar : {
group1 : ["FormatBlock"],
group2 : ["FontFamily"],
group3 : ["FontSize"],
group4 : ["Bold","Underline","Italic","Strikethrough","ForeColor","BackColor"],
group5 : ["Justifyleft","Justifycenter","Justifyright","Justifyfull"],
group6 : ["Insertorderedlist","Insertunorderedlist"],
group7 : ["Outdent","Indent"],
group8 : ["Htmlmode"]
}
};
/**
* 에디터 툴바 버튼에 적용될 버튼 정보.
* @type Json
*/
this.toolBarInfo = {
//커맨드 이름 //버튼 누르기 전 css class //버튼 누른 후 css class //버튼 효과....
FormatBlock : ["FormatBlock", "jceditor-formatblock-btn-off" ,"jceditor-formatblock-btn-on" ,"jceditor-formatblock-btn-disabled" ,"스타일" ,false ],
FontFamily : ["FontFamily", "jceditor-fontfamily-btn-off" ,"jceditor-fontfamily-btn-on" ,"jceditor-fontfamily-btn-disabled" ,"글꼴" ,false ],
FontSize : ["FontSize", "jceditor-fontsize-btn-off" ,"jceditor-fontsize-btn-on" ,"jceditor-fontsize-btn-disabled" ,"크기" ,false ],
Bold : ["Bold", "jceditor-bold-btn-off" ,"jceditor-bold-btn-on" ,"jceditor-bold-btn-disabled" ,"굵게" ,false ],
Underline : ["Underline", "jceditor-underline-btn-off" ,"jceditor-underline-btn-on" ,"jceditor-underline-btn-disabled" ,"밑줄" ,false ],
Italic : ["Italic", "jceditor-italic-btn-off" ,"jceditor-italic-btn-on" ,"jceditor-italic-btn-disabled" ,"기울림꼴" ,false ],
Strikethrough : ["Strikethrough", "jceditor-strikethrough-btn-off" ,"jceditor-strikethrough-btn-on" ,"jceditor-strikethrough-btn-disabled" ,"취소선" ,false ],
ForeColor : ["ForeColor", "jceditor-forecolor-btn-off" ,"jceditor-forecolor-btn-on" ,"jceditor-forecolor-btn-disabled" ,"글자색" ,false ],
BackColor : ["BackColor", "jceditor-backcolor-btn-off" ,"jceditor-backcolor-btn-on" ,"jceditor-backcolor-btn-disabled" ,"배경색" ,false ],
Justifyleft : ["Justifyleft", "jceditor-justifyleft-btn-off" ,"jceditor-justifyleft-btn-on" ,"jceditor-justifyleft-btn-disabled" ,"왼쪽정렬" ,false ],
Justifycenter : ["Justifycenter", "jceditor-justifycenter-btn-off" ,"jceditor-justifycenter-btn-on" ,"jceditor-justifycenter-btn-disabled" ,"중앙정렬" ,false ],
Justifyright : ["Justifyright", "jceditor-justifyright-btn-off" ,"jceditor-justifyright-btn-on" ,"jceditor-justifyright-btn-disabled" ,"오른쪽정렬" ,false ],
Justifyfull : ["Justifyfull", "jceditor-justifyfull-btn-off" ,"jceditor-justifyfull-btn-on" ,"jceditor-justifyfull-btn-disabled" ,"양쪽 맞춤" ,false ],
Insertorderedlist : ["Insertorderedlist", "jceditor-insertorderedlist-btn-off" ,"jceditor-insertorderedlist-btn-on" ,"jceditor-insertorderedlist-btn-disabled" ,"순서있는 목록" ,false ],
Insertunorderedlist : ["Insertunorderedlist", "jceditor-insertunorderedlist-btn-off" ,"jceditor-insertunorderedlist-btn-on" ,"jceditor-insertunorderedlist-btn-disabled" ,"순서없는 목록 " ,false ],
Outdent : ["Outdent", "jceditor-outdent-btn-off" ,"jceditor-outdent-btn-on" ,"jceditor-outdent-btn-disabled" ,"내어쓰기" ,true ],
Indent : ["Indent", "jceditor-indent-btn-off" ,"jceditor-indent-btn-on" ,"jceditor-indent-btn-disabled" ,"들여쓰기" ,true ],
CreateLink : ["CreateLink", "jceditor-createlink-btn-off" ,"jceditor-createlink-btn-on" ,"jceditor-createlink-btn-disabled" ,"링크" ,false ],
UnLink : ["UnLink", "jceditor-unlink-btn-off" ,"jceditor-unlink-btn-on" ,"jceditor-unlink-btn-disabled" ,"링크제거" ,false ],
Htmlmode : ["Htmlmode", "jceditor-html-btn-off" ,"jceditor-html-btn-on" ,"jceditor-html-btn-disabled" ,"배경색" ,false ],
NewDocument : ["NewDocument", "jceditor-new-btn-off" ,"jceditor-new-btn-on" ,"jceditor-new-btn-disabled" ,"새 문서" ,true ],
Undo : ["Undo", "jceditor-undo-btn-off" ,"jceditor-undo-btn-on" ,"jceditor-undo-btn-disabled" ,"되돌리기" ,true ],
Redo : ["Redo", "jceditor-redo-btn-off" ,"jceditor-redo-btn-on" ,"jceditor-redo-btn-disabled" ,"다시실행" ,true ],
Cut : ["Cut", "jceditor-cut-btn-off" ,"jceditor-cut-btn-on" ,"jceditor-cut-btn-disabled" ,"자르기" ,true ],
Copy : ["Copy", "jceditor-copy-btn-off" ,"jceditor-copy-btn-on" ,"jceditor-copy-btn-disabled" ,"복사하기" ,true ],
Paste : ["Paste", "jceditor-paste-btn-off" ,"jceditor-paste-btn-on" ,"jceditor-paste-btn-disabled" ,"붙여넣기" ,true ],
SelectAll : ["SelectAll", "jceditor-selectall-btn-off" ,"jceditor-selectall-btn-on" ,"jceditor-selectall-btn-disabled" ,"전체선택" ,true ],
SubScript : ["SubScript", "jceditor-subscript-btn-off" ,"jceditor-subscript-btn-on" ,"jceditor-subscript-btn-disabled" ,"아래첨자" ,true ],
SuperScript : ["SuperScript", "jceditor-superscript-btn-off" ,"jceditor-superscript-btn-on" ,"jceditor-superscript-btn-disabled" ,"윗첨자" ,true ],
RemoveFormat : ["RemoveFormat", "jceditor-removeformat-btn-off" ,"jceditor-removeformat-btn-on" ,"jceditor-removeformat-btn-disabled" ,"서식제거" ,true ],
Quotation : ["Quotation", "jceditor-quotation-btn-off" ,"jceditor-quotation-btn-on" ,"jceditor-quotation-btn-disabled" ,"인용구" ,false ],
Emoticon : ["Emoticon", "jceditor-emoticon-btn-off" ,"jceditor-emoticon-btn-on" ,"jceditor-emoticon-btn-disabled" ,"이모티콘" ,false ],
Scharacter : ["Scharacter", "jceditor-scharacter-btn-off" ,"jceditor-scharacter-btn-on" ,"jceditor-scharacter-btn-disabled" ,"특수문자" ,false ],
Table : ["Table", "jceditor-table-btn-off" ,"jceditor-table-btn-on" ,"jceditor-table-btn-disabled" ,"테이블" ,false ],
Picture : ["Picture", "jceditor-picture-btn-off" ,"jceditor-picture-btn-on" ,"jceditor-picture-btn-disabled" ,"사진" ,false ],
Flash : ["Flash", "jceditor-flash-btn-off" ,"jceditor-flash-btn-on" ,"jceditor-flash-btn-disabled" ,"플래시" ,false ],
Inserthorizontalrule : ["Inserthorizontalrule", "jceditor-horizon-btn-off" ,"jceditor-horizon-btn-on" ,"jceditor-horizon-btn-disabled" ,"수평선" ,true ],
PrintLine : ["PrintLine", "jceditor-printline-btn-off" ,"jceditor-printline-btn-on" ,"jceditor-printline-btn-disabled" ,"인쇄쪽나눔" ,true ],
Preview : ["Preview", "jceditor-preview-btn-off" ,"jceditor-preview-btn-on" ,"jceditor-preview-btn-disabled" ,"미리보기" ,true ],
Print : ["Print", "jceditor-print-btn-off" ,"jceditor-print-btn-on" ,"jceditor-print-btn-disabled" ,"인쇄" ,true ],
FullScreen : ["FullScreen", "jceditor-fullscreen-btn-off" ,"jceditor-fullscreen-btn-on" ,"jceditor-fullscreen-btn-disabled" ,"전체화면" ,false ]
};
this.fontcolorpalate = [ "#000000","#993300","#333300","#003300","#003366","#000080","#333399","#333333",
"#800000","#FF6600","#808000","#008000","#008080","#0000FF","#666699","#808080",
"#FF0000","#FF9900","#99CC00","#339966","#33CCCC","#3366FF","#800080","#999999",
"#FF00FF","#FFCC00","#FFFF00","#00FF00","#00FFFF","#00CCFF","#993366","#C0C0C0",
"#FF99CC","#FFCC99","#FFFF99","#CCFFCC","#CCFFFF","#99CCFF","#CC99FF","#FFFFFF"];
var setConfig = (function (self,config){
function optionAlert(optionkey){
if (typeof(optionkey) =="undefined") {
window.alert("옵션 설정 명령이 존재 하지 않습니다. 다시 확인해 주시기 바랍니다.");
return;
}
}
for ( var key in config) {
optionAlert(config[key]);
if (key =="hideGroup" || key =="hideButton") {
for ( var elkey in config[key]) {
optionAlert(self.config[key][elkey]);
self.config[key][elkey] = config[key][elkey];
}
}else{
optionAlert(self.config[key]);
self.config[key] = config[key];
}
}
})(this,config);
var init = (function(parent){
parent.setTextAreaAttribute();
var newElement = parent.wrapElement();
var layout = parent.editLayout();
parent.editPlacement(newElement,layout);
parent.iframeEditMode();
parent.setEditBoxHeight();
parent.setToolBarEvent();
//브라우져 별로 컨테츠를 조작할 수 있게 셋팅한다.
if (Browser.type == "MSIE" ) {
parent.ifrmContent = $J("#" + parent.textAreaId, "ifrm").body()[0];
}else if (Browser.type == "Opera") {
parent.ifrmContent = $J("#" + parent.textAreaId, "ifrm").contentWindow();
}else{
parent.ifrmContent = $J("#" + parent.textAreaId, "ifrm").iframe;
}
parent.ifrmDoc = $J("#" + parent.textAreaId, "ifrm").doc();
parent.taObj = $J("#" + parent.textAreaId);
parent.selection = parent.getSelection();
parent.getFocusPosition();
var drag = new DragResize(parent.textAreaId,parent.ifrmId);
drag.dragResize();
if (parent.ifrmDoc.getElementsByTagName("body")[0]) {
parent.ifrmDoc.getElementsByTagName("body")[0].innerHTML = parent.taObj.value;
}
if(parent.ifrmDoc.getElementsByTagName("body")[0].innerHTML == ""){
parent.ifrmDoc.execCommand("fontName",false,"돋움"); //10pt
parent.ifrmDoc.execCommand("formatBlock",false,"p"); //10pt
parent.ifrmDoc.execCommand("fontSize",false,2); //10pt
}
setInterval(function(){
parent.fontStyle(["font","u","em","i","strong","b","strike","p"], ["face","size","color"]);
}, 500);
})(this);
};
JCEditor.prototype = {
/**
* dropdown 레이어 아이디를 생성한다.
@param menuName select메뉴 이름
*/
getLayerId : function(menuName,type){
return this.textAreaId+"-"+menuName+type+"-div";
},
/**
* toolBar 버튼을 감싸고 있는 span 테그 이름을 생성한다.
@param menuName 메뉴 이름
*/
getBtnSpanId : function(menuName){
return this.textAreaId+"-"+menuName+"-span";
},
/**
* toolBar 버튼을 감싸고 있는 버튼(Button) 테그 이름을 생성한다.
* @param menuName 메뉴 이름
*/
getBtnId : function(menuName){
return this.textAreaId+"-"+menuName+"-btn";
},
/**
* 편집 내용을 불러온다.
* @return 편집 tag
*/
getContent : function(){
var aTag = this.ifrmDoc.getElementsByTagName("body")[0].getElementsByTagName("a");
for ( var i = 0; i < aTag.length; i++) {
if(!aTag[i].getAttribute("target") && aTag[i].getAttribute("target") != "_blank"){
aTag[i].setAttribute("target","_blank");
}
}
var html = this.ifrmDoc.getElementsByTagName("body")[0].innerHTML;
html = $J("#"+this.textAreaId).value = html ;
html = html.replace(/<(\/?)(font|Strong|i|em|u|strike|b)([^>]*)>/ig,
function (a, b, c,d) {
if (/^\S/.test(d)) return a;
return '<' + b + 'span' + d + '>';
});
if (Browser.type=="Chrome" || Browser.type=="Safari" ) {
html = html.replace(/<div([^>]*)>(.*?)<\/div>/ig,
function (a, b, c) {
if (/[a-z]*=/gi.test(b)) return a;
if (/<br>/.test(c)) c = "";
return "<br />"+c;
});
}
html = html.replace(/<br>/ig,"<br />");
var allowScript = this.config.allowScript;
var allowScriptValidateMessage = this.config.allowScriptValidateMessage;
//정규식 허용하고
if (allowScript) {
//정규식 scriptTag검증 메시지 출력시
if (allowScriptValidateMessage) {
var scriptRegex = /<script>(.*?)<\/script>/gi;
var scriptValidate ;
while (scriptValidate = scriptRegex.exec(html)) {
var scriptContentRegx = /<(\/?)script([^>]*)>/gi;
if (scriptContentRegx.test(scriptValidate[1])) {
window.alert("스크립트 테그가 올바르지 않습니다. 스크립트를 다시 확인하여 주시기 바랍니다.");
return html;
}
}
}
}else{
html = html.replace(/<script[^>]*>.*?<\/script>/gi,"").replace(/<(\/?)script([^>]*)>/gi,"");
}
// this.getContentLength();
return html;
},
/**
* html을 제거한 문자길이를 구한다.
*
* @returns 문자길이
*/
getContentLength : function() {
var html = this.ifrmDoc.getElementsByTagName("body")[0].innerHTML;
html = $J("#"+this.textAreaId).value = html ;
var tagRegex = /<(\/?).*?([^>]*)>/gi;
var whitespace = / /gi;
html = html.replace(tagRegex,"");
html = html.replace(whitespace," ");
html = html.replace(/\n|\t|\r/gi,"");
html = html.replace(/</gi,"<");
html = html.replace(/>/gi,">");
html = html.replace(/&/gi,"&");
return html.length;
}
,
/**
* LayerPopup 을 생성 한다. 경고 알림창이나 플러그인 팝업을 만들 때사용한다.
* @param width 가로 크기
* @param height 세로크기
* @param id LayerPopup id
*/
popupWindow : function(id,title){
var wrapLayer = document.createElement("div");
wrapLayer.setAttribute("id",id);
wrapLayer.className="jceditor-dialog-div";
var titleUl = document.createElement("ul");
var titleLi = document.createElement("li");
var titleSpan = document.createElement("span");
var title = document.createTextNode(title);
titleUl.className="titlebar-ul";
titleLi.className="titlebar-center-li";
titleSpan.appendChild(title);
titleLi.appendChild(titleSpan);
titleUl.appendChild(titleLi);
wrapLayer.appendChild(titleUl);
return wrapLayer;
},
/**
* 플러그인 페이지를 불러올 아이프레임 페이지를 만든다.
* @param id 팝업 아이디
*/
pluginIframe : function(id,title){
var popupWindow = this.popupWindow(id,title);
var iframe = document.createElement("iframe");
iframe.setAttribute("id", id.replace("-div","-iframe"));
iframe.setAttribute("src", "about:blank");
iframe.setAttribute("scrolling", "no");
iframe.setAttribute("frameBorder", "0");
popupWindow.appendChild(iframe);
return popupWindow;
},
/**
* 플러그인을 불러온다. 크기 및 URL 변경.
* @param width 가로 크기
* @param height 세로크기
* @param url 플러그인 URL
* @return URL로 호출하고 있는 객체.
*/
setPlugin : function(width,height,url,id){
height = (Browser.type=="MSIE" ||Browser.type=="Opera")?height:height-10;
var pluginLayerObj = $J("#"+id);
pluginLayerObj.style.cssText = "width:"+width+"px;height:"+height+"px;margin-left:"+(-(width/2))+"px;margin-top:"+(-(height/2))+"px";
var pluginIframe =$J("#"+id.replace("-div","-iframe"));
pluginIframe.style.cssText="width:"+width+"px;height:"+(height-30)+"px";
pluginIframe.src = url;
return {
plugin : pluginIframe,
layerId : id
};
},
/**
* HTML 보기나 TEXT보기 실행시 모든 버튼을 DISABLE 하고도
* IE 브라우져 에서는 버튼에 등록된 이벤트가 실행 된다.
* 이벤트 실행을 멈추기 위하여 버튼이 disabled 가 되어있다면 이벤트를 실행하지 않는다.
* @param event 이벤트 객체
*/
btnDisabledCancel : function(event){
var obj = (event.target) ? event.target : event.srcElement;
if (obj.disabled== true) {
return;
}
},
/**
* 플러그인 확인이나 취소 버튼 누를경우 실행 됌.
*
* @param id 플러그인 레이어 아이디
*
*/
pluginClose : function(id){
var toggleReturn = this.viewToggle(id);
var obj = $J("#"+id);
this.dropDownClassChange(toggleReturn, obj.parentNode);
},
/**
* 플러그인팝업이 사라지면 폼안의 내용을 초기화 한다.
*
*/
pluginFormReset : function(){
if (this.oldDropDownObj != null) {
var iframeType = typeof(this.oldDropDownObj.getElementsByTagName("iframe")[0]);
var ifrmObj = null;
if (iframeType == "object") {
ifrmObj = this.oldDropDownObj.getElementsByTagName("iframe")[0];
if (ifrmObj.tagName.toUpperCase() =="IFRAME") {
ifrmObj.contentWindow.pluginReset();
}
}
}
},
/**
* 에디터에 html 테그를 입력한다.
*
*/
pasteHTML : function(html){
var self = this;
if (Browser.type=="MSIE"&& Browser.version < 9) {
this.selection.selection.pasteHTML(html);
} else {
if(Browser.type=="MSIE" && Browser.version >= 9){
var sel = self.getSelection("NEW").selection;
var range = null;
if (sel.getRangeAt && sel.rangeCount) {
range = sel.getRangeAt(0);
range.deleteContents();
// Range.createContextualFragment() would be useful here but is
// only relatively recently standardized and is not supported in
// some browsers (IE9, for one)
var el = self.ifrmDoc.createElement("div");
el.innerHTML = html;
var frag = self.ifrmDoc.createDocumentFragment(), node, lastNode;
while ( (node = el.firstChild) ) {
lastNode = frag.appendChild(node);
}
range.insertNode(frag);
// Preserve the selection
if (lastNode) {
range = range.cloneRange();
range.setStartAfter(lastNode);
range.collapse(true);
sel.removeAllRanges();
sel.addRange(range);
}
}
}else{
this.ifrmDoc.execCommand('inserthtml', null, html);
}
}
},
/**
* 에디터에서 타이핑한 히스토리를 쌓아 놓는다.
*
*/
historyPush : function(){
//history 를 쌓을 크기.
var pushLimit = 30;
if (this.history.length > pushLimit) {
this.history = this.history.slice(0, 0).concat(this.history.slice(1, 29));
}
this.history.push(this.ifrmDoc.getElementsByTagName("body")[0].innerHTML);
this.historyPos = this.history.length;
},
/**
*기본적용된 에디터의 EnterKey 와 shiftKey+EnterKey 의 역활을 바꾼다.
* EnterKey = BR 테그, shiftKey+EnterKey = P 테그
*
*. -------- 크롬 사파리 때문에 적용 불가..-------------------
* @param event
*/
enterKeyChange : function(event){
var self = this;
function brTag(){
if (Browser.type !="Opera") {
//--아... 표준... 부르짓는것들이.. 이런거하나 안맞춰놨네... 해결못한체로 그냥 둘까?..
if (Browser.type =="Chrome"||Browser.type =="Safari") {
var anchorNode= self.selection.selection.anchorNode;
var parentNodeTagName = anchorNode.parentNode.tagName.toLowerCase();
if (parentNodeTagName=="p" || parentNodeTagName =="td" || parentNodeTagName=="pre") {
if (parentNodeTagName=="p" || parentNodeTagName =="pre") {
event.preventDefault();
function setCaretTo(iframename, d) {
var d2 = d;
obj=document.getElementById(iframename).contentWindow;
var range= obj.getSelection().getRangeAt(0);
range.setStart(range.startContainer, range.endOffset-1);
range.setEnd(range.endContainer, range.endOffset);
self.selection.selection.removeAllRanges();
self.selection.selection.addRange(range);
}
var range = self.selection.selection.getRangeAt(0);
var brEl = self.ifrmDoc.createElement("br");
brEl.id='jce_temp_br';
var tmpSpan = self.ifrmDoc.createElement("span");
tmpSpan.id="jce_temp_span";
tmpSpan.innerHTML=" ";
range.insertNode (tmpSpan);
range.insertNode (brEl);
self.pasteHTML("<br> ");
setCaretTo(self.ifrmId);
var el = self.ifrmDoc.getElementById("jce_temp_span");
el.innerHTML="";
el.parentNode.removeChild(el);
var el2 = self.ifrmDoc.getElementById("jce_temp_br");
if(el2){
el2.parentNode.removeChild(el2);
}else{
setCaretTo(self.ifrmId);
self.selection.selection.deleteFromDocument();
}
}
return;
}else{
event.preventDefault();
self.pasteHTML("<BR id='jce_tmp_paste_br'>");
}
}else{
event.preventDefault();
self.pasteHTML("<BR id='jce_tmp_paste_br'>");
}
}else{
event.preventDefault();
self.pasteHTML("<BR id='jce_tmp_paste_br'> ");
}
// 브라우져별로 Enter Key 눌렀을 경우 Br테그 처리가 어려워.. 정규표현식으로 해당 조건 검색후.
// br 테그를 더 넣는 식으로 했음. br테그가 2개이상 처리될경우 브라우져에서 알아서 처리.함....
var regx = /<br id=\"jce_tmp_paste_br\">([a-z]|[가-힣]|[^A-Za-z0-9](br)?)/gi;
var tagHtml = self.ifrmDoc.getElementsByTagName("body")[0].innerHTML;
var el = self.ifrmDoc.getElementById("jce_tmp_paste_br");
el.removeAttribute("id");
self.getSelection();
var range = self.selection.selection.getRangeAt(0);
range.selectNode(el);
var ret = regx.test(tagHtml);
if (!ret) {
if(Browser.type !="Opera"){
self.pasteHTML("<br><br><br>");
}else{
self.pasteHTML("<br>");
}
}
range.collapse(false);
if (!ret) {
self.selection.selection.deleteFromDocument();
}
}
function pTag(){
event.preventDefault();
var el =self.ifrmDoc.createElement("p");
el.id="jce_tmp_paste";
var range = self.selection.selection.getRangeAt(0);
if (self.selection.selection.anchorNode.parentNode.tagName.toLowerCase()=="p") {
range.selectNode(self.selection.selection.anchorNode.parentNode);
}
range.collapse (false);
range.insertNode(el);
var el = self.ifrmDoc.getElementById("jce_tmp_paste");
if (Browser.type == "Chrome" || Browser.type == "Safari") {
el.innerHTML=" ";
el.removeAttribute("id");
var range = self.ifrmDoc.createRange();
range.selectNodeContents(el);
self.getSelection();
self.selection.selection.removeAllRanges();
self.selection.selection.addRange(range);
self.selection.selection.getRangeAt(0).deleteContents();
}else{
el.removeAttribute("id");
var range = self.ifrmDoc.createRange();
range.selectNodeContents(el);
range.collapse(self.selection.selection.focusNode,self.selection.selection.focusOffset);
self.getSelection();
self.selection.selection.removeAllRanges();
self.selection.selection.addRange(range);
}
}