| 98 | | }; |
| 99 | | |
| 100 | | // this function requires the file PopupDiv/PopupWin to be loaded from browser |
| 101 | | TableOperations.prototype.dialogTableProperties = function() { |
| 102 | | // retrieve existing values |
| 103 | | var table = this.getClosest("table"); |
| 104 | | // this.editor.selectNodeContents(table); |
| 105 | | // this.editor.updateToolbar(); |
| 106 | | |
| 107 | | var dialog = new PopupWin(this.editor, Xinha._lc("Table Properties", "TableOperations"), function(dialog, params) { |
| 108 | | TableOperations.processStyle(params, table); |
| 109 | | for (var i in params) { |
| 110 | | if(typeof params[i] == 'function') continue; |
| 111 | | var val = params[i]; |
| 112 | | switch (i) { |
| 113 | | case "f_caption": |
| 114 | | if (/\S/.test(val)) { |
| 115 | | // contains non white-space characters |
| 116 | | var caption = table.getElementsByTagName("caption")[0]; |
| 117 | | if (!caption) { |
| 118 | | caption = dialog.editor._doc.createElement("caption"); |
| 119 | | table.insertBefore(caption, table.firstChild); |
| 120 | | } |
| 121 | | caption.innerHTML = val; |
| 122 | | } else { |
| 123 | | // search for caption and delete it if found |
| 124 | | var caption = table.getElementsByTagName("caption")[0]; |
| 125 | | if (caption) { |
| 126 | | caption.parentNode.removeChild(caption); |
| 127 | | } |
| 128 | | } |
| 129 | | break; |
| 130 | | case "f_summary": |
| 131 | | table.summary = val; |
| 132 | | break; |
| 133 | | case "f_width": |
| 134 | | table.style.width = ("" + val) + params.f_unit; |
| 135 | | break; |
| 136 | | case "f_align": |
| 137 | | table.align = val; |
| 138 | | break; |
| 139 | | case "f_spacing": |
| 140 | | table.cellSpacing = val; |
| 141 | | break; |
| 142 | | case "f_padding": |
| 143 | | table.cellPadding = val; |
| 144 | | break; |
| 145 | | case "f_borders": |
| 146 | | table.border = val; |
| 147 | | break; |
| 148 | | case "f_frames": |
| 149 | | table.frame = val; |
| 150 | | break; |
| 151 | | case "f_rules": |
| 152 | | table.rules = val; |
| 153 | | break; |
| 154 | | } |
| 155 | | } |
| 156 | | // various workarounds to refresh the table display (Gecko, |
| 157 | | // what's going on?! do not disappoint me!) |
| 158 | | dialog.editor.forceRedraw(); |
| 159 | | dialog.editor.focusEditor(); |
| 160 | | dialog.editor.updateToolbar(); |
| 161 | | var save_collapse = table.style.borderCollapse; |
| 162 | | table.style.borderCollapse = "collapse"; |
| 163 | | table.style.borderCollapse = "separate"; |
| 164 | | table.style.borderCollapse = save_collapse; |
| 165 | | }, |
| 166 | | |
| 167 | | // this function gets called when the dialog needs to be initialized |
| 168 | | function (dialog) { |
| 169 | | |
| 170 | | var f_caption = ""; |
| 171 | | var capel = table.getElementsByTagName("caption")[0]; |
| 172 | | if (capel) { |
| 173 | | f_caption = capel.innerHTML; |
| 174 | | } |
| 175 | | var f_summary = table.summary; |
| 176 | | var f_width = parseInt(table.style.width); |
| 177 | | isNaN(f_width) && (f_width = ""); |
| 178 | | var f_unit = /%/.test(table.style.width) ? 'percent' : 'pixels'; |
| 179 | | var f_align = table.align; |
| 180 | | var f_spacing = table.cellSpacing; |
| 181 | | var f_padding = table.cellPadding; |
| 182 | | var f_borders = table.border; |
| 183 | | var f_frames = table.frame; |
| 184 | | var f_rules = table.rules; |
| 185 | | |
| 186 | | function selected(val) { |
| 187 | | return val ? " selected" : ""; |
| 188 | | } |
| 189 | | |
| 190 | | // dialog contents |
| 191 | | dialog.content.style.width = "400px"; |
| 192 | | dialog.content.innerHTML = " \ |
| 193 | | <div class='title'>" + Xinha._lc("Table Properties", "TableOperations") + "\ |
| 194 | | </div> \ |
| 195 | | <table style='width:100%'> \ |
| 196 | | <tr> \ |
| 197 | | <td> \ |
| 198 | | <fieldset><legend>" + Xinha._lc("Description", "TableOperations") + "</legend> \ |
| 199 | | <table style='width:100%'> \ |
| 200 | | <tr> \ |
| 201 | | <td class='label'>" + Xinha._lc("Caption", "TableOperations") + ":</td> \ |
| 202 | | <td class='value'><input type='text' name='f_caption' value='" + f_caption + "'/></td> \ |
| 203 | | </tr><tr> \ |
| 204 | | <td class='label'>" + Xinha._lc("Summary", "TableOperations") + ":</td> \ |
| 205 | | <td class='value'><input type='text' name='f_summary' value='" + f_summary + "'/></td> \ |
| 206 | | </tr> \ |
| 207 | | </table> \ |
| 208 | | </fieldset> \ |
| 209 | | </td> \ |
| 210 | | </tr> \ |
| 211 | | <tr><td id='--HA-layout'></td></tr> \ |
| 212 | | <tr> \ |
| 213 | | <td> \ |
| 214 | | <fieldset><legend>" + Xinha._lc("Spacing and padding", "TableOperations") + "</legend> \ |
| 215 | | <table style='width:100%'> \ |
| 216 | | "+// <tr> \ |
| 217 | | // <td class='label'>" + Xinha._lc("Width", "TableOperations") + ":</td> \ |
| 218 | | // <td><input type='text' name='f_width' value='" + f_width + "' size='5' /> \ |
| 219 | | // <select name='f_unit'> \ |
| 220 | | // <option value='%'" + selected(f_unit == "percent") + ">" + Xinha._lc("percent", "TableOperations") + "</option> \ |
| 221 | | // <option value='px'" + selected(f_unit == "pixels") + ">" + Xinha._lc("pixels", "TableOperations") + "</option> \ |
| 222 | | // </select> " + Xinha._lc("Align", "TableOperations") + ": \ |
| 223 | | // <select name='f_align'> \ |
| 224 | | // <option value='left'" + selected(f_align == "left") + ">" + Xinha._lc("Left", "TableOperations") + "</option> \ |
| 225 | | // <option value='center'" + selected(f_align == "center") + ">" + Xinha._lc("Center", "TableOperations") + "</option> \ |
| 226 | | // <option value='right'" + selected(f_align == "right") + ">" + Xinha._lc("Right", "TableOperations") + "</option> \ |
| 227 | | // </select> \ |
| 228 | | // </td> \ |
| 229 | | // </tr> \ |
| 230 | | " <tr> \ |
| 231 | | <td class='label'>" + Xinha._lc("Spacing", "TableOperations") + ":</td> \ |
| 232 | | <td><input type='text' name='f_spacing' size='5' value='" + f_spacing + "' /> " + Xinha._lc("Padding", "TableOperations") + ":\ |
| 233 | | <input type='text' name='f_padding' size='5' value='" + f_padding + "' /> " + Xinha._lc("pixels", "TableOperations") + "\ |
| 234 | | </td> \ |
| 235 | | </tr> \ |
| 236 | | </table> \ |
| 237 | | </fieldset> \ |
| 238 | | </td> \ |
| 239 | | </tr> \ |
| 240 | | <tr> \ |
| 241 | | <td> \ |
| 242 | | <fieldset><legend>" + Xinha._lc("Frame and borders", "TableOperations") + "</legend> \ |
| 243 | | <table width='100%'> \ |
| 244 | | <tr> \ |
| 245 | | <td class='label'>" + Xinha._lc("Borders", "TableOperations") + ":</td> \ |
| 246 | | <td><input name='f_borders' type='text' size='5' value='" + f_borders + "' /> " + Xinha._lc("pixels", "TableOperations") + "</td> \ |
| 247 | | </tr> \ |
| 248 | | <tr> \ |
| 249 | | <td class='label'>" + Xinha._lc("Frames", "TableOperations") + ":</td> \ |
| 250 | | <td> \ |
| 251 | | <select name='f_frames'> \ |
| 252 | | <option value='void'" + selected(f_frames == "void") + ">" + Xinha._lc("No sides", "TableOperations") + "</option> \ |
| 253 | | <option value='above'" + selected(f_frames == "above") + ">" + Xinha._lc("The top side only", "TableOperations") + "</option> \ |
| 254 | | <option value='below'" + selected(f_frames == "below") + ">" + Xinha._lc("The bottom side only", "TableOperations") + "</option> \ |
| 255 | | <option value='hsides'" + selected(f_frames == "hsides") + ">" + Xinha._lc("The top and bottom sides only", "TableOperations") + "</option> \ |
| 256 | | <option value='vsides'" + selected(f_frames == "vsides") + ">" + Xinha._lc("The right and left sides only", "TableOperations") + "</option> \ |
| 257 | | <option value='lhs'" + selected(f_frames == "lhs") + ">" + Xinha._lc("The left-hand side only", "TableOperations") + "</option> \ |
| 258 | | <option value='rhs'" + selected(f_frames == "rhs") + ">" + Xinha._lc("The right-hand side only", "TableOperations") + "</option> \ |
| 259 | | <option value='box'" + selected(f_frames == "box") + ">" + Xinha._lc("All four sides", "TableOperations") + "</option> \ |
| 260 | | </select> \ |
| 261 | | </td> \ |
| 262 | | </tr> \ |
| 263 | | <tr> \ |
| 264 | | <td class='label'>" + Xinha._lc("Rules", "TableOperations") + ":</td> \ |
| 265 | | <td> \ |
| 266 | | <select name='f_rules'> \ |
| 267 | | <option value='none'" + selected(f_rules == "none") + ">" + Xinha._lc("No rules", "TableOperations") + "</option> \ |
| 268 | | <option value='rows'" + selected(f_rules == "rows") + ">" + Xinha._lc("Rules will appear between rows only", "TableOperations") + "</option> \ |
| 269 | | <option value='cols'" + selected(f_rules == "cols") + ">" + Xinha._lc("Rules will appear between columns only", "TableOperations") + "</option> \ |
| 270 | | <option value='all'" + selected(f_rules == "all") + ">" + Xinha._lc("Rules will appear between all rows and columns", "TableOperations") + "</option> \ |
| 271 | | </select> \ |
| 272 | | </td> \ |
| 273 | | </tr> \ |
| 274 | | </table> \ |
| 275 | | </fieldset> \ |
| 276 | | </td> \ |
| 277 | | </tr> \ |
| 278 | | <tr> \ |
| 279 | | <td id='--HA-style'></td> \ |
| 280 | | </tr> \ |
| 281 | | </table> \ |
| 282 | | "; |
| 283 | | var st_prop = TableOperations.createStyleFieldset(dialog.doc, dialog.editor, table); |
| 284 | | var p = dialog.doc.getElementById("--HA-style"); |
| 285 | | p.appendChild(st_prop); |
| 286 | | var st_layout = TableOperations.createStyleLayoutFieldset(dialog.doc, dialog.editor, table); |
| 287 | | p = dialog.doc.getElementById("--HA-layout"); |
| 288 | | p.appendChild(st_layout); |
| 289 | | dialog.modal = true; |
| 290 | | dialog.addButtons("OK", "Cancel"); |
| 291 | | dialog.showAtElement(dialog.editor._iframe, "c"); |
| 292 | | }); |
| 293 | | }; |
| 294 | | |
| 295 | | // this function requires the file PopupDiv/PopupWin to be loaded from browser |
| 296 | | TableOperations.prototype.dialogRowCellProperties = function(cell) { |
| 297 | | // retrieve existing values |
| 298 | | var element = this.getClosest(cell ? "td" : "tr"); |
| 299 | | var table = this.getClosest("table"); |
| 300 | | // this.editor.selectNodeContents(element); |
| 301 | | // this.editor.updateToolbar(); |
| 302 | | |
| 303 | | var dialog = new PopupWin(this.editor, cell ? Xinha._lc("Cell Properties", "TableOperations") : Xinha._lc("Row Properties", "TableOperations"), function(dialog, params) { |
| 304 | | TableOperations.processStyle(params, element); |
| 305 | | for (var i in params) { |
| 306 | | if(typeof params[i] == 'function') continue; |
| 307 | | var val = params[i]; |
| 308 | | switch (i) { |
| 309 | | case "f_align": |
| 310 | | element.align = val; |
| 311 | | break; |
| 312 | | case "f_char": |
| 313 | | element.ch = val; |
| 314 | | break; |
| 315 | | case "f_valign": |
| 316 | | element.vAlign = val; |
| 317 | | break; |
| 318 | | } |
| 319 | | } |
| 320 | | // various workarounds to refresh the table display (Gecko, |
| 321 | | // what's going on?! do not disappoint me!) |
| 322 | | dialog.editor.forceRedraw(); |
| 323 | | dialog.editor.focusEditor(); |
| 324 | | dialog.editor.updateToolbar(); |
| 325 | | var save_collapse = table.style.borderCollapse; |
| 326 | | table.style.borderCollapse = "collapse"; |
| 327 | | table.style.borderCollapse = "separate"; |
| 328 | | table.style.borderCollapse = save_collapse; |
| 329 | | }, |
| 330 | | |
| 331 | | // this function gets called when the dialog needs to be initialized |
| 332 | | function (dialog) { |
| 333 | | |
| 334 | | var f_align = element.align; |
| 335 | | var f_valign = element.vAlign; |
| 336 | | var f_char = element.ch; |
| 337 | | |
| 338 | | function selected(val) { |
| 339 | | return val ? " selected" : ""; |
| 340 | | } |
| 341 | | |
| 342 | | // dialog contents |
| 343 | | dialog.content.style.width = "400px"; |
| 344 | | dialog.content.innerHTML = " \ |
| 345 | | <div class='title'>" + Xinha._lc(cell ? "Cell Properties" : "Row Properties", "TableOperations") + "</div> \ |
| 346 | | <table style='width:100%'> \ |
| 347 | | <tr> \ |
| 348 | | <td id='--HA-layout'> \ |
| 349 | | "+// <fieldset><legend>" + Xinha._lc("Layout", "TableOperations") + "</legend> \ |
| 350 | | // <table style='width:100%'> \ |
| 351 | | // <tr> \ |
| 352 | | // <td class='label'>" + Xinha._lc("Align", "TableOperations") + ":</td> \ |
| 353 | | // <td> \ |
| 354 | | // <select name='f_align'> \ |
| 355 | | // <option value='left'" + selected(f_align == "left") + ">" + Xinha._lc("Left", "TableOperations") + "</option> \ |
| 356 | | // <option value='center'" + selected(f_align == "center") + ">" + Xinha._lc("Center", "TableOperations") + "</option> \ |
| 357 | | // <option value='right'" + selected(f_align == "right") + ">" + Xinha._lc("Right", "TableOperations") + "</option> \ |
| 358 | | // <option value='char'" + selected(f_align == "char") + ">" + Xinha._lc("Char", "TableOperations") + "</option> \ |
| 359 | | // </select> \ |
| 360 | | // " + Xinha._lc("Char", "TableOperations") + ": \ |
| 361 | | // <input type='text' style='font-family: monospace; text-align: center' name='f_char' size='1' value='" + f_char + "' /> \ |
| 362 | | // </td> \ |
| 363 | | // </tr><tr> \ |
| 364 | | // <td class='label'>" + Xinha._lc("Vertical align", "TableOperations") + ":</td> \ |
| 365 | | // <td> \ |
| 366 | | // <select name='f_valign'> \ |
| 367 | | // <option value='top'" + selected(f_valign == "top") + ">" + Xinha._lc("Top", "TableOperations") + "</option> \ |
| 368 | | // <option value='middle'" + selected(f_valign == "middle") + ">" + Xinha._lc("Middle", "TableOperations") + "</option> \ |
| 369 | | // <option value='bottom'" + selected(f_valign == "bottom") + ">" + Xinha._lc("Bottom", "TableOperations") + "</option> \ |
| 370 | | // <option value='baseline'" + selected(f_valign == "baseline") + ">" + Xinha._lc("Baseline", "TableOperations") + "</option> \ |
| 371 | | // </select> \ |
| 372 | | // </td> \ |
| 373 | | // </tr> \ |
| 374 | | // </table> \ |
| 375 | | // </fieldset> \ |
| 376 | | " </td> \ |
| 377 | | </tr> \ |
| 378 | | <tr> \ |
| 379 | | <td id='--HA-style'></td> \ |
| 380 | | </tr> \ |
| 381 | | </table> \ |
| 382 | | "; |
| 383 | | var st_prop = TableOperations.createStyleFieldset(dialog.doc, dialog.editor, element); |
| 384 | | var p = dialog.doc.getElementById("--HA-style"); |
| 385 | | p.appendChild(st_prop); |
| 386 | | var st_layout = TableOperations.createStyleLayoutFieldset(dialog.doc, dialog.editor, element); |
| 387 | | p = dialog.doc.getElementById("--HA-layout"); |
| 388 | | p.appendChild(st_layout); |
| 389 | | dialog.modal = true; |
| 390 | | dialog.addButtons("OK", "Cancel"); |
| 391 | | dialog.showAtElement(dialog.editor._iframe, "c"); |
| 392 | | }); |
| 756 | | |
| 757 | | |
| 758 | | //// GENERIC CODE [style of any element; this should be moved into a separate |
| 759 | | //// file as it'll be very useful] |
| 760 | | //// BEGIN GENERIC CODE ----------------------------------------------------- |
| 761 | | |
| 762 | | TableOperations.getLength = function(value) { |
| 763 | | var len = parseInt(value); |
| 764 | | if (isNaN(len)) { |
| 765 | | len = ""; |
| 766 | | } |
| 767 | | return len; |
| | 466 | TableOperations.prototype.dialogTableProperties = function() { |
| | 467 | |
| | 468 | var table = this.getClosest("table"); |
| | 469 | var self = this; |
| | 470 | var editor = this.editor; |
| | 471 | |
| | 472 | if(!this.dialogTablePropertiesHtml){ // retrieve the raw dialog contents |
| | 473 | Xinha._getback(_editor_url + 'plugins/TableOperations/popups/dialogTable.html', function(getback) { self.dialogTablePropertiesHtml = getback; self.dialogTableProperties(); }); |
| | 474 | return; |
| | 475 | } |
| | 476 | if (!this.dialogTable) { |
| | 477 | // Now we have everything we need, so we can build the dialog. |
| | 478 | this.dialogTable = new Xinha.Dialog(editor, this.dialogTablePropertiesHtml, 'TableOperations',{width:400}) |
| | 479 | this.dialogTable.getElementById('cancel').onclick = function() { self.dialog.hide()}; |
| | 480 | } |
| | 481 | var dialog = this.dialogTable; |
| | 482 | |
| | 483 | var Styler = new Xinha.InlineStyler(table, this.editor); |
| | 484 | |
| | 485 | function apply() { |
| | 486 | |
| | 487 | Styler.applyStyle(); |
| | 488 | var params = self.dialog.hide(); |
| | 489 | for (var i in params) { |
| | 490 | if(typeof params[i] == 'function') continue; |
| | 491 | var val = params[i]; |
| | 492 | if (typeof val == 'object' && val.tagName) val = val.value; |
| | 493 | switch (i) { |
| | 494 | case "caption": |
| | 495 | if (/\S/.test(val)) { |
| | 496 | // contains non white-space characters |
| | 497 | var caption = table.getElementsByTagName("caption")[0]; |
| | 498 | if (!caption) { |
| | 499 | caption = dialog.editor._doc.createElement("caption"); |
| | 500 | table.insertBefore(caption, table.firstChild); |
| | 501 | } |
| | 502 | caption.innerHTML = val; |
| | 503 | } else { |
| | 504 | // search for caption and delete it if found |
| | 505 | var caption = table.getElementsByTagName("caption")[0]; |
| | 506 | if (caption) { |
| | 507 | caption.parentNode.removeChild(caption); |
| | 508 | } |
| | 509 | } |
| | 510 | break; |
| | 511 | case "summary": |
| | 512 | table.summary = val; |
| | 513 | break; |
| | 514 | case "width": |
| | 515 | table.style.width = ("" + val) + params.f_unit; |
| | 516 | break; |
| | 517 | case "align": |
| | 518 | table.align = val; |
| | 519 | break; |
| | 520 | case "spacing": |
| | 521 | table.cellSpacing = val; |
| | 522 | break; |
| | 523 | case "padding": |
| | 524 | table.cellPadding = val; |
| | 525 | break; |
| | 526 | case "borders": |
| | 527 | table.border = val; |
| | 528 | break; |
| | 529 | case "frames": |
| | 530 | table.frame = val; |
| | 531 | break; |
| | 532 | case "rules": |
| | 533 | table.rules = val; |
| | 534 | break; |
| | 535 | } |
| | 536 | } |
| | 537 | |
| | 538 | // various workarounds to refresh the table display (Gecko, |
| | 539 | // what's going on?! do not disappoint me!) |
| | 540 | self.editor.forceRedraw(); |
| | 541 | self.editor.focusEditor(); |
| | 542 | self.editor.updateToolbar(); |
| | 543 | var save_collapse = table.style.borderCollapse; |
| | 544 | table.style.borderCollapse = "collapse"; |
| | 545 | table.style.borderCollapse = "separate"; |
| | 546 | table.style.borderCollapse = save_collapse; |
| | 547 | } |
| | 548 | |
| | 549 | var st_layout = Styler.createStyleLayoutFieldset(); |
| | 550 | var p = dialog.getElementById("TO_layout"); |
| | 551 | p.replaceChild(st_layout,p.firstChild); |
| | 552 | |
| | 553 | var st_prop = Styler.createStyleFieldset(); |
| | 554 | p = dialog.getElementById("TO_style"); |
| | 555 | p.replaceChild(st_prop,p.firstChild); |
| | 556 | |
| | 557 | this.dialogTable.getElementById('ok').onclick = apply; |
| | 558 | |
| | 559 | // gather element's values |
| | 560 | var values = {}; |
| | 561 | var capel = table.getElementsByTagName("caption")[0]; |
| | 562 | if (capel) { |
| | 563 | values['caption'] = capel.innerHTML; |
| | 564 | } |
| | 565 | else values['caption'] = ""; |
| | 566 | values['summary'] = table.summary; |
| | 567 | |
| | 568 | values['spacing'] = table.cellSpacing; |
| | 569 | values['padding'] = table.cellPadding; |
| | 570 | var f_borders = table.border; |
| | 571 | |
| | 572 | values['frames'] = table.frame; |
| | 573 | values['rules'] = table.rules; |
| | 574 | |
| | 575 | this.dialogTable.show(values); |
| 770 | | // Applies the style found in "params" to the given element. |
| 771 | | TableOperations.processStyle = function(params, element) { |
| 772 | | var style = element.style; |
| 773 | | for (var i in params) { |
| 774 | | if(typeof params[i] == 'function') continue; |
| 775 | | var val = params[i]; |
| 776 | | switch (i) { |
| 777 | | case "f_st_backgroundColor": |
| 778 | | style.backgroundColor = val; |
| 779 | | break; |
| 780 | | case "f_st_color": |
| 781 | | style.color = val; |
| 782 | | break; |
| 783 | | case "f_st_backgroundImage": |
| 784 | | if (/\S/.test(val)) { |
| 785 | | style.backgroundImage = "url(" + val + ")"; |
| 786 | | } else { |
| 787 | | style.backgroundImage = "none"; |
| 788 | | } |
| 789 | | break; |
| 790 | | case "f_st_borderWidth": |
| 791 | | style.borderWidth = val; |
| 792 | | break; |
| 793 | | case "f_st_borderStyle": |
| 794 | | style.borderStyle = val; |
| 795 | | break; |
| 796 | | case "f_st_borderColor": |
| 797 | | style.borderColor = val; |
| 798 | | break; |
| 799 | | case "f_st_borderCollapse": |
| 800 | | style.borderCollapse = val ? "collapse" : ""; |
| 801 | | break; |
| 802 | | case "f_st_width": |
| 803 | | if (/\S/.test(val)) { |
| 804 | | style.width = val + params["f_st_widthUnit"]; |
| 805 | | } else { |
| 806 | | style.width = ""; |
| 807 | | } |
| 808 | | break; |
| 809 | | case "f_st_height": |
| 810 | | if (/\S/.test(val)) { |
| 811 | | style.height = val + params["f_st_heightUnit"]; |
| 812 | | } else { |
| 813 | | style.height = ""; |
| 814 | | } |
| 815 | | break; |
| 816 | | case "f_st_textAlign": |
| 817 | | if (val == "char") { |
| 818 | | var ch = params["f_st_textAlignChar"]; |
| 819 | | if (ch == '"') { |
| 820 | | ch = '\\"'; |
| 821 | | } |
| 822 | | style.textAlign = '"' + ch + '"'; |
| 823 | | } else if (val == "-") { |
| 824 | | style.textAlign = ""; |
| 825 | | } else { |
| 826 | | style.textAlign = val; |
| 827 | | } |
| 828 | | break; |
| 829 | | case "f_st_verticalAlign": |
| 830 | | element.vAlign = ""; |
| 831 | | if (val == "-") { |
| 832 | | style.verticalAlign = ""; |
| 833 | | |
| 834 | | } else { |
| 835 | | style.verticalAlign = val; |
| 836 | | } |
| 837 | | break; |
| 838 | | case "f_st_float": |
| 839 | | style.cssFloat = val; |
| 840 | | break; |
| 841 | | // case "f_st_margin": |
| 842 | | // style.margin = val + "px"; |
| 843 | | // break; |
| 844 | | // case "f_st_padding": |
| 845 | | // style.padding = val + "px"; |
| 846 | | // break; |
| 847 | | } |
| 848 | | } |
| | 578 | TableOperations.prototype.dialogRowCellProperties = function(cell) { |
| | 579 | // retrieve existing values |
| | 580 | var element = this.getClosest(cell ? "td" : "tr"); |
| | 581 | var table = this.getClosest("table"); |
| | 582 | |
| | 583 | var self = this; |
| | 584 | var editor = this.editor; |
| | 585 | |
| | 586 | if(!self.dialogRowCellPropertiesHtml) // retrieve the raw dialog contents |
| | 587 | { |
| | 588 | Xinha._getback(_editor_url + 'plugins/TableOperations/popups/dialogRowCell.html', function(getback) { self.dialogRowCellPropertiesHtml = getback; self.dialogRowCellProperties(cell); }); |
| | 589 | return; |
| | 590 | } |
| | 591 | if (!this.dialogRowCell) { |
| | 592 | // Now we have everything we need, so we can build the dialog. |
| | 593 | this.dialogRowCell = new Xinha.Dialog(editor, self.dialogRowCellPropertiesHtml, 'TableOperations',{width:400}) |
| | 594 | this.dialogRowCell.getElementById('cancel').onclick = function() { self.dialog.hide()}; |
| | 595 | } |
| | 596 | |
| | 597 | var dialog = this.dialogRowCell; |
| | 598 | dialog.getElementById('title').innerHTML = cell ? Xinha._lc("Cell Properties", "TableOperations") : Xinha._lc("Row Properties", "TableOperations"); |
| | 599 | var Styler = new Xinha.InlineStyler(element, self.editor); |
| | 600 | |
| | 601 | function apply() { |
| | 602 | var params = self.dialog.hide(); |
| | 603 | Styler.applyStyle(); |
| | 604 | |
| | 605 | // various workarounds to refresh the table display (Gecko, |
| | 606 | // what's going on?! do not disappoint me!) |
| | 607 | self.editor.forceRedraw(); |
| | 608 | self.editor.focusEditor(); |
| | 609 | self.editor.updateToolbar(); |
| | 610 | var save_collapse = table.style.borderCollapse; |
| | 611 | table.style.borderCollapse = "collapse"; |
| | 612 | table.style.borderCollapse = "separate"; |
| | 613 | table.style.borderCollapse = save_collapse; |
| | 614 | } |
| | 615 | |
| | 616 | var st_layout = Styler.createStyleLayoutFieldset(); |
| | 617 | var p = dialog.getElementById("TO_layout"); |
| | 618 | |
| | 619 | p.replaceChild(st_layout,p.firstChild); |
| | 620 | |
| | 621 | var st_prop = Styler.createStyleFieldset(); |
| | 622 | p = dialog.getElementById("TO_style"); |
| | 623 | p.replaceChild(st_prop,p.firstChild); |
| | 624 | |
| | 625 | this.dialogRowCell.getElementById('ok').onclick = apply; |
| | 626 | this.dialogRowCell.show(); |
| 850 | | |
| 851 | | // Returns an HTML element for a widget that allows color selection. That is, |
| 852 | | // a button that contains the given color, if any, and when pressed will popup |
| 853 | | // the sooner-or-later-to-be-rewritten select_color.html dialog allowing user |
| 854 | | // to select some color. If a color is selected, an input field with the name |
| 855 | | // "f_st_"+name will be updated with the color value in #123456 format. |
| 856 | | TableOperations.createColorButton = function(doc, editor, color, name) { |
| 857 | | if (!color) { |
| 858 | | color = ""; |
| 859 | | } else if (!/#/.test(color)) { |
| 860 | | color = Xinha._colorToRgb(color); |
| 861 | | } |
| 862 | | |
| 863 | | var df = doc.createElement("span"); |
| 864 | | var field = doc.createElement("input"); |
| 865 | | field.type = "hidden"; |
| 866 | | df.appendChild(field); |
| 867 | | field.name = "f_st_" + name; |
| 868 | | field.value = color; |
| 869 | | var button = doc.createElement("span"); |
| 870 | | button.className = "buttonColor"; |
| 871 | | df.appendChild(button); |
| 872 | | var span = doc.createElement("span"); |
| 873 | | span.className = "chooser"; |
| 874 | | // span.innerHTML = " "; |
| 875 | | span.style.backgroundColor = color; |
| 876 | | button.appendChild(span); |
| 877 | | button.onmouseover = function() { if (!this.disabled) { this.className += " buttonColor-hilite"; }}; |
| 878 | | button.onmouseout = function() { if (!this.disabled) { this.className = "buttonColor"; }}; |
| 879 | | span.onclick = function() { |
| 880 | | if (this.parentNode.disabled) { |
| 881 | | return false; |
| 882 | | } |
| 883 | | editor._popupDialog("select_color.html", function(color) { |
| 884 | | if (color) { |
| 885 | | span.style.backgroundColor = "#" + color; |
| 886 | | field.value = "#" + color; |
| 887 | | } |
| 888 | | }, color); |
| 889 | | }; |
| 890 | | var span2 = doc.createElement("span"); |
| 891 | | span2.innerHTML = "×"; |
| 892 | | span2.className = "nocolor"; |
| 893 | | span2.title = Xinha._lc("Unset color", "TableOperations"); |
| 894 | | button.appendChild(span2); |
| 895 | | span2.onmouseover = function() { if (!this.parentNode.disabled) { this.className += " nocolor-hilite"; }}; |
| 896 | | span2.onmouseout = function() { if (!this.parentNode.disabled) { this.className = "nocolor"; }}; |
| 897 | | span2.onclick = function() { |
| 898 | | span.style.backgroundColor = ""; |
| 899 | | field.value = ""; |
| 900 | | }; |
| 901 | | return df; |
| 902 | | }; |
| 903 | | |
| 904 | | TableOperations.createStyleLayoutFieldset = function(doc, editor, el) { |
| 905 | | var fieldset = doc.createElement("fieldset"); |
| 906 | | var legend = doc.createElement("legend"); |
| 907 | | fieldset.appendChild(legend); |
| 908 | | legend.innerHTML = Xinha._lc("Layout", "TableOperations"); |
| 909 | | var table = doc.createElement("table"); |
| 910 | | fieldset.appendChild(table); |
| 911 | | table.style.width = "100%"; |
| 912 | | var tbody = doc.createElement("tbody"); |
| 913 | | table.appendChild(tbody); |
| 914 | | |
| 915 | | var tagname = el.tagName.toLowerCase(); |
| 916 | | var tr, td, input, select, option, options, i; |
| 917 | | |
| 918 | | if (tagname != "td" && tagname != "tr" && tagname != "th") { |
| 919 | | tr = doc.createElement("tr"); |
| 920 | | tbody.appendChild(tr); |
| 921 | | td = doc.createElement("td"); |
| 922 | | td.className = "label"; |
| 923 | | tr.appendChild(td); |
| 924 | | td.innerHTML = Xinha._lc("Float", "TableOperations") + ":"; |
| 925 | | td = doc.createElement("td"); |
| 926 | | tr.appendChild(td); |
| 927 | | select = doc.createElement("select"); |
| 928 | | td.appendChild(select); |
| 929 | | select.name = "f_st_float"; |
| 930 | | options = ["None", "Left", "Right"]; |
| 931 | | for (var i = 0; i < options.length; ++i) { |
| 932 | | var Val = options[i]; |
| 933 | | var val = options[i].toLowerCase(); |
| 934 | | option = doc.createElement("option"); |
| 935 | | option.innerHTML = Xinha._lc(Val, "TableOperations"); |
| 936 | | option.value = val; |
| 937 | | option.selected = (("" + el.style.cssFloat).toLowerCase() == val); |
| 938 | | select.appendChild(option); |
| 939 | | } |
| 940 | | } |
| 941 | | |
| 942 | | tr = doc.createElement("tr"); |
| 943 | | tbody.appendChild(tr); |
| 944 | | td = doc.createElement("td"); |
| 945 | | td.className = "label"; |
| 946 | | tr.appendChild(td); |
| 947 | | td.innerHTML = Xinha._lc("Width", "TableOperations") + ":"; |
| 948 | | td = doc.createElement("td"); |
| 949 | | tr.appendChild(td); |
| 950 | | input = doc.createElement("input"); |
| 951 | | input.type = "text"; |
| 952 | | input.value = TableOperations.getLength(el.style.width); |
| 953 | | input.size = "5"; |
| 954 | | input.name = "f_st_width"; |
| 955 | | input.style.marginRight = "0.5em"; |
| 956 | | td.appendChild(input); |
| 957 | | select = doc.createElement("select"); |
| 958 | | select.name = "f_st_widthUnit"; |
| 959 | | option = doc.createElement("option"); |
| 960 | | option.innerHTML = Xinha._lc("percent", "TableOperations"); |
| 961 | | option.value = "%"; |
| 962 | | option.selected = /%/.test(el.style.width); |
| 963 | | select.appendChild(option); |
| 964 | | option = doc.createElement("option"); |
| 965 | | option.innerHTML = Xinha._lc("pixels", "TableOperations"); |
| 966 | | option.value = "px"; |
| 967 | | option.selected = /px/.test(el.style.width); |
| 968 | | select.appendChild(option); |
| 969 | | td.appendChild(select); |
| 970 | | |
| 971 | | select.style.marginRight = "0.5em"; |
| 972 | | td.appendChild(doc.createTextNode(Xinha._lc("Text align", "TableOperations") + ":")); |
| 973 | | select = doc.createElement("select"); |
| 974 | | select.style.marginLeft = select.style.marginRight = "0.5em"; |
| 975 | | td.appendChild(select); |
| 976 | | select.name = "f_st_textAlign"; |
| 977 | | options = ["Left", "Center", "Right", "Justify", "-"]; |
| 978 | | if (tagname == "td") { |
| 979 | | options.push("Char"); |
| 980 | | } |
| 981 | | input = doc.createElement("input"); |
| 982 | | input.name = "f_st_textAlignChar"; |
| 983 | | input.size = "1"; |
| 984 | | input.style.fontFamily = "monospace"; |
| 985 | | td.appendChild(input); |
| 986 | | for (var i = 0; i < options.length; ++i) { |
| 987 | | var Val = options[i]; |
| 988 | | var val = Val.toLowerCase(); |
| 989 | | option = doc.createElement("option"); |
| 990 | | option.value = val; |
| 991 | | option.innerHTML = Xinha._lc(Val, "TableOperations"); |
| 992 | | option.selected = ((el.style.textAlign.toLowerCase() == val) || (el.style.textAlign == "" && Val == "-")); |
| 993 | | select.appendChild(option); |
| 994 | | } |
| 995 | | function setCharVisibility(value) { |
| 996 | | input.style.visibility = value ? "visible" : "hidden"; |
| 997 | | if (value) { |
| 998 | | input.focus(); |
| 999 | | input.select(); |
| 1000 | | } |
| 1001 | | } |
| 1002 | | select.onchange = function() { setCharVisibility(this.value == "char"); }; |
| 1003 | | setCharVisibility(select.value == "char"); |
| 1004 | | |
| 1005 | | tr = doc.createElement("tr"); |
| 1006 | | tbody.appendChild(tr); |
| 1007 | | td = doc.createElement("td"); |
| 1008 | | td.className = "label"; |
| 1009 | | tr.appendChild(td); |
| 1010 | | td.innerHTML = Xinha._lc("Height", "TableOperations") + ":"; |
| 1011 | | td = doc.createElement("td"); |
| 1012 | | tr.appendChild(td); |
| 1013 | | input = doc.createElement("input"); |
| 1014 | | input.type = "text"; |
| 1015 | | input.value = TableOperations.getLength(el.style.height); |
| 1016 | | input.size = "5"; |
| 1017 | | input.name = "f_st_height"; |
| 1018 | | input.style.marginRight = "0.5em"; |
| 1019 | | td.appendChild(input); |
| 1020 | | select = doc.createElement("select"); |
| 1021 | | select.name = "f_st_heightUnit"; |
| 1022 | | option = doc.createElement("option"); |
| 1023 | | option.innerHTML = Xinha._lc("percent", "TableOperations"); |
| 1024 | | option.value = "%"; |
| 1025 | | option.selected = /%/.test(el.style.height); |
| 1026 | | select.appendChild(option); |
| 1027 | | option = doc.createElement("option"); |
| 1028 | | option.innerHTML = Xinha._lc("pixels", "TableOperations"); |
| 1029 | | option.value = "px"; |
| 1030 | | option.selected = /px/.test(el.style.height); |
| 1031 | | select.appendChild(option); |
| 1032 | | td.appendChild(select); |
| 1033 | | |
| 1034 | | select.style.marginRight = "0.5em"; |
| 1035 | | td.appendChild(doc.createTextNode(Xinha._lc("Vertical align", "TableOperations") + ":")); |
| 1036 | | select = doc.createElement("select"); |
| 1037 | | select.name = "f_st_verticalAlign"; |
| 1038 | | select.style.marginLeft = "0.5em"; |
| 1039 | | td.appendChild(select); |
| 1040 | | options = ["Top", "Middle", "Bottom", "Baseline", "-"]; |
| 1041 | | for (var i = 0; i < options.length; ++i) { |
| 1042 | | var Val = options[i]; |
| 1043 | | var val = Val.toLowerCase(); |
| 1044 | | option = doc.createElement("option"); |
| 1045 | | option.value = val; |
| 1046 | | option.innerHTML = Xinha._lc(Val, "TableOperations"); |
| 1047 | | option.selected = ((el.style.verticalAlign.toLowerCase() == val) || (el.style.verticalAlign == "" && Val == "-")); |
| 1048 | | select.appendChild(option); |
| 1049 | | } |
| 1050 | | |
| 1051 | | return fieldset; |
| 1052 | | }; |
| 1053 | | |
| 1054 | | // Returns an HTML element containing the style attributes for the given |
| 1055 | | // element. This can be easily embedded into any dialog; the functionality is |
| 1056 | | // also provided. |
| 1057 | | TableOperations.createStyleFieldset = function(doc, editor, el) { |
| 1058 | | var fieldset = doc.createElement("fieldset"); |
| 1059 | | var legend = doc.createElement("legend"); |
| 1060 | | fieldset.appendChild(legend); |
| 1061 | | legend.innerHTML = Xinha._lc("CSS Style", "TableOperations"); |
| 1062 | | var table = doc.createElement("table"); |
| 1063 | | fieldset.appendChild(table); |
| 1064 | | table.style.width = "100%"; |
| 1065 | | var tbody = doc.createElement("tbody"); |
| 1066 | | table.appendChild(tbody); |
| 1067 | | |
| 1068 | | var tr, td, input, select, option, options, i; |
| 1069 | | |
| 1070 | | tr = doc.createElement("tr"); |
| 1071 | | tbody.appendChild(tr); |
| 1072 | | td = doc.createElement("td"); |
| 1073 | | tr.appendChild(td); |
| 1074 | | td.className = "label"; |
| 1075 | | td.innerHTML = Xinha._lc("Background", "TableOperations") + ":"; |
| 1076 | | td = doc.createElement("td"); |
| 1077 | | tr.appendChild(td); |
| 1078 | | var df = TableOperations.createColorButton(doc, editor, el.style.backgroundColor, "backgroundColor"); |
| 1079 | | df.firstChild.nextSibling.style.marginRight = "0.5em"; |
| 1080 | | td.appendChild(df); |
| 1081 | | td.appendChild(doc.createTextNode(Xinha._lc("Image URL", "TableOperations") + ": ")); |
| 1082 | | input = doc.createElement("input"); |
| 1083 | | input.type = "text"; |
| 1084 | | input.name = "f_st_backgroundImage"; |
| 1085 | | if (el.style.backgroundImage.match(/url\(\s*(.*?)\s*\)/)) { |
| 1086 | | input.value = RegExp.$1; |
| 1087 | | } |
| 1088 | | // input.style.width = "100%"; |
| 1089 | | td.appendChild(input); |
| 1090 | | |
| 1091 | | tr = doc.createElement("tr"); |
| 1092 | | tbody.appendChild(tr); |
| 1093 | | td = doc.createElement("td"); |
| 1094 | | tr.appendChild(td); |
| 1095 | | td.className = "label"; |
| 1096 | | td.innerHTML = Xinha._lc("FG Color", "TableOperations") + ":"; |
| 1097 | | td = doc.createElement("td"); |
| 1098 | | tr.appendChild(td); |
| 1099 | | td.appendChild(TableOperations.createColorButton(doc, editor, el.style.color, "color")); |
| 1100 | | |
| 1101 | | // for better alignment we include an invisible field. |
| 1102 | | input = doc.createElement("input"); |
| 1103 | | input.style.visibility = "hidden"; |
| 1104 | | input.type = "text"; |
| 1105 | | td.appendChild(input); |
| 1106 | | |
| 1107 | | tr = doc.createElement("tr"); |
| 1108 | | tbody.appendChild(tr); |
| 1109 | | td = doc.createElement("td"); |
| 1110 | | tr.appendChild(td); |
| 1111 | | td.className = "label"; |
| 1112 | | td.innerHTML = Xinha._lc("Border", "TableOperations") + ":"; |
| 1113 | | td = doc.createElement("td"); |
| 1114 | | tr.appendChild(td); |
| 1115 | | |
| 1116 | | var colorButton = TableOperations.createColorButton(doc, editor, el.style.borderColor, "borderColor"); |
| 1117 | | var btn = colorButton.firstChild.nextSibling; |
| 1118 | | td.appendChild(colorButton); |
| 1119 | | // borderFields.push(btn); |
| 1120 | | btn.style.marginRight = "0.5em"; |
| 1121 | | |
| 1122 | | select = doc.createElement("select"); |
| 1123 | | var borderFields = []; |
| 1124 | | td.appendChild(select); |
| 1125 | | select.name = "f_st_borderStyle"; |
| 1126 | | options = ["none", "dotted", "dashed", "solid", "double", "groove", "ridge", "inset", "outset"]; |
| 1127 | | var currentBorderStyle = el.style.borderStyle; |
| 1128 | | // Gecko reports "solid solid solid solid" for "border-style: solid". |
| 1129 | | // That is, "top right bottom left" -- we only consider the first |
| 1130 | | // value. |
| 1131 | | (currentBorderStyle.match(/([^\s]*)\s/)) && (currentBorderStyle = RegExp.$1); |
| 1132 | | for (var i in options) { |
| 1133 | | if(typeof options[i] == 'function') continue; |
| 1134 | | var val = options[i]; |
| 1135 | | option = doc.createElement("option"); |
| 1136 | | option.value = val; |
| 1137 | | option.innerHTML = val; |
| 1138 | | (val == currentBorderStyle) && (option.selected = true); |
| 1139 | | select.appendChild(option); |
| 1140 | | } |
| 1141 | | select.style.marginRight = "0.5em"; |
| 1142 | | function setBorderFieldsStatus(value) { |
| 1143 | | for (var i = 0; i < borderFields.length; ++i) { |
| 1144 | | var el = borderFields[i]; |
| 1145 | | el.style.visibility = value ? "hidden" : "visible"; |
| 1146 | | if (!value && (el.tagName.toLowerCase() == "input")) { |
| 1147 | | el.focus(); |
| 1148 | | el.select(); |
| 1149 | | } |
| 1150 | | } |
| 1151 | | } |
| 1152 | | select.onchange = function() { setBorderFieldsStatus(this.value == "none"); }; |
| 1153 | | |
| 1154 | | input = doc.createElement("input"); |
| 1155 | | borderFields.push(input); |
| 1156 | | input.type = "text"; |
| 1157 | | input.name = "f_st_borderWidth"; |
| 1158 | | input.value = TableOperations.getLength(el.style.borderWidth); |
| 1159 | | input.size = "5"; |
| 1160 | | td.appendChild(input); |
| 1161 | | input.style.marginRight = "0.5em"; |
| 1162 | | var span = doc.createElement("span"); |
| 1163 | | span.innerHTML = Xinha._lc("pixels", "TableOperations"); |
| 1164 | | td.appendChild(span); |
| 1165 | | borderFields.push(span); |
| 1166 | | |
| 1167 | | setBorderFieldsStatus(select.value == "none"); |
| 1168 | | |
| 1169 | | if (el.tagName.toLowerCase() == "table") { |
| 1170 | | // the border-collapse style is only for tables |
| 1171 | | tr = doc.createElement("tr"); |
| 1172 | | tbody.appendChild(tr); |
| 1173 | | td = doc.createElement("td"); |
| 1174 | | td.className = "label"; |
| 1175 | | tr.appendChild(td); |
| 1176 | | input = doc.createElement("input"); |
| 1177 | | input.type = "checkbox"; |
| 1178 | | input.name = "f_st_borderCollapse"; |
| 1179 | | input.id = "f_st_borderCollapse"; |
| 1180 | | var val = (/collapse/i.test(el.style.borderCollapse)); |
| 1181 | | input.checked = val ? 1 : 0; |
| 1182 | | td.appendChild(input); |
| 1183 | | |
| 1184 | | td = doc.createElement("td"); |
| 1185 | | tr.appendChild(td); |
| 1186 | | var label = doc.createElement("label"); |
| 1187 | | label.htmlFor = "f_st_borderCollapse"; |
| 1188 | | label.innerHTML = Xinha._lc("Collapsed borders", "TableOperations"); |
| 1189 | | td.appendChild(label); |
| 1190 | | } |
| 1191 | | |
| 1192 | | // tr = doc.createElement("tr"); |
| 1193 | | // tbody.appendChild(tr); |
| 1194 | | // td = doc.createElement("td"); |
| 1195 | | // td.className = "label"; |
| 1196 | | // tr.appendChild(td); |
| 1197 | | // td.innerHTML = Xinha._lc("Margin", "TableOperations") + ":"; |
| 1198 | | // td = doc.createElement("td"); |
| 1199 | | // tr.appendChild(td); |
| 1200 | | // input = doc.createElement("input"); |
| 1201 | | // input.type = "text"; |
| 1202 | | // input.size = "5"; |
| 1203 | | // input.name = "f_st_margin"; |
| 1204 | | // td.appendChild(input); |
| 1205 | | // input.style.marginRight = "0.5em"; |
| 1206 | | // td.appendChild(doc.createTextNode(Xinha._lc("Padding", "TableOperations") + ":")); |
| 1207 | | |
| 1208 | | // input = doc.createElement("input"); |
| 1209 | | // input.type = "text"; |
| 1210 | | // input.size = "5"; |
| 1211 | | // input.name = "f_st_padding"; |
| 1212 | | // td.appendChild(input); |
| 1213 | | // input.style.marginLeft = "0.5em"; |
| 1214 | | // input.style.marginRight = "0.5em"; |
| 1215 | | // td.appendChild(doc.createTextNode(Xinha._lc("pixels", "TableOperations"))); |
| 1216 | | |
| 1217 | | return fieldset; |
| 1218 | | }; |
| 1219 | | |
| 1220 | | //// END GENERIC CODE ------------------------------------------------------- |