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 serializer = editor.serializer;
\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 : 'full'}},
\r
39 // Change the basic formatting elements to use deprecated element types
\r
40 bold : {inline : 'b'},
\r
41 italic : {inline : 'i'},
\r
42 underline : {inline : 'u'},
\r
43 strikethrough : {inline : 'strike'},
\r
45 // Change font size and font family to use the deprecated font element
\r
46 fontname : {inline : 'font', attributes : {face : '%value'}},
\r
50 size : function(vars) {
\r
51 return tinymce.inArray(fontSizes, vars.value) + 1;
\r
56 // Setup font elements for colors as well
\r
57 forecolor : {inline : 'font', styles : {color : '%value'}},
\r
58 hilitecolor : {inline : 'font', styles : {backgroundColor : '%value'}}
\r
61 // Force parsing of the serializer rules
\r
62 serializer._setup();
\r
64 // Check that deprecated elements are allowed if not add them
\r
65 tinymce.each('b,i,u,strike'.split(','), function(name) {
\r
66 var rule = serializer.rules[name];
\r
69 serializer.addRules(name);
\r
72 // Add font element if it's missing
\r
73 if (!serializer.rules["font"])
\r
74 serializer.addRules("font[face|size|color|style]");
\r
76 // Add the missing and depreacted align attribute for the serialization engine
\r
77 tinymce.each(alignElements.split(','), function(name) {
\r
78 var rule = serializer.rules[name], found;
\r
81 tinymce.each(rule.attribs, function(name, attr) {
\r
82 if (attr.name == 'align') {
\r
89 rule.attribs.push({name : 'align'});
\r
93 // Listen for the onNodeChange event so that we can do special logic for the font size and font name drop boxes
\r
94 editor.onNodeChange.add(function(editor, control_manager) {
\r
95 var control, fontElm, fontName, fontSize;
\r
97 // Find font element get it's name and size
\r
98 fontElm = editor.dom.getParent(editor.selection.getNode(), 'font');
\r
100 fontName = fontElm.face;
\r
101 fontSize = fontElm.size;
\r
104 // Select/unselect the font name in droplist
\r
105 if (control = control_manager.get('fontselect')) {
\r
106 control.select(function(value) {
\r
107 return value == fontName;
\r
111 // Select/unselect the font size in droplist
\r
112 if (control = control_manager.get('fontsizeselect')) {
\r
113 control.select(function(value) {
\r
114 var index = tinymce.inArray(fontSizes, value.fontSize);
\r
116 return index + 1 == fontSize;
\r
123 getInfo : function() {
\r
125 longname : 'LegacyOutput',
\r
126 author : 'Moxiecode Systems AB',
\r
127 authorurl : 'http://tinymce.moxiecode.com',
\r
128 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/legacyoutput',
\r
129 version : tinymce.majorVersion + "." + tinymce.minorVersion
\r
135 tinymce.PluginManager.add('legacyoutput', tinymce.plugins.LegacyOutput);
\r