summaryrefslogtreecommitdiff
path: root/program/js/tiny_mce/plugins/table/jscripts
diff options
context:
space:
mode:
authorsvncommit <devs@roundcube.net>2006-09-14 03:49:28 +0000
committersvncommit <devs@roundcube.net>2006-09-14 03:49:28 +0000
commita0109c4933e0bfb5ed9dbcf94f932991ca689542 (patch)
tree955246969bf9da5d5335d1d7c483025fdbd50407 /program/js/tiny_mce/plugins/table/jscripts
parentbb5ddfa0ade5fbd2ed9be16e51d4ce695252eece (diff)
Initial TinyMCE editor support (still need to work on spellcheck and skins)
Diffstat (limited to 'program/js/tiny_mce/plugins/table/jscripts')
-rw-r--r--program/js/tiny_mce/plugins/table/jscripts/cell.js249
-rw-r--r--program/js/tiny_mce/plugins/table/jscripts/merge_cells.js19
-rw-r--r--program/js/tiny_mce/plugins/table/jscripts/row.js200
-rw-r--r--program/js/tiny_mce/plugins/table/jscripts/table.js344
4 files changed, 812 insertions, 0 deletions
diff --git a/program/js/tiny_mce/plugins/table/jscripts/cell.js b/program/js/tiny_mce/plugins/table/jscripts/cell.js
new file mode 100644
index 000000000..436eaad17
--- /dev/null
+++ b/program/js/tiny_mce/plugins/table/jscripts/cell.js
@@ -0,0 +1,249 @@
+function init() {
+ tinyMCEPopup.resizeToInnerSize();
+
+ document.getElementById('backgroundimagebrowsercontainer').innerHTML = getBrowserHTML('backgroundimagebrowser','backgroundimage','image','table');
+ document.getElementById('bordercolor_pickcontainer').innerHTML = getColorPickerHTML('bordercolor_pick','bordercolor');
+ document.getElementById('bgcolor_pickcontainer').innerHTML = getColorPickerHTML('bgcolor_pick','bgcolor')
+
+ var inst = tinyMCE.selectedInstance;
+ var tdElm = tinyMCE.getParentElement(inst.getFocusElement(), "td,th");
+ var formObj = document.forms[0];
+ var st = tinyMCE.parseStyle(tinyMCE.getAttrib(tdElm, "style"));
+
+ // Get table cell data
+ var celltype = tdElm.nodeName.toLowerCase();
+ var align = tinyMCE.getAttrib(tdElm, 'align');
+ var valign = tinyMCE.getAttrib(tdElm, 'valign');
+ var width = trimSize(getStyle(tdElm, 'width', 'width'));
+ var height = trimSize(getStyle(tdElm, 'height', 'height'));
+ var bordercolor = convertRGBToHex(getStyle(tdElm, 'bordercolor', 'borderLeftColor'));
+ var bgcolor = convertRGBToHex(getStyle(tdElm, 'bgcolor', 'backgroundColor'));
+ var className = tinyMCE.getVisualAidClass(tinyMCE.getAttrib(tdElm, 'class'), false);
+ var backgroundimage = getStyle(tdElm, 'background', 'backgroundImage').replace(new RegExp("url\\('?([^']*)'?\\)", 'gi'), "$1");;
+ var id = tinyMCE.getAttrib(tdElm, 'id');
+ var lang = tinyMCE.getAttrib(tdElm, 'lang');
+ var dir = tinyMCE.getAttrib(tdElm, 'dir');
+ var scope = tinyMCE.getAttrib(tdElm, 'scope');
+
+ // Setup form
+ addClassesToList('class', 'table_cell_styles');
+ formObj.bordercolor.value = bordercolor;
+ formObj.bgcolor.value = bgcolor;
+ formObj.backgroundimage.value = backgroundimage;
+ formObj.width.value = width;
+ formObj.height.value = height;
+ formObj.id.value = id;
+ formObj.lang.value = lang;
+ formObj.style.value = tinyMCE.serializeStyle(st);
+ selectByValue(formObj, 'align', align);
+ selectByValue(formObj, 'valign', valign);
+ selectByValue(formObj, 'class', className);
+ selectByValue(formObj, 'celltype', celltype);
+ selectByValue(formObj, 'dir', dir);
+ selectByValue(formObj, 'scope', scope);
+
+ // Resize some elements
+ if (isVisible('backgroundimagebrowser'))
+ document.getElementById('backgroundimage').style.width = '180px';
+
+ updateColor('bordercolor_pick', 'bordercolor');
+ updateColor('bgcolor_pick', 'bgcolor');
+}
+
+function updateAction() {
+ tinyMCEPopup.restoreSelection();
+
+ var inst = tinyMCE.selectedInstance;
+ var tdElm = tinyMCE.getParentElement(inst.getFocusElement(), "td,th");
+ var trElm = tinyMCE.getParentElement(inst.getFocusElement(), "tr");
+ var tableElm = tinyMCE.getParentElement(inst.getFocusElement(), "table");
+ var formObj = document.forms[0];
+
+ inst.execCommand('mceBeginUndoLevel');
+
+ switch (getSelectValue(formObj, 'action')) {
+ case "cell":
+ var celltype = getSelectValue(formObj, 'celltype');
+ var scope = getSelectValue(formObj, 'scope');
+
+ if (tinyMCE.getParam("accessibility_warnings")) {
+ if (celltype == "th" && scope == "")
+ var answer = confirm(tinyMCE.getLang('lang_table_missing_scope', '', true));
+ else
+ var answer = true;
+
+ if (!answer)
+ return;
+ }
+
+ updateCell(tdElm);
+ break;
+
+ case "row":
+ var cell = trElm.firstChild;
+
+ if (cell.nodeName != "TD" && cell.nodeName != "TH")
+ cell = nextCell(cell);
+
+ do {
+ cell = updateCell(cell, true);
+ } while ((cell = nextCell(cell)) != null);
+
+ break;
+
+ case "all":
+ var rows = tableElm.getElementsByTagName("tr");
+
+ for (var i=0; i<rows.length; i++) {
+ var cell = rows[i].firstChild;
+
+ if (cell.nodeName != "TD" && cell.nodeName != "TH")
+ cell = nextCell(cell);
+
+ do {
+ cell = updateCell(cell, true);
+ } while ((cell = nextCell(cell)) != null);
+ }
+
+ break;
+ }
+
+ tinyMCE.handleVisualAid(inst.getBody(), true, inst.visualAid, inst);
+ tinyMCE.triggerNodeChange();
+ inst.execCommand('mceEndUndoLevel');
+ tinyMCEPopup.close();
+}
+
+function nextCell(elm) {
+ while ((elm = elm.nextSibling) != null) {
+ if (elm.nodeName == "TD" || elm.nodeName == "TH")
+ return elm;
+ }
+
+ return null;
+}
+
+function updateCell(td, skip_id) {
+ var inst = tinyMCE.selectedInstance;
+ var formObj = document.forms[0];
+ var curCellType = td.nodeName.toLowerCase();
+ var celltype = getSelectValue(formObj, 'celltype');
+ var doc = inst.getDoc();
+
+ if (!skip_id)
+ td.setAttribute('id', formObj.id.value);
+
+ td.setAttribute('align', formObj.align.value);
+ td.setAttribute('vAlign', formObj.valign.value);
+ td.setAttribute('lang', formObj.lang.value);
+ td.setAttribute('dir', getSelectValue(formObj, 'dir'));
+ td.setAttribute('style', tinyMCE.serializeStyle(tinyMCE.parseStyle(formObj.style.value)));
+ td.setAttribute('scope', formObj.scope.value);
+ tinyMCE.setAttrib(td, 'class', getSelectValue(formObj, 'class'));
+
+ // Clear deprecated attributes
+ tinyMCE.setAttrib(td, 'width', '');
+ tinyMCE.setAttrib(td, 'height', '');
+ tinyMCE.setAttrib(td, 'bgColor', '');
+ tinyMCE.setAttrib(td, 'borderColor', '');
+ tinyMCE.setAttrib(td, 'background', '');
+
+ // Set styles
+ td.style.width = getCSSSize(formObj.width.value);
+ td.style.height = getCSSSize(formObj.height.value);
+ if (formObj.bordercolor.value != "") {
+ td.style.borderColor = formObj.bordercolor.value;
+ td.style.borderStyle = td.style.borderStyle == "" ? "solid" : td.style.borderStyle;
+ td.style.borderWidth = td.style.borderWidth == "" ? "1px" : td.style.borderWidth;
+ } else
+ td.style.borderColor = '';
+
+ td.style.backgroundColor = formObj.bgcolor.value;
+
+ if (formObj.backgroundimage.value != "")
+ td.style.backgroundImage = "url('" + formObj.backgroundimage.value + "')";
+ else
+ td.style.backgroundImage = '';
+
+ if (curCellType != celltype) {
+ // changing to a different node type
+ var newCell = doc.createElement(celltype);
+
+ for (var c=0; c<td.childNodes.length; c++)
+ newCell.appendChild(td.childNodes[c].cloneNode(1));
+
+ for (var a=0; a<td.attributes.length; a++) {
+ var attr = td.attributes[a];
+ newCell.setAttribute(attr.name, attr.value);
+ }
+
+ td.parentNode.replaceChild(newCell, td);
+ td = newCell;
+ }
+
+ return td;
+}
+
+function changedBackgroundImage() {
+ var formObj = document.forms[0];
+ var st = tinyMCE.parseStyle(formObj.style.value);
+
+ st['background-image'] = "url('" + formObj.backgroundimage.value + "')";
+
+ formObj.style.value = tinyMCE.serializeStyle(st);
+}
+
+function changedSize() {
+ var formObj = document.forms[0];
+ var st = tinyMCE.parseStyle(formObj.style.value);
+
+ var width = formObj.width.value;
+ if (width != "")
+ st['width'] = getCSSSize(width);
+ else
+ st['width'] = "";
+
+ var height = formObj.height.value;
+ if (height != "")
+ st['height'] = getCSSSize(height);
+ else
+ st['height'] = "";
+
+ formObj.style.value = tinyMCE.serializeStyle(st);
+}
+
+function changedColor() {
+ var formObj = document.forms[0];
+ var st = tinyMCE.parseStyle(formObj.style.value);
+
+ st['background-color'] = formObj.bgcolor.value;
+ st['border-color'] = formObj.bordercolor.value;
+
+ formObj.style.value = tinyMCE.serializeStyle(st);
+}
+
+function changedStyle() {
+ var formObj = document.forms[0];
+ var st = tinyMCE.parseStyle(formObj.style.value);
+
+ if (st['background-image'])
+ formObj.backgroundimage.value = st['background-image'].replace(new RegExp("url\\('?([^']*)'?\\)", 'gi'), "$1");
+ else
+ formObj.backgroundimage.value = '';
+
+ if (st['width'])
+ formObj.width.value = trimSize(st['width']);
+
+ if (st['height'])
+ formObj.height.value = trimSize(st['height']);
+
+ if (st['background-color']) {
+ formObj.bgcolor.value = st['background-color'];
+ updateColor('bgcolor_pick','bgcolor');
+ }
+
+ if (st['border-color']) {
+ formObj.bordercolor.value = st['border-color'];
+ updateColor('bordercolor_pick','bordercolor');
+ }
+}
diff --git a/program/js/tiny_mce/plugins/table/jscripts/merge_cells.js b/program/js/tiny_mce/plugins/table/jscripts/merge_cells.js
new file mode 100644
index 000000000..51a274962
--- /dev/null
+++ b/program/js/tiny_mce/plugins/table/jscripts/merge_cells.js
@@ -0,0 +1,19 @@
+function init() {
+ tinyMCEPopup.resizeToInnerSize();
+
+ var formObj = document.forms[0];
+
+ formObj.numcols.value = tinyMCE.getWindowArg('numcols', 1);
+ formObj.numrows.value = tinyMCE.getWindowArg('numrows', 1);
+}
+
+function mergeCells() {
+ var args = new Array();
+ var formObj = document.forms[0];
+
+ args["numcols"] = formObj.numcols.value;
+ args["numrows"] = formObj.numrows.value;
+
+ tinyMCEPopup.execCommand("mceTableMergeCells", false, args);
+ tinyMCEPopup.close();
+}
diff --git a/program/js/tiny_mce/plugins/table/jscripts/row.js b/program/js/tiny_mce/plugins/table/jscripts/row.js
new file mode 100644
index 000000000..395ddf028
--- /dev/null
+++ b/program/js/tiny_mce/plugins/table/jscripts/row.js
@@ -0,0 +1,200 @@
+function init() {
+ tinyMCEPopup.resizeToInnerSize();
+
+ document.getElementById('backgroundimagebrowsercontainer').innerHTML = getBrowserHTML('backgroundimagebrowser','backgroundimage','image','table');
+ document.getElementById('bgcolor_pickcontainer').innerHTML = getColorPickerHTML('bgcolor_pick','bgcolor');
+
+ var inst = tinyMCE.selectedInstance;
+ var trElm = tinyMCE.getParentElement(inst.getFocusElement(), "tr");
+ var formObj = document.forms[0];
+ var st = tinyMCE.parseStyle(tinyMCE.getAttrib(trElm, "style"));
+
+ // Get table row data
+ var rowtype = trElm.parentNode.nodeName.toLowerCase();
+ var align = tinyMCE.getAttrib(trElm, 'align');
+ var valign = tinyMCE.getAttrib(trElm, 'valign');
+ var height = trimSize(getStyle(trElm, 'height', 'height'));
+ var className = tinyMCE.getVisualAidClass(tinyMCE.getAttrib(trElm, 'class'), false);
+ var bgcolor = convertRGBToHex(getStyle(trElm, 'bgcolor', 'backgroundColor'));
+ var backgroundimage = getStyle(trElm, 'background', 'backgroundImage').replace(new RegExp("url\\('?([^']*)'?\\)", 'gi'), "$1");;
+ var id = tinyMCE.getAttrib(trElm, 'id');
+ var lang = tinyMCE.getAttrib(trElm, 'lang');
+ var dir = tinyMCE.getAttrib(trElm, 'dir');
+
+ // Setup form
+ addClassesToList('class', 'table_row_styles');
+ formObj.bgcolor.value = bgcolor;
+ formObj.backgroundimage.value = backgroundimage;
+ formObj.height.value = height;
+ formObj.id.value = id;
+ formObj.lang.value = lang;
+ formObj.style.value = tinyMCE.serializeStyle(st);
+ selectByValue(formObj, 'align', align);
+ selectByValue(formObj, 'valign', valign);
+ selectByValue(formObj, 'class', className);
+ selectByValue(formObj, 'rowtype', rowtype);
+ selectByValue(formObj, 'dir', dir);
+
+ // Resize some elements
+ if (isVisible('backgroundimagebrowser'))
+ document.getElementById('backgroundimage').style.width = '180px';
+
+ updateColor('bgcolor_pick', 'bgcolor');
+}
+
+function updateAction() {
+ tinyMCEPopup.restoreSelection();
+
+ var inst = tinyMCE.selectedInstance;
+ var trElm = tinyMCE.getParentElement(inst.getFocusElement(), "tr");
+ var tableElm = tinyMCE.getParentElement(inst.getFocusElement(), "table");
+ var formObj = document.forms[0];
+ var action = getSelectValue(formObj, 'action');
+
+ inst.execCommand('mceBeginUndoLevel');
+
+ switch (action) {
+ case "row":
+ updateRow(trElm);
+ break;
+
+ case "all":
+ var rows = tableElm.getElementsByTagName("tr");
+
+ for (var i=0; i<rows.length; i++)
+ updateRow(rows[i], true);
+
+ break;
+
+ case "odd":
+ case "even":
+ var rows = tableElm.getElementsByTagName("tr");
+
+ for (var i=0; i<rows.length; i++) {
+ if ((i % 2 == 0 && action == "odd") || (i % 2 != 0 && action == "even"))
+ updateRow(rows[i], true, true);
+ }
+
+ break;
+ }
+
+ tinyMCE.handleVisualAid(inst.getBody(), true, inst.visualAid, inst);
+ tinyMCE.triggerNodeChange();
+ inst.execCommand('mceEndUndoLevel');
+ tinyMCEPopup.close();
+}
+
+function updateRow(tr_elm, skip_id, skip_parent) {
+ var inst = tinyMCE.selectedInstance;
+ var formObj = document.forms[0];
+ var curRowType = tr_elm.parentNode.nodeName.toLowerCase();
+ var rowtype = getSelectValue(formObj, 'rowtype');
+ var doc = inst.getDoc();
+
+ // Update row element
+ if (!skip_id)
+ tr_elm.setAttribute('id', formObj.id.value);
+
+ tr_elm.setAttribute('align', getSelectValue(formObj, 'align'));
+ tr_elm.setAttribute('vAlign', getSelectValue(formObj, 'valign'));
+ tr_elm.setAttribute('lang', formObj.lang.value);
+ tr_elm.setAttribute('dir', getSelectValue(formObj, 'dir'));
+ tr_elm.setAttribute('style', tinyMCE.serializeStyle(tinyMCE.parseStyle(formObj.style.value)));
+ tinyMCE.setAttrib(tr_elm, 'class', getSelectValue(formObj, 'class'));
+
+ // Clear deprecated attributes
+ tr_elm.setAttribute('background', '');
+ tr_elm.setAttribute('bgColor', '');
+ tr_elm.setAttribute('height', '');
+
+ // Set styles
+ tr_elm.style.height = getCSSSize(formObj.height.value);
+ tr_elm.style.backgroundColor = formObj.bgcolor.value;
+
+ if (formObj.backgroundimage.value != "")
+ tr_elm.style.backgroundImage = "url('" + formObj.backgroundimage.value + "')";
+ else
+ tr_elm.style.backgroundImage = '';
+
+ // Setup new rowtype
+ if (curRowType != rowtype && !skip_parent) {
+ // first, clone the node we are working on
+ var newRow = tr_elm.cloneNode(1);
+
+ // next, find the parent of its new destination (creating it if necessary)
+ var theTable = tinyMCE.getParentElement(tr_elm, "table");
+ var dest = rowtype;
+ var newParent = null;
+ for (var i = 0; i < theTable.childNodes.length; i++) {
+ if (theTable.childNodes[i].nodeName.toLowerCase() == dest)
+ newParent = theTable.childNodes[i];
+ }
+
+ if (newParent == null) {
+ newParent = doc.createElement(dest);
+
+ if (dest == "thead")
+ theTable.insertBefore(newParent, theTable.firstChild);
+ else
+ theTable.appendChild(newParent);
+ }
+
+ // append the row to the new parent
+ newParent.appendChild(newRow);
+
+ // remove the original
+ tr_elm.parentNode.removeChild(tr_elm);
+
+ // set tr_elm to the new node
+ tr_elm = newRow;
+ }
+}
+
+function changedBackgroundImage() {
+ var formObj = document.forms[0];
+ var st = tinyMCE.parseStyle(formObj.style.value);
+
+ st['background-image'] = "url('" + formObj.backgroundimage.value + "')";
+
+ formObj.style.value = tinyMCE.serializeStyle(st);
+}
+
+function changedStyle() {
+ var formObj = document.forms[0];
+ var st = tinyMCE.parseStyle(formObj.style.value);
+
+ if (st['background-image'])
+ formObj.backgroundimage.value = st['background-image'].replace(new RegExp("url\\('?([^']*)'?\\)", 'gi'), "$1");
+ else
+ formObj.backgroundimage.value = '';
+
+ if (st['height'])
+ formObj.height.value = trimSize(st['height']);
+
+ if (st['background-color']) {
+ formObj.bgcolor.value = st['background-color'];
+ updateColor('bgcolor_pick','bgcolor');
+ }
+}
+
+function changedSize() {
+ var formObj = document.forms[0];
+ var st = tinyMCE.parseStyle(formObj.style.value);
+
+ var height = formObj.height.value;
+ if (height != "")
+ st['height'] = getCSSSize(height);
+ else
+ st['height'] = "";
+
+ formObj.style.value = tinyMCE.serializeStyle(st);
+}
+
+function changedColor() {
+ var formObj = document.forms[0];
+ var st = tinyMCE.parseStyle(formObj.style.value);
+
+ st['background-color'] = formObj.bgcolor.value;
+
+ formObj.style.value = tinyMCE.serializeStyle(st);
+}
diff --git a/program/js/tiny_mce/plugins/table/jscripts/table.js b/program/js/tiny_mce/plugins/table/jscripts/table.js
new file mode 100644
index 000000000..02eaeee27
--- /dev/null
+++ b/program/js/tiny_mce/plugins/table/jscripts/table.js
@@ -0,0 +1,344 @@
+var action, orgTableWidth, orgTableHeight;
+
+function insertTable() {
+ var formObj = document.forms[0];
+ var inst = tinyMCE.selectedInstance;
+ var cols = 2, rows = 2, border = 0, cellpadding = -1, cellspacing = -1, align, width, height, className;
+ var html = '';
+ var elm = tinyMCE.tableElm;
+ var cellLimit, rowLimit, colLimit;
+
+ tinyMCEPopup.restoreSelection();
+
+ // Get form data
+ cols = formObj.elements['cols'].value;
+ rows = formObj.elements['rows'].value;
+ border = formObj.elements['border'].value != "" ? formObj.elements['border'].value : 0;
+ cellpadding = formObj.elements['cellpadding'].value != "" ? formObj.elements['cellpadding'].value : "";
+ cellspacing = formObj.elements['cellspacing'].value != "" ? formObj.elements['cellspacing'].value : "";
+ align = formObj.elements['align'].options[formObj.elements['align'].selectedIndex].value;
+ width = formObj.elements['width'].value;
+ height = formObj.elements['height'].value;
+ bordercolor = formObj.elements['bordercolor'].value;
+ bgcolor = formObj.elements['bgcolor'].value;
+ className = formObj.elements['class'].options[formObj.elements['class'].selectedIndex].value;
+ id = formObj.elements['id'].value;
+ summary = formObj.elements['summary'].value;
+ style = formObj.elements['style'].value;
+ dir = formObj.elements['dir'].value;
+ lang = formObj.elements['lang'].value;
+ background = formObj.elements['backgroundimage'].value;
+
+ cellLimit = tinyMCE.getParam('table_cell_limit', false);
+ rowLimit = tinyMCE.getParam('table_row_limit', false);
+ colLimit = tinyMCE.getParam('table_col_limit', false);
+
+ // Validate table size
+ if (colLimit && cols > colLimit) {
+ alert(tinyMCE.getLang('lang_table_col_limit', '', true, {cols : colLimit}));
+ return false;
+ } else if (rowLimit && rows > rowLimit) {
+ alert(tinyMCE.getLang('lang_table_row_limit', '', true, {rows : rowLimit}));
+ return false;
+ } else if (cellLimit && cols * rows > cellLimit) {
+ alert(tinyMCE.getLang('lang_table_cell_limit', '', true, {cells : cellLimit}));
+ return false;
+ }
+
+ // Update table
+ if (action == "update") {
+ inst.execCommand('mceBeginUndoLevel');
+
+ tinyMCE.setAttrib(elm, 'cellPadding', cellpadding, true);
+ tinyMCE.setAttrib(elm, 'cellSpacing', cellspacing, true);
+ tinyMCE.setAttrib(elm, 'border', border, true);
+ tinyMCE.setAttrib(elm, 'align', align);
+ tinyMCE.setAttrib(elm, 'class', className);
+ tinyMCE.setAttrib(elm, 'style', style);
+ tinyMCE.setAttrib(elm, 'id', id);
+ tinyMCE.setAttrib(elm, 'summary', summary);
+ tinyMCE.setAttrib(elm, 'dir', dir);
+ tinyMCE.setAttrib(elm, 'lang', lang);
+
+ // Not inline styles
+ if (!tinyMCE.getParam("inline_styles"))
+ tinyMCE.setAttrib(elm, 'width', width, true);
+
+ // Remove these since they are not valid XHTML
+ tinyMCE.setAttrib(elm, 'borderColor', '');
+ tinyMCE.setAttrib(elm, 'bgColor', '');
+ tinyMCE.setAttrib(elm, 'background', '');
+ tinyMCE.setAttrib(elm, 'height', '');
+
+ if (background != '')
+ elm.style.backgroundImage = "url('" + background + "')";
+ else
+ elm.style.backgroundImage = '';
+
+ if (tinyMCE.getParam("inline_styles"))
+ elm.style.borderWidth = border + "px";
+
+ if (tinyMCE.getParam("inline_styles")) {
+ if (width != '')
+ elm.style.width = getCSSSize(width);
+ }
+
+ if (bordercolor != "") {
+ elm.style.borderColor = bordercolor;
+ elm.style.borderStyle = elm.style.borderStyle == "" ? "solid" : elm.style.borderStyle;
+ elm.style.borderWidth = border == "" ? "1px" : border;
+ } else
+ elm.style.borderColor = '';
+
+ elm.style.backgroundColor = bgcolor;
+ elm.style.height = getCSSSize(height);
+
+ tinyMCE.handleVisualAid(tinyMCE.tableElm, false, inst.visualAid, inst);
+
+ // Fix for stange MSIE align bug
+ tinyMCE.tableElm.outerHTML = tinyMCE.tableElm.outerHTML;
+
+ tinyMCE.handleVisualAid(inst.getBody(), true, inst.visualAid, inst);
+ tinyMCE.triggerNodeChange();
+ inst.execCommand('mceEndUndoLevel');
+
+ // Repaint if dimensions changed
+ if (formObj.width.value != orgTableWidth || formObj.height.value != orgTableHeight)
+ inst.repaint();
+
+ tinyMCEPopup.close();
+ return true;
+ }
+
+ // Create new table
+ html += '<table';
+
+ html += makeAttrib('id', id);
+ html += makeAttrib('border', border);
+ html += makeAttrib('cellpadding', cellpadding);
+ html += makeAttrib('cellspacing', cellspacing);
+ html += makeAttrib('width', width);
+ //html += makeAttrib('height', height);
+ //html += makeAttrib('bordercolor', bordercolor);
+ //html += makeAttrib('bgcolor', bgcolor);
+ html += makeAttrib('align', align);
+ html += makeAttrib('class', tinyMCE.getVisualAidClass(className, border == 0));
+ html += makeAttrib('style', style);
+ html += makeAttrib('summary', summary);
+ html += makeAttrib('dir', dir);
+ html += makeAttrib('lang', lang);
+
+ html += '>';
+
+ for (var y=0; y<rows; y++) {
+ html += "<tr>";
+
+ for (var x=0; x<cols; x++)
+ html += '<td>&nbsp;</td>';
+
+ html += "</tr>";
+ }
+
+ html += "</table>";
+
+ inst.execCommand('mceBeginUndoLevel');
+ inst.execCommand('mceInsertContent', false, html);
+ tinyMCE.handleVisualAid(inst.getBody(), true, tinyMCE.settings['visual']);
+ inst.execCommand('mceEndUndoLevel');
+
+ tinyMCEPopup.close();
+}
+
+function makeAttrib(attrib, value) {
+ var formObj = document.forms[0];
+ var valueElm = formObj.elements[attrib];
+
+ if (typeof(value) == "undefined" || value == null) {
+ value = "";
+
+ if (valueElm)
+ value = valueElm.value;
+ }
+
+ if (value == "")
+ return "";
+
+ // XML encode it
+ value = value.replace(/&/g, '&amp;');
+ value = value.replace(/\"/g, '&quot;');
+ value = value.replace(/</g, '&lt;');
+ value = value.replace(/>/g, '&gt;');
+
+ return ' ' + attrib + '="' + value + '"';
+}
+
+function init() {
+ tinyMCEPopup.resizeToInnerSize();
+
+ document.getElementById('backgroundimagebrowsercontainer').innerHTML = getBrowserHTML('backgroundimagebrowser','backgroundimage','image','table');
+ document.getElementById('backgroundimagebrowsercontainer').innerHTML = getBrowserHTML('backgroundimagebrowser','backgroundimage','image','table');
+ document.getElementById('bordercolor_pickcontainer').innerHTML = getColorPickerHTML('bordercolor_pick','bordercolor');
+ document.getElementById('bgcolor_pickcontainer').innerHTML = getColorPickerHTML('bgcolor_pick','bgcolor');
+
+ var cols = 2, rows = 2, border = 0, cellpadding = "", cellspacing = "";
+ var align = "", width = "", height = "", bordercolor = "", bgcolor = "", className = "";
+ var id = "", summary = "", style = "", dir = "", lang = "", background = "", bgcolor = "", bordercolor = "";
+ var inst = tinyMCE.selectedInstance;
+ var formObj = document.forms[0];
+ var elm = tinyMCE.getParentElement(inst.getFocusElement(), "table");
+
+ tinyMCE.tableElm = elm;
+ action = tinyMCE.getWindowArg('action');
+ if (action == null)
+ action = tinyMCE.tableElm ? "update" : "insert";
+
+ if (tinyMCE.tableElm && action != "insert") {
+ var rowsAr = tinyMCE.tableElm.rows;
+ var cols = 0;
+ for (var i=0; i<rowsAr.length; i++)
+ if (rowsAr[i].cells.length > cols)
+ cols = rowsAr[i].cells.length;
+
+ cols = cols;
+ rows = rowsAr.length;
+
+ st = tinyMCE.parseStyle(tinyMCE.getAttrib(tinyMCE.tableElm, "style"));
+ border = trimSize(getStyle(elm, 'border', 'borderWidth'));
+ cellpadding = tinyMCE.getAttrib(tinyMCE.tableElm, 'cellpadding', "");
+ cellspacing = tinyMCE.getAttrib(tinyMCE.tableElm, 'cellspacing', "");
+ width = trimSize(getStyle(elm, 'width', 'width'));
+ height = trimSize(getStyle(elm, 'height', 'height'));
+ bordercolor = convertRGBToHex(getStyle(elm, 'bordercolor', 'borderLeftColor'));
+ bgcolor = convertRGBToHex(getStyle(elm, 'bgcolor', 'backgroundColor'));
+ align = tinyMCE.getAttrib(tinyMCE.tableElm, 'align', align);
+ className = tinyMCE.getVisualAidClass(tinyMCE.getAttrib(tinyMCE.tableElm, 'class'), false);
+ id = tinyMCE.getAttrib(tinyMCE.tableElm, 'id');
+ summary = tinyMCE.getAttrib(tinyMCE.tableElm, 'summary');
+ style = tinyMCE.serializeStyle(st);
+ dir = tinyMCE.getAttrib(tinyMCE.tableElm, 'dir');
+ lang = tinyMCE.getAttrib(tinyMCE.tableElm, 'lang');
+ background = getStyle(elm, 'background', 'backgroundImage').replace(new RegExp("url\\('?([^']*)'?\\)", 'gi'), "$1");
+
+ orgTableWidth = width;
+ orgTableHeight = height;
+
+ action = "update";
+ }
+
+ addClassesToList('class', "table_styles");
+
+ // Update form
+ selectByValue(formObj, 'align', align);
+ selectByValue(formObj, 'class', className);
+ formObj.cols.value = cols;
+ formObj.rows.value = rows;
+ formObj.border.value = border;
+ formObj.cellpadding.value = cellpadding;
+ formObj.cellspacing.value = cellspacing;
+ formObj.width.value = width;
+ formObj.height.value = height;
+ formObj.bordercolor.value = bordercolor;
+ formObj.bgcolor.value = bgcolor;
+ formObj.id.value = id;
+ formObj.summary.value = summary;
+ formObj.style.value = style;
+ formObj.dir.value = dir;
+ formObj.lang.value = lang;
+ formObj.backgroundimage.value = background;
+ formObj.insert.value = tinyMCE.getLang('lang_' + action, 'Insert', true);
+
+ updateColor('bordercolor_pick', 'bordercolor');
+ updateColor('bgcolor_pick', 'bgcolor');
+
+ // Resize some elements
+ if (isVisible('backgroundimagebrowser'))
+ document.getElementById('backgroundimage').style.width = '180px';
+
+ // Disable some fields in update mode
+ if (action == "update") {
+ formObj.cols.disabled = true;
+ formObj.rows.disabled = true;
+ }
+}
+
+function changedSize() {
+ var formObj = document.forms[0];
+ var st = tinyMCE.parseStyle(formObj.style.value);
+
+ var width = formObj.width.value;
+ if (width != "")
+ st['width'] = tinyMCE.getParam("inline_styles") ? getCSSSize(width) : "";
+ else
+ st['width'] = "";
+
+ var height = formObj.height.value;
+ if (height != "")
+ st['height'] = getCSSSize(height);
+ else
+ st['height'] = "";
+
+ formObj.style.value = tinyMCE.serializeStyle(st);
+}
+
+function changedBackgroundImage() {
+ var formObj = document.forms[0];
+ var st = tinyMCE.parseStyle(formObj.style.value);
+
+ st['background-image'] = "url('" + formObj.backgroundimage.value + "')";
+
+ formObj.style.value = tinyMCE.serializeStyle(st);
+}
+
+function changedBorder() {
+ var formObj = document.forms[0];
+ var st = tinyMCE.parseStyle(formObj.style.value);
+
+ // Update border width if the element has a color
+ if (formObj.border.value != "" && formObj.bordercolor.value != "")
+ st['border-width'] = formObj.border.value + "px";
+
+ formObj.style.value = tinyMCE.serializeStyle(st);
+}
+
+function changedColor() {
+ var formObj = document.forms[0];
+ var st = tinyMCE.parseStyle(formObj.style.value);
+
+ st['background-color'] = formObj.bgcolor.value;
+
+ if (formObj.bordercolor.value != "") {
+ st['border-color'] = formObj.bordercolor.value;
+
+ // Add border-width if it's missing
+ if (!st['border-width'])
+ st['border-width'] = formObj.border.value == "" ? "1px" : formObj.border.value + "px";
+ }
+
+ formObj.style.value = tinyMCE.serializeStyle(st);
+}
+
+function changedStyle() {
+ var formObj = document.forms[0];
+ var st = tinyMCE.parseStyle(formObj.style.value);
+
+ if (st['background-image'])
+ formObj.backgroundimage.value = st['background-image'].replace(new RegExp("url\\('?([^']*)'?\\)", 'gi'), "$1");
+ else
+ formObj.backgroundimage.value = '';
+
+ if (st['width'])
+ formObj.width.value = trimSize(st['width']);
+
+ if (st['height'])
+ formObj.height.value = trimSize(st['height']);
+
+ if (st['background-color']) {
+ formObj.bgcolor.value = st['background-color'];
+ updateColor('bgcolor_pick','bgcolor');
+ }
+
+ if (st['border-color']) {
+ formObj.bordercolor.value = st['border-color'];
+ updateColor('bordercolor_pick','bordercolor');
+ }
+}