[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

/sites/all/modules/yui_editor/plugins/ -> table.js (source)

   1  // $Id: table.js,v 1.1.2.2 2008/11/21 22:54:27 jeffcd Exp $
   2  
   3  function yui_editor_table() {
   4    for (var e in YAHOO.Drupal.editors) {
   5      var myEditor = YAHOO.Drupal.editors[e].editor;
   6      var config = YAHOO.Drupal.editors[e].config;
   7      var id = YAHOO.Drupal.editors[e].id;
   8  
   9      if (config.table == 1) {
  10        myEditor.on('toolbarLoaded', function () {
  11          var tableConfig = {
  12            type: 'push', label: 'Create Table', value: 'table'
  13          };
  14          myEditor.toolbar.addButtonToGroup(tableConfig, 'plugins');
  15          myEditor.win = null;
  16  
  17          myEditor.createTableHTML =
  18            '<table><tbody>' +
  19            '<tr><td>Rows:</td><td><input type="text" size="1" id="tableRows' + id + '" value="3"></td><td>Columns:</td><td><input type="text" size="1" id="tableColumns' + id + '" value="3"></td></tr>' +
  20            '<tr><td>Width:</td><td><input type="text" size="1" id="tableWidth' + id + '" value=""></td><td>Height:</td><td><input type="text" size="1" id="tableHeight' + id + '" value=""></td></tr>' +
  21            '<tr><td><br />Border Size:</td><td colspan="3"><br /><input type="text" size="1" id="tableBorderSize' + id + '" value="1"></td></tr>' +
  22            '<tr><td>Cell Spacing:</td><td colspan="3"><input type="text" size="1" id="tableCellspacing' + id + '" value="0"></td></tr>' +
  23            '<tr><td>Cell Padding:</td><td colspan="3"><input type="text" size="1" id="tableCellpadding' + id + '" value="0"></td></tr>' +
  24            '<tr><td colspan="4"><div align="right"><input type="button" id="tableCreate' + id + '" value="Create"></div></td></tr>' +
  25            '</tbody></table>';
  26  
  27          myEditor.toolbar.on('tableClick', function(ev) {
  28            if (this.win !== null) {
  29              this.win.setBody(myEditor.createTableHTML);
  30              this.win.show();
  31            }
  32            else {
  33              this.win = new YAHOO.widget.Panel('test', {
  34                modal: true,
  35                fixedcenter: true,
  36                draggable: false,
  37                width: '350px'
  38              });
  39              this.win.setHeader('Create Table');
  40              this.win.setBody(myEditor.createTableHTML);
  41              this.win.render(document.body);
  42              this.win.hideEvent.subscribe(function() {
  43                //Just to make sure we didn't loose it
  44                this._setDesignMode('on');
  45                this._focusWindow();
  46              }, myEditor, true);
  47            }
  48  
  49            var tableCreateButton = new YAHOO.widget.Button('tableCreate' + id);
  50            tableCreateButton.on('click', function() {
  51              var rows =
  52                document.getElementById('tableRows' + id).value.match('[0-9]+') ? document.getElementById('tableRows' + id).value : 3;
  53              var columns =
  54                document.getElementById('tableColumns' + id).value.match('[0-9]+') ? document.getElementById('tableColumns' + id).value : 3;
  55              var borderSize =
  56                document.getElementById('tableBorderSize' + id).value.match('[0-9]+') ? document.getElementById('tableBorderSize' + id).value : 1;
  57              var cellspacing =
  58                document.getElementById('tableCellspacing' + id).value.match('[0-9]+') ? document.getElementById('tableCellspacing' + id).value : 0;
  59              var cellpadding =
  60                document.getElementById('tableCellpadding' + id).value.match('[0-9]+') ? document.getElementById('tableCellpadding' + id).value : 0;
  61              var width =
  62                document.getElementById('tableWidth' + id).value.match('[0-9]+') ? document.getElementById('tableWidth' + id).value : 0;
  63              var height =
  64                document.getElementById('tableHeight' + id).value.match('[0-9]+') ? document.getElementById('tableHeight' + id).value : 0;
  65              var tableHTML =
  66                '<table border="' + borderSize + '" cellspacing="' + cellspacing + '" cellpadding="' + cellpadding + '" height="' + height + '" width="' + width + '"><tbody>';
  67  
  68              // Build table
  69              for (var i = 0;i < rows;i++) {
  70                tableHTML += '<tr>\n';
  71  
  72                for (var j = 0;j < columns;j++) {
  73                  tableHTML += '<td>&nbsp;</td>\n';
  74                }
  75  
  76                tableHTML += '</tr>\n';
  77              }
  78              tableHTML += '</tbody></table>';
  79              myEditor.execCommand('inserthtml', tableHTML);
  80              createTablePanel.hide();
  81            });
  82  
  83            return false;
  84          }, myEditor, true);
  85        });
  86      }
  87    }
  88  }
  89  YAHOO.Drupal.yui_editor_load.subscribe(yui_editor_table);


Generated: Mon Jul 9 18:01:44 2012 Cross-referenced by PHPXref 0.7