Ticket #1176: TableOperationsPlugin.patch

File TableOperationsPlugin.patch, 3.7 kB (added by guest, 3 months ago)

Patch for the TableOperations plugin to only use the new dialogs (it previously used a popup for the merge cells dialog)

  • table-operations.js

     
    399399                                alert(Xinha._lc("Please click into some cell", "TableOperations")); 
    400400                                break; 
    401401                        } 
    402                         editor._popupDialog("plugin://TableOperations/merge_cells.html", function(param) { 
    403                                 if (!param) {   // user pressed Cancel 
    404                                         return false; 
    405                                 } 
    406                                 no_cols = parseInt(param['f_cols'],10) + 1; 
    407                                 no_rows = parseInt(param['f_rows'],10) + 1; 
    408                                 var tr = td.parentNode; 
    409                                 var cell_index = td.cellIndex; 
    410                                 var row_index = tr.rowIndex; 
    411                                 var table = tr.parentNode; 
    412                                 cellMerge(table, cell_index, row_index, no_cols, no_rows); 
    413                         }, null);        
     402                        var tr = td.parentNode; 
     403                        var cell_index = td.cellIndex; 
     404                        var row_index = tr.rowIndex; 
     405                        // pass cellMerge and the indices so apply() can call cellMerge and know  
     406                        // what cell was selected when the dialog was opened 
     407                        this.dialogMerge(cellMerge, cell_index, row_index); 
    414408                } 
    415409                break; 
    416410 
     
    463457        ["cell-split",         "td[colSpan!=1,rowSpan!=1]", "Split cell"] 
    464458        ]; 
    465459 
     460TableOperations.prototype.dialogMerge = function(merge_func, cell_index, row_index) { 
     461  var table = this.getClosest("table"); 
     462  var self = this; 
     463  var editor = this.editor; 
     464 
     465  if (!this.dialogMergeCellsHtml) { 
     466    Xinha._getback(Xinha.getPluginDir("TableOperations") + '/popups/dialogMergeCells.html', function(getback) { self.dialogMergeCellsHtml = getback; self.dialogMerge(merge_func, cell_index, row_index); }); 
     467    return; 
     468  } 
     469 
     470  if (!this.dialogMergeCells) { 
     471    this.dialogMergeCells = new Xinha.Dialog(editor, this.dialogMergeCellsHtml, 'TableOperations', {width:400}); 
     472    this.dialogMergeCells.getElementById('cancel').onclick = function() { self.dialogMergeCells.hide(); }; 
     473  } 
     474 
     475  var dialog = this.dialogMergeCells; 
     476  function apply() { 
     477    dialog.hide(); 
     478    no_cols = parseInt(dialog.getElementById('f_cols').value,10) + 1; 
     479    no_rows = parseInt(dialog.getElementById('f_rows').value,10) + 1; 
     480    merge_func(table, cell_index, row_index, no_cols, no_rows);     
     481    return 
     482  } 
     483 
     484  this.dialogMergeCells.getElementById('ok').onclick = apply; 
     485  this.dialogMergeCells.show(); 
     486  this.dialogMergeCells.getElementById('f_cols').focus(); 
     487} 
     488 
    466489TableOperations.prototype.dialogTableProperties = function() { 
    467490 
    468491        var table = this.getClosest("table"); 
  • popups/dialogMergeCells.html

     
     1<h1 id="[h1]"><l10n>Merge Cells</l10n></h1> 
     2<table width="100%"> 
     3  <tr> 
     4    <td colspan="2"> 
     5      <l10n>Merge current cell with:</l10n> 
     6    </td> 
     7  </tr> 
     8  <tr> 
     9    <td style="text-align: right;" width="30%"><input type="text" name="[cols]" value="0" id="[f_cols]" size="4" title="Columns" /></td> 
     10    <td width="70%"><l10n>Cells to the right, and</l10n></td> 
     11  </tr> 
     12  <tr> 
     13    <td style="text-align: right;"><input type="text" name="[rows]" value="0" id="[f_rows]" size="4" title="Rows" /></td> 
     14    <td><l10n>Cells down</l10n></td> 
     15  </tr> 
     16  <tr> 
     17    <td colspan="2" style="text-align: right;"> 
     18      <hr /> 
     19      <div class="buttons" id="[buttons]"> 
     20        <input type="button" id="[ok]" value="_(OK)" /> 
     21        <input type="button" id="[cancel]" value="_(Cancel)" /> 
     22      </div> 
     23    </td> 
     24  </tr> 
     25</table> 
     26