v1.0
只读模式 group, 分享 评论更多问题 博客标签总是存在一个
This commit is contained in:
27
public/tinymce/plugins/table/classes/CellSelection.js
Normal file → Executable file
27
public/tinymce/plugins/table/classes/CellSelection.js
Normal file → Executable file
@ -21,13 +21,13 @@ define("tinymce/tableplugin/CellSelection", [
|
||||
"tinymce/util/Tools"
|
||||
], function(TableGrid, TreeWalker, Tools) {
|
||||
return function(editor) {
|
||||
var dom = editor.dom, tableGrid, startCell, startTable, hasCellSelection = true;
|
||||
var dom = editor.dom, tableGrid, startCell, startTable, hasCellSelection = true, resizing;
|
||||
|
||||
function clear() {
|
||||
function clear(force) {
|
||||
// Restore selection possibilities
|
||||
editor.getBody().style.webkitUserSelect = '';
|
||||
|
||||
if (hasCellSelection) {
|
||||
if (force || hasCellSelection) {
|
||||
editor.dom.removeClass(
|
||||
editor.dom.select('td.mce-item-selected,th.mce-item-selected'),
|
||||
'mce-item-selected'
|
||||
@ -40,6 +40,10 @@ define("tinymce/tableplugin/CellSelection", [
|
||||
function cellSelectionHandler(e) {
|
||||
var sel, table, target = e.target;
|
||||
|
||||
if (resizing) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (startCell && (tableGrid || target != startCell) && (target.nodeName == 'TD' || target.nodeName == 'TH')) {
|
||||
table = dom.getParent(target, 'table');
|
||||
if (table == startTable) {
|
||||
@ -73,7 +77,7 @@ define("tinymce/tableplugin/CellSelection", [
|
||||
|
||||
// Add cell selection logic
|
||||
editor.on('MouseDown', function(e) {
|
||||
if (e.button != 2) {
|
||||
if (e.button != 2 && !resizing) {
|
||||
clear();
|
||||
|
||||
startCell = dom.getParent(e.target, 'td,th');
|
||||
@ -81,14 +85,14 @@ define("tinymce/tableplugin/CellSelection", [
|
||||
}
|
||||
});
|
||||
|
||||
dom.bind(editor.getDoc(), 'mouseover', cellSelectionHandler);
|
||||
editor.on('mouseover', cellSelectionHandler);
|
||||
|
||||
editor.on('remove', function() {
|
||||
dom.unbind(editor.getDoc(), 'mouseover', cellSelectionHandler);
|
||||
});
|
||||
|
||||
editor.on('MouseUp', function() {
|
||||
var rng, sel = editor.selection, selectedCells, walker, node, lastNode, endNode;
|
||||
var rng, sel = editor.selection, selectedCells, walker, node, lastNode;
|
||||
|
||||
function setPoint(node, start) {
|
||||
var walker = new TreeWalker(node, node);
|
||||
@ -129,7 +133,6 @@ define("tinymce/tableplugin/CellSelection", [
|
||||
if (selectedCells.length > 0) {
|
||||
rng = dom.createRng();
|
||||
node = selectedCells[0];
|
||||
endNode = selectedCells[selectedCells.length - 1];
|
||||
rng.setStartBefore(node);
|
||||
rng.setEndAfter(node);
|
||||
|
||||
@ -156,8 +159,14 @@ define("tinymce/tableplugin/CellSelection", [
|
||||
}
|
||||
});
|
||||
|
||||
editor.on('KeyUp', function() {
|
||||
clear();
|
||||
editor.on('KeyUp Drop SetContent', function(e) {
|
||||
clear(e.type == 'setcontent');
|
||||
startCell = tableGrid = startTable = null;
|
||||
resizing = false;
|
||||
});
|
||||
|
||||
editor.on('ObjectResizeStart ObjectResized', function(e) {
|
||||
resizing = e.type != 'objectresized';
|
||||
});
|
||||
|
||||
return {
|
||||
|
824
public/tinymce/plugins/table/classes/Dialogs.js
Executable file
824
public/tinymce/plugins/table/classes/Dialogs.js
Executable file
@ -0,0 +1,824 @@
|
||||
/**
|
||||
* Dialogs.js
|
||||
*
|
||||
* Copyright, Moxiecode Systems AB
|
||||
* Released under LGPL License.
|
||||
*
|
||||
* License: http://www.tinymce.com/license
|
||||
* Contributing: http://www.tinymce.com/contributing
|
||||
*/
|
||||
|
||||
/*eslint dot-notation:0*/
|
||||
|
||||
/**
|
||||
* ...
|
||||
*
|
||||
* @class tinymce.tableplugin.Dialogs
|
||||
* @private
|
||||
*/
|
||||
define("tinymce/tableplugin/Dialogs", [
|
||||
"tinymce/util/Tools",
|
||||
"tinymce/Env"
|
||||
], function(Tools, Env) {
|
||||
var each = Tools.each;
|
||||
|
||||
return function(editor) {
|
||||
var self = this;
|
||||
|
||||
function createColorPickAction() {
|
||||
var colorPickerCallback = editor.settings.color_picker_callback;
|
||||
|
||||
if (colorPickerCallback) {
|
||||
return function() {
|
||||
var self = this;
|
||||
|
||||
colorPickerCallback.call(
|
||||
editor,
|
||||
function(value) {
|
||||
self.value(value).fire('change');
|
||||
},
|
||||
self.value()
|
||||
);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function createStyleForm(dom) {
|
||||
return {
|
||||
title: 'Advanced',
|
||||
type: 'form',
|
||||
defaults: {
|
||||
onchange: function() {
|
||||
updateStyle(dom, this.parents().reverse()[0], this.name() == "style");
|
||||
}
|
||||
},
|
||||
items: [
|
||||
{
|
||||
label: 'Style',
|
||||
name: 'style',
|
||||
type: 'textbox'
|
||||
},
|
||||
|
||||
{
|
||||
type: 'form',
|
||||
padding: 0,
|
||||
formItemDefaults: {
|
||||
layout: 'grid',
|
||||
alignH: ['start', 'right']
|
||||
},
|
||||
defaults: {
|
||||
size: 7
|
||||
},
|
||||
items: [
|
||||
{
|
||||
label: 'Border color',
|
||||
type: 'colorbox',
|
||||
name: 'borderColor',
|
||||
onaction: createColorPickAction()
|
||||
},
|
||||
|
||||
{
|
||||
label: 'Background color',
|
||||
type: 'colorbox',
|
||||
name: 'backgroundColor',
|
||||
onaction: createColorPickAction()
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
||||
|
||||
function removePxSuffix(size) {
|
||||
return size ? size.replace(/px$/, '') : "";
|
||||
}
|
||||
|
||||
function addSizeSuffix(size) {
|
||||
if (/^[0-9]+$/.test(size)) {
|
||||
size += "px";
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
function unApplyAlign(elm) {
|
||||
each('left center right'.split(' '), function(name) {
|
||||
editor.formatter.remove('align' + name, {}, elm);
|
||||
});
|
||||
}
|
||||
|
||||
function unApplyVAlign(elm) {
|
||||
each('top middle bottom'.split(' '), function(name) {
|
||||
editor.formatter.remove('valign' + name, {}, elm);
|
||||
});
|
||||
}
|
||||
|
||||
function buildListItems(inputList, itemCallback, startItems) {
|
||||
function appendItems(values, output) {
|
||||
output = output || [];
|
||||
|
||||
Tools.each(values, function(item) {
|
||||
var menuItem = {text: item.text || item.title};
|
||||
|
||||
if (item.menu) {
|
||||
menuItem.menu = appendItems(item.menu);
|
||||
} else {
|
||||
menuItem.value = item.value;
|
||||
|
||||
if (itemCallback) {
|
||||
itemCallback(menuItem);
|
||||
}
|
||||
}
|
||||
|
||||
output.push(menuItem);
|
||||
});
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
return appendItems(inputList, startItems || []);
|
||||
}
|
||||
|
||||
function updateStyle(dom, win, isStyleCtrl) {
|
||||
var data = win.toJSON();
|
||||
var css = dom.parseStyle(data.style);
|
||||
|
||||
if (isStyleCtrl) {
|
||||
win.find('#borderColor').value(css["border-color"] || '')[0].fire('change');
|
||||
win.find('#backgroundColor').value(css["background-color"] || '')[0].fire('change');
|
||||
} else {
|
||||
css["border-color"] = data.borderColor;
|
||||
css["background-color"] = data.backgroundColor;
|
||||
}
|
||||
|
||||
win.find('#style').value(dom.serializeStyle(dom.parseStyle(dom.serializeStyle(css))));
|
||||
}
|
||||
|
||||
function appendStylesToData(dom, data, elm) {
|
||||
var css = dom.parseStyle(dom.getAttrib(elm, 'style'));
|
||||
|
||||
if (css["border-color"]) {
|
||||
data.borderColor = css["border-color"];
|
||||
}
|
||||
|
||||
if (css["background-color"]) {
|
||||
data.backgroundColor = css["background-color"];
|
||||
}
|
||||
|
||||
data.style = dom.serializeStyle(css);
|
||||
}
|
||||
|
||||
function mergeStyles(dom, elm, styles) {
|
||||
var css = dom.parseStyle(dom.getAttrib(elm, 'style'));
|
||||
|
||||
each(styles, function(style) {
|
||||
css[style.name] = style.value;
|
||||
});
|
||||
|
||||
dom.setAttrib(elm, 'style', dom.serializeStyle(dom.parseStyle(dom.serializeStyle(css))));
|
||||
}
|
||||
|
||||
self.tableProps = function() {
|
||||
self.table(true);
|
||||
};
|
||||
|
||||
self.table = function(isProps) {
|
||||
var dom = editor.dom, tableElm, colsCtrl, rowsCtrl, classListCtrl, data = {}, generalTableForm, stylesToMerge;
|
||||
|
||||
function onSubmitTableForm() {
|
||||
|
||||
//Explore the layers of the table till we find the first layer of tds or ths
|
||||
function styleTDTH (elm, name, value) {
|
||||
if (elm.tagName === "TD" || elm.tagName === "TH") {
|
||||
dom.setStyle(elm, name, value);
|
||||
} else {
|
||||
if (elm.children) {
|
||||
for (var i = 0; i < elm.children.length; i++) {
|
||||
styleTDTH(elm.children[i], name, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var captionElm;
|
||||
|
||||
updateStyle(dom, this);
|
||||
data = Tools.extend(data, this.toJSON());
|
||||
|
||||
if (data["class"] === false) {
|
||||
delete data["class"];
|
||||
}
|
||||
|
||||
editor.undoManager.transact(function() {
|
||||
if (!tableElm) {
|
||||
tableElm = editor.plugins.table.insertTable(data.cols || 1, data.rows || 1);
|
||||
}
|
||||
|
||||
editor.dom.setAttribs(tableElm, {
|
||||
style: data.style,
|
||||
'class': data['class']
|
||||
});
|
||||
|
||||
if (editor.settings.table_style_by_css) {
|
||||
stylesToMerge = [];
|
||||
stylesToMerge.push({name: 'border', value: data.border});
|
||||
stylesToMerge.push({name: 'border-spacing', value: addSizeSuffix(data.cellspacing)});
|
||||
mergeStyles(dom, tableElm, stylesToMerge);
|
||||
dom.setAttribs(tableElm, {
|
||||
'data-mce-border-color': data.borderColor,
|
||||
'data-mce-cell-padding': data.cellpadding,
|
||||
'data-mce-border': data.border
|
||||
});
|
||||
if (tableElm.children) {
|
||||
for (var i = 0; i < tableElm.children.length; i++) {
|
||||
styleTDTH(tableElm.children[i], 'border', data.border);
|
||||
styleTDTH(tableElm.children[i], 'padding', addSizeSuffix(data.cellpadding));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
editor.dom.setAttribs(tableElm, {
|
||||
border: data.border,
|
||||
cellpadding: data.cellpadding,
|
||||
cellspacing: data.cellspacing
|
||||
});
|
||||
}
|
||||
|
||||
if (dom.getAttrib(tableElm, 'width') && !editor.settings.table_style_by_css) {
|
||||
dom.setAttrib(tableElm, 'width', removePxSuffix(data.width));
|
||||
} else {
|
||||
dom.setStyle(tableElm, 'width', addSizeSuffix(data.width));
|
||||
}
|
||||
|
||||
dom.setStyle(tableElm, 'height', addSizeSuffix(data.height));
|
||||
|
||||
// Toggle caption on/off
|
||||
captionElm = dom.select('caption', tableElm)[0];
|
||||
|
||||
if (captionElm && !data.caption) {
|
||||
dom.remove(captionElm);
|
||||
}
|
||||
|
||||
if (!captionElm && data.caption) {
|
||||
captionElm = dom.create('caption');
|
||||
captionElm.innerHTML = !Env.ie ? '<br data-mce-bogus="1"/>' : '\u00a0';
|
||||
tableElm.insertBefore(captionElm, tableElm.firstChild);
|
||||
}
|
||||
unApplyAlign(tableElm);
|
||||
if (data.align) {
|
||||
editor.formatter.apply('align' + data.align, {}, tableElm);
|
||||
}
|
||||
|
||||
editor.focus();
|
||||
editor.addVisual();
|
||||
});
|
||||
}
|
||||
|
||||
function getTDTHOverallStyle (elm, name) {
|
||||
var cells = editor.dom.select("td,th", elm), firstChildStyle;
|
||||
|
||||
function checkChildren(firstChildStyle, elms) {
|
||||
|
||||
for (var i = 0; i < elms.length; i++) {
|
||||
var currentStyle = dom.getStyle(elms[i], name);
|
||||
if (typeof firstChildStyle === "undefined") {
|
||||
firstChildStyle = currentStyle;
|
||||
}
|
||||
if (firstChildStyle != currentStyle) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
return firstChildStyle;
|
||||
|
||||
}
|
||||
|
||||
firstChildStyle = checkChildren(firstChildStyle, cells);
|
||||
|
||||
return firstChildStyle;
|
||||
}
|
||||
|
||||
if (isProps === true) {
|
||||
tableElm = dom.getParent(editor.selection.getStart(), 'table');
|
||||
|
||||
if (tableElm) {
|
||||
data = {
|
||||
width: removePxSuffix(dom.getStyle(tableElm, 'width') || dom.getAttrib(tableElm, 'width')),
|
||||
height: removePxSuffix(dom.getStyle(tableElm, 'height') || dom.getAttrib(tableElm, 'height')),
|
||||
cellspacing: removePxSuffix(dom.getStyle(tableElm, 'border-spacing') ||
|
||||
dom.getAttrib(tableElm, 'cellspacing')),
|
||||
cellpadding: dom.getAttrib(tableElm, 'data-mce-cell-padding') || dom.getAttrib(tableElm, 'cellpadding') ||
|
||||
getTDTHOverallStyle(tableElm, 'padding'),
|
||||
border: dom.getAttrib(tableElm, 'data-mce-border') || dom.getAttrib(tableElm, 'border') ||
|
||||
getTDTHOverallStyle(tableElm, 'border'),
|
||||
borderColor: dom.getAttrib(tableElm, 'data-mce-border-color'),
|
||||
caption: !!dom.select('caption', tableElm)[0],
|
||||
'class': dom.getAttrib(tableElm, 'class')
|
||||
};
|
||||
|
||||
each('left center right'.split(' '), function(name) {
|
||||
if (editor.formatter.matchNode(tableElm, 'align' + name)) {
|
||||
data.align = name;
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
colsCtrl = {label: 'Cols', name: 'cols'};
|
||||
rowsCtrl = {label: 'Rows', name: 'rows'};
|
||||
}
|
||||
|
||||
if (editor.settings.table_class_list) {
|
||||
if (data["class"]) {
|
||||
data["class"] = data["class"].replace(/\s*mce\-item\-table\s*/g, '');
|
||||
}
|
||||
|
||||
classListCtrl = {
|
||||
name: 'class',
|
||||
type: 'listbox',
|
||||
label: 'Class',
|
||||
values: buildListItems(
|
||||
editor.settings.table_class_list,
|
||||
function(item) {
|
||||
if (item.value) {
|
||||
item.textStyle = function() {
|
||||
return editor.formatter.getCssText({block: 'table', classes: [item.value]});
|
||||
};
|
||||
}
|
||||
}
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
generalTableForm = {
|
||||
type: 'form',
|
||||
layout: 'flex',
|
||||
direction: 'column',
|
||||
labelGapCalc: 'children',
|
||||
padding: 0,
|
||||
items: [
|
||||
{
|
||||
type: 'form',
|
||||
labelGapCalc: false,
|
||||
padding: 0,
|
||||
layout: 'grid',
|
||||
columns: 2,
|
||||
defaults: {
|
||||
type: 'textbox',
|
||||
maxWidth: 50
|
||||
},
|
||||
items: (editor.settings.table_appearance_options !== false) ? [
|
||||
colsCtrl,
|
||||
rowsCtrl,
|
||||
{label: 'Width', name: 'width'},
|
||||
{label: 'Height', name: 'height'},
|
||||
{label: 'Cell spacing', name: 'cellspacing'},
|
||||
{label: 'Cell padding', name: 'cellpadding'},
|
||||
{label: 'Border', name: 'border'},
|
||||
{label: 'Caption', name: 'caption', type: 'checkbox'}
|
||||
] : [
|
||||
colsCtrl,
|
||||
rowsCtrl,
|
||||
{label: 'Width', name: 'width'},
|
||||
{label: 'Height', name: 'height'}
|
||||
]
|
||||
},
|
||||
|
||||
{
|
||||
label: 'Alignment',
|
||||
name: 'align',
|
||||
type: 'listbox',
|
||||
text: 'None',
|
||||
values: [
|
||||
{text: 'None', value: ''},
|
||||
{text: 'Left', value: 'left'},
|
||||
{text: 'Center', value: 'center'},
|
||||
{text: 'Right', value: 'right'}
|
||||
]
|
||||
},
|
||||
|
||||
classListCtrl
|
||||
]
|
||||
};
|
||||
|
||||
if (editor.settings.table_advtab !== false) {
|
||||
appendStylesToData(dom, data, tableElm);
|
||||
|
||||
editor.windowManager.open({
|
||||
title: "Table properties",
|
||||
data: data,
|
||||
bodyType: 'tabpanel',
|
||||
body: [
|
||||
{
|
||||
title: 'General',
|
||||
type: 'form',
|
||||
items: generalTableForm
|
||||
},
|
||||
createStyleForm(dom)
|
||||
],
|
||||
|
||||
onsubmit: onSubmitTableForm
|
||||
});
|
||||
} else {
|
||||
editor.windowManager.open({
|
||||
title: "Table properties",
|
||||
data: data,
|
||||
body: generalTableForm,
|
||||
onsubmit: onSubmitTableForm
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
self.merge = function(grid, cell) {
|
||||
editor.windowManager.open({
|
||||
title: "Merge cells",
|
||||
body: [
|
||||
{label: 'Cols', name: 'cols', type: 'textbox', value: '1', size: 10},
|
||||
{label: 'Rows', name: 'rows', type: 'textbox', value: '1', size: 10}
|
||||
],
|
||||
onsubmit: function() {
|
||||
var data = this.toJSON();
|
||||
|
||||
editor.undoManager.transact(function() {
|
||||
grid.merge(cell, data.cols, data.rows);
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
self.cell = function() {
|
||||
var dom = editor.dom, cellElm, data, classListCtrl, cells = [];
|
||||
|
||||
function onSubmitCellForm() {
|
||||
updateStyle(dom, this);
|
||||
data = Tools.extend(data, this.toJSON());
|
||||
|
||||
editor.undoManager.transact(function() {
|
||||
each(cells, function(cellElm) {
|
||||
editor.dom.setAttribs(cellElm, {
|
||||
scope: data.scope,
|
||||
style: data.style,
|
||||
'class': data['class']
|
||||
});
|
||||
|
||||
editor.dom.setStyles(cellElm, {
|
||||
width: addSizeSuffix(data.width),
|
||||
height: addSizeSuffix(data.height)
|
||||
});
|
||||
|
||||
// Switch cell type
|
||||
if (data.type && cellElm.nodeName.toLowerCase() != data.type) {
|
||||
cellElm = dom.rename(cellElm, data.type);
|
||||
}
|
||||
|
||||
// Apply/remove alignment
|
||||
unApplyAlign(cellElm);
|
||||
if (data.align) {
|
||||
editor.formatter.apply('align' + data.align, {}, cellElm);
|
||||
}
|
||||
|
||||
// Apply/remove vertical alignment
|
||||
unApplyVAlign(cellElm);
|
||||
if (data.valign) {
|
||||
editor.formatter.apply('valign' + data.valign, {}, cellElm);
|
||||
}
|
||||
});
|
||||
|
||||
editor.focus();
|
||||
});
|
||||
}
|
||||
|
||||
// Get selected cells or the current cell
|
||||
cells = editor.dom.select('td.mce-item-selected,th.mce-item-selected');
|
||||
cellElm = editor.dom.getParent(editor.selection.getStart(), 'td,th');
|
||||
if (!cells.length && cellElm) {
|
||||
cells.push(cellElm);
|
||||
}
|
||||
|
||||
cellElm = cellElm || cells[0];
|
||||
|
||||
if (!cellElm) {
|
||||
// If this element is null, return now to avoid crashing.
|
||||
return;
|
||||
}
|
||||
|
||||
data = {
|
||||
width: removePxSuffix(dom.getStyle(cellElm, 'width') || dom.getAttrib(cellElm, 'width')),
|
||||
height: removePxSuffix(dom.getStyle(cellElm, 'height') || dom.getAttrib(cellElm, 'height')),
|
||||
scope: dom.getAttrib(cellElm, 'scope'),
|
||||
'class': dom.getAttrib(cellElm, 'class')
|
||||
};
|
||||
|
||||
data.type = cellElm.nodeName.toLowerCase();
|
||||
|
||||
each('left center right'.split(' '), function(name) {
|
||||
if (editor.formatter.matchNode(cellElm, 'align' + name)) {
|
||||
data.align = name;
|
||||
}
|
||||
});
|
||||
|
||||
each('top middle bottom'.split(' '), function(name) {
|
||||
if (editor.formatter.matchNode(cellElm, 'valign' + name)) {
|
||||
data.valign = name;
|
||||
}
|
||||
});
|
||||
|
||||
if (editor.settings.table_cell_class_list) {
|
||||
classListCtrl = {
|
||||
name: 'class',
|
||||
type: 'listbox',
|
||||
label: 'Class',
|
||||
values: buildListItems(
|
||||
editor.settings.table_cell_class_list,
|
||||
function(item) {
|
||||
if (item.value) {
|
||||
item.textStyle = function() {
|
||||
return editor.formatter.getCssText({block: 'td', classes: [item.value]});
|
||||
};
|
||||
}
|
||||
}
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
var generalCellForm = {
|
||||
type: 'form',
|
||||
layout: 'flex',
|
||||
direction: 'column',
|
||||
labelGapCalc: 'children',
|
||||
padding: 0,
|
||||
items: [
|
||||
{
|
||||
type: 'form',
|
||||
layout: 'grid',
|
||||
columns: 2,
|
||||
labelGapCalc: false,
|
||||
padding: 0,
|
||||
defaults: {
|
||||
type: 'textbox',
|
||||
maxWidth: 50
|
||||
},
|
||||
items: [
|
||||
{label: 'Width', name: 'width'},
|
||||
{label: 'Height', name: 'height'},
|
||||
{
|
||||
label: 'Cell type',
|
||||
name: 'type',
|
||||
type: 'listbox',
|
||||
text: 'None',
|
||||
minWidth: 90,
|
||||
maxWidth: null,
|
||||
values: [
|
||||
{text: 'Cell', value: 'td'},
|
||||
{text: 'Header cell', value: 'th'}
|
||||
]
|
||||
},
|
||||
{
|
||||
label: 'Scope',
|
||||
name: 'scope',
|
||||
type: 'listbox',
|
||||
text: 'None',
|
||||
minWidth: 90,
|
||||
maxWidth: null,
|
||||
values: [
|
||||
{text: 'None', value: ''},
|
||||
{text: 'Row', value: 'row'},
|
||||
{text: 'Column', value: 'col'},
|
||||
{text: 'Row group', value: 'rowgroup'},
|
||||
{text: 'Column group', value: 'colgroup'}
|
||||
]
|
||||
},
|
||||
{
|
||||
label: 'H Align',
|
||||
name: 'align',
|
||||
type: 'listbox',
|
||||
text: 'None',
|
||||
minWidth: 90,
|
||||
maxWidth: null,
|
||||
values: [
|
||||
{text: 'None', value: ''},
|
||||
{text: 'Left', value: 'left'},
|
||||
{text: 'Center', value: 'center'},
|
||||
{text: 'Right', value: 'right'}
|
||||
]
|
||||
},
|
||||
{
|
||||
label: 'V Align',
|
||||
name: 'valign',
|
||||
type: 'listbox',
|
||||
text: 'None',
|
||||
minWidth: 90,
|
||||
maxWidth: null,
|
||||
values: [
|
||||
{text: 'None', value: ''},
|
||||
{text: 'Top', value: 'top'},
|
||||
{text: 'Middle', value: 'middle'},
|
||||
{text: 'Bottom', value: 'bottom'}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
classListCtrl
|
||||
]
|
||||
};
|
||||
|
||||
if (editor.settings.table_cell_advtab !== false) {
|
||||
appendStylesToData(dom, data, cellElm);
|
||||
|
||||
editor.windowManager.open({
|
||||
title: "Cell properties",
|
||||
bodyType: 'tabpanel',
|
||||
data: data,
|
||||
body: [
|
||||
{
|
||||
title: 'General',
|
||||
type: 'form',
|
||||
items: generalCellForm
|
||||
},
|
||||
|
||||
createStyleForm(dom)
|
||||
],
|
||||
|
||||
onsubmit: onSubmitCellForm
|
||||
});
|
||||
} else {
|
||||
editor.windowManager.open({
|
||||
title: "Cell properties",
|
||||
data: data,
|
||||
body: generalCellForm,
|
||||
onsubmit: onSubmitCellForm
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
self.row = function() {
|
||||
var dom = editor.dom, tableElm, cellElm, rowElm, classListCtrl, data, rows = [], generalRowForm;
|
||||
|
||||
function onSubmitRowForm() {
|
||||
var tableElm, oldParentElm, parentElm;
|
||||
|
||||
updateStyle(dom, this);
|
||||
data = Tools.extend(data, this.toJSON());
|
||||
|
||||
editor.undoManager.transact(function() {
|
||||
var toType = data.type;
|
||||
|
||||
each(rows, function(rowElm) {
|
||||
editor.dom.setAttribs(rowElm, {
|
||||
scope: data.scope,
|
||||
style: data.style,
|
||||
'class': data['class']
|
||||
});
|
||||
|
||||
editor.dom.setStyles(rowElm, {
|
||||
height: addSizeSuffix(data.height)
|
||||
});
|
||||
|
||||
if (toType != rowElm.parentNode.nodeName.toLowerCase()) {
|
||||
tableElm = dom.getParent(rowElm, 'table');
|
||||
|
||||
oldParentElm = rowElm.parentNode;
|
||||
parentElm = dom.select(toType, tableElm)[0];
|
||||
if (!parentElm) {
|
||||
parentElm = dom.create(toType);
|
||||
if (tableElm.firstChild) {
|
||||
tableElm.insertBefore(parentElm, tableElm.firstChild);
|
||||
} else {
|
||||
tableElm.appendChild(parentElm);
|
||||
}
|
||||
}
|
||||
|
||||
parentElm.appendChild(rowElm);
|
||||
|
||||
if (!oldParentElm.hasChildNodes()) {
|
||||
dom.remove(oldParentElm);
|
||||
}
|
||||
}
|
||||
|
||||
// Apply/remove alignment
|
||||
unApplyAlign(rowElm);
|
||||
if (data.align) {
|
||||
editor.formatter.apply('align' + data.align, {}, rowElm);
|
||||
}
|
||||
});
|
||||
|
||||
editor.focus();
|
||||
});
|
||||
}
|
||||
|
||||
tableElm = editor.dom.getParent(editor.selection.getStart(), 'table');
|
||||
cellElm = editor.dom.getParent(editor.selection.getStart(), 'td,th');
|
||||
|
||||
each(tableElm.rows, function(row) {
|
||||
each(row.cells, function(cell) {
|
||||
if (dom.hasClass(cell, 'mce-item-selected') || cell == cellElm) {
|
||||
rows.push(row);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
rowElm = rows[0];
|
||||
if (!rowElm) {
|
||||
// If this element is null, return now to avoid crashing.
|
||||
return;
|
||||
}
|
||||
|
||||
data = {
|
||||
height: removePxSuffix(dom.getStyle(rowElm, 'height') || dom.getAttrib(rowElm, 'height')),
|
||||
scope: dom.getAttrib(rowElm, 'scope'),
|
||||
'class': dom.getAttrib(rowElm, 'class')
|
||||
};
|
||||
|
||||
data.type = rowElm.parentNode.nodeName.toLowerCase();
|
||||
|
||||
each('left center right'.split(' '), function(name) {
|
||||
if (editor.formatter.matchNode(rowElm, 'align' + name)) {
|
||||
data.align = name;
|
||||
}
|
||||
});
|
||||
|
||||
if (editor.settings.table_row_class_list) {
|
||||
classListCtrl = {
|
||||
name: 'class',
|
||||
type: 'listbox',
|
||||
label: 'Class',
|
||||
values: buildListItems(
|
||||
editor.settings.table_row_class_list,
|
||||
function(item) {
|
||||
if (item.value) {
|
||||
item.textStyle = function() {
|
||||
return editor.formatter.getCssText({block: 'tr', classes: [item.value]});
|
||||
};
|
||||
}
|
||||
}
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
generalRowForm = {
|
||||
type: 'form',
|
||||
columns: 2,
|
||||
padding: 0,
|
||||
defaults: {
|
||||
type: 'textbox'
|
||||
},
|
||||
items: [
|
||||
{
|
||||
type: 'listbox',
|
||||
name: 'type',
|
||||
label: 'Row type',
|
||||
text: 'None',
|
||||
maxWidth: null,
|
||||
values: [
|
||||
{text: 'Header', value: 'thead'},
|
||||
{text: 'Body', value: 'tbody'},
|
||||
{text: 'Footer', value: 'tfoot'}
|
||||
]
|
||||
},
|
||||
{
|
||||
type: 'listbox',
|
||||
name: 'align',
|
||||
label: 'Alignment',
|
||||
text: 'None',
|
||||
maxWidth: null,
|
||||
values: [
|
||||
{text: 'None', value: ''},
|
||||
{text: 'Left', value: 'left'},
|
||||
{text: 'Center', value: 'center'},
|
||||
{text: 'Right', value: 'right'}
|
||||
]
|
||||
},
|
||||
{label: 'Height', name: 'height'},
|
||||
classListCtrl
|
||||
]
|
||||
};
|
||||
|
||||
if (editor.settings.table_row_advtab !== false) {
|
||||
appendStylesToData(dom, data, rowElm);
|
||||
|
||||
editor.windowManager.open({
|
||||
title: "Row properties",
|
||||
data: data,
|
||||
bodyType: 'tabpanel',
|
||||
body: [
|
||||
{
|
||||
title: 'General',
|
||||
type: 'form',
|
||||
items: generalRowForm
|
||||
},
|
||||
createStyleForm(dom)
|
||||
],
|
||||
|
||||
onsubmit: onSubmitRowForm
|
||||
});
|
||||
} else {
|
||||
editor.windowManager.open({
|
||||
title: "Row properties",
|
||||
data: data,
|
||||
body: generalRowForm,
|
||||
onsubmit: onSubmitRowForm
|
||||
});
|
||||
}
|
||||
};
|
||||
};
|
||||
});
|
618
public/tinymce/plugins/table/classes/Plugin.js
Normal file → Executable file
618
public/tinymce/plugins/table/classes/Plugin.js
Normal file → Executable file
@ -18,382 +18,16 @@ define("tinymce/tableplugin/Plugin", [
|
||||
"tinymce/tableplugin/TableGrid",
|
||||
"tinymce/tableplugin/Quirks",
|
||||
"tinymce/tableplugin/CellSelection",
|
||||
"tinymce/tableplugin/Dialogs",
|
||||
"tinymce/util/Tools",
|
||||
"tinymce/dom/TreeWalker",
|
||||
"tinymce/Env",
|
||||
"tinymce/PluginManager"
|
||||
], function(TableGrid, Quirks, CellSelection, Tools, TreeWalker, Env, PluginManager) {
|
||||
], function(TableGrid, Quirks, CellSelection, Dialogs, Tools, TreeWalker, Env, PluginManager) {
|
||||
var each = Tools.each;
|
||||
|
||||
function Plugin(editor) {
|
||||
var winMan, clipboardRows, self = this; // Might be selected cells on reload
|
||||
|
||||
function removePxSuffix(size) {
|
||||
return size ? size.replace(/px$/, '') : "";
|
||||
}
|
||||
|
||||
function addSizeSuffix(size) {
|
||||
if (/^[0-9]+$/.test(size)) {
|
||||
size += "px";
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
function unApplyAlign(elm) {
|
||||
each('left center right'.split(' '), function(name) {
|
||||
editor.formatter.remove('align' + name, {}, elm);
|
||||
});
|
||||
}
|
||||
|
||||
function tableDialog() {
|
||||
var dom = editor.dom, tableElm, data, createNewTable;
|
||||
|
||||
tableElm = editor.dom.getParent(editor.selection.getStart(), 'table');
|
||||
createNewTable = false;
|
||||
|
||||
data = {
|
||||
width: removePxSuffix(dom.getStyle(tableElm, 'width') || dom.getAttrib(tableElm, 'width')),
|
||||
height: removePxSuffix(dom.getStyle(tableElm, 'height') || dom.getAttrib(tableElm, 'height')),
|
||||
cellspacing: dom.getAttrib(tableElm, 'cellspacing'),
|
||||
cellpadding: dom.getAttrib(tableElm, 'cellpadding'),
|
||||
border: dom.getAttrib(tableElm, 'border'),
|
||||
caption: !!dom.select('caption', tableElm)[0]
|
||||
};
|
||||
|
||||
each('left center right'.split(' '), function(name) {
|
||||
if (editor.formatter.matchNode(tableElm, 'align' + name)) {
|
||||
data.align = name;
|
||||
}
|
||||
});
|
||||
|
||||
editor.windowManager.open({
|
||||
title: "Table properties",
|
||||
items: {
|
||||
type: 'form',
|
||||
layout: 'grid',
|
||||
columns: 2,
|
||||
data: data,
|
||||
defaults: {
|
||||
type: 'textbox',
|
||||
maxWidth: 50
|
||||
},
|
||||
items: [
|
||||
createNewTable ? {label: 'Cols', name: 'cols', disabled: true} : null,
|
||||
createNewTable ? {label: 'Rows', name: 'rows', disabled: true} : null,
|
||||
{label: 'Width', name: 'width'},
|
||||
{label: 'Height', name: 'height'},
|
||||
{label: 'Cell spacing', name: 'cellspacing'},
|
||||
{label: 'Cell padding', name: 'cellpadding'},
|
||||
{label: 'Border', name: 'border'},
|
||||
{label: 'Caption', name: 'caption', type: 'checkbox'},
|
||||
{
|
||||
label: 'Alignment',
|
||||
minWidth: 90,
|
||||
name: 'align',
|
||||
type: 'listbox',
|
||||
text: 'None',
|
||||
maxWidth: null,
|
||||
values: [
|
||||
{text: 'None', value: ''},
|
||||
{text: 'Left', value: 'left'},
|
||||
{text: 'Center', value: 'center'},
|
||||
{text: 'Right', value: 'right'}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
onsubmit: function() {
|
||||
var data = this.toJSON(), captionElm;
|
||||
|
||||
editor.undoManager.transact(function() {
|
||||
editor.dom.setAttribs(tableElm, {
|
||||
cellspacing: data.cellspacing,
|
||||
cellpadding: data.cellpadding,
|
||||
border: data.border
|
||||
});
|
||||
|
||||
editor.dom.setStyles(tableElm, {
|
||||
width: addSizeSuffix(data.width),
|
||||
height: addSizeSuffix(data.height)
|
||||
});
|
||||
|
||||
// Toggle caption on/off
|
||||
captionElm = dom.select('caption', tableElm)[0];
|
||||
|
||||
if (captionElm && !data.caption) {
|
||||
dom.remove(captionElm);
|
||||
}
|
||||
|
||||
if (!captionElm && data.caption) {
|
||||
captionElm = dom.create('caption');
|
||||
|
||||
if (!Env.ie) {
|
||||
captionElm.innerHTML = '<br data-mce-bogus="1"/>';
|
||||
}
|
||||
|
||||
tableElm.insertBefore(captionElm, tableElm.firstChild);
|
||||
}
|
||||
|
||||
unApplyAlign(tableElm);
|
||||
if (data.align) {
|
||||
editor.formatter.apply('align' + data.align, {}, tableElm);
|
||||
}
|
||||
|
||||
editor.focus();
|
||||
editor.addVisual();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function mergeDialog(grid, cell) {
|
||||
editor.windowManager.open({
|
||||
title: "Merge cells",
|
||||
body: [
|
||||
{label: 'Cols', name: 'cols', type: 'textbox', size: 10},
|
||||
{label: 'Rows', name: 'rows', type: 'textbox', size: 10}
|
||||
],
|
||||
onsubmit: function() {
|
||||
var data = this.toJSON();
|
||||
|
||||
editor.undoManager.transact(function() {
|
||||
grid.merge(cell, data.cols, data.rows);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function cellDialog() {
|
||||
var dom = editor.dom, cellElm, data, cells = [];
|
||||
|
||||
// Get selected cells or the current cell
|
||||
cells = editor.dom.select('td.mce-item-selected,th.mce-item-selected');
|
||||
cellElm = editor.dom.getParent(editor.selection.getStart(), 'td,th');
|
||||
if (!cells.length && cellElm) {
|
||||
cells.push(cellElm);
|
||||
}
|
||||
|
||||
cellElm = cellElm || cells[0];
|
||||
|
||||
data = {
|
||||
width: removePxSuffix(dom.getStyle(cellElm, 'width') || dom.getAttrib(cellElm, 'width')),
|
||||
height: removePxSuffix(dom.getStyle(cellElm, 'height') || dom.getAttrib(cellElm, 'height')),
|
||||
scope: dom.getAttrib(cellElm, 'scope')
|
||||
};
|
||||
|
||||
data.type = cellElm.nodeName.toLowerCase();
|
||||
|
||||
each('left center right'.split(' '), function(name) {
|
||||
if (editor.formatter.matchNode(cellElm, 'align' + name)) {
|
||||
data.align = name;
|
||||
}
|
||||
});
|
||||
|
||||
editor.windowManager.open({
|
||||
title: "Cell properties",
|
||||
items: {
|
||||
type: 'form',
|
||||
data: data,
|
||||
layout: 'grid',
|
||||
columns: 2,
|
||||
defaults: {
|
||||
type: 'textbox',
|
||||
maxWidth: 50
|
||||
},
|
||||
items: [
|
||||
{label: 'Width', name: 'width'},
|
||||
{label: 'Height', name: 'height'},
|
||||
{
|
||||
label: 'Cell type',
|
||||
name: 'type',
|
||||
type: 'listbox',
|
||||
text: 'None',
|
||||
minWidth: 90,
|
||||
maxWidth: null,
|
||||
menu: [
|
||||
{text: 'Cell', value: 'td'},
|
||||
{text: 'Header cell', value: 'th'}
|
||||
]
|
||||
},
|
||||
{
|
||||
label: 'Scope',
|
||||
name: 'scope',
|
||||
type: 'listbox',
|
||||
text: 'None',
|
||||
minWidth: 90,
|
||||
maxWidth: null,
|
||||
menu: [
|
||||
{text: 'None', value: ''},
|
||||
{text: 'Row', value: 'row'},
|
||||
{text: 'Column', value: 'col'},
|
||||
{text: 'Row group', value: 'rowgroup'},
|
||||
{text: 'Column group', value: 'colgroup'}
|
||||
]
|
||||
},
|
||||
{
|
||||
label: 'Alignment',
|
||||
name: 'align',
|
||||
type: 'listbox',
|
||||
text: 'None',
|
||||
minWidth: 90,
|
||||
maxWidth: null,
|
||||
values: [
|
||||
{text: 'None', value: ''},
|
||||
{text: 'Left', value: 'left'},
|
||||
{text: 'Center', value: 'center'},
|
||||
{text: 'Right', value: 'right'}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
onsubmit: function() {
|
||||
var data = this.toJSON();
|
||||
|
||||
editor.undoManager.transact(function() {
|
||||
each(cells, function(cellElm) {
|
||||
editor.dom.setAttrib(cellElm, 'scope', data.scope);
|
||||
|
||||
editor.dom.setStyles(cellElm, {
|
||||
width: addSizeSuffix(data.width),
|
||||
height: addSizeSuffix(data.height)
|
||||
});
|
||||
|
||||
// Switch cell type
|
||||
if (data.type && cellElm.nodeName.toLowerCase() != data.type) {
|
||||
cellElm = dom.rename(cellElm, data.type);
|
||||
}
|
||||
|
||||
// Apply/remove alignment
|
||||
unApplyAlign(cellElm);
|
||||
if (data.align) {
|
||||
editor.formatter.apply('align' + data.align, {}, cellElm);
|
||||
}
|
||||
});
|
||||
|
||||
editor.focus();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function rowDialog() {
|
||||
var dom = editor.dom, tableElm, cellElm, rowElm, data, rows = [];
|
||||
|
||||
tableElm = editor.dom.getParent(editor.selection.getStart(), 'table');
|
||||
cellElm = editor.dom.getParent(editor.selection.getStart(), 'td,th');
|
||||
|
||||
each(tableElm.rows, function(row) {
|
||||
each(row.cells, function(cell) {
|
||||
if (dom.hasClass(cell, 'mce-item-selected') || cell == cellElm) {
|
||||
rows.push(row);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
rowElm = rows[0];
|
||||
|
||||
data = {
|
||||
height: removePxSuffix(dom.getStyle(rowElm, 'height') || dom.getAttrib(rowElm, 'height')),
|
||||
scope: dom.getAttrib(rowElm, 'scope')
|
||||
};
|
||||
|
||||
data.type = rowElm.parentNode.nodeName.toLowerCase();
|
||||
|
||||
each('left center right'.split(' '), function(name) {
|
||||
if (editor.formatter.matchNode(rowElm, 'align' + name)) {
|
||||
data.align = name;
|
||||
}
|
||||
});
|
||||
|
||||
editor.windowManager.open({
|
||||
title: "Row properties",
|
||||
items: {
|
||||
type: 'form',
|
||||
data: data,
|
||||
columns: 2,
|
||||
defaults: {
|
||||
type: 'textbox'
|
||||
},
|
||||
items: [
|
||||
{
|
||||
type: 'listbox',
|
||||
name: 'type',
|
||||
label: 'Row type',
|
||||
text: 'None',
|
||||
maxWidth: null,
|
||||
menu: [
|
||||
{text: 'Header', value: 'thead'},
|
||||
{text: 'Body', value: 'tbody'},
|
||||
{text: 'Footer', value: 'tfoot'}
|
||||
]
|
||||
},
|
||||
{
|
||||
type: 'listbox',
|
||||
name: 'align',
|
||||
label: 'Alignment',
|
||||
text: 'None',
|
||||
maxWidth: null,
|
||||
menu: [
|
||||
{text: 'None', value: ''},
|
||||
{text: 'Left', value: 'left'},
|
||||
{text: 'Center', value: 'center'},
|
||||
{text: 'Right', value: 'right'}
|
||||
]
|
||||
},
|
||||
{label: 'Height', name: 'height'}
|
||||
]
|
||||
},
|
||||
|
||||
onsubmit: function() {
|
||||
var data = this.toJSON(), tableElm, oldParentElm, parentElm;
|
||||
|
||||
editor.undoManager.transact(function() {
|
||||
var toType = data.type;
|
||||
|
||||
each(rows, function(rowElm) {
|
||||
editor.dom.setAttrib(rowElm, 'scope', data.scope);
|
||||
|
||||
editor.dom.setStyles(rowElm, {
|
||||
height: addSizeSuffix(data.height)
|
||||
});
|
||||
|
||||
if (toType != rowElm.parentNode.nodeName.toLowerCase()) {
|
||||
tableElm = dom.getParent(rowElm, 'table');
|
||||
|
||||
oldParentElm = rowElm.parentNode;
|
||||
parentElm = dom.select(toType, tableElm)[0];
|
||||
if (!parentElm) {
|
||||
parentElm = dom.create(toType);
|
||||
if (tableElm.firstChild) {
|
||||
tableElm.insertBefore(parentElm, tableElm.firstChild);
|
||||
} else {
|
||||
tableElm.appendChild(parentElm);
|
||||
}
|
||||
}
|
||||
|
||||
parentElm.appendChild(rowElm);
|
||||
|
||||
if (!oldParentElm.hasChildNodes()) {
|
||||
dom.remove(oldParentElm);
|
||||
}
|
||||
}
|
||||
|
||||
// Apply/remove alignment
|
||||
unApplyAlign(rowElm);
|
||||
if (data.align) {
|
||||
editor.formatter.apply('align' + data.align, {}, rowElm);
|
||||
}
|
||||
});
|
||||
|
||||
editor.focus();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
var clipboardRows, self = this, dialogs = new Dialogs(editor);
|
||||
|
||||
function cmd(command) {
|
||||
return function() {
|
||||
@ -402,9 +36,9 @@ define("tinymce/tableplugin/Plugin", [
|
||||
}
|
||||
|
||||
function insertTable(cols, rows) {
|
||||
var y, x, html;
|
||||
var y, x, html, tableElm;
|
||||
|
||||
html = '<table><tbody>';
|
||||
html = '<table id="__mce"><tbody>';
|
||||
|
||||
for (y = 0; y < rows; y++) {
|
||||
html += '<tr>';
|
||||
@ -418,7 +52,17 @@ define("tinymce/tableplugin/Plugin", [
|
||||
|
||||
html += '</tbody></table>';
|
||||
|
||||
editor.insertContent(html);
|
||||
editor.undoManager.transact(function() {
|
||||
editor.insertContent(html);
|
||||
|
||||
tableElm = editor.dom.get('__mce');
|
||||
editor.dom.setAttrib(tableElm, 'id', null);
|
||||
|
||||
editor.dom.setAttribs(tableElm, editor.settings.table_default_attributes || {});
|
||||
editor.dom.setStyles(tableElm, editor.settings.table_default_styles || {});
|
||||
});
|
||||
|
||||
return tableElm;
|
||||
}
|
||||
|
||||
function handleDisabledState(ctrl, selector) {
|
||||
@ -450,13 +94,14 @@ define("tinymce/tableplugin/Plugin", [
|
||||
function generateTableGrid() {
|
||||
var html = '';
|
||||
|
||||
html = '<table role="presentation" class="mce-grid mce-grid-border">';
|
||||
html = '<table role="grid" class="mce-grid mce-grid-border" aria-readonly="true">';
|
||||
|
||||
for (var y = 0; y < 10; y++) {
|
||||
html += '<tr>';
|
||||
|
||||
for (var x = 0; x < 10; x++) {
|
||||
html += '<td><a href="#" data-mce-index="' + x + ',' + y + '"></a></td>';
|
||||
html += '<td role="gridcell" tabindex="-1"><a id="mcegrid' + (y * 10 + x) + '" href="#" ' +
|
||||
'data-mce-x="' + x + '" data-mce-y="' + y + '"></a></td>';
|
||||
}
|
||||
|
||||
html += '</tr>';
|
||||
@ -464,88 +109,120 @@ define("tinymce/tableplugin/Plugin", [
|
||||
|
||||
html += '</table>';
|
||||
|
||||
html += '<div class="mce-text-center">0 x 0</div>';
|
||||
html += '<div class="mce-text-center" role="presentation">1 x 1</div>';
|
||||
|
||||
return html;
|
||||
}
|
||||
|
||||
editor.addMenuItem('inserttable', {
|
||||
text: 'Insert table',
|
||||
icon: 'table',
|
||||
context: 'table',
|
||||
onhide: function() {
|
||||
editor.dom.removeClass(this.menu.items()[0].getEl().getElementsByTagName('a'), 'mce-active');
|
||||
},
|
||||
menu: [
|
||||
{
|
||||
type: 'container',
|
||||
html: generateTableGrid(),
|
||||
function selectGrid(tx, ty, control) {
|
||||
var table = control.getEl().getElementsByTagName('table')[0];
|
||||
var x, y, focusCell, cell, active;
|
||||
var rtl = control.isRtl() || control.parent().rel == 'tl-tr';
|
||||
|
||||
onmousemove: function(e) {
|
||||
var x, y, target = e.target;
|
||||
table.nextSibling.innerHTML = (tx + 1) + ' x ' + (ty + 1);
|
||||
|
||||
if (target.nodeName == 'A') {
|
||||
var table = editor.dom.getParent(target, 'table');
|
||||
var pos = target.getAttribute('data-mce-index');
|
||||
var rel = e.control.parent().rel;
|
||||
if (rtl) {
|
||||
tx = 9 - tx;
|
||||
}
|
||||
|
||||
if (pos != this.lastPos) {
|
||||
pos = pos.split(',');
|
||||
for (y = 0; y < 10; y++) {
|
||||
for (x = 0; x < 10; x++) {
|
||||
cell = table.rows[y].childNodes[x].firstChild;
|
||||
active = (rtl ? x >= tx : x <= tx) && y <= ty;
|
||||
|
||||
pos[0] = parseInt(pos[0], 10);
|
||||
pos[1] = parseInt(pos[1], 10);
|
||||
editor.dom.toggleClass(cell, 'mce-active', active);
|
||||
|
||||
if (e.control.isRtl() || rel == 'tl-tr') {
|
||||
for (y = 9; y >= 0; y--) {
|
||||
for (x = 0; x < 10; x++) {
|
||||
editor.dom.toggleClass(
|
||||
table.rows[y].childNodes[x].firstChild,
|
||||
'mce-active',
|
||||
x >= pos[0] && y <= pos[1]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pos[0] = 9 - pos[0];
|
||||
table.nextSibling.innerHTML = pos[0] + ' x '+ (pos[1] + 1);
|
||||
} else {
|
||||
for (y = 0; y < 10; y++) {
|
||||
for (x = 0; x < 10; x++) {
|
||||
editor.dom.toggleClass(
|
||||
table.rows[y].childNodes[x].firstChild,
|
||||
'mce-active',
|
||||
x <= pos[0] && y <= pos[1]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
table.nextSibling.innerHTML = (pos[0] + 1) + ' x '+ (pos[1] + 1);
|
||||
}
|
||||
|
||||
this.lastPos = pos;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
onclick: function(e) {
|
||||
if (e.target.nodeName == 'A' && this.lastPos) {
|
||||
e.preventDefault();
|
||||
|
||||
insertTable(this.lastPos[0] + 1, this.lastPos[1] + 1);
|
||||
|
||||
// TODO: Maybe rework this?
|
||||
this.parent().cancel(); // Close parent menu as if it was a click
|
||||
}
|
||||
if (active) {
|
||||
focusCell = cell;
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
return focusCell.parentNode;
|
||||
}
|
||||
|
||||
if (editor.settings.table_grid === false) {
|
||||
editor.addMenuItem('inserttable', {
|
||||
text: 'Insert table',
|
||||
icon: 'table',
|
||||
context: 'table',
|
||||
onclick: dialogs.table
|
||||
});
|
||||
} else {
|
||||
editor.addMenuItem('inserttable', {
|
||||
text: 'Insert table',
|
||||
icon: 'table',
|
||||
context: 'table',
|
||||
ariaHideMenu: true,
|
||||
onclick: function(e) {
|
||||
if (e.aria) {
|
||||
this.parent().hideAll();
|
||||
e.stopImmediatePropagation();
|
||||
dialogs.table();
|
||||
}
|
||||
},
|
||||
onshow: function() {
|
||||
selectGrid(0, 0, this.menu.items()[0]);
|
||||
},
|
||||
onhide: function() {
|
||||
var elements = this.menu.items()[0].getEl().getElementsByTagName('a');
|
||||
editor.dom.removeClass(elements, 'mce-active');
|
||||
editor.dom.addClass(elements[0], 'mce-active');
|
||||
},
|
||||
menu: [
|
||||
{
|
||||
type: 'container',
|
||||
html: generateTableGrid(),
|
||||
|
||||
onPostRender: function() {
|
||||
this.lastX = this.lastY = 0;
|
||||
},
|
||||
|
||||
onmousemove: function(e) {
|
||||
var target = e.target, x, y;
|
||||
|
||||
if (target.tagName.toUpperCase() == 'A') {
|
||||
x = parseInt(target.getAttribute('data-mce-x'), 10);
|
||||
y = parseInt(target.getAttribute('data-mce-y'), 10);
|
||||
|
||||
if (this.isRtl() || this.parent().rel == 'tl-tr') {
|
||||
x = 9 - x;
|
||||
}
|
||||
|
||||
if (x !== this.lastX || y !== this.lastY) {
|
||||
selectGrid(x, y, e.control);
|
||||
|
||||
this.lastX = x;
|
||||
this.lastY = y;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
onclick: function(e) {
|
||||
var self = this;
|
||||
|
||||
if (e.target.tagName.toUpperCase() == 'A') {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
self.parent().cancel();
|
||||
|
||||
editor.undoManager.transact(function() {
|
||||
insertTable(self.lastX + 1, self.lastY + 1);
|
||||
});
|
||||
|
||||
editor.addVisual();
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
editor.addMenuItem('tableprops', {
|
||||
text: 'Table properties',
|
||||
context: 'table',
|
||||
onPostRender: postRender,
|
||||
onclick: tableDialog
|
||||
onclick: dialogs.tableProps
|
||||
});
|
||||
|
||||
editor.addMenuItem('deletetable', {
|
||||
@ -622,10 +299,23 @@ define("tinymce/tableplugin/Plugin", [
|
||||
self.quirks = new Quirks(editor);
|
||||
|
||||
editor.on('Init', function() {
|
||||
winMan = editor.windowManager;
|
||||
self.cellSelection = new CellSelection(editor);
|
||||
});
|
||||
|
||||
editor.on('PreInit', function() {
|
||||
// Remove internal data attributes
|
||||
editor.serializer.addAttributeFilter(
|
||||
'data-mce-cell-padding,data-mce-border,data-mce-border-color',
|
||||
function(nodes, name) {
|
||||
|
||||
var i = nodes.length;
|
||||
|
||||
while (i--) {
|
||||
nodes[i].attr(name, null);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Register action commands
|
||||
each({
|
||||
mceTableSplitCells: function(grid) {
|
||||
@ -633,16 +323,12 @@ define("tinymce/tableplugin/Plugin", [
|
||||
},
|
||||
|
||||
mceTableMergeCells: function(grid) {
|
||||
var rowSpan, colSpan, cell;
|
||||
var cell;
|
||||
|
||||
cell = editor.dom.getParent(editor.selection.getStart(), 'th,td');
|
||||
if (cell) {
|
||||
rowSpan = cell.rowSpan;
|
||||
colSpan = cell.colSpan;
|
||||
}
|
||||
|
||||
if (!editor.dom.select('td.mce-item-selected,th.mce-item-selected').length) {
|
||||
mergeDialog(grid, cell);
|
||||
dialogs.merge(grid, cell);
|
||||
} else {
|
||||
grid.merge();
|
||||
}
|
||||
@ -705,17 +391,45 @@ define("tinymce/tableplugin/Plugin", [
|
||||
|
||||
// Register dialog commands
|
||||
each({
|
||||
mceInsertTable: function() {
|
||||
tableDialog();
|
||||
mceInsertTable: dialogs.table,
|
||||
mceTableProps: function() {
|
||||
dialogs.table(true);
|
||||
},
|
||||
|
||||
mceTableRowProps: rowDialog,
|
||||
mceTableCellProps: cellDialog
|
||||
mceTableRowProps: dialogs.row,
|
||||
mceTableCellProps: dialogs.cell
|
||||
}, function(func, name) {
|
||||
editor.addCommand(name, function(ui, val) {
|
||||
func(val);
|
||||
});
|
||||
});
|
||||
|
||||
// Enable tab key cell navigation
|
||||
if (editor.settings.table_tab_navigation !== false) {
|
||||
editor.on('keydown', function(e) {
|
||||
var cellElm, grid, delta;
|
||||
|
||||
if (e.keyCode == 9) {
|
||||
cellElm = editor.dom.getParent(editor.selection.getStart(), 'th,td');
|
||||
|
||||
if (cellElm) {
|
||||
e.preventDefault();
|
||||
|
||||
grid = new TableGrid(editor);
|
||||
delta = e.shiftKey ? -1 : 1;
|
||||
|
||||
editor.undoManager.transact(function() {
|
||||
if (!grid.moveRelIdx(cellElm, delta) && delta > 0) {
|
||||
grid.insertRow();
|
||||
grid.refresh();
|
||||
grid.moveRelIdx(cellElm, delta);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
self.insertTable = insertTable;
|
||||
}
|
||||
|
||||
PluginManager.add('table', Plugin);
|
||||
|
39
public/tinymce/plugins/table/classes/Quirks.js
Normal file → Executable file
39
public/tinymce/plugins/table/classes/Quirks.js
Normal file → Executable file
@ -106,7 +106,7 @@ define("tinymce/tableplugin/Quirks", [
|
||||
}
|
||||
|
||||
function getChildForDirection(parent, up) {
|
||||
var child = parent && parent[up ? 'lastChild' : 'firstChild'];
|
||||
var child = parent && parent[up ? 'lastChild' : 'firstChild'];
|
||||
// BR is not a valid table child to return in this case we return the table cell
|
||||
return child && child.nodeName === 'BR' ? editor.dom.getParent(child, 'td,th') : child;
|
||||
}
|
||||
@ -237,7 +237,7 @@ define("tinymce/tableplugin/Quirks", [
|
||||
if (last.nodeValue.length > 0) {
|
||||
break;
|
||||
}
|
||||
} else if (last.nodeType == 1 && !last.getAttribute('data-mce-bogus')) {
|
||||
} else if (last.nodeType == 1 && (last.tagName == 'BR' || !last.getAttribute('data-mce-bogus'))) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -281,7 +281,7 @@ define("tinymce/tableplugin/Quirks", [
|
||||
tableParent = table.parentNode;
|
||||
}
|
||||
|
||||
allOfCellSelected =rng.startContainer.nodeType == TEXT_NODE &&
|
||||
allOfCellSelected = rng.startContainer.nodeType == TEXT_NODE &&
|
||||
rng.startOffset === 0 &&
|
||||
rng.endOffset === 0 &&
|
||||
currentCell &&
|
||||
@ -302,7 +302,7 @@ define("tinymce/tableplugin/Quirks", [
|
||||
}
|
||||
|
||||
if (!currentCell) {
|
||||
currentCell=n;
|
||||
currentCell = n;
|
||||
}
|
||||
|
||||
// Get the very last node inside the table cell
|
||||
@ -312,8 +312,10 @@ define("tinymce/tableplugin/Quirks", [
|
||||
}
|
||||
|
||||
// Select the entire table cell. Nothing outside of the table cell should be selected.
|
||||
rng.setEnd(end, end.nodeValue.length);
|
||||
editor.selection.setRng(rng);
|
||||
if (end.nodeType == 3) {
|
||||
rng.setEnd(end, end.data.length);
|
||||
editor.selection.setRng(rng);
|
||||
}
|
||||
}
|
||||
|
||||
editor.on('KeyDown', function() {
|
||||
@ -327,6 +329,31 @@ define("tinymce/tableplugin/Quirks", [
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete table if all cells are selected.
|
||||
*/
|
||||
function deleteTable() {
|
||||
editor.on('keydown', function(e) {
|
||||
if ((e.keyCode == VK.DELETE || e.keyCode == VK.BACKSPACE) && !e.isDefaultPrevented()) {
|
||||
var table = editor.dom.getParent(editor.selection.getStart(), 'table');
|
||||
|
||||
if (table) {
|
||||
var cells = editor.dom.select('td,th', table), i = cells.length;
|
||||
while (i--) {
|
||||
if (!editor.dom.hasClass(cells[i], 'mce-item-selected')) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
e.preventDefault();
|
||||
editor.execCommand('mceTableDelete');
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
deleteTable();
|
||||
|
||||
if (Env.webkit) {
|
||||
moveWebKitSelection();
|
||||
fixTableCellSelection();
|
||||
|
80
public/tinymce/plugins/table/classes/TableGrid.js
Normal file → Executable file
80
public/tinymce/plugins/table/classes/TableGrid.js
Normal file → Executable file
@ -27,12 +27,13 @@ define("tinymce/tableplugin/TableGrid", [
|
||||
}
|
||||
|
||||
return function(editor, table) {
|
||||
var grid, startPos, endPos, selectedCell, selection = editor.selection, dom = selection.dom;
|
||||
var grid, gridWidth, startPos, endPos, selectedCell, selection = editor.selection, dom = selection.dom;
|
||||
|
||||
function buildGrid() {
|
||||
var startY = 0;
|
||||
|
||||
grid = [];
|
||||
gridWidth = 0;
|
||||
|
||||
each(['thead', 'tbody', 'tfoot'], function(part) {
|
||||
var rows = dom.select('> ' + part + ' tr', table);
|
||||
@ -70,6 +71,8 @@ define("tinymce/tableplugin/TableGrid", [
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
gridWidth = Math.max(gridWidth, x + 1);
|
||||
});
|
||||
});
|
||||
|
||||
@ -114,7 +117,7 @@ define("tinymce/tableplugin/TableGrid", [
|
||||
|
||||
each(table.rows, function(row) {
|
||||
each(row.cells, function(cell) {
|
||||
if (dom.hasClass(cell, 'mce-item-selected') || cell == selectedCell.elm) {
|
||||
if (dom.hasClass(cell, 'mce-item-selected') || (selectedCell && cell == selectedCell.elm)) {
|
||||
rows.push(row);
|
||||
return false;
|
||||
}
|
||||
@ -182,7 +185,7 @@ define("tinymce/tableplugin/TableGrid", [
|
||||
if (formatNode) {
|
||||
cell.appendChild(formatNode);
|
||||
} else {
|
||||
if (!Env.ie) {
|
||||
if (!Env.ie || Env.ie > 10) {
|
||||
cell.innerHTML = '<br data-mce-bogus="1" />';
|
||||
}
|
||||
}
|
||||
@ -219,11 +222,14 @@ define("tinymce/tableplugin/TableGrid", [
|
||||
// Restore selection to start position if it still exists
|
||||
buildGrid();
|
||||
|
||||
// Restore the selection to the closest table position
|
||||
row = grid[Math.min(grid.length - 1, startPos.y)];
|
||||
if (row) {
|
||||
selection.select(row[Math.min(row.length - 1, startPos.x)].elm, true);
|
||||
selection.collapse(true);
|
||||
// If we have a valid startPos object
|
||||
if (startPos) {
|
||||
// Restore the selection to the closest table position
|
||||
row = grid[Math.min(grid.length - 1, startPos.y)];
|
||||
if (row) {
|
||||
selection.select(row[Math.min(row.length - 1, startPos.x)].elm, true);
|
||||
selection.collapse(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -311,11 +317,13 @@ define("tinymce/tableplugin/TableGrid", [
|
||||
});
|
||||
});
|
||||
|
||||
// Use selection
|
||||
startX = startPos.x;
|
||||
startY = startPos.y;
|
||||
endX = endPos.x;
|
||||
endY = endPos.y;
|
||||
// Use selection, but make sure startPos is valid before accessing
|
||||
if (startPos) {
|
||||
startX = startPos.x;
|
||||
startY = startPos.y;
|
||||
endX = endPos.x;
|
||||
endY = endPos.y;
|
||||
}
|
||||
}
|
||||
|
||||
// Find start/end cells
|
||||
@ -343,6 +351,7 @@ define("tinymce/tableplugin/TableGrid", [
|
||||
cell = grid[y][x].elm;
|
||||
|
||||
/*jshint loopfunc:true */
|
||||
/*eslint no-loop-func:0 */
|
||||
if (cell != startCell) {
|
||||
// Move children to startCell
|
||||
children = Tools.grep(cell.childNodes);
|
||||
@ -394,6 +403,11 @@ define("tinymce/tableplugin/TableGrid", [
|
||||
}
|
||||
});
|
||||
|
||||
// If posY is undefined there is nothing for us to do here...just return to avoid crashing below
|
||||
if (posY === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (x = 0; x < grid[0].length; x++) {
|
||||
// Cell not found could be because of an invalid table structure
|
||||
if (!grid[posY][x]) {
|
||||
@ -520,9 +534,7 @@ define("tinymce/tableplugin/TableGrid", [
|
||||
var rows;
|
||||
|
||||
function deleteRow(tr) {
|
||||
var nextTr, pos, lastCell;
|
||||
|
||||
nextTr = dom.getNext(tr, 'tr');
|
||||
var pos, lastCell;
|
||||
|
||||
// Move down row spanned cells
|
||||
each(tr.cells, function(cell) {
|
||||
@ -658,7 +670,7 @@ define("tinymce/tableplugin/TableGrid", [
|
||||
each(grid, function(row, y) {
|
||||
each(row, function(cell, x) {
|
||||
if (cell.elm == target) {
|
||||
pos = {x : x, y : y};
|
||||
pos = {x: x, y: y};
|
||||
return false;
|
||||
}
|
||||
});
|
||||
@ -713,7 +725,7 @@ define("tinymce/tableplugin/TableGrid", [
|
||||
});
|
||||
});
|
||||
|
||||
return {x : maxX, y : maxY};
|
||||
return {x: maxX, y: maxY};
|
||||
}
|
||||
|
||||
function setEndCell(cell) {
|
||||
@ -792,6 +804,34 @@ define("tinymce/tableplugin/TableGrid", [
|
||||
}
|
||||
}
|
||||
|
||||
function moveRelIdx(cellElm, delta) {
|
||||
var pos, index, cell;
|
||||
|
||||
pos = getPos(cellElm);
|
||||
index = pos.y * gridWidth + pos.x;
|
||||
|
||||
do {
|
||||
index += delta;
|
||||
cell = getCell(index % gridWidth, Math.floor(index / gridWidth));
|
||||
|
||||
if (!cell) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (cell.elm != cellElm) {
|
||||
selection.select(cell.elm, true);
|
||||
|
||||
if (dom.isEmpty(cell.elm)) {
|
||||
selection.collapse(true);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
} while (cell.elm == cellElm);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
table = table || dom.getParent(selection.getStart(), 'table');
|
||||
|
||||
buildGrid();
|
||||
@ -816,7 +856,9 @@ define("tinymce/tableplugin/TableGrid", [
|
||||
pasteRows: pasteRows,
|
||||
getPos: getPos,
|
||||
setStartCell: setStartCell,
|
||||
setEndCell: setEndCell
|
||||
setEndCell: setEndCell,
|
||||
moveRelIdx: moveRelIdx,
|
||||
refresh: buildGrid
|
||||
});
|
||||
};
|
||||
});
|
5
public/tinymce/plugins/table/plugin.dev.js
Normal file → Executable file
5
public/tinymce/plugins/table/plugin.dev.js
Normal file → Executable file
@ -106,14 +106,13 @@
|
||||
exports.define = define;
|
||||
exports.require = require;
|
||||
|
||||
expose(["tinymce/tableplugin/TableGrid","tinymce/tableplugin/Quirks","tinymce/tableplugin/CellSelection","tinymce/tableplugin/Plugin"]);
|
||||
|
||||
load('classes/TableGrid.js');
|
||||
load('classes/Quirks.js');
|
||||
load('classes/CellSelection.js');
|
||||
load('classes/Dialogs.js');
|
||||
load('classes/Plugin.js');
|
||||
|
||||
writeScripts();
|
||||
})(this);
|
||||
|
||||
// $hash: cc4206b9f467adfd42760ee5a6c3606f
|
||||
// $hash: 79c1674ebd5e6bf17b5996c1cdb2b5e2
|
1593
public/tinymce/plugins/table/plugin.js
Normal file → Executable file
1593
public/tinymce/plugins/table/plugin.js
Normal file → Executable file
File diff suppressed because it is too large
Load Diff
2
public/tinymce/plugins/table/plugin.min.js
vendored
Normal file → Executable file
2
public/tinymce/plugins/table/plugin.min.js
vendored
Normal file → Executable file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user