📄 table-operations.js
字号:
}; function splitRow(td) { var n = parseInt("" + td.rowSpan); var nc = parseInt("" + td.colSpan); td.rowSpan = 1; tr = td.parentNode; var itr = tr.rowIndex; var trs = tr.parentNode.rows; var index = td.cellIndex; while (--n > 0) { tr = trs[++itr]; var otd = editor._doc.createElement("td"); otd.colSpan = td.colSpan; otd.innerHTML = mozbr; tr.insertBefore(otd, tr.cells[index]); } editor.forceRedraw(); editor.updateToolbar(); }; function splitCol(td) { var nc = parseInt("" + td.colSpan); td.colSpan = 1; tr = td.parentNode; var ref = td.nextSibling; while (--nc > 0) { var otd = editor._doc.createElement("td"); otd.rowSpan = td.rowSpan; otd.innerHTML = mozbr; tr.insertBefore(otd, ref); } editor.forceRedraw(); editor.updateToolbar(); }; function splitCell(td) { var nc = parseInt("" + td.colSpan); splitCol(td); var items = td.parentNode.cells; var index = td.cellIndex; while (nc-- > 0) { splitRow(items[index++]); } }; function selectNextNode(el) { var node = el.nextSibling; while (node && node.nodeType != 1) { node = node.nextSibling; } if (!node) { node = el.previousSibling; while (node && node.nodeType != 1) { node = node.previousSibling; } } if (!node) { node = el.parentNode; } editor.selectNodeContents(node); }; switch (button_id) { // ROWS case "TO-row-insert-above": case "TO-row-insert-under": var tr = this.getClosest("tr"); if (!tr) { break; } var otr = tr.cloneNode(true); clearRow(otr); tr.parentNode.insertBefore(otr, /under/.test(button_id) ? tr.nextSibling : tr); editor.forceRedraw(); editor.focusEditor(); break; case "TO-row-delete": var tr = this.getClosest("tr"); if (!tr) { break; } var par = tr.parentNode; if (par.rows.length == 1) { alert(i18n["not-del-last-row"]); break; } // set the caret first to a position that doesn't // disappear. selectNextNode(tr); par.removeChild(tr); editor.forceRedraw(); editor.focusEditor(); editor.updateToolbar(); break; case "TO-row-split": var td = this.getClosest("td"); if (!td) { break; } splitRow(td); break; // COLUMNS case "TO-col-insert-before": case "TO-col-insert-after": var td = this.getClosest("td"); if (!td) { break; } var rows = td.parentNode.parentNode.rows; var index = td.cellIndex; for (var i = rows.length; --i >= 0;) { /* var tr = rows; var otd = tr.insertCell(index + (/after/.test(button_id) ? 1 : 0)); otd.innerHTML = mozbr; */ var tr = rows[i]; var ref = tr.cells[index + (/after/.test(button_id) ? 1 : 0)]; var otd = editor._doc.createElement("td"); otd.innerHTML = mozbr; tr.insertBefore(otd, ref); } editor.focusEditor(); break; case "TO-col-split": var td = this.getClosest("td"); if (!td) { break; } splitCol(td); break; case "TO-col-delete": var td = this.getClosest("td"); if (!td) { break; } var index = td.cellIndex; if (td.parentNode.cells.length == 1) { alert(i18n["not-del-last-col"]); break; } // set the caret first to a position that doesn't disappear selectNextNode(td); var rows = td.parentNode.parentNode.rows; for (var i = rows.length; --i >= 0;) { var tr = rows[i]; tr.removeChild(tr.cells[index]); } editor.forceRedraw(); editor.focusEditor(); editor.updateToolbar(); break; // CELLS case "TO-cell-split": var td = this.getClosest("td"); if (!td) { break; } splitCell(td); break; case "TO-cell-insert-before": case "TO-cell-insert-after": var td = this.getClosest("td"); if (!td) { break; } var tr = td.parentNode; var otd = editor._doc.createElement("td"); otd.innerHTML = mozbr; tr.insertBefore(otd, /after/.test(button_id) ? td.nextSibling : td); editor.forceRedraw(); editor.focusEditor(); break; case "TO-cell-delete": var td = this.getClosest("td"); if (!td) { break; } if (td.parentNode.cells.length == 1) { alert(i18n["not-del-last-cell"]); break; } // set the caret first to a position that doesn't disappear selectNextNode(td); td.parentNode.removeChild(td); editor.forceRedraw(); editor.updateToolbar(); break; case "TO-cell-merge": // !! FIXME: Mozilla specific !! var sel = editor._getSelection(); var range, i = 0; var rows = []; var row = null; var cells = null; if (!HTMLArea.is_ie) { try { while (range = sel.getRangeAt(i++)) { var td = range.startContainer.childNodes[range.startOffset]; if (td.parentNode != row) { row = td.parentNode; (cells) && rows.push(cells); cells = []; } cells.push(td); } } catch(e) {/* finished walking through selection */} rows.push(cells); } else { // Internet Explorer "browser" var td = this.getClosest("td"); if (!td) { alert(i18n["Please click into some cell"]); break; } var tr = td.parentElement; var no_cols = prompt(i18n["How many columns would you like to merge?"], 2); if (!no_cols) { // cancelled break; } var no_rows = prompt(i18n["How many rows would you like to merge?"], 2); if (!no_rows) { // cancelled break; } var cell_index = td.cellIndex; while (no_rows-- > 0) { td = tr.cells[cell_index]; cells = [td]; for (var i = 1; i < no_cols; ++i) { td = td.nextSibling; if (!td) { break; } cells.push(td); } rows.push(cells); tr = tr.nextSibling; if (!tr) { break; } } } var HTML = ""; for (i = 0; i < rows.length; ++i) { // i && (HTML += "<br />"); var cells = rows[i]; for (var j = 0; j < cells.length; ++j) { // j && (HTML += " "); var cell = cells[j]; HTML += cell.innerHTML; (i || j) && (cell.parentNode.removeChild(cell)); } } var td = rows[0][0]; td.innerHTML = HTML; td.rowSpan = rows.length; td.colSpan = rows[0].length; editor.selectNodeContents(td); editor.forceRedraw(); editor.focusEditor(); break; // PROPERTIES case "TO-table-prop": this.dialogTableProperties(); break; case "TO-row-prop": this.dialogRowCellProperties(false); break; case "TO-cell-prop": this.dialogRowCellProperties(true); break; default: alert("Button [" + button_id + "] not yet implemented"); }};// the list of buttons added by this pluginTableOperations.btnList = [ // table properties button ["table-prop", "table"], null, // separator // ROWS ["row-prop", "tr"], ["row-insert-above", "tr"], ["row-insert-under", "tr"], ["row-delete", "tr"], ["row-split", "td[rowSpan!=1]"], null, // COLS ["col-insert-before", "td"], ["col-insert-after", "td"], ["col-delete", "td"], ["col-split", "td[colSpan!=1]"], null, // CELLS ["cell-prop", "td"], ["cell-insert-before", "td"], ["cell-insert-after", "td"], ["cell-delete", "td"], ["cell-merge", "tr"], ["cell-split", "td[colSpan!=1,rowSpan!=1]"] ];//// GENERIC CODE [style of any element; this should be moved into a separate//// file as it'll be very useful]//// BEGIN GENERIC CODE -----------------------------------------------------TableOperations.getLength = function(value) { var len = parseInt(value); if (isNaN(len)) { len = ""; } return len;};// Applies the style found in "params" to the given element.TableOperations.processStyle = function(params, element) { var style = element.style; for (var i in params) { var val = params[i]; switch (i) { case "f_st_backgroundColor": style.backgroundColor = val; break; case "f_st_color": style.color = val; break; case "f_st_backgroundImage": if (/\S/.test(val)) { style.backgroundImage = "url(" + val + ")"; } else { style.backgroundImage = "none"; } break; case "f_st_borderWidth": style.borderWidth = val; break; case "f_st_borderStyle": style.borderStyle = val; break; case "f_st_borderColor": style.borderColor = val; break; case "f_st_borderCollapse": style.borderCollapse = val ? "collapse" : ""; break; case "f_st_width": if (/\S/.test(val)) { style.width = val + params["f_st_widthUnit"]; } else { style.width = ""; } break; case "f_st_height": if (/\S/.test(val)) { style.height = val + params["f_st_heightUnit"]; } else { style.height = ""; } break; case "f_st_textAlign": if (val == "char") { var ch = params["f_st_textAlignChar"]; if (ch == '"') { ch = '\\"'; } style.textAlign = '"' + ch + '"'; } else { style.textAlign = val; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -