init
This commit is contained in:
15
public/tinymce/src/plugins/legacyoutput/demo/html/demo.html
Normal file
15
public/tinymce/src/plugins/legacyoutput/demo/html/demo.html
Normal file
@@ -0,0 +1,15 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Plugin: legacyoutput Demo Page</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h2>Plugin: legacyoutput Demo Page</h2>
|
||||
<div id="ephox-ui">
|
||||
<textarea name="" id="" cols="30" rows="10" class="tinymce"><font size="3">font</font><u>underline</u><strike>strike</strike></textarea>
|
||||
</div>
|
||||
<script src="../../../../../js/tinymce/tinymce.js"></script>
|
||||
<script src="../../../../../scratch/demos/plugins/legacyoutput/demo.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
22
public/tinymce/src/plugins/legacyoutput/demo/ts/demo/Demo.ts
Normal file
22
public/tinymce/src/plugins/legacyoutput/demo/ts/demo/Demo.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Demo.js
|
||||
*
|
||||
* Released under LGPL License.
|
||||
* Copyright (c) 1999-2017 Ephox Corp. All rights reserved
|
||||
*
|
||||
* License: http://www.tinymce.com/license
|
||||
* Contributing: http://www.tinymce.com/contributing
|
||||
*/
|
||||
|
||||
declare let tinymce: any;
|
||||
|
||||
tinymce.init({
|
||||
selector: 'textarea.tinymce',
|
||||
theme: 'modern',
|
||||
skin_url: '../../../../../js/tinymce/skins/lightgray',
|
||||
plugins: 'legacyoutput code',
|
||||
toolbar: 'legacyoutput fontselect fontsizeselect code',
|
||||
height: 600
|
||||
});
|
||||
|
||||
export {};
|
||||
24
public/tinymce/src/plugins/legacyoutput/main/ts/Plugin.ts
Normal file
24
public/tinymce/src/plugins/legacyoutput/main/ts/Plugin.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* Copyright (c) Tiny Technologies, Inc. All rights reserved.
|
||||
* Licensed under the LGPL or a commercial license.
|
||||
* For LGPL see License.txt in the project root for license information.
|
||||
* For commercial licenses see https://www.tiny.cloud/
|
||||
*/
|
||||
|
||||
import PluginManager from 'tinymce/core/api/PluginManager';
|
||||
import Formats from './core/Formats';
|
||||
import Buttons from './ui/Buttons';
|
||||
|
||||
/**
|
||||
* This class contains all core logic for the legacyoutput plugin.
|
||||
*
|
||||
* @class tinymce.legacyoutput.Plugin
|
||||
* @private
|
||||
*/
|
||||
|
||||
PluginManager.add('legacyoutput', function (editor) {
|
||||
Formats.setup(editor);
|
||||
Buttons.register(editor);
|
||||
});
|
||||
|
||||
export default function () { }
|
||||
@@ -0,0 +1,91 @@
|
||||
/**
|
||||
* Copyright (c) Tiny Technologies, Inc. All rights reserved.
|
||||
* Licensed under the LGPL or a commercial license.
|
||||
* For LGPL see License.txt in the project root for license information.
|
||||
* For commercial licenses see https://www.tiny.cloud/
|
||||
*/
|
||||
|
||||
import Tools from 'tinymce/core/api/util/Tools';
|
||||
|
||||
const overrideFormats = function (editor) {
|
||||
const alignElements = 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img',
|
||||
fontSizes = Tools.explode(editor.settings.font_size_style_values),
|
||||
schema = editor.schema;
|
||||
|
||||
// Override some internal formats to produce legacy elements and attributes
|
||||
editor.formatter.register({
|
||||
// Change alignment formats to use the deprecated align attribute
|
||||
alignleft: { selector: alignElements, attributes: { align: 'left' } },
|
||||
aligncenter: { selector: alignElements, attributes: { align: 'center' } },
|
||||
alignright: { selector: alignElements, attributes: { align: 'right' } },
|
||||
alignjustify: { selector: alignElements, attributes: { align: 'justify' } },
|
||||
|
||||
// Change the basic formatting elements to use deprecated element types
|
||||
bold: [
|
||||
{ inline: 'b', remove: 'all' },
|
||||
{ inline: 'strong', remove: 'all' },
|
||||
{ inline: 'span', styles: { fontWeight: 'bold' } }
|
||||
],
|
||||
italic: [
|
||||
{ inline: 'i', remove: 'all' },
|
||||
{ inline: 'em', remove: 'all' },
|
||||
{ inline: 'span', styles: { fontStyle: 'italic' } }
|
||||
],
|
||||
underline: [
|
||||
{ inline: 'u', remove: 'all' },
|
||||
{ inline: 'span', styles: { textDecoration: 'underline' }, exact: true }
|
||||
],
|
||||
strikethrough: [
|
||||
{ inline: 'strike', remove: 'all' },
|
||||
{ inline: 'span', styles: { textDecoration: 'line-through' }, exact: true }
|
||||
],
|
||||
|
||||
// Change font size and font family to use the deprecated font element
|
||||
fontname: { inline: 'font', attributes: { face: '%value' } },
|
||||
fontsize: {
|
||||
inline: 'font',
|
||||
attributes: {
|
||||
size (vars) {
|
||||
return Tools.inArray(fontSizes, vars.value) + 1;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// Setup font elements for colors as well
|
||||
forecolor: { inline: 'font', attributes: { color: '%value' } },
|
||||
hilitecolor: { inline: 'font', styles: { backgroundColor: '%value' } }
|
||||
});
|
||||
|
||||
// Check that deprecated elements are allowed if not add them
|
||||
Tools.each('b,i,u,strike'.split(','), function (name) {
|
||||
schema.addValidElements(name + '[*]');
|
||||
});
|
||||
|
||||
// Add font element if it's missing
|
||||
if (!schema.getElementRule('font')) {
|
||||
schema.addValidElements('font[face|size|color|style]');
|
||||
}
|
||||
|
||||
// Add the missing and depreacted align attribute for the serialization engine
|
||||
Tools.each(alignElements.split(','), function (name) {
|
||||
const rule = schema.getElementRule(name);
|
||||
|
||||
if (rule) {
|
||||
if (!rule.attributes.align) {
|
||||
rule.attributes.align = {};
|
||||
rule.attributesOrder.push('align');
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const setup = function (editor) {
|
||||
editor.settings.inline_styles = false;
|
||||
editor.on('init', function () {
|
||||
overrideFormats(editor);
|
||||
});
|
||||
};
|
||||
|
||||
export default {
|
||||
setup
|
||||
};
|
||||
125
public/tinymce/src/plugins/legacyoutput/main/ts/ui/Buttons.ts
Normal file
125
public/tinymce/src/plugins/legacyoutput/main/ts/ui/Buttons.ts
Normal file
@@ -0,0 +1,125 @@
|
||||
/**
|
||||
* Copyright (c) Tiny Technologies, Inc. All rights reserved.
|
||||
* Licensed under the LGPL or a commercial license.
|
||||
* For LGPL see License.txt in the project root for license information.
|
||||
* For commercial licenses see https://www.tiny.cloud/
|
||||
*/
|
||||
|
||||
const register = function (editor) {
|
||||
editor.addButton('fontsizeselect', function () {
|
||||
const items = [], defaultFontsizeFormats = '8pt=1 10pt=2 12pt=3 14pt=4 18pt=5 24pt=6 36pt=7';
|
||||
const fontsizeFormats = editor.settings.fontsizeFormats || defaultFontsizeFormats;
|
||||
|
||||
editor.$.each(fontsizeFormats.split(' '), function (i, item) {
|
||||
let text = item, value = item;
|
||||
const values = item.split('=');
|
||||
|
||||
if (values.length > 1) {
|
||||
text = values[0];
|
||||
value = values[1];
|
||||
}
|
||||
|
||||
items.push({ text, value });
|
||||
});
|
||||
|
||||
return {
|
||||
type: 'listbox',
|
||||
text: 'Font Sizes',
|
||||
tooltip: 'Font Sizes',
|
||||
values: items,
|
||||
fixedWidth: true,
|
||||
onPostRender () {
|
||||
const self = this;
|
||||
|
||||
editor.on('NodeChange', function () {
|
||||
let fontElm;
|
||||
|
||||
fontElm = editor.dom.getParent(editor.selection.getNode(), 'font');
|
||||
if (fontElm) {
|
||||
self.value(fontElm.size);
|
||||
} else {
|
||||
self.value('');
|
||||
}
|
||||
});
|
||||
},
|
||||
onclick (e) {
|
||||
if (e.control.settings.value) {
|
||||
editor.execCommand('FontSize', false, e.control.settings.value);
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
editor.addButton('fontselect', function () {
|
||||
function createFormats(formats) {
|
||||
formats = formats.replace(/;$/, '').split(';');
|
||||
|
||||
let i = formats.length;
|
||||
while (i--) {
|
||||
formats[i] = formats[i].split('=');
|
||||
}
|
||||
|
||||
return formats;
|
||||
}
|
||||
|
||||
const defaultFontsFormats =
|
||||
'Andale Mono=andale mono,monospace;' +
|
||||
'Arial=arial,helvetica,sans-serif;' +
|
||||
'Arial Black=arial black,sans-serif;' +
|
||||
'Book Antiqua=book antiqua,palatino,serif;' +
|
||||
'Comic Sans MS=comic sans ms,sans-serif;' +
|
||||
'Courier New=courier new,courier,monospace;' +
|
||||
'Georgia=georgia,palatino,serif;' +
|
||||
'Helvetica=helvetica,arial,sans-serif;' +
|
||||
'Impact=impact,sans-serif;' +
|
||||
'Symbol=symbol;' +
|
||||
'Tahoma=tahoma,arial,helvetica,sans-serif;' +
|
||||
'Terminal=terminal,monaco,monospace;' +
|
||||
'Times New Roman=times new roman,times,serif;' +
|
||||
'Trebuchet MS=trebuchet ms,geneva,sans-serif;' +
|
||||
'Verdana=verdana,geneva,sans-serif;' +
|
||||
'Webdings=webdings;' +
|
||||
'Wingdings=wingdings,zapf dingbats';
|
||||
|
||||
const items = [], fonts = createFormats(editor.settings.font_formats || defaultFontsFormats);
|
||||
|
||||
editor.$.each(fonts, function (i, font) {
|
||||
items.push({
|
||||
text: { raw: font[0] },
|
||||
value: font[1],
|
||||
textStyle: font[1].indexOf('dings') === -1 ? 'font-family:' + font[1] : ''
|
||||
});
|
||||
});
|
||||
|
||||
return {
|
||||
type: 'listbox',
|
||||
text: 'Font Family',
|
||||
tooltip: 'Font Family',
|
||||
values: items,
|
||||
fixedWidth: true,
|
||||
onPostRender () {
|
||||
const self = this;
|
||||
|
||||
editor.on('NodeChange', function () {
|
||||
let fontElm;
|
||||
|
||||
fontElm = editor.dom.getParent(editor.selection.getNode(), 'font');
|
||||
if (fontElm) {
|
||||
self.value(fontElm.face);
|
||||
} else {
|
||||
self.value('');
|
||||
}
|
||||
});
|
||||
},
|
||||
onselect (e) {
|
||||
if (e.control.settings.value) {
|
||||
editor.execCommand('FontName', false, e.control.settings.value);
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
export default {
|
||||
register
|
||||
};
|
||||
@@ -0,0 +1,104 @@
|
||||
import { Pipeline } from '@ephox/agar';
|
||||
import { UnitTest } from '@ephox/bedrock';
|
||||
import { LegacyUnit, TinyLoader } from '@ephox/mcagar';
|
||||
|
||||
import Plugin from 'tinymce/plugins/legacyoutput/Plugin';
|
||||
import Theme from 'tinymce/themes/modern/Theme';
|
||||
|
||||
UnitTest.asynctest(
|
||||
'browser.tinymce.plugins.legacyoutput.LegacyOutputPluginTest',
|
||||
function () {
|
||||
const success = arguments[arguments.length - 2];
|
||||
const failure = arguments[arguments.length - 1];
|
||||
const suite = LegacyUnit.createSuite();
|
||||
|
||||
Plugin();
|
||||
Theme();
|
||||
|
||||
suite.test('Font color', function (editor) {
|
||||
editor.focus();
|
||||
editor.setContent('<p>text</p>');
|
||||
LegacyUnit.setSelection(editor, 'p', 0, 'p', 4);
|
||||
editor.execCommand('forecolor', false, '#FF0000');
|
||||
LegacyUnit.equal(editor.getContent().toLowerCase(), '<p><font color="#ff0000">text</font></p>');
|
||||
});
|
||||
|
||||
suite.test('Font size', function (editor) {
|
||||
editor.setContent('<p>text</p>');
|
||||
LegacyUnit.setSelection(editor, 'p', 0, 'p', 4);
|
||||
editor.execCommand('fontsize', false, 7);
|
||||
LegacyUnit.equal(editor.getContent(), '<p><font size="7">text</font></p>');
|
||||
});
|
||||
|
||||
suite.test('Font face', function (editor) {
|
||||
editor.setContent('<p>text</p>');
|
||||
LegacyUnit.setSelection(editor, 'p', 0, 'p', 4);
|
||||
editor.execCommand('fontname', false, 'times');
|
||||
LegacyUnit.equal(editor.getContent(), '<p><font face="times">text</font></p>');
|
||||
});
|
||||
|
||||
suite.test('Bold', function (editor) {
|
||||
editor.setContent('<p>text</p>');
|
||||
LegacyUnit.setSelection(editor, 'p', 0, 'p', 4);
|
||||
editor.execCommand('bold');
|
||||
LegacyUnit.equal(editor.getContent(), '<p><b>text</b></p>');
|
||||
});
|
||||
|
||||
suite.test('Italic', function (editor) {
|
||||
editor.setContent('<p>text</p>');
|
||||
LegacyUnit.setSelection(editor, 'p', 0, 'p', 4);
|
||||
editor.execCommand('italic');
|
||||
LegacyUnit.equal(editor.getContent(), '<p><i>text</i></p>');
|
||||
});
|
||||
|
||||
suite.test('Underline', function (editor) {
|
||||
editor.setContent('<p>text</p>');
|
||||
LegacyUnit.setSelection(editor, 'p', 0, 'p', 4);
|
||||
editor.execCommand('underline');
|
||||
LegacyUnit.equal(editor.getContent(), '<p><u>text</u></p>');
|
||||
});
|
||||
|
||||
suite.test('Strikethrough', function (editor) {
|
||||
editor.setContent('<p>text</p>');
|
||||
LegacyUnit.setSelection(editor, 'p', 0, 'p', 4);
|
||||
editor.execCommand('strikethrough');
|
||||
LegacyUnit.equal(editor.getContent(), '<p><strike>text</strike></p>');
|
||||
});
|
||||
|
||||
suite.test('Justifyleft', function (editor) {
|
||||
editor.setContent('<p>text</p>');
|
||||
LegacyUnit.setSelection(editor, 'p', 0, 'p', 4);
|
||||
editor.execCommand('justifyleft');
|
||||
LegacyUnit.equal(editor.getContent(), '<p align="left">text</p>');
|
||||
});
|
||||
|
||||
suite.test('Justifycenter', function (editor) {
|
||||
editor.setContent('<p>text</p>');
|
||||
LegacyUnit.setSelection(editor, 'p', 0, 'p', 4);
|
||||
editor.execCommand('justifycenter');
|
||||
LegacyUnit.equal(editor.getContent(), '<p align="center">text</p>');
|
||||
});
|
||||
|
||||
suite.test('Justifyright', function (editor) {
|
||||
editor.setContent('<p>text</p>');
|
||||
LegacyUnit.setSelection(editor, 'p', 0, 'p', 4);
|
||||
editor.execCommand('justifyright');
|
||||
LegacyUnit.equal(editor.getContent(), '<p align="right">text</p>');
|
||||
});
|
||||
|
||||
suite.test('Justifyfull', function (editor) {
|
||||
editor.setContent('<p>text</p>');
|
||||
LegacyUnit.setSelection(editor, 'p', 0, 'p', 4);
|
||||
editor.execCommand('justifyfull');
|
||||
LegacyUnit.equal(editor.getContent(), '<p align="justify">text</p>');
|
||||
});
|
||||
|
||||
TinyLoader.setup(function (editor, onSuccess, onFailure) {
|
||||
Pipeline.async({}, suite.toSteps(editor), onSuccess, onFailure);
|
||||
}, {
|
||||
plugins: 'legacyoutput',
|
||||
indent: false,
|
||||
skin_url: '/project/js/tinymce/skins/lightgray'
|
||||
}, success, failure);
|
||||
}
|
||||
);
|
||||
Reference in New Issue
Block a user