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