-
Notifications
You must be signed in to change notification settings - Fork 5
/
xed.js
3457 lines (3042 loc) · 104 KB
/
xed.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
//
// +----------------------------------------------------------------------+
// | Sitellite Content Management System |
// +----------------------------------------------------------------------+
// | Copyright (c) 2010 Sitellite.org Community |
// +----------------------------------------------------------------------+
// | This software is released under the GNU GPL License. |
// | Please see the accompanying file docs/LICENSE for licensing details. |
// | |
// | You should have received a copy of the GNU GPL License |
// | along with this program; if not, visit www.sitellite.org. |
// | The license text is also available at the following web site |
// | address: <http://www.sitellite.org/index/license |
// +----------------------------------------------------------------------+
// | Authors: John Luxford <john.luxford@gmail.com> |
// +----------------------------------------------------------------------+
//
// XED is a cross-browser, cross-platform wysiwyg editor. The name XED is
// pronounced like the letter "Z" (zed, not zee).
//
// Credits:
//
// - Much assistance has been privided by my patient sidekick:
// Dynamic HTML: The Definitive Reference (O'Reilly, ISBN: 0-596-00316-1)
// This book paid for itself twofold the first time I opened it.
//
// - Some plagiarism of code and ideas has occurred here, notably from the
// following list of victims:
//
// - htmlArea (http://www.interactivetools.com/products/htmlarea/) which
// I probably would have simply customized this had it been around before
// I started Xed, and I admit currently has some advantages over Xed.
// Note: htmlArea is easily integrated into Sitellite anyway, so if you
// like, use it in place of Xed. No hard feelings... However, Xed is
// much prettier. ;)
//
// initial value array -- keys are editor iframe ids
var xed_initial_value = new Array ();
// this is the URL and path to the XED editor directory. it is set from
// the GUI screen
var xed_path = '';
var xed_web_path = '';
var xed_prefix = '';
// this is the value used by the link action as a default. you may
// wish to modify it to include your full web site address, which you
// may do externally -- it is a bad idea to modify the values here.
var xed_default_link = 'http://';
var xed_site_url = location.protocol + '://' + location.host;
var xed_site_domain = location.host;
// box settings
var xed_boxes = false;
var xed_box_link = '/index/boxchooser-app?';
var xed_box_image = '/pix/box.gif';
// form settings
var xed_forms = false;
var xed_form_link = '/index/formchooser-app?';
var xed_form_image = '/pix/form.gif';
// image settings
var xed_images_link = '/index/xed-images-action?';
var xed_images = true;
var xed_spellchecker = false;
var xed_scroller = false;
var xed_scroller_data = false;
// preview settings
var xed_preview_css = '/inc/html/default/site.css';
var xed_preview_insert_close = true;
var xed_edit_mode = 'edit';
var xed_edit_state = 'edit';
var xed_source_positioned = false;
var xed_agent = navigator.userAgent.toLowerCase();
var xed_msie = ((xed_agent.indexOf ('msie') != -1) && (xed_agent.indexOf ('opera') == -1));
var xed_msie7 = false;
var xed_ff36 = false;
var xed_events = [];
var xed_error_window = false;
// undo/redo stores
var xed_history = [];
var xed_future = [];
var xed_undo_max_length = 12;
var xed_prev_char = 0;
// whether the context menu is visible or not
var xed_context_menu = false;
var xed_mouse_x = 0;
var xed_mouse_y = 0;
// optional maximum height and width for images
var xed_max_height = false;
var xed_max_width = false;
var xed_img_popup = false;
var xed_login_timer = 0;
var xed_rx_tag_name = /(<\/|<)\s*([^ \t\n>]+)/ig;
var xed_selected = false;
var xed_fullsize = false;
var xed_debug_view = false;
var xed_selected_node = null;
var xed_rpc = new rpc ();
var xed_loading_ifname = null;
function xed_do_nothing (n) {}
// call this in the onload attribute of the body
// ie. onload="xed_init ('editor')"
function xed_init (ifname) {
// decode initial values
try {
xed_initial_value[ifname] = decodeURIComponent (xed_initial_value[ifname]);
} catch (e) {
xed_initial_value[ifname] = unescape (xed_initial_value[ifname]);
}
try {
xed_scroller_data = decodeURIComponent (xed_scroller_data);
} catch (e) {
xed_scroller_data = unescape (xed_scroller_data);
}
for (var i = 0; i < xed_templates.length; i++) {
try {
xed_templates[i] = decodeURIComponent (xed_templates[i]);
} catch (e) {
xed_templates[i] = unescape (xed_templates[i]);
}
}
e = document.getElementById (ifname);
e.contentWindow.document.designMode = 'on';
if (xed_safari) {
e.contentWindow.document.execCommand ('styleWithCSS', false, false);
} else if (! xed_msie) { // midas-only
try {
e.contentWindow.document.execCommand ('styleWithCSS', false, false);
} catch (ex) {
e.contentWindow.document.execCommand ('useCSS', false, '');
}
//this doesn't work quite as advertised...
//e.contentWindow.document.execCommand ('insertBrOnReturn', false, false);
//e.contentWindow.document.execCommand ('enableObjectResizing', false, false);
//e.contentWindow.document.execCommand ('enableInlineTableEditing', false, false);
}
if (xed_msie7 && xed_initial_value[ifname].length == 0) {
xed_initial_value[ifname] = '<p>Enter your content here.</p>';
}
if (xed_initial_value[ifname].length > 0) {
try { // midas-way
e.contentWindow.document.body.innerHTML = xed_initial_value[ifname];
} catch (ex) { // msie-way
if (xed_initial_value[ifname].match (/^<xt:/i) || xed_initial_value[ifname].match (/^<p><xt:/i) || xed_initial_value[ifname].match (/^<p><\/p><xt:/i)) {
xed_initial_value[ifname] = ' <br />' + xed_initial_value[ifname];
}
e.contentWindow.document.write (xed_initial_value[ifname]);
links = e.contentWindow.document.getElementsByTagName ('a');
winhref = window.location.href;
if (winhref.indexOf ('#') != -1) {
arr = winhref.split ('#');
winhref = arr.shift ();
}
for (i = 0; i < links.length; i++) {
if (links[i].href.indexOf (winhref + '#') != -1) {
arr = links[i].href.split ('#');
links[i].href = '#' + arr.pop ();
}
}
// set a timer to fix ie's idiocy once it's had a chance to calm down:
// for some reason, it munges up the xt:box and xt:form tags when first
// inserted, adding an extra closing tag and making the real closing tag
// a self-closing tag, e.g. </xt:box />, ugh...
xed_loading_ifname = ifname;
window.setTimeout (
function () {
html = xed_get_source (xed_loading_ifname);
html = html.replace (/><\/xt:(box|form)>/ig, '>').replace (/<\/xt:(box|form) \/>/ig, '</xt:$1>');
xed_set_source (xed_loading_ifname, html);
},
10
);
}
}
if (xed_fullsize) {
width = screen.availWidth - 100;
if (width > 1000) {
width = 1000;
}
height = screen.availHeight - 250;
e.style.width = width;
e.style.height = height;
}
e = document.getElementById (ifname);
e.contentWindow.document.designMode = 'off';
e.contentWindow.document.designMode = 'on';
if (xed_safari) {
e.contentWindow.document.execCommand ('styleWithCSS', false, false);
} else if (! xed_msie) { // midas-only
try {
e.contentWindow.document.execCommand ('styleWithCSS', false, false);
} catch (ex) {
e.contentWindow.document.execCommand ('useCSS', false, '');
}
//this doesn't work quite as advertised...
//e.contentWindow.document.execCommand ('insertBrOnReturn', false, false);
//e.contentWindow.document.execCommand ('enableObjectResizing', false, false);
//e.contentWindow.document.execCommand ('enableInlineTableEditing', false, false);
}
// events
xed_add_events (
e.contentWindow.document,
['keydown', 'keypress', 'mousedown', 'mouseup', 'drag', 'focus', 'mousemove'],
xed_event
);
if (xed_adobeair) {
e.contentWindow.document.addEventListener ('click', function (ev) {
if (ev.srcElement.nodeName.toLowerCase () == 'a') {
ev.preventDefault (); // prevent the default behaviour
//alert (ev.srcElement.getAttribute ('href'));
}
}, true); // capture=true
}
e.contentWindow.document.ifname = ifname;
// keep user logged in via rpc call every 15 minutes
xed_login_timer = setInterval ("rpc_call (xed_web_path + '/index/xed-notimeout-action');", 900000);
if (xed_scroller) {
scroller_init ('xed-' + ifname + '-reference', ifname);
r = document.getElementById ('xed-' + ifname + '-reference');
try {
r.contentWindow.document.body.innerHTML = xed_scroller_data;
} catch (ex) {
r.contentWindow.document.write (s.value);
}
}
/*s = document.getElementById('xed-' + ifname + '-source');
b = document.getElementById('xed-' + ifname + '-source-bar');
if (xed_scroller) {
s.style.left = s.offsetLeft - 451;
} else {
s.style.left = s.offsetLeft - 662;
}
s.style.marginTop = 0;
b.style.top = b.offsetTop - 15;
xed_source_positioned = true;*/
/*
try {
netscape.security.PrivilegeManager.enablePrivilege ("UniversalPreferencesWrite");
user_pref ("capability.policy.policynames", "allowclipboard");
user_pref ("capability.policy.allowclipboard.sites", xed_site_url);
user_pref ("capability.policy.allowclipboard.Clipboard.cutcopy", "allAccess");
user_pref ("capability.policy.allowclipboard.Clipboard.paste", "allAccess");
} catch (e) {}
*/
}
// call this in the onsubmit attribute of the form
// ie. onsubmit="xed_copy_value (this, 'editor')"
function xed_copy_value (form, ifname) {
html = xed_get_source (ifname);
form.elements[ifname].value = html;
}
// call this from the onclick of a submit button
// ie. onclick="return xed_preview ('editor')"
function xed_preview (ifname) {
p = window.open ('about:blank', 'xedPreviewWindow', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,fullscreen=no,width=500,height=400,top=100,left=150');
if (xed_preview_css.length > 0) {
p.document.write ('<link rel="stylesheet" type="text/css" href="' + xed_preview_css + '" />');
}
p.document.write (xed_get_source (ifname));
if (xed_preview_insert_close) {
p.document.write ('<p align="center"><a href="javascript: window.close ()"><strong>Close Window</strong></a></p>');
}
return false;
}
// call this from the onclick of a submit button
// ie. onclick="return xed_write_to_element ('editor', 'element')"
function xed_write_to_element (ifname, element) {
document.getElementById(element).innerHTML = xed_html_entities (xed_get_source (ifname));
return false;
}
function xed_safari_fix (ifname) {
if (! xed_safari) {
return false;
}
html = xed_get_source (ifname);
// fix span tags to be <strong> <em> etc.
html = html.replace (/<span class="Apple-style-span" style="font-weight: bold; ?">([^<]+)<\/span>/g, '<strong>$1</strong>');
html = html.replace (/<span class="Apple-style-span" style="font-style: italic; ?">([^<]+)<\/span>/g, '<em>$1</em>');
html = html.replace (/<span class="Apple-style-span" style="text-decoration: underline; ?">([^<]+)<\/span>/g, '<u>$1</u>');
html = html.replace (/<span class="Apple-style-span" style="vertical-align: sub; ?">([^<]+)<\/span>/g, '<sub>$1</sub>');
html = html.replace (/<span class="Apple-style-span" style="vertical-align: super; ?">([^<]+)<\/span>/g, '<sup>$1</sup>');
xed_set_source (ifname, html);
}
function xed_bold (ifname) {
xed_historian (ifname);
if (! xed_msie) {
try {
document.getElementById(ifname).contentWindow.document.execCommand ('styleWithCSS', false, false);
} catch (ex) {
document.getElementById(ifname).contentWindow.document.execCommand ('useCSS', false, '');
}
}
document.getElementById(ifname).contentWindow.document.execCommand ('Bold', false, null);
xed_safari_fix (ifname);
document.getElementById(ifname).contentWindow.focus ();
return false;
}
function xed_italic (ifname) {
xed_historian (ifname);
if (! xed_msie) {
try {
document.getElementById(ifname).contentWindow.document.execCommand ('styleWithCSS', false, false);
} catch (ex) {
document.getElementById(ifname).contentWindow.document.execCommand ('useCSS', false, '');
}
}
document.getElementById(ifname).contentWindow.document.execCommand ('Italic', false, null);
xed_safari_fix (ifname);
document.getElementById(ifname).contentWindow.focus ();
return false;
}
function xed_horizontal_rule (ifname) {
xed_historian (ifname);
document.getElementById(ifname).contentWindow.document.execCommand ('InsertHorizontalRule', false, null);
document.getElementById(ifname).contentWindow.focus ();
return false;
}
function xed_underline (ifname) {
xed_historian (ifname);
if (! xed_msie) {
try {
document.getElementById(ifname).contentWindow.document.execCommand ('styleWithCSS', false, false);
} catch (ex) {
document.getElementById(ifname).contentWindow.document.execCommand ('useCSS', false, '');
}
}
document.getElementById(ifname).contentWindow.document.execCommand ('Underline', false, null);
xed_safari_fix (ifname);
document.getElementById(ifname).contentWindow.focus ();
return false;
}
function xed_align_left (ifname) {
xed_historian (ifname);
document.getElementById(ifname).contentWindow.document.execCommand ('JustifyLeft', false, null);
document.getElementById(ifname).contentWindow.focus ();
return false;
}
function xed_align_right (ifname) {
xed_historian (ifname);
document.getElementById(ifname).contentWindow.document.execCommand ('JustifyRight', false, null);
document.getElementById(ifname).contentWindow.focus ();
return false;
}
function xed_align_center (ifname) {
xed_historian (ifname);
document.getElementById(ifname).contentWindow.document.execCommand ('JustifyCenter', false, null);
document.getElementById(ifname).contentWindow.focus ();
return false;
}
function xed_unordered_list (ifname) {
xed_historian (ifname);
document.getElementById(ifname).contentWindow.document.execCommand ('InsertUnorderedList', false, null);
document.getElementById(ifname).contentWindow.focus ();
return false;
}
function xed_ordered_list (ifname) {
xed_historian (ifname);
document.getElementById(ifname).contentWindow.document.execCommand ('InsertOrderedList', false, null);
document.getElementById(ifname).contentWindow.focus ();
return false;
}
function xed_indent (ifname) {
xed_historian (ifname);
document.getElementById(ifname).contentWindow.document.execCommand ('Indent', false, null);
document.getElementById(ifname).contentWindow.focus ();
return false;
}
function xed_outdent (ifname) {
xed_historian (ifname);
document.getElementById(ifname).contentWindow.document.execCommand ('Outdent', false, null);
document.getElementById(ifname).contentWindow.focus ();
return false;
}
function xed_link (ifname) {
n = xed_get_parent (ifname);
if (n.tagName.toLowerCase () == 'a') {
xed_select_node (ifname, n);
return xed_unlink (ifname);
}
if (xed_msie) {
h = 350;
} else {
h = 300;
}
w = window.open (
xed_web_path + '/index/xed-link-form?ifname=' + ifname,
'xedLinkWindow',
'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,fullscreen=no,width=580,height=' + h + ',top=100,left=150'
);
/*
prompt (
'Link:',
xed_default_link,
function (link) {
if (link == null || link == undefined || link == false) {
document.getElementById(ifname).contentWindow.focus ();
return false;
}
if (xed_get_selection (ifname) == '') {
n = xed_get_parent (ifname);
xed_select_node (ifname, n);
}
document.getElementById(ifname).contentWindow.document.execCommand ('CreateLink', false, link);
document.getElementById(ifname).contentWindow.focus ();
}
);
*/
return false;
}
function xed_add_link (ifname, properties) {
xed_historian (ifname);
if (xed_get_selection (ifname) == '') {
n = xed_get_parent (ifname);
xed_select_node (ifname, n);
}
xed_insert_element (ifname, 'a', properties);
/*
document.getElementById(ifname).contentWindow.document.execCommand ('CreateLink', false, properties[0].value);
if (properties[1].value.length != 0) {
alert (properties[1].value);
a = xed_get_parent (ifname, 'a');
a.setAttribute ('target', properties[1].value);
}
*/
document.getElementById(ifname).contentWindow.focus ();
}
function xed_unlink (ifname) {
xed_historian (ifname);
document.getElementById(ifname).contentWindow.document.execCommand ('Unlink', false, null);
document.getElementById(ifname).contentWindow.focus ();
return false;
}
function xed_image (ifname) {
eval ('imagechooser_' + ifname + '_attrs = true');
eval ('imagechooser_' + ifname + '_get_image (ifname)');
return false;
}
function xed_set_image (ifname, src, alt, flt, h, w) {
xed_historian (ifname);
e = document.getElementById (ifname);
if (xed_max_height < h || xed_max_width < w) {
hw_resized = true;
if (h > w) {
w = w * (xed_max_height / h);
h = xed_max_height;
} else {
h = h * (xed_max_width / w);
w = xed_max_width;
}
} else {
hw_resized = false;
}
if (document.all) {
img = '';
if (hw_resized && xed_img_popup) {
img += '<a href="' + src + '" target="_blank">';
}
img += '<img src="' + src + '" alt="' + alt + '"';
if (h != false && w != false) {
img = img + ' height="' + h + '" width="' + w + '"';
}
if (flt != false) {
img = img + ' align="' + flt + '"';
}
img = img + ' border="0" />';
if (hw_resized && xed_img_popup) {
img += '</a>';
}
document.getElementById(ifname).contentWindow.focus ();
} else {
img = e.contentWindow.document.createElement ('img');
img.setAttribute ('src', src);
if (h != false && w != false) {
img.setAttribute ('height', h);
img.setAttribute ('width', w);
}
if (flt != false) {
img.setAttribute ('align', flt);
}
img.setAttribute ('alt', alt);
img.setAttribute ('border', 0);
if (hw_resized && xed_img_popup) {
img_inner = img;
img = e.contentWindow.document.createElement ('a');
img.setAttribute ('href', src);
img.setAttribute ('target', '_blank');
img.appendChild (img_inner);
}
}
xed_insert_node_at_selection (e.contentWindow, img);
document.getElementById(ifname).contentWindow.focus ();
}
function xed_clean (ifname) {
/*rpc_call (
xed_web_path + '/index/xed-cleaners-action?ifname=' + ifname
+ '&data=' + xed_url_encode (xed_get_source (ifname))
);*/
/*xed_rpc.addParameter ('ifname', ifname);
xed_rpc.addParameter ('data', xed_get_source (ifname));
xed_rpc.post (
xed_rpc.action ('cleaners'),
function (request) {
//data = eval (request.responseText);
//xed_set_source (data[0], data[1]);
alert ('Document has been cleaned.');
//document.getElementById (data[0]).contentWindow.document.body.innerHTML = unescape (data[1]);
}
);*/
w = window.open (
'about:blank',
'xedCleanersWindow',
'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,fullscreen=no,width=300,height=100,top=100,left=150'
);
f = document.forms[0];
xed_copy_value (f, ifname);
t = f.target;
a = f.action;
f.target = 'xedCleanersWindow';
f.action = xed_prefix + '/index/xed-cleaners-action?ifname=' + ifname;
f.submit ();
f.target = t;
f.action = a;
return false;
}
function xed_cleaner (ifname, data) {
xed_historian (ifname);
document.getElementById (ifname).contentWindow.document.body.innerHTML = unescape (data);
return false;
}
function xed_filechooser (ifname) {
filechooser_attrs = true;
filechooser_get_file (ifname);
return false;
}
function xed_set_file (ifname, src, name) {
xed_historian (ifname);
e = document.getElementById (ifname);
if (document.all) {
arr = src.split ('?file=');
name = arr.pop ();
txt = '';
if (window.getSelection) {
txt = e.contentWindow.getSelection ();
e.contentWindow.selection.clear ();
} else if (document.getSelection) {
txt = e.contentWindow.document.getSelection ();
e.contentWindow.document.selection.clear ();
} else if (document.selection) {
txt = e.contentWindow.document.selection.createRange ().text;
e.contentWindow.document.selection.clear ();
}
if (txt.length == 0) {
txt = name;
}
file = '<a href="' + src + '">' + txt + '</a>';
} else {
file = e.contentWindow.document.createElement ('a');
file.setAttribute ('href', src);
txt = '';
if (window.getSelection) {
txt = e.contentWindow.getSelection ();
} else if (document.getSelection) {
txt = e.contentWindow.document.getSelection ();
} else if (document.selection) {
txt = e.contentWindow.document.selection.createRange ().text;
}
if (txt.length == 0) {
txt = name;
}
txt = e.contentWindow.document.createTextNode (txt);
file.appendChild (txt);
}
document.getElementById(ifname).contentWindow.focus ();
xed_insert_node_at_selection (e.contentWindow, file);
document.getElementById(ifname).contentWindow.focus ();
}
function xed_select (ifname, format) {
xed_historian (ifname);
c1 = document.getElementById(format).selectedIndex;
var type = document.getElementById(format).options[c1].value;
if (type.length == 0) {
type = '<p>';
}
if (type == '<pre>') {
// strip <br /> from selected text
//document.getElementById(ifname).contentWindow.document.execCommand ('removeformat', false, null);
xed_insert_pre (ifname);
} else {
document.getElementById(ifname).contentWindow.document.execCommand ('formatblock', false, type);
document.getElementById(format).selectedIndex = 0;
}
document.getElementById(ifname).contentWindow.focus ();
return false;
}
function xed_table (ifname) {
w = window.open (
xed_web_path + '/index/xed-tablesizer-action?ifname=' + ifname,
'xedTableWindow',
'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,fullscreen=no,width=300,height=300,top=100,left=150'
);
return false;
}
function xed_insert_table (ifname, choice) {
xed_historian (ifname);
var ch = choice.split ('x');
var rows = ch.shift ();
var cols = ch.shift ();
var e = document.getElementById(ifname);
if (document.all) {
var table = '<table border="2" cellpadding="5" cellspacing="2" width="98%">';
for (var i = 0; i < rows; i++) {
table = table + "\n\t<tr>";
for (var j = 0; j < cols; j++) {
table = table + "\n\t\t<td border=\"2\" valign=\"top\"><br /></td>";
}
table = table + "\n\t</tr>";
}
table = table + "\n</table>\n";
} else {
var table = e.contentWindow.document.createElement ('table');
table.setAttribute ('width', '98%');
for (var i = 0; i < rows; i++) {
var row = e.contentWindow.document.createElement ('tr');
for (var j = 0; j < cols; j++) {
var col = e.contentWindow.document.createElement ('td');
col.setAttribute ('valign', 'top');
var br = e.contentWindow.document.createElement ('br');
col.appendChild (br);
row.appendChild (col);
}
table.appendChild (row);
}
}
document.getElementById (ifname).contentWindow.focus ();
xed_insert_node_at_selection (e.contentWindow, table);
document.getElementById (ifname).contentWindow.focus ();
return false;
}
function xed_table_cellspan (td) {
try {
var col = td.colSpan == '' ? 1 : parseInt (td.colSpan);
var row = td.rowSpan == '' ? 1 : parseInt (td.rowSpan);
return {colspan: col, rowspan: row};
} catch (e) {
return {colspan: 1, rowspan: 1};
}
}
function xed_table_grid (table) {
var grid = new Array ();
if (xed_msie) {
for (i = 0; i < table.rows.length; i++) {
cur = table.rows[i];
for (x = 0; x < cur.cells.length; x++) {
td = cur.cells[x];
sd = xed_table_cellspan (td);
for (y = x; grid[i] && grid[i][y]; y++);
for (i2 = i; i2 < i + sd['rowspan']; i2++) {
if (! grid[i2]) {
grid[i2] = new Array ();
}
for (y2 = y; y2 < y + sd['colspan']; y2++) {
grid[i2][y2] = td;
}
}
}
}
return grid;
}
for (i = 0; i < table.childNodes.length; i++) {
cur = table.childNodes[i];
if (cur.tagName && cur.tagName.toLowerCase () == 'tbody') {
for (x = 0; x < cur.childNodes.length; x++) {
if (cur.childNodes[x].tagName && cur.childNodes[x].tagName.toLowerCase () == 'tr') {
tr = cur.childNodes[x];
// we've got a row!
for (y = 0; y < tr.childNodes.length; y++) {
if (tr.childNodes[y].tagName && tr.childNodes[y].tagName.toLowerCase () == 'td') {
// we've got a cell!
td = tr.childNodes[y];
sd = xed_table_cellspan (td);
for (z = x; grid[i] && grid[i][z]; z++);
for (i2 = i; i2 < i + sd['rowspan']; i2++) {
if (! grid[i2]) {
grid[i2] = new Array ();
}
for (z2 = z; z2 < z + sd['colspan']; z2++) {
grid[i2][z2] = td;
}
}
}
}
}
}
} else if (cur.tagName && cur.tagName.toLowerCase () == 'tr') {
// we've got a row!
for (x = 0; x < cur.childNodes.length; x++) {
if (cur.childNodes[x].tagName && cur.childNodes[x].tagName.toLowerCase () == 'td') {
// we've got a cell!
td = cur.childNodes[x];
sd = xed_table_cellspan (td);
for (y = x; grid[i] && grid[i][y]; y++);
for (i2 = i; i2 < i + sd['rowspan']; i2++) {
if (! grid[i2]) {
grid[i2] = new Array ();
}
for (y2 = y; y2 < y + sd['colspan']; y2++) {
grid[i2][y2] = td;
}
}
}
}
}
}
return grid;
}
function xed_table_cellpos (grid, td) {
var y, x;
for (y = 0; y < grid.length; y++) {
for (x = 0; x < grid[y].length; x++) {
if (grid[y][x] == td) {
return {cellindex: x, rowindex: y};
}
}
}
return null;
}
function xed_table_get_cell (grid, row, col) {
if (grid[row] && grid[row][col]) {
return grid[row][col];
}
return null;
}
function xed_table_add_rows (td, tr, rowspan) {
xed_historian (ifname);
ifname = xed_get_ifname (td);
e = document.getElementById (ifname);
td.rowSpan = 1;
var next_tr = xed_get_next_element (tr);
for (var i = 1; i < rowspan && next_tr; i++) {
var new_td = e.contentWindow.document.createElement ('td');
new_td.innerHTML = '<br />';
if (xed_msie) {
next_tr.insertBefore (new_td, next_tr.cells (td.cellIndex));
} else {
next_tr.insertBefore (new_td, next_tr.cells[td.cellIndex]);
}
next_tr = xed_get_next_element (next_tr);
}
}
function xed_table_row_before (ifname) {
xed_historian (ifname);
var ancestors = xed_get_ancestors (ifname);
var tr = null;
var table = null;
for (i = 0; i < ancestors.length; i++) {
//for (var i = ancestors.length; --i >= 0;) {
el = ancestors[i];
if (! el) {
// hmmm?
continue;
}
if (el.tagName.toLowerCase () == 'tr') {
tr = el;
} else if (el.tagName.toLowerCase () == 'table' || el.tagName.toLowerCase () == 'tbody') {
table = el;
break;
}
}
if (xed_msie) {
new_tr = table.insertRow (tr.rowIndex);
for (i = 0; i < tr.cells.length; i++) {
new_td = new_tr.insertCell (-1);
new_td.innerHTML = '<br />';
new_td.colSpan = tr.cells[i].colSpan;
}
return;
}
e = document.getElementById (ifname);
new_tr = e.contentWindow.document.createElement ('tr');
for (i = 0; i < tr.cells.length; i++) {
td = e.contentWindow.document.createElement ('td');
td.innerHTML = '<br />';
td.colSpan = tr.cells[i].colSpan;
new_tr.appendChild (td);
}
tr.parentNode.insertBefore (new_tr, tr);
}
function xed_table_row_after (ifname) {
xed_historian (ifname);
var ancestors = xed_get_ancestors (ifname);
var tr = null;
var table = null;
for (i = 0; i < ancestors.length; i++) {
//for (var i = ancestors.length; --i >= 0;) {
el = ancestors[i];
if (! el) {
// hmmm?
continue;
}
if (el.tagName.toLowerCase () == 'tr') {
tr = el;
} else if (el.tagName.toLowerCase () == 'table' || el.tagName.toLowerCase () == 'tbody') {
table = el;
break;
}
}
if (xed_msie) {
next = xed_get_next_element (tr);
new_tr = table.insertRow (next.rowIndex);
for (i = 0; i < tr.cells.length; i++) {
new_td = new_tr.insertCell (-1);
new_td.innerHTML = '<br />';
new_td.colSpan = tr.cells[i].colSpan;
}
return;
}
e = document.getElementById (ifname);
new_tr = e.contentWindow.document.createElement ('tr');
for (i = 0; i < tr.cells.length; i++) {
td = e.contentWindow.document.createElement ('td');
td.innerHTML = '<br />';
td.colSpan = tr.cells[i].colSpan;
new_tr.appendChild (td);
}
next = xed_get_next_element (tr);
if (next) {
next.parentNode.insertBefore (new_tr, next);
} else {
tr.parentNode.appendChild (new_tr);
}
}
function xed_table_row_delete (ifname) {
xed_historian (ifname);
var ancestors = xed_get_ancestors (ifname);
var tr = null;
var table = null;
for (var i = ancestors.length; --i >= 0;) {
el = ancestors[i];
if (! el) {
// hmmm?
continue;
}
if (el.tagName.toLowerCase () == 'tr') {
tr = el;
} else if (el.tagName.toLowerCase () == 'table') {
table = el;
}
}
//if (table.rows.length <= 1) {
// table.parentNode.removeChild (table);
//} else {
//table.deleteRow (tr.sectionRowIndex);
tr.parentNode.removeChild (tr);
//}
}
function xed_table_col_before (ifname) {
xed_historian (ifname);
var ancestors = xed_get_ancestors (ifname);
var td = null;
var table = null;
for (var i = ancestors.length; --i >= 0;) {
el = ancestors[i];
if (! el) {
// hmmm?
continue;
}
if (el.tagName.toLowerCase () == 'td') {
td = el;
} else if (el.tagName.toLowerCase () == 'table') {
table = el;
}
}
var grid = xed_table_grid (table);
var cpos = xed_table_cellpos (grid, td);
var last_td = null;
if (xed_msie) {
for (var y = 0; y < grid.length; y++) {
td = xed_table_get_cell (grid, y, cpos.cellindex);
if (td != last_td) {
sd = xed_table_cellspan (td);
if (sd['colspan'] == 1) {
new_td = td.parentNode.insertCell (cpos.cellindex);
new_td.innerHTML = '<br />';
new_td.rowSpan = td.rowSpan;
} else {
td.colSpan++;
}
last_td = td;
}
}
return;
}
for (var y = 0; td = xed_table_get_cell (grid, y, cpos.cellindex); y++) {
if (td != last_td) {
sd = xed_table_cellspan (td);
if (sd['colspan'] == 1) {