1
// control registration array
2
var spaw_editors = new Array();
4
// returns true if editor is already registered
5
function SPAW_editor_registered(editor)
8
for(var i=0;i<spaw_editors.length;i++)
10
if (spaw_editors[i] == editor)
20
function SPAW_UpdateFields()
22
for (var i=0; i<spaw_editors.length; i++)
24
SPAW_updateField(spaw_editors[i], null);
28
// adds event handler for the form to update hidden fields
29
function SPAW_addOnSubmitHandler(editor)
31
thefield = SPAW_getFieldByEditor(editor, null);
34
oForm = document.getElementById(thefield).form;
35
if(oForm.onsubmit != null) {
36
sTemp = oForm.onsubmit.toString();
37
iStart = sTemp.indexOf("{") + 2;
38
sTemp = sTemp.substr(iStart,sTemp.length-iStart-2);
40
if (sTemp.indexOf("SPAW_UpdateFields();") == -1)
42
oForm.onsubmit = new Function("SPAW_UpdateFields();" + sTemp);
46
// editor initialization
47
function SPAW_editorInit(editor, css_stylesheet, direction)
49
var ed = document.getElementById(editor+'_rEdit');
50
if (!SPAW_editor_registered(editor))
52
// register the editor
53
spaw_editors[spaw_editors.length] = editor;
55
// add on submit handler
56
SPAW_addOnSubmitHandler(editor);
58
ed.contentDocument.designMode = 'on';
59
var s_sheet = ed.contentDocument.createElement("link");
60
s_sheet.setAttribute("rel","stylesheet");
61
s_sheet.setAttribute("type","text/css");
62
s_sheet.setAttribute("href",css_stylesheet);
64
var head = ed.contentDocument.getElementsByTagName("head");
65
head[0].appendChild(s_sheet);
68
var ta_field = document.getElementById(editor);
69
var html = ta_field.value;
70
if (html != null && html != "\n")
71
ed.contentDocument.body.innerHTML = html;
73
// hookup active toolbar related events
74
ed.contentDocument.addEventListener('keyup', new Function("e","SPAW_onkeyup('"+editor+"',e);"), false);
75
ed.contentDocument.addEventListener('mouseup', new Function("SPAW_update_toolbar('"+editor+"', true);"), false);
78
spaw_context_html = "";
79
SPAW_update_toolbar(editor, true);
81
// workaround to missing cursor on first load
82
ed.contentDocument.designMode = 'on';
88
function SPAW_showColorPicker(editor,curcolor,callback)
90
var wnd = window.open('<?php echo $GLOBALS["spaw_dir"]?>dialogs/colorpicker.php?lang='
91
+ document.getElementById('SPAW_'+editor+'_lang').value + '&theme='
92
+ document.getElementById('SPAW_'+editor+'_theme').value
93
+ '&editor=' + editor + '&callback=' + callback, "color_picker",
94
'status=no,modal=yes,width=350,height=250');
95
wnd.dialogArguments = curcolor;
99
function SPAW_bold_click(editor, sender)
101
var ed = document.getElementById(editor+'_rEdit');
102
ed.contentDocument.execCommand('bold', false, null);
103
ed.contentWindow.focus();
104
SPAW_update_toolbar(editor, true);
107
function SPAW_italic_click(editor, sender)
109
var ed = document.getElementById(editor+'_rEdit');
110
ed.contentDocument.execCommand('italic', false, null);
111
ed.contentWindow.focus();
112
SPAW_update_toolbar(editor, true);
115
function SPAW_underline_click(editor, sender)
117
var ed = document.getElementById(editor+'_rEdit');
118
ed.contentDocument.execCommand('underline', false, null);
119
ed.contentWindow.focus();
120
SPAW_update_toolbar(editor, true);
123
function SPAW_left_click(editor, sender)
125
var ed = document.getElementById(editor+'_rEdit');
126
ed.contentDocument.execCommand('justifyleft', false, null);
127
ed.contentWindow.focus();
128
SPAW_update_toolbar(editor, true);
131
function SPAW_center_click(editor, sender)
133
var ed = document.getElementById(editor+'_rEdit');
134
ed.contentDocument.execCommand('justifycenter', false, null);
135
ed.contentWindow.focus();
136
SPAW_update_toolbar(editor, true);
139
function SPAW_right_click(editor, sender)
141
var ed = document.getElementById(editor+'_rEdit');
142
ed.contentDocument.execCommand('justifyright', false, null);
143
ed.contentWindow.focus();
144
SPAW_update_toolbar(editor, true);
147
function SPAW_justify_click(editor, sender)
149
var ed = document.getElementById(editor+'_rEdit');
150
ed.contentDocument.execCommand('justifyfull', false, null);
151
ed.contentWindow.focus();
152
SPAW_update_toolbar(editor, true);
155
function SPAW_ordered_list_click(editor, sender)
157
var ed = document.getElementById(editor+'_rEdit');
158
ed.contentDocument.execCommand('insertorderedlist', false, null);
159
ed.contentWindow.focus();
160
SPAW_update_toolbar(editor, true);
163
function SPAW_bulleted_list_click(editor, sender)
165
var ed = document.getElementById(editor+'_rEdit');
166
ed.contentDocument.execCommand('insertunorderedlist', false, null);
167
ed.contentWindow.focus();
168
SPAW_update_toolbar(editor, true);
171
function SPAW_fore_color_click(editor, sender)
173
var wnd = SPAW_showColorPicker(editor,null,'SPAW_fore_color_click_callback');
176
function SPAW_fore_color_click_callback(editor, sender)
178
var fCol = sender.returnValue;
181
var ed = document.getElementById(editor+'_rEdit');
182
ed.contentDocument.execCommand('forecolor', false, fCol);
184
ed.contentWindow.focus();
187
function SPAW_bg_color_click(editor, sender)
189
var wnd = SPAW_showColorPicker(editor,null,'SPAW_bg_color_click_callback');
192
function SPAW_bg_color_click_callback(editor, sender)
194
var fCol = sender.returnValue;
197
var ed = document.getElementById(editor+'_rEdit');
198
ed.contentDocument.execCommand('hilitecolor', false, fCol);
200
ed.contentWindow.focus();
203
function SPAW_getA(editor)
205
var ed = document.getElementById(editor+'_rEdit');
206
var selection = ed.contentWindow.getSelection();
208
if (selection.rangeCount > 0) {
209
selectedRange = selection.getRangeAt(0);
211
var aControl = selectedRange.startContainer;
212
while ((aControl.tagName != 'A') && (aControl.tagName != 'BODY'))
214
aControl = aControl.parentNode;
216
if (aControl.tagName == 'A')
222
function SPAW_hyperlink_click(editor, sender)
224
var ed = document.getElementById(editor+'_rEdit');
225
var a = SPAW_getA(editor);
228
// get anchors on the page
229
aProps.anchors = new Array();
230
var links = ed.contentDocument.getElementsByTagName('A');
232
if (links != null) aln = links.length;
233
for (var i=0;i<aln;i++)
235
if (links[i].name != null && links[i].name != '')
236
aProps.anchors[aProps.anchors.length] = links[i].name;
241
aProps.href = a.attributes["href"]?a.attributes["href"].nodeValue:'';
242
aProps.name = a.name;
243
aProps.target = a.target;
244
aProps.title = a.title;
246
var wnd = window.open('<?php echo $GLOBALS["spaw_dir"]?>dialogs/a.php?lang='
247
+ document.getElementById('SPAW_'+editor+'_lang').value + '&theme='
248
+ document.getElementById('SPAW_'+editor+'_theme').value
249
+ '&editor=' + editor + '&callback=SPAW_hyperlink_click_callback', "link_window",
250
'status=no,modal=yes,width=350,height=250');
251
wnd.dialogArguments = aProps;
254
/***********************/
255
function insertNodeAtSelection(win, insertNode)
257
// get current selection
258
var sel = win.getSelection();
260
// get the first range of the selection
261
// (there's almost always only one range)
262
var range = sel.getRangeAt(0);
264
// deselect everything
265
sel.removeAllRanges();
267
// remove content of current selection from document
268
range.deleteContents();
270
// get location of current selection
271
var container = range.startContainer;
272
var pos = range.startOffset;
274
// make a new range for the new selection
275
range=document.createRange();
277
if (container.nodeType==3 && insertNode.nodeType==3) {
279
// if we insert text in a textnode, do optimized insertion
280
container.insertData(pos, insertNode.nodeValue);
282
// put cursor after inserted text
283
range.setEnd(container, pos+insertNode.length);
284
range.setStart(container, pos+insertNode.length);
290
if (container.nodeType==3) {
292
// when inserting into a textnode
293
// we create 2 new textnodes
294
// and put the insertNode in between
296
var textNode = container;
297
container = textNode.parentNode;
298
var text = textNode.nodeValue;
300
// text before the split
301
var textBefore = text.substr(0,pos);
302
// text after the split
303
var textAfter = text.substr(pos);
305
var beforeNode = document.createTextNode(textBefore);
306
var afterNode = document.createTextNode(textAfter);
308
// insert the 3 new nodes before the old one
309
container.insertBefore(afterNode, textNode);
310
container.insertBefore(insertNode, afterNode);
311
container.insertBefore(beforeNode, insertNode);
313
// remove the old node
314
container.removeChild(textNode);
318
// else simply insert the node
319
afterNode = container.childNodes[pos];
320
container.insertBefore(insertNode, afterNode);
323
range.setEnd(afterNode, 0);
324
range.setStart(afterNode, 0);
330
win.getSelection().removeAllRanges();
332
/***********************/
334
function SPAW_hyperlink_click_callback(editor, sender)
336
var naProps = sender.returnValue;
338
var ed = document.getElementById(editor+'_rEdit');
339
var a = SPAW_getA(editor);
344
if (!naProps.href && !naProps.name)
347
a.outerHTML = a.innerHTML;
351
// set link properties
353
a.href = naProps.href;
355
a.removeAttribute('href',0);
357
a.name = naProps.name;
359
a.removeAttribute('name',0);
360
if (naProps.target && naProps.target!='_self')
361
a.target = naProps.target;
363
a.removeAttribute('target',0);
365
a.title = naProps.title;
367
a.removeAttribute('title',0);
369
a.removeAttribute('onclick',0);
376
a = document.createElement('A');
379
a.name = naProps.name;
383
a.href = naProps.href;
384
if (naProps.target && naProps.target!='_self')
385
a.target = naProps.target;
387
a.title = naProps.title;
389
if (ed.contentWindow.getSelection().rangeCount>0
390
&& ed.contentWindow.getSelection().getRangeAt(0).startOffset != ed.contentWindow.getSelection().getRangeAt(0).endOffset)
392
a.appendChild(ed.contentWindow.getSelection().getRangeAt(0).cloneContents());
396
a.innerHTML = (a.href && a.attributes["href"].nodeValue!='')?a.attributes["href"].nodeValue:a.name;
399
insertNodeAtSelection(ed.contentWindow, a);
404
function SPAW_internal_link_click(editor, sender)
408
function SPAW_image_insert_click(editor, sender)
410
var wnd = window.open('<?php echo $GLOBALS["spaw_dir"]?>dialogs/img_library.php?lang='
411
+ document.getElementById('SPAW_'+editor+'_lang').value + '&theme='
412
+ document.getElementById('SPAW_'+editor+'_theme').value
413
+ '&editor=' + editor + '&callback=SPAW_image_insert_click_callback', "img_library",
414
'status=no,modal=yes,width=420,height=420');
417
function SPAW_image_insert_click_callback(editor, sender)
419
var imgSrc = sender.returnValue;
422
var ed = document.getElementById(editor+'_rEdit');
423
ed.contentDocument.execCommand('insertimage', false, imgSrc);
425
ed.contentWindow.focus();
428
function SPAW_image_prop_click(editor, sender)
430
var im = SPAW_getImg(editor); // current img
435
if (im.attributes["src"])
436
iProps.src = im.attributes["src"].nodeValue;
438
iProps.width = (im.style.width)?im.style.width:im.width;
439
iProps.height = (im.style.height)?im.style.height:im.height;
440
iProps.border = im.border;
441
iProps.align = im.align;
442
if (im.hspace>-1) // (-1 when not set under gecko for some reason)
443
iProps.hspace = im.attributes["hspace"].nodeValue;
445
iProps.vspace = im.attributes["vspace"].nodeValue;
447
var wnd = window.open('<?php echo $GLOBALS["spaw_dir"]?>dialogs/img.php?lang='
448
+ document.getElementById('SPAW_'+editor+'_lang').value + '&theme='
449
+ document.getElementById('SPAW_'+editor+'_theme').value
450
+ '&editor=' + editor + '&callback=SPAW_image_prop_click_callback', "img_prop",
451
'status=no,modal=yes,width=420,height=420');
452
wnd.dialogArguments = iProps;
456
function SPAW_image_prop_click_callback(editor, sender)
458
var ed = document.getElementById(editor+'_rEdit');
459
var niProps = sender.returnValue;
460
var im = SPAW_getImg(editor); // current img
464
im.src = (niProps.src)?niProps.src:'';
466
im.alt = niProps.alt;
470
im.removeAttribute("alt",0);
472
im.align = (niProps.align)?niProps.align:'';
473
im.width = (niProps.width)?niProps.width:'';
474
//im.style.width = (niProps.width)?niProps.width:'';
475
im.height = (niProps.height)?niProps.height:'';
476
//im.style.height = (niProps.height)?niProps.height:'';
477
if (niProps.border) {
478
im.border = niProps.border;
482
im.removeAttribute("border",0);
484
if (niProps.hspace) {
485
im.hspace = niProps.hspace;
489
im.removeAttribute("hspace",0);
491
if (niProps.vspace) {
492
im.vspace = niProps.vspace;
496
im.removeAttribute("vspace",0);
500
ed.contentWindow.focus();
504
function SPAW_image_popup_click(editor, sender)
506
var wnd = window.open('<?php echo $GLOBALS["spaw_dir"]?>dialogs/img_library.php?lang='
507
+ document.getElementById('SPAW_'+editor+'_lang').value + '&theme='
508
+ document.getElementById('SPAW_'+editor+'_theme').value
509
+ '&editor=' + editor + '&callback=SPAW_image_popup_click_callback', "img_library",
510
'status=no,modal=yes,width=420,height=420');
513
function SPAW_image_popup_click_callback(editor, sender)
515
var ed = document.getElementById(editor+'_rEdit');
516
var a = SPAW_getA(editor);
517
var imgSrc = sender.returnValue;
525
a.setAttribute("onclick","window.open('<?php echo $spaw_img_popup_url?>?img_url="+imgSrc+"','Image','width=500,height=300,scrollbars=no,toolbar=no,location=no,status=no,resizable=yes,screenX=120,screenY=100');return false;");
530
a = document.createElement('A');
532
a.setAttribute("onclick","window.open('<?php echo $spaw_img_popup_url?>?img_url="+imgSrc+"','Image','width=500,height=300,scrollbars=no,toolbar=no,location=no,status=no,resizable=yes,screenX=120,screenY=100');return false;");
534
if (ed.contentWindow.getSelection().rangeCount>0
535
&& ed.contentWindow.getSelection().getRangeAt(0).startOffset != ed.contentWindow.getSelection().getRangeAt(0).endOffset)
537
a.appendChild(ed.contentWindow.getSelection().getRangeAt(0).cloneContents());
541
a.innerHTML = (a.href && a.attributes["href"].nodeValue!='')?a.attributes["href"].nodeValue:a.name;
544
insertNodeAtSelection(ed.contentWindow, a);
547
ed.contentWindow.focus();
550
function SPAW_hr_click(editor, sender)
552
var ed = document.getElementById(editor+'_rEdit');
553
ed.contentDocument.execCommand('inserthorizontalrule', false, null);
554
ed.contentWindow.focus();
555
SPAW_update_toolbar(editor, true);
558
function SPAW_copy_click(editor, sender)
560
// not implemented in gecko
563
function SPAW_paste_click(editor, sender)
565
// not implemented in gecko
568
function SPAW_cut_click(editor, sender)
570
// not implemented in gecko
573
function SPAW_delete_click(editor, sender)
575
// not implemented in gecko
578
function SPAW_indent_click(editor, sender)
580
var ed = document.getElementById(editor+'_rEdit');
581
ed.contentDocument.execCommand('indent', false, null);
582
ed.contentWindow.focus();
583
SPAW_update_toolbar(editor, true);
586
function SPAW_unindent_click(editor, sender)
588
var ed = document.getElementById(editor+'_rEdit');
589
ed.contentDocument.execCommand('outdent', false, null);
590
ed.contentWindow.focus();
591
SPAW_update_toolbar(editor, true);
594
function SPAW_undo_click(editor, sender)
596
var ed = document.getElementById(editor+'_rEdit');
597
ed.contentDocument.execCommand('undo','',null);
598
ed.contentWindow.focus();
599
SPAW_update_toolbar(editor, true);
602
function SPAW_redo_click(editor, sender)
604
var ed = document.getElementById(editor+'_rEdit');
605
ed.contentDocument.execCommand('redo', false, null);
606
ed.contentWindow.focus();
607
SPAW_update_toolbar(editor, true);
611
function SPAW_getParentTag(editor)
613
var ed = document.getElementById(editor+'_rEdit');
614
var selection = ed.contentWindow.getSelection();
617
if (selection && selection.rangeCount > 0) {
618
selectedRange = selection.getRangeAt(0);
619
aControl = selectedRange.startContainer;
620
if (aControl.nodeType != 1)
621
aControl = aControl.parentNode;
628
function SPAW_ltrim(txt)
631
function SPAW_rtrim(txt)
634
function SPAW_trim(txt)
639
// is selected text a full tags inner html?
640
function SPAW_isFoolTag(editor, el)
644
function SPAW_style_change(editor, sender)
646
var ed = document.getElementById(editor+'_rEdit');
648
var classname = sender.options[sender.selectedIndex].value;
650
if (ed.contentWindow.getSelection().rangeCount>0)
652
var currentRange = ed.contentWindow.getSelection().getRangeAt(0);
654
var parent = currentRange.commonAncestorContainer;
655
if (parent.nodeType != 1)
656
parent = currentRange.commonAncestorContainer.parentNode;
658
if (parent && parent.tagName.toLowerCase() != "body" && parent.tagName.toLowerCase() != "html")
660
// set class on parent
661
parent.className = classname;
665
// create new container
666
var newSpan = ed.contentDocument.createElement("SPAN");
667
newSpan.className = classname;
668
newSpan.appendChild(currentRange.cloneContents());
669
insertNodeAtSelection(ed.contentWindow, newSpan);
673
ed.contentWindow.focus();
674
SPAW_update_toolbar(editor, true);
677
function SPAW_font_change(editor, sender)
679
var ed = document.getElementById(editor+'_rEdit');
680
var fontname = sender.options[sender.selectedIndex].value;
682
if (fontname == null || fontname == '')
684
ed.contentDocument.execCommand('RemoveFormat', false, null);
688
ed.contentDocument.execCommand('fontname', false, fontname);
691
sender.selectedIndex = 0;
693
ed.contentWindow.focus();
694
SPAW_update_toolbar(editor, true);
698
function SPAW_fontsize_change(editor, sender)
700
var ed = document.getElementById(editor+'_rEdit');
701
var fontsize = sender.options[sender.selectedIndex].value;
703
ed.contentDocument.execCommand('fontsize', false, fontsize);
705
sender.selectedIndex = 0;
706
ed.contentWindow.focus();
707
SPAW_update_toolbar(editor, true);
710
function SPAW_paragraph_change(editor, sender)
712
var ed = document.getElementById(editor+'_rEdit');
713
var format = sender.options[sender.selectedIndex].value;
715
ed.contentDocument.execCommand('formatBlock', false, format);
717
sender.selectedIndex = 0;
718
ed.contentWindow.focus();
719
SPAW_update_toolbar(editor, true);
722
function SPAW_table_create_click(editor, sender)
724
var wnd = window.open('<?php echo $GLOBALS["spaw_dir"]?>dialogs/table.php?lang='
725
+ document.getElementById('SPAW_'+editor+'_lang').value + '&theme='
726
+ document.getElementById('SPAW_'+editor+'_theme').value
727
+ '&editor=' + editor + '&callback=SPAW_table_create_click_callback', "table_prop",
728
'status=no,modal=yes,width=420,height=420');
731
function SPAW_table_create_click_callback(editor, sender)
733
var nt = sender.returnValue;
735
var ed = document.getElementById(editor+'_rEdit');
739
var newtable = document.createElement('TABLE');
743
newtable.width = nt.width;
745
newtable.height = nt.height;
747
newtable.border = nt.border;
749
newtable.cellPadding = nt.cellPadding;
751
newtable.cellSpacing = nt.cellSpacing;
753
newtable.bgColor = nt.bgColor;
755
newtable.style.backgroundImage = "url("+nt.background+");";
757
newtable.className = nt.className;
760
for (var i=0;i<parseInt(nt.rows);i++)
762
var newrow = document.createElement('TR');
763
for (var j=0; j<parseInt(nt.cols); j++)
765
var newcell = document.createElement('TD');
766
newcell.innerHTML = " "; // otherwise it doesn't show cell borders
767
newrow.appendChild(newcell);
769
newtable.appendChild(newrow);
772
insertNodeAtSelection(ed.contentWindow, newtable);
774
SPAW_toggle_borders(editor, ed.contentDocument.body, null);
775
SPAW_update_toolbar(editor, true);
784
function SPAW_table_prop_click(editor, sender)
786
var tTable = SPAW_getTable(editor);
791
tProps.width = (tTable.style.width)?tTable.style.width:tTable.width;
792
tProps.height = (tTable.style.height)?tTable.style.height:tTable.height;
793
tProps.border = tTable.border;
794
tProps.cellPadding = tTable.cellPadding;
795
tProps.cellSpacing = tTable.cellSpacing;
796
tProps.bgColor = tTable.bgColor;
797
tProps.className = tTable.className;
798
if (tTable.style.backgroundImage != undefined)
799
tProps.background = tTable.style.backgroundImage.substr(4,tTable.style.backgroundImage.length-5);
801
var wnd = window.open('<?php echo $GLOBALS["spaw_dir"]?>dialogs/table.php?lang='
802
+ document.getElementById('SPAW_'+editor+'_lang').value + '&theme='
803
+ document.getElementById('SPAW_'+editor+'_theme').value
804
+ '&editor=' + editor + '&callback=SPAW_table_prop_click_callback', "table_prop",
805
'status=no,modal=yes,width=420,height=420');
806
wnd.dialogArguments = tProps;
811
function SPAW_table_prop_click_callback(editor, sender)
813
var ntProps = sender.returnValue;
815
var ed = document.getElementById(editor+'_rEdit');
817
var tTable = SPAW_getTable(editor)
819
if (tTable && ntProps)
823
tTable.width = ntProps.width;
825
tTable.removeAttribute('width',0);
827
tTable.height = ntProps.height
829
tTable.removeAttribute('height',0);
831
tTable.border = ntProps.border;
833
tTable.removeAttribute('border',0);
834
if (ntProps.cellPadding)
835
tTable.cellPadding = ntProps.cellPadding;
837
tTable.removeAttribute('cellpadding',0);
838
if (ntProps.cellSpacing)
839
tTable.cellSpacing = ntProps.cellSpacing;
841
tTable.removeAttribute('cellspacing',0);
843
tTable.bgColor = ntProps.bgColor;
845
tTable.removeAttribute('bgcolor',0);
846
if (ntProps.background)
847
tTable.style.backgroundImage = "url("+ntProps.background+")";
849
tTable.style.backgroundImage = "";
850
if (ntProps.className)
851
tTable.className = ntProps.className;
853
tTable.removeAttribute('className',0);
855
SPAW_toggle_borders(editor, tTable, null);
858
SPAW_update_toolbar(editor, true);
861
// edits table cell properties
862
function SPAW_table_cell_prop_click(editor, sender)
864
var cd = SPAW_getTD(editor);
868
cProps.width = (cd.style.width)?cd.style.width:cd.width;
869
cProps.height = (cd.style.height)?cd.style.height:cd.height;
870
cProps.bgColor = cd.bgColor;
871
if (cd.style.backgroundImage != undefined)
872
cProps.background = cd.style.backgroundImage.substr(4,cd.style.backgroundImage.length-5);
874
cProps.align = cd.align;
875
cProps.vAlign = cd.vAlign;
876
cProps.className = cd.className;
877
cProps.noWrap = cd.noWrap;
878
cProps.styleOptions = new Array();
879
if (document.getElementById('SPAW_'+editor+'_tb_style') != null)
881
cProps.styleOptions = document.getElementById('SPAW_'+editor+'_tb_style').options;
884
var wnd = window.open('<?php echo $GLOBALS["spaw_dir"]?>dialogs/td.php?lang='
885
+ document.getElementById('SPAW_'+editor+'_lang').value + '&theme='
886
+ document.getElementById('SPAW_'+editor+'_theme').value
887
+ '&editor=' + editor + '&callback=SPAW_table_cell_prop_click_callback', "table_prop",
888
'status=no,modal=yes,width=420,height=420');
889
wnd.dialogArguments = cProps;
893
function SPAW_table_cell_prop_click_callback(editor, sender)
895
var ncProps = sender.returnValue;
897
var ed = document.getElementById(editor+'_rEdit');
899
var cd = SPAW_getTD(editor)
904
cd.align = ncProps.align;
906
cd.removeAttribute('align',0);
908
cd.vAlign = ncProps.vAlign;
910
cd.removeAttribute('valign',0);
912
cd.width = ncProps.width;
914
cd.removeAttribute('width',0);
916
cd.height = ncProps.height;
918
cd.removeAttribute('height',0);
920
cd.bgColor = ncProps.bgColor;
922
cd.removeAttribute('bgcolor',0);
923
if (ncProps.background)
924
cd.style.backgroundImage = "url(" + ncProps.background + ")";
926
cd.style.backgroundImage = "";
927
if (ncProps.className)
928
cd.className = ncProps.className;
930
cd.removeAttribute('className',0);
932
cd.noWrap = ncProps.noWrap;
934
cd.removeAttribute('nowrap',0);
936
SPAW_update_toolbar(editor, true);
940
// returns current table cell
941
function SPAW_getTD(editor)
943
var ed = document.getElementById(editor+'_rEdit');
944
var selection = ed.contentWindow.getSelection();
947
if (selection.rangeCount > 0) {
948
selectedRange = selection.getRangeAt(0);
949
aControl = selectedRange.startContainer;
950
if (aControl.nodeType != 1)
951
aControl = aControl.parentNode;
952
while ((aControl.tagName.toLowerCase() != 'td')
953
&& (aControl.tagName.toLowerCase() != 'th')
954
&& (aControl.tagName.toLowerCase() != 'table')
955
&& (aControl.tagName.toLowerCase() != 'body'))
957
aControl = aControl.parentNode;
960
if (aControl.tagName.toLowerCase() == 'td' || aControl.tagName.toLowerCase() == 'th')
966
// returns current table row
967
function SPAW_getTR(editor)
969
var ed = document.getElementById(editor+'_rEdit');
970
var selection = ed.contentWindow.getSelection();
973
if (selection.rangeCount > 0) {
974
selectedRange = selection.getRangeAt(0);
975
aControl = selectedRange.startContainer;
976
if (aControl.nodeType != 1)
977
aControl = aControl.parentNode;
978
while ((aControl.tagName.toLowerCase() != 'tr')
979
&& (aControl.tagName.toLowerCase() != 'table')
980
&& (aControl.tagName.toLowerCase() != 'body'))
982
aControl = aControl.parentNode;
985
if (aControl.tagName.toLowerCase() == 'tr')
991
// returns current table
992
function SPAW_getTable(editor)
994
var ed = document.getElementById(editor+'_rEdit');
995
var selection = ed.contentWindow.getSelection();
998
if (selection && selection.rangeCount > 0) {
999
selectedRange = selection.getRangeAt(0);
1000
aControl = selectedRange.startContainer;
1001
if (aControl.nodeType != 1)
1002
aControl = aControl.parentNode;
1003
while ((aControl.tagName.toLowerCase() != 'table') && (aControl.tagName.toLowerCase() != 'body'))
1005
aControl = aControl.parentNode;
1007
if (aControl.tagName.toLowerCase() != 'table')
1013
// returns selected image
1014
function SPAW_getImg(editor)
1017
var ed = document.getElementById(editor+'_rEdit');
1018
var selection = ed.contentWindow.getSelection();
1020
if (selection && selection.rangeCount > 0) {
1021
selectedRange = selection.getRangeAt(0);
1022
if (selectedRange.startContainer.nodeType == 1) // element node
1024
var aControl = selectedRange.startContainer.childNodes[selectedRange.startOffset];
1025
if (aControl && aControl.tagName && aControl.tagName.toLowerCase() == 'img')
1032
function SPAW_table_row_insert_click(editor, sender)
1036
function SPAW_formCellMatrix(ct)
1040
function SPAW_table_column_insert_click(editor, sender)
1044
function SPAW_table_cell_merge_right_click(editor, sender)
1049
function SPAW_table_cell_merge_down_click(editor, sender)
1053
function SPAW_table_row_delete_click(editor, sender)
1057
function SPAW_table_column_delete_click(editor, sender)
1061
// split cell horizontally
1062
function SPAW_table_cell_split_horizontal_click(editor, sender)
1066
function SPAW_table_cell_split_vertical_click(editor, sender)
1071
// switch to wysiwyg mode
1072
function SPAW_design_tab_click(editor, sender)
1074
var ed = document.getElementById(editor+'_rEdit');
1075
iText = document.getElementById(editor).value;
1076
// mozilla bug? workaround
1077
ed.contentDocument.designMode = "off";
1079
ed.contentDocument.body.innerHTML = iText;
1081
document.getElementById('SPAW_'+editor+'_editor_mode').value = 'design';
1083
// turn off html mode toolbars
1084
document.getElementById('SPAW_'+editor+'_toolbar_top_html').style.display = 'none';
1085
document.getElementById('SPAW_'+editor+'_toolbar_left_html').style.display = 'none';
1086
document.getElementById('SPAW_'+editor+'_toolbar_right_html').style.display = 'none';
1087
document.getElementById('SPAW_'+editor+'_toolbar_bottom_html').style.display = 'none';
1089
// turn on design mode toolbars
1090
document.getElementById('SPAW_'+editor+'_toolbar_top_design').style.display = '';
1091
document.getElementById('SPAW_'+editor+'_toolbar_left_design').style.display = '';
1092
document.getElementById('SPAW_'+editor+'_toolbar_right_design').style.display = '';
1093
document.getElementById('SPAW_'+editor+'_toolbar_bottom_design').style.display = '';
1096
document.getElementById(editor).style.display = "none";
1097
ed.style.display = "";
1098
// workaround mozilla bug with losing design mode
1099
ed.contentDocument.designMode = "on";
1100
//document.getElementById(editor+"_rEdit").contentDocument.body.focus();
1102
// turn on invisible borders if needed
1103
//SPAW_toggle_borders(editor,ed.contentDocument.body, null);
1105
SPAW_update_toolbar(editor, true);
1108
// switch to html mode
1109
function SPAW_html_tab_click(editor, sender)
1111
var ed = document.getElementById(editor+'_rEdit');
1112
var iHTML = SPAW_getHtmlValue(editor, null);
1114
document.getElementById(editor).value = iHTML;
1116
document.getElementById('SPAW_'+editor+'_editor_mode').value = 'html';
1118
// turn off design mode toolbars
1119
document.getElementById('SPAW_'+editor+'_toolbar_top_design').style.display = 'none';
1120
document.getElementById('SPAW_'+editor+'_toolbar_left_design').style.display = 'none';
1121
document.getElementById('SPAW_'+editor+'_toolbar_right_design').style.display = 'none';
1122
document.getElementById('SPAW_'+editor+'_toolbar_bottom_design').style.display = 'none';
1124
// turn on html mode toolbars
1125
document.getElementById('SPAW_'+editor+'_toolbar_top_html').style.display = '';
1126
document.getElementById('SPAW_'+editor+'_toolbar_left_html').style.display = '';
1127
document.getElementById('SPAW_'+editor+'_toolbar_right_html').style.display = '';
1128
document.getElementById('SPAW_'+editor+'_toolbar_bottom_html').style.display = '';
1131
document.getElementById(editor+"_rEdit").style.display = "none";
1132
document.getElementById(editor).style.display = "";
1133
//document.getElementById(editor).focus();
1135
//SPAW_update_toolbar(editor, true);
1138
function SPAW_getFieldByEditor(editor, field)
1141
// get field by editor id
1142
if (field == null || field == "")
1144
thefield = document.getElementById(editor).id;
1153
function SPAW_stripAbsoluteUrl(url)
1157
function SPAW_stripAbsoluteUrlFromImg(url)
1161
function SPAW_getHtmlValue(editor, thefield)
1163
// temporary simplified
1164
return document.getElementById(editor+"_rEdit").contentDocument.body.innerHTML;
1167
function SPAW_updateField(editor, field)
1169
var thefield = SPAW_getFieldByEditor(editor, field);
1171
var htmlvalue = SPAW_getHtmlValue(editor, thefield);
1173
if (document.getElementById(thefield).value != htmlvalue)
1175
// something changed
1176
document.getElementById(thefield).value = htmlvalue;
1180
function SPAW_confirm(editor,block,message)
1185
function SPAW_cleanup_click(editor, sender)
1187
} // SPAW_cleanup_click
1189
// toggle borders worker function
1190
function SPAW_toggle_borders(editor, root, toggle)
1192
} // SPAW_toggle_borders
1194
// toggle borders click event
1195
function SPAW_toggle_borders_click(editor, sender)
1197
} // SPAW_toggle_borders_click
1199
// returns base toolbar image name
1200
function SPAW_base_image_name(ctrl)
1202
var imgname = ctrl.src.substring(0,ctrl.src.lastIndexOf("/"))+"/tb_"+ctrl.id.substr(ctrl.id.lastIndexOf("_tb_")+4, ctrl.id.length);
1206
// update toolbar if cursor moved or some event happened
1207
function SPAW_onkeyup(editor, e)
1209
if (e.ctrlKey || (e.keyCode >= 33 && e.keyCode<=40))
1211
SPAW_update_toolbar(editor, false);
1215
var spaw_context_html = null;
1217
// update active toolbar state
1218
function SPAW_update_toolbar(editor, force)
1220
document.getElementById(editor+'_rEdit').contentWindow.focus();
1221
var pt = SPAW_getParentTag(editor);
1224
if (pt.outerHTML == pt && !force)
1230
spaw_context_html = pt;
1239
table_cell_items = [
1241
"table_column_insert",
1242
"table_column_delete",
1243
"table_cell_merge_right",
1244
"table_cell_merge_down",
1245
"table_cell_split_horizontal",
1246
"table_cell_split_vertical"
1255
standard_cmd_items = [ // command, control id
1262
["italic", "italic"],
1263
["underline", "underline"],
1264
["justifyleft", "left"],
1265
["justifycenter", "center"],
1266
["justifyright", "right"],
1267
["justifyfull", "justify"],
1268
["indent", "indent"],
1269
["outdent", "unindent"],
1270
["forecolor", "fore_color"],
1271
["backcolor", "bg_color"],
1272
["insertorderedlist", "ordered_list"],
1273
["insertunorderedlist", "bulleted_list"],
1274
["createlink", "hyperlink"],
1275
["createlink", "internal_link"],
1276
["createlink", "image_popup"],
1277
["inserthorizontalrule","hr"],
1278
["subscript", "subscript"],
1279
["superscript", "superscript"]
1282
togglable_items = [ // command, control id
1284
["italic", "italic"],
1285
["underline", "underline"],
1286
["justifyleft", "left"],
1287
["justifycenter", "center"],
1288
["justifyright", "right"],
1289
["justifyfull", "justify"],
1290
["subscript", "subscript"],
1291
["superscript", "superscript"]
1293
standard_dropdowns = [ // command, control id
1294
["fontname", "font"],
1295
["fontsize", "fontsize"],
1296
["formatblock", "paragraph"]
1299
// proceed only if active toolbar is enabled
1300
if (!spaw_active_toolbar) return;
1302
//window.frames[editor+'_rEdit'].focus();
1304
// get object references
1305
var eobj = document.getElementById(editor+'_rEdit'); // editor iframe
1306
var edoc = eobj.contentDocument; // editor docutment
1308
// enable image insert
1309
SPAW_toggle_tbi(editor,"image_insert", true);
1310
// enable table insert
1311
SPAW_toggle_tbi(editor,"table_create", true);
1313
// toggle table buttons
1315
var ct = SPAW_getTable(editor);
1319
// enable table properties
1320
SPAW_toggle_tb_items(editor,table_obj_items, true);
1323
var cr = SPAW_getTR(editor);
1326
// enable table row features
1327
SPAW_toggle_tb_items(editor,table_row_items, true);
1330
var cd = SPAW_getTD(editor);
1333
// enable cell features
1334
SPAW_toggle_tb_items(editor,table_cell_items, true);
1338
// disable cell features
1339
SPAW_toggle_tb_items(editor,table_cell_items, false);
1340
// disable image insert
1341
SPAW_toggle_tbi(editor,"image_insert", false);
1346
// disable table row and cell features
1347
SPAW_toggle_tb_items(editor,table_cell_items, false);
1348
SPAW_toggle_tb_items(editor,table_row_items, false);
1349
// disable image insert
1350
SPAW_toggle_tbi(editor,"image_insert", false);
1355
// disable all available table related buttons
1356
SPAW_toggle_tb_items(editor,table_obj_items, false);
1357
SPAW_toggle_tb_items(editor,table_row_items, false);
1358
SPAW_toggle_tb_items(editor,table_cell_items, false);
1360
// end table buttons
1364
var im = SPAW_getImg(editor);
1367
// enable image buttons
1368
SPAW_toggle_tb_items(editor,img_obj_items, true);
1369
// disable table insert
1370
SPAW_toggle_tbi(editor,"table_create", false);
1374
// disable image buttons
1375
SPAW_toggle_tb_items(editor,img_obj_items, false);
1377
// end image buttons
1379
// set state and enable/disable standard command buttons
1380
for (var i=0; i<togglable_items.length; i++)
1384
SPAW_toggle_tbi_state(editor, togglable_items[i][1], edoc.queryCommandState(togglable_items[i][0]));
1388
for (var i=0; i<standard_cmd_items.length; i++)
1392
SPAW_toggle_tbi(editor, standard_cmd_items[i][1], edoc.queryCommandEnabled(standard_cmd_items[i][0]));
1397
// set state of toggle borders button
1398
if (document.getElementById("SPAW_"+editor+"_borders").value == "on")
1400
SPAW_toggle_tbi_state(editor, "toggle_borders", true);
1404
SPAW_toggle_tbi_state(editor, "toggle_borders", false);
1408
for (var i=0; i<standard_dropdowns.length; i++)
1412
SPAW_toggle_tbi_dropdown(editor, standard_dropdowns[i][1], edoc.queryCommandValue(standard_dropdowns[i][0]));
1417
var pt = SPAW_getParentTag(editor);
1419
SPAW_toggle_tbi_dropdown(editor, "style", pt.className);
1422
// enable/disable toolbar item
1423
function SPAW_toggle_tb_items(editor, items, enable)
1425
for (var i=0; i<items.length; i++)
1427
SPAW_toggle_tbi(editor, items[i], enable);
1431
// enable/disable toolbar item
1432
function SPAW_toggle_tbi(editor, item, enable)
1434
if (document.getElementById("SPAW_"+editor+"_tb_"+item))
1436
var ctrl = document.getElementById("SPAW_"+editor+"_tb_"+item);
1441
ctrl.disabled = false;
1442
eval("SPAW_"+document.getElementById("SPAW_"+editor+"_theme").value+"_bt_out(ctrl);");
1449
ctrl.disabled = true;
1450
eval("SPAW_"+document.getElementById("SPAW_"+editor+"_theme").value+"_bt_off(ctrl);");
1456
// set state of the toolbar item
1457
function SPAW_toggle_tbi_state(editor, item, state)
1459
if (document.getElementById("SPAW_"+editor+"_tb_"+item))
1461
var ctrl = document.getElementById("SPAW_"+editor+"_tb_"+item);
1462
ctrl.setAttribute("spaw_state",state)
1463
eval("SPAW_"+document.getElementById("SPAW_"+editor+"_theme").value+"_bt_out(ctrl);");
1467
// set dropdown value
1468
function SPAW_toggle_tbi_dropdown(editor, item, value)
1470
if (document.getElementById("SPAW_"+editor+"_tb_"+item))
1472
var ctrl = document.getElementById("SPAW_"+editor+"_tb_"+item);
1473
ctrl.options[0].selected = true;
1474
for (var ii=0; ii<ctrl.options.length; ii++)
1476
if (ctrl.options[ii].value == value)
1478
ctrl.options[ii].selected = true;
1482
ctrl.options[ii].selected = false;
1488
function SPAW_superscript_click(editor, sender)
1490
var ed = document.getElementById(editor+'_rEdit');
1491
ed.contentDocument.execCommand('superscript', false, null);
1492
ed.contentWindow.focus();
1493
SPAW_update_toolbar(editor, true);
1496
function SPAW_subscript_click(editor, sender)
1498
var ed = document.getElementById(editor+'_rEdit');
1499
ed.contentDocument.execCommand('subscript', false, null);
1500
ed.contentWindow.focus();
1501
SPAW_update_toolbar(editor, true);