Upgrade TinyMCE to v3.4.5
[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                                         schema = editor.schema;\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 : 'justify'}},\r
38 \r
39                                         // Change the basic formatting elements to use deprecated element types
40                                         bold : [\r
41                                                 {inline : 'b', remove : 'all'},\r
42                                                 {inline : 'strong', remove : 'all'},\r
43                                                 {inline : 'span', styles : {fontWeight : 'bold'}}\r
44                                         ],\r
45                                         italic : [\r
46                                                 {inline : 'i', remove : 'all'},\r
47                                                 {inline : 'em', remove : 'all'},\r
48                                                 {inline : 'span', styles : {fontStyle : 'italic'}}\r
49                                         ],\r
50                                         underline : [\r
51                                                 {inline : 'u', remove : 'all'},\r
52                                                 {inline : 'span', styles : {textDecoration : 'underline'}, exact : true}\r
53                                         ],\r
54                                         strikethrough : [\r
55                                                 {inline : 'strike', remove : 'all'},\r
56                                                 {inline : 'span', styles : {textDecoration: 'line-through'}, exact : true}\r
57                                         ],
58 \r
59                                         // Change font size and font family to use the deprecated font element\r
60                                         fontname : {inline : 'font', attributes : {face : '%value'}},\r
61                                         fontsize : {\r
62                                                 inline : 'font',\r
63                                                 attributes : {\r
64                                                         size : function(vars) {\r
65                                                                 return tinymce.inArray(fontSizes, vars.value) + 1;\r
66                                                         }\r
67                                                 }\r
68                                         },\r
69 \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
73                                 });\r
74 \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
78                                 });\r
79 \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
83 \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
87 \r
88                                         if (rule) {\r
89                                                 if (!rule.attributes.align) {\r
90                                                         rule.attributes.align = {};\r
91                                                         rule.attributesOrder.push('align');\r
92                                                 }\r
93                                         }\r
94                                 });\r
95 \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
99 \r
100                                         // Find font element get it's name and size\r
101                                         fontElm = editor.dom.getParent(editor.selection.getNode(), 'font');\r
102                                         if (fontElm) {\r
103                                                 fontName = fontElm.face;\r
104                                                 fontSize = fontElm.size;\r
105                                         }\r
106 \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
111                                                 });\r
112                                         }\r
113 \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
118 \r
119                                                         return index + 1 == fontSize;\r
120                                                 });\r
121                                         }\r
122                                 });\r
123                         });\r
124                 },\r
125 \r
126                 getInfo : function() {\r
127                         return {\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
133                         };\r
134                 }\r
135         });\r
136 \r
137         // Register plugin\r
138         tinymce.PluginManager.add('legacyoutput', tinymce.plugins.LegacyOutput);\r
139 })(tinymce);\r