Upgrade TinyMCE
[citadel.git] / webcit / tiny_mce / plugins / legacyoutput / editor_plugin_src.js
1 /**\r
2  * editor_plugin_src.js\r
3  *\r
4  * Copyright 2009, Moxiecode Systems AB\r
5  * Released under LGPL License.\r
6  *\r
7  * License: http://tinymce.moxiecode.com/license\r
8  * Contributing: http://tinymce.moxiecode.com/contributing\r
9  *\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
12  *\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
15  */\r
16 \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
21         });\r
22 \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
30 \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
38 \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
44 \r
45                                         // Change font size and font family to use the deprecated font element\r
46                                         fontname : {inline : 'font', attributes : {face : '%value'}},\r
47                                         fontsize : {\r
48                                                 inline : 'font',\r
49                                                 attributes : {\r
50                                                         size : function(vars) {\r
51                                                                 return tinymce.inArray(fontSizes, vars.value) + 1;\r
52                                                         }\r
53                                                 }\r
54                                         },\r
55 \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
59                                 });\r
60 \r
61                                 // Force parsing of the serializer rules\r
62                                 serializer._setup();\r
63 \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
67 \r
68                                         if (!rule)\r
69                                                 serializer.addRules(name);\r
70                                 });\r
71 \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
75 \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
79 \r
80                                         if (rule) {\r
81                                                 tinymce.each(rule.attribs, function(name, attr) {\r
82                                                         if (attr.name == 'align') {\r
83                                                                 found = true;\r
84                                                                 return false;\r
85                                                         }\r
86                                                 });\r
87 \r
88                                                 if (!found)\r
89                                                         rule.attribs.push({name : 'align'});\r
90                                         }\r
91                                 });\r
92 \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
96 \r
97                                         // Find font element get it's name and size\r
98                                         fontElm = editor.dom.getParent(editor.selection.getNode(), 'font');\r
99                                         if (fontElm) {\r
100                                                 fontName = fontElm.face;\r
101                                                 fontSize = fontElm.size;\r
102                                         }\r
103 \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
108                                                 });\r
109                                         }\r
110 \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
115 \r
116                                                         return index + 1 == fontSize;\r
117                                                 });\r
118                                         }\r
119                                 });\r
120                         });\r
121                 },\r
122 \r
123                 getInfo : function() {\r
124                         return {\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
130                         };\r
131                 }\r
132         });\r
133 \r
134         // Register plugin\r
135         tinymce.PluginManager.add('legacyoutput', tinymce.plugins.LegacyOutput);\r
136 })(tinymce);