4 * Copyright 2009, Moxiecode Systems AB
5 * Released under LGPL License.
7 * License: http://tinymce.moxiecode.com/license
8 * Contributing: http://tinymce.moxiecode.com/contributing
10 * This plugin will force TinyMCE to produce deprecated legacy output such as font elements, u elements, align
11 * attributes and so forth. There are a few cases where these old items might be needed for example in email applications or with Flash
13 * However you should NOT use this plugin if you are building some system that produces web contents such as a CMS. All these elements are
14 * not apart of the newer specifications for HTML and XHTML.
18 // Override inline_styles setting to force TinyMCE to produce deprecated contents
19 tinymce.onAddEditor.addToTop(function(tinymce, editor) {
20 editor.settings.inline_styles = false;
23 // Create the legacy ouput plugin
24 tinymce.create('tinymce.plugins.LegacyOutput', {
25 init : function(editor) {
26 editor.onInit.add(function() {
27 var alignElements = 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img',
28 fontSizes = tinymce.explode(editor.settings.font_size_style_values),
29 schema = editor.schema;
31 // Override some internal formats to produce legacy elements and attributes
32 editor.formatter.register({
33 // Change alignment formats to use the deprecated align attribute
34 alignleft : {selector : alignElements, attributes : {align : 'left'}},
35 aligncenter : {selector : alignElements, attributes : {align : 'center'}},
36 alignright : {selector : alignElements, attributes : {align : 'right'}},
37 alignfull : {selector : alignElements, attributes : {align : 'justify'}},
39 // Change the basic formatting elements to use deprecated element types
41 {inline : 'b', remove : 'all'},
42 {inline : 'strong', remove : 'all'},
43 {inline : 'span', styles : {fontWeight : 'bold'}}
46 {inline : 'i', remove : 'all'},
47 {inline : 'em', remove : 'all'},
48 {inline : 'span', styles : {fontStyle : 'italic'}}
51 {inline : 'u', remove : 'all'},
52 {inline : 'span', styles : {textDecoration : 'underline'}, exact : true}
55 {inline : 'strike', remove : 'all'},
56 {inline : 'span', styles : {textDecoration: 'line-through'}, exact : true}
59 // Change font size and font family to use the deprecated font element
60 fontname : {inline : 'font', attributes : {face : '%value'}},
64 size : function(vars) {
65 return tinymce.inArray(fontSizes, vars.value) + 1;
70 // Setup font elements for colors as well
71 forecolor : {inline : 'font', styles : {color : '%value'}},
72 hilitecolor : {inline : 'font', styles : {backgroundColor : '%value'}}
75 // Check that deprecated elements are allowed if not add them
76 tinymce.each('b,i,u,strike'.split(','), function(name) {
77 schema.addValidElements(name + '[*]');
80 // Add font element if it's missing
81 if (!schema.getElementRule("font"))
82 schema.addValidElements("font[face|size|color|style]");
84 // Add the missing and depreacted align attribute for the serialization engine
85 tinymce.each(alignElements.split(','), function(name) {
86 var rule = schema.getElementRule(name), found;
89 if (!rule.attributes.align) {
90 rule.attributes.align = {};
91 rule.attributesOrder.push('align');
96 // Listen for the onNodeChange event so that we can do special logic for the font size and font name drop boxes
97 editor.onNodeChange.add(function(editor, control_manager) {
98 var control, fontElm, fontName, fontSize;
100 // Find font element get it's name and size
101 fontElm = editor.dom.getParent(editor.selection.getNode(), 'font');
103 fontName = fontElm.face;
104 fontSize = fontElm.size;
107 // Select/unselect the font name in droplist
108 if (control = control_manager.get('fontselect')) {
109 control.select(function(value) {
110 return value == fontName;
114 // Select/unselect the font size in droplist
115 if (control = control_manager.get('fontsizeselect')) {
116 control.select(function(value) {
117 var index = tinymce.inArray(fontSizes, value.fontSize);
119 return index + 1 == fontSize;
126 getInfo : function() {
128 longname : 'LegacyOutput',
129 author : 'Moxiecode Systems AB',
130 authorurl : 'http://tinymce.moxiecode.com',
131 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/legacyoutput',
132 version : tinymce.majorVersion + "." + tinymce.minorVersion
138 tinymce.PluginManager.add('legacyoutput', tinymce.plugins.LegacyOutput);