b2evolution PHP Cross Reference Blogging Systems

Source: /plugins/tinymce_plugin/tiny_mce/plugins/table/js/table.js - 488 lines - 14408 bytes - Summary - Text - Print

   1  tinyMCEPopup.requireLangPack();
   2  
   3  var action, orgTableWidth, orgTableHeight, dom = tinyMCEPopup.editor.dom;
   4  
   5  function insertTable() {
   6      var formObj = document.forms[0];
   7      var inst = tinyMCEPopup.editor, dom = inst.dom;
   8      var cols = 2, rows = 2, border = 0, cellpadding = -1, cellspacing = -1, align, width, height, className, caption, frame, rules;
   9      var html = '', capEl, elm;
  10      var cellLimit, rowLimit, colLimit;
  11  
  12      tinyMCEPopup.restoreSelection();
  13  
  14      if (!AutoValidator.validate(formObj)) {
  15          tinyMCEPopup.alert(AutoValidator.getErrorMessages(formObj).join('. ') + '.');
  16          return false;
  17      }
  18  
  19      elm = dom.getParent(inst.selection.getNode(), 'table');
  20  
  21      // Get form data
  22      cols = formObj.elements['cols'].value;
  23      rows = formObj.elements['rows'].value;
  24      border = formObj.elements['border'].value != "" ? formObj.elements['border'].value : 0;
  25      cellpadding = formObj.elements['cellpadding'].value != "" ? formObj.elements['cellpadding'].value : "";
  26      cellspacing = formObj.elements['cellspacing'].value != "" ? formObj.elements['cellspacing'].value : "";
  27      align = getSelectValue(formObj, "align");
  28      frame = getSelectValue(formObj, "tframe");
  29      rules = getSelectValue(formObj, "rules");
  30      width = formObj.elements['width'].value;
  31      height = formObj.elements['height'].value;
  32      bordercolor = formObj.elements['bordercolor'].value;
  33      bgcolor = formObj.elements['bgcolor'].value;
  34      className = getSelectValue(formObj, "class");
  35      id = formObj.elements['id'].value;
  36      summary = formObj.elements['summary'].value;
  37      style = formObj.elements['style'].value;
  38      dir = formObj.elements['dir'].value;
  39      lang = formObj.elements['lang'].value;
  40      background = formObj.elements['backgroundimage'].value;
  41      caption = formObj.elements['caption'].checked;
  42  
  43      cellLimit = tinyMCEPopup.getParam('table_cell_limit', false);
  44      rowLimit = tinyMCEPopup.getParam('table_row_limit', false);
  45      colLimit = tinyMCEPopup.getParam('table_col_limit', false);
  46  
  47      // Validate table size
  48      if (colLimit && cols > colLimit) {
  49          tinyMCEPopup.alert(inst.getLang('table_dlg.col_limit').replace(/\{\$cols\}/g, colLimit));
  50          return false;
  51      } else if (rowLimit && rows > rowLimit) {
  52          tinyMCEPopup.alert(inst.getLang('table_dlg.row_limit').replace(/\{\$rows\}/g, rowLimit));
  53          return false;
  54      } else if (cellLimit && cols * rows > cellLimit) {
  55          tinyMCEPopup.alert(inst.getLang('table_dlg.cell_limit').replace(/\{\$cells\}/g, cellLimit));
  56          return false;
  57      }
  58  
  59      // Update table
  60      if (action == "update") {
  61          dom.setAttrib(elm, 'cellPadding', cellpadding, true);
  62          dom.setAttrib(elm, 'cellSpacing', cellspacing, true);
  63  
  64          if (!isCssSize(border)) {
  65              dom.setAttrib(elm, 'border', border);
  66          } else {
  67              dom.setAttrib(elm, 'border', '');
  68          }
  69  
  70          if (border == '') {
  71              dom.setStyle(elm, 'border-width', '');
  72              dom.setStyle(elm, 'border', '');
  73              dom.setAttrib(elm, 'border', '');
  74          }
  75  
  76          dom.setAttrib(elm, 'align', align);
  77          dom.setAttrib(elm, 'frame', frame);
  78          dom.setAttrib(elm, 'rules', rules);
  79          dom.setAttrib(elm, 'class', className);
  80          dom.setAttrib(elm, 'style', style);
  81          dom.setAttrib(elm, 'id', id);
  82          dom.setAttrib(elm, 'summary', summary);
  83          dom.setAttrib(elm, 'dir', dir);
  84          dom.setAttrib(elm, 'lang', lang);
  85  
  86          capEl = inst.dom.select('caption', elm)[0];
  87  
  88          if (capEl && !caption)
  89              capEl.parentNode.removeChild(capEl);
  90  
  91          if (!capEl && caption) {
  92              capEl = elm.ownerDocument.createElement('caption');
  93  
  94              if (!tinymce.isIE)
  95                  capEl.innerHTML = '<br data-mce-bogus="1"/>';
  96  
  97              elm.insertBefore(capEl, elm.firstChild);
  98          }
  99  
 100          if (width && inst.settings.inline_styles) {
 101              dom.setStyle(elm, 'width', width);
 102              dom.setAttrib(elm, 'width', '');
 103          } else {
 104              dom.setAttrib(elm, 'width', width, true);
 105              dom.setStyle(elm, 'width', '');
 106          }
 107  
 108          // Remove these since they are not valid XHTML
 109          dom.setAttrib(elm, 'borderColor', '');
 110          dom.setAttrib(elm, 'bgColor', '');
 111          dom.setAttrib(elm, 'background', '');
 112  
 113          if (height && inst.settings.inline_styles) {
 114              dom.setStyle(elm, 'height', height);
 115              dom.setAttrib(elm, 'height', '');
 116          } else {
 117              dom.setAttrib(elm, 'height', height, true);
 118              dom.setStyle(elm, 'height', '');
 119           }
 120  
 121          if (background != '')
 122              elm.style.backgroundImage = "url('" + background + "')";
 123          else
 124              elm.style.backgroundImage = '';
 125  
 126  /*        if (tinyMCEPopup.getParam("inline_styles")) {
 127              if (width != '')
 128                  elm.style.width = getCSSSize(width);
 129          }*/
 130  
 131          if (bordercolor != "") {
 132              elm.style.borderColor = bordercolor;
 133              elm.style.borderStyle = elm.style.borderStyle == "" ? "solid" : elm.style.borderStyle;
 134              elm.style.borderWidth = cssSize(border);
 135          } else
 136              elm.style.borderColor = '';
 137  
 138          elm.style.backgroundColor = bgcolor;
 139          elm.style.height = getCSSSize(height);
 140  
 141          inst.addVisual();
 142  
 143          // Fix for stange MSIE align bug
 144          //elm.outerHTML = elm.outerHTML;
 145  
 146          inst.nodeChanged();
 147          inst.execCommand('mceEndUndoLevel');
 148  
 149          // Repaint if dimensions changed
 150          if (formObj.width.value != orgTableWidth || formObj.height.value != orgTableHeight)
 151              inst.execCommand('mceRepaint');
 152  
 153          tinyMCEPopup.close();
 154          return true;
 155      }
 156  
 157      // Create new table
 158      html += '<table';
 159  
 160      html += makeAttrib('id', id);
 161      if (!isCssSize(border)) {
 162          html += makeAttrib('border', border);
 163      }
 164  
 165      html += makeAttrib('cellpadding', cellpadding);
 166      html += makeAttrib('cellspacing', cellspacing);
 167      html += makeAttrib('data-mce-new', '1');
 168  
 169      if (width && inst.settings.inline_styles) {
 170          if (style)
 171              style += '; ';
 172  
 173          // Force px
 174          if (/^[0-9\.]+$/.test(width))
 175              width += 'px';
 176  
 177          style += 'width: ' + width;
 178      } else
 179          html += makeAttrib('width', width);
 180  
 181  /*    if (height) {
 182          if (style)
 183              style += '; ';
 184  
 185          style += 'height: ' + height;
 186      }*/
 187  
 188      //html += makeAttrib('height', height);
 189      //html += makeAttrib('bordercolor', bordercolor);
 190      //html += makeAttrib('bgcolor', bgcolor);
 191      html += makeAttrib('align', align);
 192      html += makeAttrib('frame', frame);
 193      html += makeAttrib('rules', rules);
 194      html += makeAttrib('class', className);
 195      html += makeAttrib('style', style);
 196      html += makeAttrib('summary', summary);
 197      html += makeAttrib('dir', dir);
 198      html += makeAttrib('lang', lang);
 199      html += '>';
 200  
 201      if (caption) {
 202          if (!tinymce.isIE)
 203              html += '<caption><br data-mce-bogus="1"/></caption>';
 204          else
 205              html += '<caption></caption>';
 206      }
 207  
 208      for (var y=0; y<rows; y++) {
 209          html += "<tr>";
 210  
 211          for (var x=0; x<cols; x++) {
 212              if (!tinymce.isIE)
 213                  html += '<td><br data-mce-bogus="1"/></td>';
 214              else
 215                  html += '<td></td>';
 216          }
 217  
 218          html += "</tr>";
 219      }
 220  
 221      html += "</table>";
 222  
 223      // Move table
 224      if (inst.settings.fix_table_elements) {
 225          var patt = '';
 226  
 227          inst.focus();
 228          inst.selection.setContent('<br class="_mce_marker" />');
 229  
 230          tinymce.each('h1,h2,h3,h4,h5,h6,p'.split(','), function(n) {
 231              if (patt)
 232                  patt += ',';
 233  
 234              patt += n + ' ._mce_marker';
 235          });
 236  
 237          tinymce.each(inst.dom.select(patt), function(n) {
 238              inst.dom.split(inst.dom.getParent(n, 'h1,h2,h3,h4,h5,h6,p'), n);
 239          });
 240  
 241          dom.setOuterHTML(dom.select('br._mce_marker')[0], html);
 242      } else
 243          inst.execCommand('mceInsertContent', false, html);
 244  
 245      tinymce.each(dom.select('table[data-mce-new]'), function(node) {
 246          // Fixes a bug in IE where the caret cannot be placed after the table if the table is at the end of the document
 247          if (tinymce.isIE && node.nextSibling == null) {
 248              dom.insertAfter(dom.create('p'), node);
 249          }
 250  
 251          var tdorth = dom.select('td,th', node);
 252          try {
 253              // IE9 might fail to do this selection 
 254              inst.selection.setCursorLocation(tdorth[0], 0);
 255          } catch (ex) {
 256              // Ignore
 257          }
 258  
 259          dom.setAttrib(node, 'data-mce-new', '');
 260      });
 261  
 262      inst.addVisual();
 263      inst.execCommand('mceEndUndoLevel');
 264  
 265      tinyMCEPopup.close();
 266  }
 267  
 268  function makeAttrib(attrib, value) {
 269      var formObj = document.forms[0];
 270      var valueElm = formObj.elements[attrib];
 271  
 272      if (typeof(value) == "undefined" || value == null) {
 273          value = "";
 274  
 275          if (valueElm)
 276              value = valueElm.value;
 277      }
 278  
 279      if (value == "")
 280          return "";
 281  
 282      // XML encode it
 283      value = value.replace(/&/g, '&amp;');
 284      value = value.replace(/\"/g, '&quot;');
 285      value = value.replace(/</g, '&lt;');
 286      value = value.replace(/>/g, '&gt;');
 287  
 288      return ' ' + attrib + '="' + value + '"';
 289  }
 290  
 291  function init() {
 292      tinyMCEPopup.resizeToInnerSize();
 293  
 294      document.getElementById('backgroundimagebrowsercontainer').innerHTML = getBrowserHTML('backgroundimagebrowser','backgroundimage','image','table');
 295      document.getElementById('backgroundimagebrowsercontainer').innerHTML = getBrowserHTML('backgroundimagebrowser','backgroundimage','image','table');
 296      document.getElementById('bordercolor_pickcontainer').innerHTML = getColorPickerHTML('bordercolor_pick','bordercolor');
 297      document.getElementById('bgcolor_pickcontainer').innerHTML = getColorPickerHTML('bgcolor_pick','bgcolor');
 298  
 299      var cols = 2, rows = 2, border = tinyMCEPopup.getParam('table_default_border', '0'), cellpadding = tinyMCEPopup.getParam('table_default_cellpadding', ''), cellspacing = tinyMCEPopup.getParam('table_default_cellspacing', '');
 300      var align = "", width = "", height = "", bordercolor = "", bgcolor = "", className = "";
 301      var id = "", summary = "", style = "", dir = "", lang = "", background = "", bgcolor = "", bordercolor = "", rules = "", frame = "";
 302      var inst = tinyMCEPopup.editor, dom = inst.dom;
 303      var formObj = document.forms[0];
 304      var elm = dom.getParent(inst.selection.getNode(), "table");
 305  
 306      action = tinyMCEPopup.getWindowArg('action');
 307  
 308      if (!action)
 309          action = elm ? "update" : "insert";
 310  
 311      if (elm && action != "insert") {
 312          var rowsAr = elm.rows;
 313          var cols = 0;
 314          for (var i=0; i<rowsAr.length; i++)
 315              if (rowsAr[i].cells.length > cols)
 316                  cols = rowsAr[i].cells.length;
 317  
 318          cols = cols;
 319          rows = rowsAr.length;
 320  
 321          st = dom.parseStyle(dom.getAttrib(elm, "style"));
 322          border = trimSize(getStyle(elm, 'border', 'borderWidth'));
 323          cellpadding = dom.getAttrib(elm, 'cellpadding', "");
 324          cellspacing = dom.getAttrib(elm, 'cellspacing', "");
 325          width = trimSize(getStyle(elm, 'width', 'width'));
 326          height = trimSize(getStyle(elm, 'height', 'height'));
 327          bordercolor = convertRGBToHex(getStyle(elm, 'bordercolor', 'borderLeftColor'));
 328          bgcolor = convertRGBToHex(getStyle(elm, 'bgcolor', 'backgroundColor'));
 329          align = dom.getAttrib(elm, 'align', align);
 330          frame = dom.getAttrib(elm, 'frame');
 331          rules = dom.getAttrib(elm, 'rules');
 332          className = tinymce.trim(dom.getAttrib(elm, 'class').replace(/mceItem.+/g, ''));
 333          id = dom.getAttrib(elm, 'id');
 334          summary = dom.getAttrib(elm, 'summary');
 335          style = dom.serializeStyle(st);
 336          dir = dom.getAttrib(elm, 'dir');
 337          lang = dom.getAttrib(elm, 'lang');
 338          background = getStyle(elm, 'background', 'backgroundImage').replace(new RegExp("url\\(['\"]?([^'\"]*)['\"]?\\)", 'gi'), "$1");
 339          formObj.caption.checked = elm.getElementsByTagName('caption').length > 0;
 340  
 341          orgTableWidth = width;
 342          orgTableHeight = height;
 343  
 344          action = "update";
 345          formObj.insert.value = inst.getLang('update');
 346      }
 347  
 348      addClassesToList('class', "table_styles");
 349      TinyMCE_EditableSelects.init();
 350  
 351      // Update form
 352      selectByValue(formObj, 'align', align);
 353      selectByValue(formObj, 'tframe', frame);
 354      selectByValue(formObj, 'rules', rules);
 355      selectByValue(formObj, 'class', className, true, true);
 356      formObj.cols.value = cols;
 357      formObj.rows.value = rows;
 358      formObj.border.value = border;
 359      formObj.cellpadding.value = cellpadding;
 360      formObj.cellspacing.value = cellspacing;
 361      formObj.width.value = width;
 362      formObj.height.value = height;
 363      formObj.bordercolor.value = bordercolor;
 364      formObj.bgcolor.value = bgcolor;
 365      formObj.id.value = id;
 366      formObj.summary.value = summary;
 367      formObj.style.value = style;
 368      formObj.dir.value = dir;
 369      formObj.lang.value = lang;
 370      formObj.backgroundimage.value = background;
 371  
 372      updateColor('bordercolor_pick', 'bordercolor');
 373      updateColor('bgcolor_pick', 'bgcolor');
 374  
 375      // Resize some elements
 376      if (isVisible('backgroundimagebrowser'))
 377          document.getElementById('backgroundimage').style.width = '180px';
 378  
 379      // Disable some fields in update mode
 380      if (action == "update") {
 381          formObj.cols.disabled = true;
 382          formObj.rows.disabled = true;
 383      }
 384  }
 385  
 386  function changedSize() {
 387      var formObj = document.forms[0];
 388      var st = dom.parseStyle(formObj.style.value);
 389  
 390  /*    var width = formObj.width.value;
 391      if (width != "")
 392          st['width'] = tinyMCEPopup.getParam("inline_styles") ? getCSSSize(width) : "";
 393      else
 394          st['width'] = "";*/
 395  
 396      var height = formObj.height.value;
 397      if (height != "")
 398          st['height'] = getCSSSize(height);
 399      else
 400          st['height'] = "";
 401  
 402      formObj.style.value = dom.serializeStyle(st);
 403  }
 404  
 405  function isCssSize(value) {
 406      return /^[0-9.]+(%|in|cm|mm|em|ex|pt|pc|px)$/.test(value);
 407  }
 408  
 409  function cssSize(value, def) {
 410      value = tinymce.trim(value || def);
 411  
 412      if (!isCssSize(value)) {
 413          return parseInt(value, 10) + 'px';
 414      }
 415  
 416      return value;
 417  }
 418  
 419  function changedBackgroundImage() {
 420      var formObj = document.forms[0];
 421      var st = dom.parseStyle(formObj.style.value);
 422  
 423      st['background-image'] = "url('" + formObj.backgroundimage.value + "')";
 424  
 425      formObj.style.value = dom.serializeStyle(st);
 426  }
 427  
 428  function changedBorder() {
 429      var formObj = document.forms[0];
 430      var st = dom.parseStyle(formObj.style.value);
 431  
 432      // Update border width if the element has a color
 433      if (formObj.border.value != "" && (isCssSize(formObj.border.value) || formObj.bordercolor.value != ""))
 434          st['border-width'] = cssSize(formObj.border.value);
 435      else {
 436          if (!formObj.border.value) {
 437              st['border'] = '';
 438              st['border-width'] = '';
 439          }
 440      }
 441  
 442      formObj.style.value = dom.serializeStyle(st);
 443  }
 444  
 445  function changedColor() {
 446      var formObj = document.forms[0];
 447      var st = dom.parseStyle(formObj.style.value);
 448  
 449      st['background-color'] = formObj.bgcolor.value;
 450  
 451      if (formObj.bordercolor.value != "") {
 452          st['border-color'] = formObj.bordercolor.value;
 453  
 454          // Add border-width if it's missing
 455          if (!st['border-width'])
 456              st['border-width'] = cssSize(formObj.border.value, 1);
 457      }
 458  
 459      formObj.style.value = dom.serializeStyle(st);
 460  }
 461  
 462  function changedStyle() {
 463      var formObj = document.forms[0];
 464      var st = dom.parseStyle(formObj.style.value);
 465  
 466      if (st['background-image'])
 467          formObj.backgroundimage.value = st['background-image'].replace(new RegExp("url\\(['\"]?([^'\"]*)['\"]?\\)", 'gi'), "$1");
 468      else
 469          formObj.backgroundimage.value = '';
 470  
 471      if (st['width'])
 472          formObj.width.value = trimSize(st['width']);
 473  
 474      if (st['height'])
 475          formObj.height.value = trimSize(st['height']);
 476  
 477      if (st['background-color']) {
 478          formObj.bgcolor.value = st['background-color'];
 479          updateColor('bgcolor_pick','bgcolor');
 480      }
 481  
 482      if (st['border-color']) {
 483          formObj.bordercolor.value = st['border-color'];
 484          updateColor('bordercolor_pick','bordercolor');
 485      }
 486  }
 487  
 488  tinyMCEPopup.onInit.add(init);

title

Description

title

Description

title

Description

title

title

Body