📄 table-operations.js
字号:
/**************************************************************** Copyright notice** (c) 2002 interactivetools.com, inc. Authored by Mihai Bazon, sponsored by http://www.bloki.com.* (c) 2005 Xinha, http://xinha.gogo.co.nz/ for the original toggle borders function.* (c) 2004, 2005, 2006 Stanislas Rolland <stanislas.rolland(arobas)fructifor.ca>* All rights reserved** This script is part of the TYPO3 project. The TYPO3 project is* free software; you can redistribute it and/or modify* it under the terms of the GNU General Public License as published by* the Free Software Foundation; either version 2 of the License, or* (at your option) any later version.** The GNU General Public License can be found at* http://www.gnu.org/copyleft/gpl.html.* A copy is found in the textfile GPL.txt and important notices to the license* from the author is found in LICENSE.txt distributed with these scripts.*** This script is distributed in the hope that it will be useful,* but WITHOUT ANY WARRANTY; without even the implied warranty of* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the* GNU General Public License for more details.** This script is a modified version of a script published under the htmlArea License.* A copy of the htmlArea License may be found in the textfile HTMLAREA_LICENSE.txt.** This copyright notice MUST APPEAR in all copies of the script!***************************************************************//* * Table Operations Plugin for TYPO3 htmlArea RTE * * TYPO3 CVS ID: $Id: table-operations.js 1676 2006-08-15 04:51:33Z stanrolland $ *//* * Initialize the plugin and register its buttons */TableOperations = function(editor) { this.editor = editor; var cfg = editor.config; var bl = TableOperations.btnList; var actionHandlerFunctRef = TableOperations.actionHandler(this); var hideToggleBorders = cfg.hideTableOperationsInToolbar && !(cfg.buttons["toggleborders"] && cfg.buttons["toggleborders"]["keepInToolbar"]); for(var i=0;i < bl.length;++i) { var btn = bl[i]; var id = "TO-" + btn[0]; cfg.registerButton(id, TableOperations_langArray[id], editor.imgURL(btn[0] + ".gif", "TableOperations"), false, actionHandlerFunctRef, btn[1], ((id == "TO-toggle-borders") ? hideToggleBorders : cfg.hideTableOperationsInToolbar)); }};TableOperations.actionHandler = function(instance) { return (function(editor,id) { instance.buttonPress(editor,id); });};/* * Set the language file for the plugin */TableOperations.I18N = TableOperations_langArray;/* * The information about the plugin */TableOperations._pluginInfo = { name : "TableOperations", version : "3.6", developer : "Mihai Bazon & Stanislas Rolland", developer_url : "http://www.fructifor.ca/", c_owner : "Mihai Bazon & Stanislas Rolland", sponsor : "Zapatec Inc. & Fructifor Inc.", sponsor_url : "http://www.fructifor.ca/", license : "GPL"};/* * The list of buttons added by this plugin */TableOperations.btnList = [ ["toggle-borders", null], ["table-prop", "table"], ["row-prop", "tr"], ["row-insert-above", "tr"], ["row-insert-under", "tr"], ["row-delete", "tr"], ["row-split", "td,th[rowSpan!=1]"], ["col-insert-before", "td,th"], ["col-insert-after", "td,th"], ["col-delete", "td,th"], ["col-split", "td,th[colSpan!=1]"], ["cell-prop", "td,th"], ["cell-insert-before", "td,th"], ["cell-insert-after", "td,th"], ["cell-delete", "td,th"], ["cell-merge", "tr"], ["cell-split", "td,th[colSpan!=1,rowSpan!=1]"] ];/************************ * UTILITIES ************************//* * Retrieve the closest element having the specified tagName in the list of * ancestors of the current selection/caret. */TableOperations.prototype.getClosest = function(tagName) { var editor = this.editor; var ancestors = editor.getAllAncestors(); var ret = null; tagName = ("" + tagName).toLowerCase(); for (var i=0; i < ancestors.length; ++i) { var el = ancestors[i]; if (el.tagName.toLowerCase() == tagName) { ret = el; break; } } return ret;};/* * Open the table properties dialog. */TableOperations.prototype.dialogTableProperties = function() { // retrieve existing values var table = this.getClosest("table"); var tablePropertiesInitFunctRef = TableOperations.tablePropertiesInit(table); var tablePropertiesUpdateFunctRef = TableOperations.tablePropertiesUpdate(table); var dialog = new PopupWin(this.editor, TableOperations.I18N["Table Properties"], tablePropertiesUpdateFunctRef, tablePropertiesInitFunctRef, 570, 600);};/* * Initialize the table properties dialog */TableOperations.tablePropertiesInit = function(table) { return (function (dialog) { var doc = dialog.doc; var content = dialog.content; var i18n = TableOperations.I18N; TableOperations.buildTitle(doc, i18n, content, "Table Properties"); TableOperations.buildDescriptionFieldset(doc, table, i18n, content); var obj = dialog.editor.config.customSelects["DynamicCSS-class"]; if (obj && obj.loaded) TableOperations.buildStylingFieldset(doc, table, i18n, content, obj.cssArray); if (!dialog.editor.config.disableLayoutFieldsetInTableOperations) TableOperations.buildLayoutFieldset(doc, table, i18n, content); if (!dialog.editor.config.disableAlignmentFieldsetInTableOperations) TableOperations.buildAlignmentFieldset(doc, table, i18n, content, "floating"); if (!dialog.editor.config.disableSpacingFieldsetInTableOperations) TableOperations.buildSpacingFieldset(doc, table, i18n, content); if (!dialog.editor.config.disableBordersFieldsetInTableOperations) TableOperations.buildBordersFieldset(dialog.dialogWindow, doc, dialog.editor, table, i18n, content); if (!dialog.editor.config.disableColorFieldsetInTableOperations) TableOperations.buildColorsFieldset(dialog.dialogWindow, doc, dialog.editor, table, i18n, content); dialog.modal = true; dialog.addButtons("ok", "cancel"); dialog.showAtElement(); });};/* * Update the table properties and close the dialog */TableOperations.tablePropertiesUpdate = function(table) { return (function (dialog,params) { dialog.editor.focusEditor(); TableOperations.processStyle(params, table); table.removeAttribute("border"); for (var i in params) { var val = params[i]; switch (i) { case "f_caption": if (/\S/.test(val)) { // contains non white-space characters var caption = table.getElementsByTagName("caption")[0]; if (!caption) { caption = dialog.editor._doc.createElement("caption"); table.insertBefore(caption, table.firstChild); } caption.innerHTML = val; } else { // search for caption and delete it if found var caption = table.getElementsByTagName("caption")[0]; if (caption) caption.parentNode.removeChild(caption); } break; case "f_summary": table.summary = val; break; case "f_width": table.style.width = ("" + val) + params.f_unit; break; case "f_align": table.align = val; break; case "f_spacing": table.cellSpacing = val; break; case "f_padding": table.cellPadding = val; break; case "f_frames": table.frame = (val != "not set") ? val : ""; break; case "f_rules": if (val != "not set") table.rules = val; else table.removeAttribute("rules"); break; case "f_class": case "f_class_tbody": case "f_class_thead": case "f_class_tfoot": var tpart = table; if (i.length > 7) tpart = table.getElementsByTagName(i.substring(8,13))[0]; var cls = tpart.className.trim().split(" "); for (var j = cls.length;j > 0;) { if (!HTMLArea.reservedClassNames.test(cls[--j])) HTMLArea._removeClass(tpart,cls[j]); } if (val != 'none') HTMLArea._addClass(tpart,val); break; } } dialog.editor.focusEditor(); dialog.editor.updateToolbar(); });};/* * Open the row/cell properties dialog. * This function requires the file PopupWin to be loaded. */TableOperations.prototype.dialogRowCellProperties = function(cell) { // retrieve existing values if (cell) { var element = this.getClosest("td"); if (!element) var element = this.getClosest("th"); } else { var element = this.getClosest("tr"); } if(element) { var rowCellPropertiesInitFunctRef = TableOperations.rowCellPropertiesInit(element, cell); var rowCellPropertiesUpdateFunctRef = TableOperations.rowCellPropertiesUpdate(element); var dialog = new PopupWin(this.editor, TableOperations.I18N[cell ? "Cell Properties" : "Row Properties"], rowCellPropertiesUpdateFunctRef, rowCellPropertiesInitFunctRef, 700, 425); }};/* * Initialize the row/cell properties dialog */TableOperations.rowCellPropertiesInit = function(element,cell) { return (function (dialog) { var doc = dialog.doc; var content = dialog.content; var i18n = TableOperations.I18N; TableOperations.buildTitle(doc, i18n, content, (cell ? "Cell Properties" : "Row Properties")); if (cell) TableOperations.buildCellTypeFieldset(dialog.dialogWindow, doc, dialog.editor, element, i18n, content); else TableOperations.buildRowGroupFieldset(dialog.dialogWindow, doc, dialog.editor, element, i18n, content); var obj = dialog.editor.config.customSelects["DynamicCSS-class"]; if (obj && obj.loaded) TableOperations.buildStylingFieldset(doc, element, i18n, content, obj.cssArray); else TableOperations.insertSpace(doc, content); if (!dialog.editor.config.disableLayoutFieldsetInTableOperations) TableOperations.buildLayoutFieldset(doc, element, i18n, content, "floating"); if (!dialog.editor.config.disableAlignmentFieldsetInTableOperations) TableOperations.buildAlignmentFieldset(doc, element, i18n, content); if (!dialog.editor.config.disableBordersFieldsetInTableOperations) TableOperations.buildBordersFieldset(dialog.dialogWindow, doc, dialog.editor, element, i18n, content); if (!dialog.editor.config.disableColorFieldsetInTableOperations) TableOperations.buildColorsFieldset(dialog.dialogWindow, doc, dialog.editor, element, i18n, content); dialog.modal = true; dialog.addButtons("ok", "cancel"); dialog.showAtElement(); });};/* * Update the row/cell properties and close the dialog */TableOperations.rowCellPropertiesUpdate = function(element) { return (function (dialog,params) { dialog.editor.focusEditor(); TableOperations.processStyle(params, element); var convertCellType = false; for (var i in params) { var val = params[i]; switch (i) { case "f_scope": if (val != "not set") element.scope = val; else element.removeAttribute('scope'); break; case "f_cell_type": // Set all cell attributes before cloning it with a new tag if (val != element.tagName.toLowerCase()) { var newCellType = val; convertCellType = true; } break; case "f_rowgroup": var section = element.parentNode; var tagName = section.tagName.toLowerCase(); if (val != tagName) { var table = section.parentNode; var newSection = table.getElementsByTagName(val)[0]; if (!newSection) var newSection = table.insertBefore(dialog.editor._doc.createElement(val), table.getElementsByTagName("tbody")[0]); if (tagName == "thead" && val == "tbody") var newElement = newSection.insertBefore(element, newSection.firstChild); else var newElement = newSection.appendChild(element); if (!section.hasChildNodes()) table.removeChild(section); } break; case "f_char": element.ch = val; break; case "f_class": var cls = element.className.trim().split(" "); for (var j = cls.length;j > 0;) { if (!HTMLArea.reservedClassNames.test(cls[--j])) HTMLArea._removeClass(element,cls[j]); } if (val != 'none') HTMLArea._addClass(element,val); break; } } if (convertCellType) { var newCell = dialog.editor._doc.createElement(newCellType), p = element.parentNode, a, attrName, name; var attrs = element.attributes; for (var i = attrs.length; --i >= 0 ;) { a = attrs.item(i); attrName = a.nodeName; name = attrName.toLowerCase(); // IE5.5 reports wrong values. For this reason we extract the values directly from the root node. if (typeof(element[attrName]) != "undefined" && name != "style" && !/^on/.test(name)) { if (element[attrName]) newCell.setAttribute(attrName, element[attrName]); } else { if (a.nodeValue) newCell.setAttribute(attrName, a.nodeValue); } } // In IE, the above fails to update the classname and style attributes. if (HTMLArea.is_ie) { if (element.style.cssText) newCell.style.cssText = element.style.cssText; if (element.className) { newCell.setAttribute("className", element.className);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -