Menu

[r10]: / includes / htmlarea / plugins / TableOperations / table-operations.js  Maximize  Restore  History

Download this file

1161 lines (1089 with data), 35.6 kB

   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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
// Table Operations Plugin for HTMLArea-3.0
// Implementation by Mihai Bazon. Sponsored by http://www.bloki.com
//
// htmlArea v3.0 - Copyright (c) 2002 interactivetools.com, inc.
// This notice MUST stay intact for use (see license.txt).
//
// A free WYSIWYG editor replacement for <textarea> fields.
// For full source code and docs, visit http://www.interactivetools.com/
//
// Version 3.0 developed by Mihai Bazon for InteractiveTools.
// http://dynarch.com/mishoo
//
// $Id: table-operations.js,v 1.3 2004/01/15 01:44:50 fullo Exp $
// Object that will encapsulate all the table operations provided by
// HTMLArea-3.0 (except "insert table" which is included in the main file)
function TableOperations(editor) {
this.editor = editor;
var cfg = editor.config;
var tt = TableOperations.I18N;
var bl = TableOperations.btnList;
var self = this;
// register the toolbar buttons provided by this plugin
var toolbar = ["linebreak"];
for (var i in bl) {
var btn = bl[i];
if (!btn) {
toolbar.push("separator");
} else {
var id = "TO-" + btn[0];
cfg.registerButton(id, tt[id], editor.imgURL(btn[0] + ".gif", "TableOperations"), false,
function(editor, id) {
// dispatch button press event
self.buttonPress(editor, id);
}, btn[1]);
toolbar.push(id);
}
}
// add a new line in the toolbar
cfg.toolbar.push(toolbar);
};
TableOperations._pluginInfo = {
name : "TableOperations",
version : "1.0",
developer : "Mihai Bazon",
developer_url : "http://dynarch.com/mishoo/",
c_owner : "Mihai Bazon",
sponsor : "Zapatec Inc.",
sponsor_url : "http://www.bloki.com",
license : "htmlArea"
};
/************************
* UTILITIES
************************/
// retrieves the closest element having the specified tagName in the list of
// ancestors of the current selection/caret.
TableOperations.prototype.getClosest = function(tagName) {
var editor = this.editor;
var ancestors = editor.getAllAncestors();
var ret = null;
tagName = ("" + tagName).toLowerCase();
for (var i in ancestors) {
var el = ancestors[i];
if (el.tagName.toLowerCase() == tagName) {
ret = el;
break;
}
}
return ret;
};
// this function requires the file PopupDiv/PopupWin to be loaded from browser
TableOperations.prototype.dialogTableProperties = function() {
var i18n = TableOperations.I18N;
// retrieve existing values
var table = this.getClosest("table");
// this.editor.selectNodeContents(table);
// this.editor.updateToolbar();
var dialog = new PopupWin(this.editor, i18n["Table Properties"], function(dialog, params) {
TableOperations.processStyle(params, table);
for (var i in params) {
var val = params[i];
switch (i) {
case "f_caption":
if (/\S/.test(val)) {
// contains non white-space characters
var caption = table.getElementsByTagName("caption")[0];
if (!caption) {
caption = dialog.editor._doc.createElement("caption");
table.insertBefore(caption, table.firstChild);
}
caption.innerHTML = val;
} else {
// search for caption and delete it if found
var caption = table.getElementsByTagName("caption")[0];
if (caption) {
caption.parentNode.removeChild(caption);
}
}
break;
case "f_summary":
table.summary = val;
break;
case "f_width":
table.style.width = ("" + val) + params.f_unit;
break;
case "f_align":
table.align = val;
break;
case "f_spacing":
table.cellSpacing = val;
break;
case "f_padding":
table.cellPadding = val;
break;
case "f_borders":
table.border = val;
break;
case "f_frames":
table.frame = val;
break;
case "f_rules":
table.rules = val;
break;
}
}
// various workarounds to refresh the table display (Gecko,
// what's going on?! do not disappoint me!)
dialog.editor.forceRedraw();
dialog.editor.focusEditor();
dialog.editor.updateToolbar();
var save_collapse = table.style.borderCollapse;
table.style.borderCollapse = "collapse";
table.style.borderCollapse = "separate";
table.style.borderCollapse = save_collapse;
},
// this function gets called when the dialog needs to be initialized
function (dialog) {
var f_caption = "";
var capel = table.getElementsByTagName("caption")[0];
if (capel) {
f_caption = capel.innerHTML;
}
var f_summary = table.summary;
var f_width = parseInt(table.style.width);
isNaN(f_width) && (f_width = "");
var f_unit = /%/.test(table.style.width) ? 'percent' : 'pixels';
var f_align = table.align;
var f_spacing = table.cellSpacing;
var f_padding = table.cellPadding;
var f_borders = table.border;
var f_frames = table.frame;
var f_rules = table.rules;
function selected(val) {
return val ? " selected" : "";
};
// dialog contents
dialog.content.style.width = "400px";
dialog.content.innerHTML = " \
<div class='title'\
style='background: url(" + dialog.baseURL + dialog.editor.imgURL("table-prop.gif", "TableOperations") + ") #fff 98% 50% no-repeat'>" + i18n["Table Properties"] + "\
</div> \
<table style='width:100%'> \
<tr> \
<td> \
<fieldset><legend>" + i18n["Description"] + "</legend> \
<table style='width:100%'> \
<tr> \
<td class='label'>" + i18n["Caption"] + ":</td> \
<td class='value'><input type='text' name='f_caption' value='" + f_caption + "'/></td> \
</tr><tr> \
<td class='label'>" + i18n["Summary"] + ":</td> \
<td class='value'><input type='text' name='f_summary' value='" + f_summary + "'/></td> \
</tr> \
</table> \
</fieldset> \
</td> \
</tr> \
<tr><td id='--HA-layout'></td></tr> \
<tr> \
<td> \
<fieldset><legend>" + i18n["Spacing and padding"] + "</legend> \
<table style='width:100%'> \
"+// <tr> \
// <td class='label'>" + i18n["Width"] + ":</td> \
// <td><input type='text' name='f_width' value='" + f_width + "' size='5' /> \
// <select name='f_unit'> \
// <option value='%'" + selected(f_unit == "percent") + ">" + i18n["percent"] + "</option> \
// <option value='px'" + selected(f_unit == "pixels") + ">" + i18n["pixels"] + "</option> \
// </select> &nbsp;&nbsp;" + i18n["Align"] + ": \
// <select name='f_align'> \
// <option value='left'" + selected(f_align == "left") + ">" + i18n["Left"] + "</option> \
// <option value='center'" + selected(f_align == "center") + ">" + i18n["Center"] + "</option> \
// <option value='right'" + selected(f_align == "right") + ">" + i18n["Right"] + "</option> \
// </select> \
// </td> \
// </tr> \
" <tr> \
<td class='label'>" + i18n["Spacing"] + ":</td> \
<td><input type='text' name='f_spacing' size='5' value='" + f_spacing + "' /> &nbsp;" + i18n["Padding"] + ":\
<input type='text' name='f_padding' size='5' value='" + f_padding + "' /> &nbsp;&nbsp;" + i18n["pixels"] + "\
</td> \
</tr> \
</table> \
</fieldset> \
</td> \
</tr> \
<tr> \
<td> \
<fieldset><legend>Frame and borders</legend> \
<table width='100%'> \
<tr> \
<td class='label'>" + i18n["Borders"] + ":</td> \
<td><input name='f_borders' type='text' size='5' value='" + f_borders + "' /> &nbsp;&nbsp;" + i18n["pixels"] + "</td> \
</tr> \
<tr> \
<td class='label'>" + i18n["Frames"] + ":</td> \
<td> \
<select name='f_frames'> \
<option value='void'" + selected(f_frames == "void") + ">" + i18n["No sides"] + "</option> \
<option value='above'" + selected(f_frames == "above") + ">" + i18n["The top side only"] + "</option> \
<option value='below'" + selected(f_frames == "below") + ">" + i18n["The bottom side only"] + "</option> \
<option value='hsides'" + selected(f_frames == "hsides") + ">" + i18n["The top and bottom sides only"] + "</option> \
<option value='vsides'" + selected(f_frames == "vsides") + ">" + i18n["The right and left sides only"] + "</option> \
<option value='lhs'" + selected(f_frames == "lhs") + ">" + i18n["The left-hand side only"] + "</option> \
<option value='rhs'" + selected(f_frames == "rhs") + ">" + i18n["The right-hand side only"] + "</option> \
<option value='box'" + selected(f_frames == "box") + ">" + i18n["All four sides"] + "</option> \
</select> \
</td> \
</tr> \
<tr> \
<td class='label'>" + i18n["Rules"] + ":</td> \
<td> \
<select name='f_rules'> \
<option value='none'" + selected(f_rules == "none") + ">" + i18n["No rules"] + "</option> \
<option value='rows'" + selected(f_rules == "rows") + ">" + i18n["Rules will appear between rows only"] + "</option> \
<option value='cols'" + selected(f_rules == "cols") + ">" + i18n["Rules will appear between columns only"] + "</option> \
<option value='all'" + selected(f_rules == "all") + ">" + i18n["Rules will appear between all rows and columns"] + "</option> \
</select> \
</td> \
</tr> \
</table> \
</fieldset> \
</td> \
</tr> \
<tr> \
<td id='--HA-style'></td> \
</tr> \
</table> \
";
var st_prop = TableOperations.createStyleFieldset(dialog.doc, dialog.editor, table);
var p = dialog.doc.getElementById("--HA-style");
p.appendChild(st_prop);
var st_layout = TableOperations.createStyleLayoutFieldset(dialog.doc, dialog.editor, table);
p = dialog.doc.getElementById("--HA-layout");
p.appendChild(st_layout);
dialog.modal = true;
dialog.addButtons("ok", "cancel");
dialog.showAtElement(dialog.editor._iframe, "c");
});
};
// this function requires the file PopupDiv/PopupWin to be loaded from browser
TableOperations.prototype.dialogRowCellProperties = function(cell) {
var i18n = TableOperations.I18N;
// retrieve existing values
var element = this.getClosest(cell ? "td" : "tr");
var table = this.getClosest("table");
// this.editor.selectNodeContents(element);
// this.editor.updateToolbar();
var dialog = new PopupWin(this.editor, i18n[cell ? "Cell Properties" : "Row Properties"], function(dialog, params) {
TableOperations.processStyle(params, element);
for (var i in params) {
var val = params[i];
switch (i) {
case "f_align":
element.align = val;
break;
case "f_char":
element.ch = val;
break;
case "f_valign":
element.vAlign = val;
break;
}
}
// various workarounds to refresh the table display (Gecko,
// what's going on?! do not disappoint me!)
dialog.editor.forceRedraw();
dialog.editor.focusEditor();
dialog.editor.updateToolbar();
var save_collapse = table.style.borderCollapse;
table.style.borderCollapse = "collapse";
table.style.borderCollapse = "separate";
table.style.borderCollapse = save_collapse;
},
// this function gets called when the dialog needs to be initialized
function (dialog) {
var f_align = element.align;
var f_valign = element.vAlign;
var f_char = element.ch;
function selected(val) {
return val ? " selected" : "";
};
// dialog contents
dialog.content.style.width = "400px";
dialog.content.innerHTML = " \
<div class='title'\
style='background: url(" + dialog.baseURL + dialog.editor.imgURL(cell ? "cell-prop.gif" : "row-prop.gif", "TableOperations") + ") #fff 98% 50% no-repeat'>" + i18n[cell ? "Cell Properties" : "Row Properties"] + "</div> \
<table style='width:100%'> \
<tr> \
<td id='--HA-layout'> \
"+// <fieldset><legend>" + i18n["Layout"] + "</legend> \
// <table style='width:100%'> \
// <tr> \
// <td class='label'>" + i18n["Align"] + ":</td> \
// <td> \
// <select name='f_align'> \
// <option value='left'" + selected(f_align == "left") + ">" + i18n["Left"] + "</option> \
// <option value='center'" + selected(f_align == "center") + ">" + i18n["Center"] + "</option> \
// <option value='right'" + selected(f_align == "right") + ">" + i18n["Right"] + "</option> \
// <option value='char'" + selected(f_align == "char") + ">" + i18n["Char"] + "</option> \
// </select> \
// &nbsp;&nbsp;" + i18n["Char"] + ": \
// <input type='text' style='font-family: monospace; text-align: center' name='f_char' size='1' value='" + f_char + "' /> \
// </td> \
// </tr><tr> \
// <td class='label'>" + i18n["Vertical align"] + ":</td> \
// <td> \
// <select name='f_valign'> \
// <option value='top'" + selected(f_valign == "top") + ">" + i18n["Top"] + "</option> \
// <option value='middle'" + selected(f_valign == "middle") + ">" + i18n["Middle"] + "</option> \
// <option value='bottom'" + selected(f_valign == "bottom") + ">" + i18n["Bottom"] + "</option> \
// <option value='baseline'" + selected(f_valign == "baseline") + ">" + i18n["Baseline"] + "</option> \
// </select> \
// </td> \
// </tr> \
// </table> \
// </fieldset> \
" </td> \
</tr> \
<tr> \
<td id='--HA-style'></td> \
</tr> \
</table> \
";
var st_prop = TableOperations.createStyleFieldset(dialog.doc, dialog.editor, element);
var p = dialog.doc.getElementById("--HA-style");
p.appendChild(st_prop);
var st_layout = TableOperations.createStyleLayoutFieldset(dialog.doc, dialog.editor, element);
p = dialog.doc.getElementById("--HA-layout");
p.appendChild(st_layout);
dialog.modal = true;
dialog.addButtons("ok", "cancel");
dialog.showAtElement(dialog.editor._iframe, "c");
});
};
// this function gets called when some button from the TableOperations toolbar
// was pressed.
TableOperations.prototype.buttonPress = function(editor, button_id) {
this.editor = editor;
var mozbr = HTMLArea.is_gecko ? "<br />" : "";
var i18n = TableOperations.I18N;
// helper function that clears the content in a table row
function clearRow(tr) {
var tds = tr.getElementsByTagName("td");
for (var i = tds.length; --i >= 0;) {
var td = tds[i];
td.rowSpan = 1;
td.innerHTML = mozbr;
}
};
function splitRow(td) {
var n = parseInt("" + td.rowSpan);
var nc = parseInt("" + td.colSpan);
td.rowSpan = 1;
tr = td.parentNode;
var itr = tr.rowIndex;
var trs = tr.parentNode.rows;
var index = td.cellIndex;
while (--n > 0) {
tr = trs[++itr];
var otd = editor._doc.createElement("td");
otd.colSpan = td.colSpan;
otd.innerHTML = mozbr;
tr.insertBefore(otd, tr.cells[index]);
}
editor.forceRedraw();
editor.updateToolbar();
};
function splitCol(td) {
var nc = parseInt("" + td.colSpan);
td.colSpan = 1;
tr = td.parentNode;
var ref = td.nextSibling;
while (--nc > 0) {
var otd = editor._doc.createElement("td");
otd.rowSpan = td.rowSpan;
otd.innerHTML = mozbr;
tr.insertBefore(otd, ref);
}
editor.forceRedraw();
editor.updateToolbar();
};
function splitCell(td) {
var nc = parseInt("" + td.colSpan);
splitCol(td);
var items = td.parentNode.cells;
var index = td.cellIndex;
while (nc-- > 0) {
splitRow(items[index++]);
}
};
function selectNextNode(el) {
var node = el.nextSibling;
while (node && node.nodeType != 1) {
node = node.nextSibling;
}
if (!node) {
node = el.previousSibling;
while (node && node.nodeType != 1) {
node = node.previousSibling;
}
}
if (!node) {
node = el.parentNode;
}
editor.selectNodeContents(node);
};
switch (button_id) {
// ROWS
case "TO-row-insert-above":
case "TO-row-insert-under":
var tr = this.getClosest("tr");
if (!tr) {
break;
}
var otr = tr.cloneNode(true);
clearRow(otr);
tr.parentNode.insertBefore(otr, /under/.test(button_id) ? tr.nextSibling : tr);
editor.forceRedraw();
editor.focusEditor();
break;
case "TO-row-delete":
var tr = this.getClosest("tr");
if (!tr) {
break;
}
var par = tr.parentNode;
if (par.rows.length == 1) {
alert(i18n["not-del-last-row"]);
break;
}
// set the caret first to a position that doesn't
// disappear.
selectNextNode(tr);
par.removeChild(tr);
editor.forceRedraw();
editor.focusEditor();
editor.updateToolbar();
break;
case "TO-row-split":
var td = this.getClosest("td");
if (!td) {
break;
}
splitRow(td);
break;
// COLUMNS
case "TO-col-insert-before":
case "TO-col-insert-after":
var td = this.getClosest("td");
if (!td) {
break;
}
var rows = td.parentNode.parentNode.rows;
var index = td.cellIndex;
for (var i = rows.length; --i >= 0;) {
var tr = rows[i];
var ref = tr.cells[index + (/after/.test(button_id) ? 1 : 0)];
var otd = editor._doc.createElement("td");
otd.innerHTML = mozbr;
tr.insertBefore(otd, ref);
}
editor.focusEditor();
break;
case "TO-col-split":
var td = this.getClosest("td");
if (!td) {
break;
}
splitCol(td);
break;
case "TO-col-delete":
var td = this.getClosest("td");
if (!td) {
break;
}
var index = td.cellIndex;
if (td.parentNode.cells.length == 1) {
alert(i18n["not-del-last-col"]);
break;
}
// set the caret first to a position that doesn't disappear
selectNextNode(td);
var rows = td.parentNode.parentNode.rows;
for (var i = rows.length; --i >= 0;) {
var tr = rows[i];
tr.removeChild(tr.cells[index]);
}
editor.forceRedraw();
editor.focusEditor();
editor.updateToolbar();
break;
// CELLS
case "TO-cell-split":
var td = this.getClosest("td");
if (!td) {
break;
}
splitCell(td);
break;
case "TO-cell-insert-before":
case "TO-cell-insert-after":
var td = this.getClosest("td");
if (!td) {
break;
}
var tr = td.parentNode;
var otd = editor._doc.createElement("td");
otd.innerHTML = mozbr;
tr.insertBefore(otd, /after/.test(button_id) ? td.nextSibling : td);
editor.forceRedraw();
editor.focusEditor();
break;
case "TO-cell-delete":
var td = this.getClosest("td");
if (!td) {
break;
}
if (td.parentNode.cells.length == 1) {
alert(i18n["not-del-last-cell"]);
break;
}
// set the caret first to a position that doesn't disappear
selectNextNode(td);
td.parentNode.removeChild(td);
editor.forceRedraw();
editor.updateToolbar();
break;
case "TO-cell-merge":
// !! FIXME: Mozilla specific !!
var sel = editor._getSelection();
var range, i = 0;
var rows = [];
var row = null;
var cells = null;
if (!HTMLArea.is_ie) {
try {
while (range = sel.getRangeAt(i++)) {
var td = range.startContainer.childNodes[range.startOffset];
if (td.parentNode != row) {
row = td.parentNode;
(cells) && rows.push(cells);
cells = [];
}
cells.push(td);
}
} catch(e) {/* finished walking through selection */}
rows.push(cells);
} else {
// Internet Explorer "browser"
var td = this.getClosest("td");
if (!td) {
alert(i18n["Please click into some cell"]);
break;
}
var tr = td.parentElement;
var no_cols = prompt(i18n["How many columns would you like to merge?"], 2);
if (!no_cols) {
// cancelled
break;
}
var no_rows = prompt(i18n["How many rows would you like to merge?"], 2);
if (!no_rows) {
// cancelled
break;
}
var cell_index = td.cellIndex;
while (no_rows-- > 0) {
td = tr.cells[cell_index];
cells = [td];
for (var i = 1; i < no_cols; ++i) {
td = td.nextSibling;
if (!td) {
break;
}
cells.push(td);
}
rows.push(cells);
tr = tr.nextSibling;
if (!tr) {
break;
}
}
}
var HTML = "";
for (i = 0; i < rows.length; ++i) {
// i && (HTML += "<br />");
var cells = rows[i];
for (var j = 0; j < cells.length; ++j) {
// j && (HTML += "&nbsp;");
var cell = cells[j];
HTML += cell.innerHTML;
(i || j) && (cell.parentNode.removeChild(cell));
}
}
var td = rows[0][0];
td.innerHTML = HTML;
td.rowSpan = rows.length;
td.colSpan = rows[0].length;
editor.selectNodeContents(td);
editor.forceRedraw();
editor.focusEditor();
break;
// PROPERTIES
case "TO-table-prop":
this.dialogTableProperties();
break;
case "TO-row-prop":
this.dialogRowCellProperties(false);
break;
case "TO-cell-prop":
this.dialogRowCellProperties(true);
break;
default:
alert("Button [" + button_id + "] not yet implemented");
}
};
// the list of buttons added by this plugin
TableOperations.btnList = [
// table properties button
["table-prop", "table"],
null, // separator
// ROWS
["row-prop", "tr"],
["row-insert-above", "tr"],
["row-insert-under", "tr"],
["row-delete", "tr"],
["row-split", "td[rowSpan!=1]"],
null,
// COLS
["col-insert-before", "td"],
["col-insert-after", "td"],
["col-delete", "td"],
["col-split", "td[colSpan!=1]"],
null,
// CELLS
["cell-prop", "td"],
["cell-insert-before", "td"],
["cell-insert-after", "td"],
["cell-delete", "td"],
["cell-merge", "tr"],
["cell-split", "td[colSpan!=1,rowSpan!=1]"]
];
//// GENERIC CODE [style of any element; this should be moved into a separate
//// file as it'll be very useful]
//// BEGIN GENERIC CODE -----------------------------------------------------
TableOperations.getLength = function(value) {
var len = parseInt(value);
if (isNaN(len)) {
len = "";
}
return len;
};
// Applies the style found in "params" to the given element.
TableOperations.processStyle = function(params, element) {
var style = element.style;
for (var i in params) {
var val = params[i];
switch (i) {
case "f_st_backgroundColor":
style.backgroundColor = val;
break;
case "f_st_color":
style.color = val;
break;
case "f_st_backgroundImage":
if (/\S/.test(val)) {
style.backgroundImage = "url(" + val + ")";
} else {
style.backgroundImage = "none";
}
break;
case "f_st_borderWidth":
style.borderWidth = val;
break;
case "f_st_borderStyle":
style.borderStyle = val;
break;
case "f_st_borderColor":
style.borderColor = val;
break;
case "f_st_borderCollapse":
style.borderCollapse = val ? "collapse" : "";
break;
case "f_st_width":
if (/\S/.test(val)) {
style.width = val + params["f_st_widthUnit"];
} else {
style.width = "";
}
break;
case "f_st_height":
if (/\S/.test(val)) {
style.height = val + params["f_st_heightUnit"];
} else {
style.height = "";
}
break;
case "f_st_textAlign":
if (val == "char") {
var ch = params["f_st_textAlignChar"];
if (ch == '"') {
ch = '\\"';
}
style.textAlign = '"' + ch + '"';
} else {
style.textAlign = val;
}
break;
case "f_st_verticalAlign":
style.verticalAlign = val;
break;
case "f_st_float":
style.cssFloat = val;
break;
// case "f_st_margin":
// style.margin = val + "px";
// break;
// case "f_st_padding":
// style.padding = val + "px";
// break;
}
}
};
// Returns an HTML element for a widget that allows color selection. That is,
// a button that contains the given color, if any, and when pressed will popup
// the sooner-or-later-to-be-rewritten select_color.html dialog allowing user
// to select some color. If a color is selected, an input field with the name
// "f_st_"+name will be updated with the color value in #123456 format.
TableOperations.createColorButton = function(doc, editor, color, name) {
if (!color) {
color = "";
} else if (!/#/.test(color)) {
color = HTMLArea._colorToRgb(color);
}
var df = doc.createElement("span");
var field = doc.createElement("input");
field.type = "hidden";
df.appendChild(field);
field.name = "f_st_" + name;
field.value = color;
var button = doc.createElement("span");
button.className = "buttonColor";
df.appendChild(button);
var span = doc.createElement("span");
span.className = "chooser";
// span.innerHTML = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
span.style.backgroundColor = color;
button.appendChild(span);
button.onmouseover = function() { if (!this.disabled) { this.className += " buttonColor-hilite"; }};
button.onmouseout = function() { if (!this.disabled) { this.className = "buttonColor"; }};
span.onclick = function() {
if (this.parentNode.disabled) {
return false;
}
editor._popupDialog("select_color.html", function(color) {
if (color) {
span.style.backgroundColor = "#" + color;
field.value = "#" + color;
}
}, color);
};
var span2 = doc.createElement("span");
span2.innerHTML = "&#x00d7;";
span2.className = "nocolor";
span2.title = TableOperations.I18N["Unset color"];
button.appendChild(span2);
span2.onmouseover = function() { if (!this.parentNode.disabled) { this.className += " nocolor-hilite"; }};
span2.onmouseout = function() { if (!this.parentNode.disabled) { this.className = "nocolor"; }};
span2.onclick = function() {
span.style.backgroundColor = "";
field.value = "";
};
return df;
};
TableOperations.createStyleLayoutFieldset = function(doc, editor, el) {
var i18n = TableOperations.I18N;
var fieldset = doc.createElement("fieldset");
var legend = doc.createElement("legend");
fieldset.appendChild(legend);
legend.innerHTML = i18n["Layout"];
var table = doc.createElement("table");
fieldset.appendChild(table);
table.style.width = "100%";
var tbody = doc.createElement("tbody");
table.appendChild(tbody);
var tagname = el.tagName.toLowerCase();
var tr, td, input, select, option, options, i;
if (tagname != "td" && tagname != "tr" && tagname != "th") {
tr = doc.createElement("tr");
tbody.appendChild(tr);
td = doc.createElement("td");
td.className = "label";
tr.appendChild(td);
td.innerHTML = i18n["Float"] + ":";
td = doc.createElement("td");
tr.appendChild(td);
select = doc.createElement("select");
td.appendChild(select);
select.name = "f_st_float";
options = ["None", "Left", "Right"];
for (i in options) {
var Val = options[i];
var val = options[i].toLowerCase();
option = doc.createElement("option");
option.innerHTML = i18n[Val];
option.value = val;
option.selected = (("" + el.style.cssFloat).toLowerCase() == val);
select.appendChild(option);
}
}
tr = doc.createElement("tr");
tbody.appendChild(tr);
td = doc.createElement("td");
td.className = "label";
tr.appendChild(td);
td.innerHTML = i18n["Width"] + ":";
td = doc.createElement("td");
tr.appendChild(td);
input = doc.createElement("input");
input.type = "text";
input.value = TableOperations.getLength(el.style.width);
input.size = "5";
input.name = "f_st_width";
input.style.marginRight = "0.5em";
td.appendChild(input);
select = doc.createElement("select");
select.name = "f_st_widthUnit";
option = doc.createElement("option");
option.innerHTML = i18n["percent"];
option.value = "%";
option.selected = /%/.test(el.style.width);
select.appendChild(option);
option = doc.createElement("option");
option.innerHTML = i18n["pixels"];
option.value = "px";
option.selected = /px/.test(el.style.width);
select.appendChild(option);
td.appendChild(select);
select.style.marginRight = "0.5em";
td.appendChild(doc.createTextNode(i18n["Text align"] + ":"));
select = doc.createElement("select");
select.style.marginLeft = select.style.marginRight = "0.5em";
td.appendChild(select);
select.name = "f_st_textAlign";
options = ["Left", "Center", "Right", "Justify"];
if (tagname == "td") {
options.push("Char");
}
input = doc.createElement("input");
input.name = "f_st_textAlignChar";
input.size = "1";
input.style.fontFamily = "monospace";
td.appendChild(input);
for (i in options) {
var Val = options[i];
var val = Val.toLowerCase();
option = doc.createElement("option");
option.value = val;
option.innerHTML = i18n[Val];
option.selected = (el.style.textAlign.toLowerCase() == val);
select.appendChild(option);
}
function setCharVisibility(value) {
input.style.visibility = value ? "visible" : "hidden";
if (value) {
input.focus();
input.select();
}
};
select.onchange = function() { setCharVisibility(this.value == "char"); };
setCharVisibility(select.value == "char");
tr = doc.createElement("tr");
tbody.appendChild(tr);
td = doc.createElement("td");
td.className = "label";
tr.appendChild(td);
td.innerHTML = i18n["Height"] + ":";
td = doc.createElement("td");
tr.appendChild(td);
input = doc.createElement("input");
input.type = "text";
input.value = TableOperations.getLength(el.style.height);
input.size = "5";
input.name = "f_st_height";
input.style.marginRight = "0.5em";
td.appendChild(input);
select = doc.createElement("select");
select.name = "f_st_heightUnit";
option = doc.createElement("option");
option.innerHTML = i18n["percent"];
option.value = "%";
option.selected = /%/.test(el.style.height);
select.appendChild(option);
option = doc.createElement("option");
option.innerHTML = i18n["pixels"];
option.value = "px";
option.selected = /px/.test(el.style.height);
select.appendChild(option);
td.appendChild(select);
select.style.marginRight = "0.5em";
td.appendChild(doc.createTextNode(i18n["Vertical align"] + ":"));
select = doc.createElement("select");
select.name = "f_st_verticalAlign";
select.style.marginLeft = "0.5em";
td.appendChild(select);
options = ["Top", "Middle", "Bottom", "Baseline"];
for (i in options) {
var Val = options[i];
var val = Val.toLowerCase();
option = doc.createElement("option");
option.value = val;
option.innerHTML = i18n[Val];
option.selected = (el.style.verticalAlign.toLowerCase() == val);
select.appendChild(option);
}
return fieldset;
};
// Returns an HTML element containing the style attributes for the given
// element. This can be easily embedded into any dialog; the functionality is
// also provided.
TableOperations.createStyleFieldset = function(doc, editor, el) {
var i18n = TableOperations.I18N;
var fieldset = doc.createElement("fieldset");
var legend = doc.createElement("legend");
fieldset.appendChild(legend);
legend.innerHTML = i18n["CSS Style"];
var table = doc.createElement("table");
fieldset.appendChild(table);
table.style.width = "100%";
var tbody = doc.createElement("tbody");
table.appendChild(tbody);
var tr, td, input, select, option, options, i;
tr = doc.createElement("tr");
tbody.appendChild(tr);
td = doc.createElement("td");
tr.appendChild(td);
td.className = "label";
td.innerHTML = i18n["Background"] + ":";
td = doc.createElement("td");
tr.appendChild(td);
var df = TableOperations.createColorButton(doc, editor, el.style.backgroundColor, "backgroundColor");
df.firstChild.nextSibling.style.marginRight = "0.5em";
td.appendChild(df);
td.appendChild(doc.createTextNode(i18n["Image URL"] + ": "));
input = doc.createElement("input");
input.type = "text";
input.name = "f_st_backgroundImage";
if (el.style.backgroundImage.match(/url\(\s*(.*?)\s*\)/)) {
input.value = RegExp.$1;
}
// input.style.width = "100%";
td.appendChild(input);
tr = doc.createElement("tr");
tbody.appendChild(tr);
td = doc.createElement("td");
tr.appendChild(td);
td.className = "label";
td.innerHTML = i18n["FG Color"] + ":";
td = doc.createElement("td");
tr.appendChild(td);
td.appendChild(TableOperations.createColorButton(doc, editor, el.style.color, "color"));
// for better alignment we include an invisible field.
input = doc.createElement("input");
input.style.visibility = "hidden";
input.type = "text";
td.appendChild(input);
tr = doc.createElement("tr");
tbody.appendChild(tr);
td = doc.createElement("td");
tr.appendChild(td);
td.className = "label";
td.innerHTML = i18n["Border"] + ":";
td = doc.createElement("td");
tr.appendChild(td);
var colorButton = TableOperations.createColorButton(doc, editor, el.style.borderColor, "borderColor");
var btn = colorButton.firstChild.nextSibling;
td.appendChild(colorButton);
// borderFields.push(btn);
btn.style.marginRight = "0.5em";
select = doc.createElement("select");
var borderFields = [];
td.appendChild(select);
select.name = "f_st_borderStyle";
options = ["none", "dotted", "dashed", "solid", "double", "groove", "ridge", "inset", "outset"];
var currentBorderStyle = el.style.borderStyle;
// Gecko reports "solid solid solid solid" for "border-style: solid".
// That is, "top right bottom left" -- we only consider the first
// value.
(currentBorderStyle.match(/([^\s]*)\s/)) && (currentBorderStyle = RegExp.$1);
for (i in options) {
var val = options[i];
option = doc.createElement("option");
option.value = val;
option.innerHTML = val;
(val == currentBorderStyle) && (option.selected = true);
select.appendChild(option);
}
select.style.marginRight = "0.5em";
function setBorderFieldsStatus(value) {
for (i in borderFields) {
var el = borderFields[i];
el.style.visibility = value ? "hidden" : "visible";
if (!value && (el.tagName.toLowerCase() == "input")) {
el.focus();
el.select();
}
}
};
select.onchange = function() { setBorderFieldsStatus(this.value == "none"); };
input = doc.createElement("input");
borderFields.push(input);
input.type = "text";
input.name = "f_st_borderWidth";
input.value = TableOperations.getLength(el.style.borderWidth);
input.size = "5";
td.appendChild(input);
input.style.marginRight = "0.5em";
var span = doc.createElement("span");
span.innerHTML = i18n["pixels"];
td.appendChild(span);
borderFields.push(span);
setBorderFieldsStatus(select.value == "none");
if (el.tagName.toLowerCase() == "table") {
// the border-collapse style is only for tables
tr = doc.createElement("tr");
tbody.appendChild(tr);
td = doc.createElement("td");
td.className = "label";
tr.appendChild(td);
input = doc.createElement("input");
input.type = "checkbox";
input.name = "f_st_borderCollapse";
input.id = "f_st_borderCollapse";
var val = (/collapse/i.test(el.style.borderCollapse));
input.checked = val ? 1 : 0;
td.appendChild(input);
td = doc.createElement("td");
tr.appendChild(td);
var label = doc.createElement("label");
label.htmlFor = "f_st_borderCollapse";
label.innerHTML = i18n["Collapsed borders"];
td.appendChild(label);
}
// tr = doc.createElement("tr");
// tbody.appendChild(tr);
// td = doc.createElement("td");
// td.className = "label";
// tr.appendChild(td);
// td.innerHTML = i18n["Margin"] + ":";
// td = doc.createElement("td");
// tr.appendChild(td);
// input = doc.createElement("input");
// input.type = "text";
// input.size = "5";
// input.name = "f_st_margin";
// td.appendChild(input);
// input.style.marginRight = "0.5em";
// td.appendChild(doc.createTextNode(i18n["Padding"] + ":"));
// input = doc.createElement("input");
// input.type = "text";
// input.size = "5";
// input.name = "f_st_padding";
// td.appendChild(input);
// input.style.marginLeft = "0.5em";
// input.style.marginRight = "0.5em";
// td.appendChild(doc.createTextNode(i18n["pixels"]));
return fieldset;
};
//// END GENERIC CODE -------------------------------------------------------
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.