1 |
3 |
ahitrov@rambler.ru |
/** |
2 |
|
|
* editor_plugin_src.js |
3 |
|
|
* |
4 |
|
|
* Copyright 2009, Moxiecode Systems AB |
5 |
|
|
* Released under LGPL License. |
6 |
|
|
* |
7 |
|
|
* License: http://tinymce.moxiecode.com/license |
8 |
|
|
* Contributing: http://tinymce.moxiecode.com/contributing |
9 |
|
|
* |
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 |
12 |
|
|
* |
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. |
15 |
|
|
*/ |
16 |
|
|
|
17 |
|
|
(function(tinymce) { |
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; |
21 |
|
|
}); |
22 |
|
|
|
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 |
|
|
serializer = editor.serializer; |
30 |
|
|
|
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 : 'full'}}, |
38 |
|
|
|
39 |
|
|
// Change the basic formatting elements to use deprecated element types |
40 |
|
|
bold : {inline : 'b'}, |
41 |
|
|
italic : {inline : 'i'}, |
42 |
|
|
underline : {inline : 'u'}, |
43 |
|
|
strikethrough : {inline : 'strike'}, |
44 |
|
|
|
45 |
|
|
// Change font size and font family to use the deprecated font element |
46 |
|
|
fontname : {inline : 'font', attributes : {face : '%value'}}, |
47 |
|
|
fontsize : { |
48 |
|
|
inline : 'font', |
49 |
|
|
attributes : { |
50 |
|
|
size : function(vars) { |
51 |
|
|
return tinymce.inArray(fontSizes, vars.value) + 1; |
52 |
|
|
} |
53 |
|
|
} |
54 |
|
|
}, |
55 |
|
|
|
56 |
|
|
// Setup font elements for colors as well |
57 |
|
|
forecolor : {inline : 'font', styles : {color : '%value'}}, |
58 |
|
|
hilitecolor : {inline : 'font', styles : {backgroundColor : '%value'}}, |
59 |
|
|
}); |
60 |
|
|
|
61 |
|
|
// Force parsing of the serializer rules |
62 |
|
|
serializer._setup(); |
63 |
|
|
|
64 |
|
|
// Check that deprecated elements are allowed if not add them |
65 |
|
|
tinymce.each('b,i,u,strike'.split(','), function(name) { |
66 |
|
|
var rule = serializer.rules[name]; |
67 |
|
|
|
68 |
|
|
if (!rule) |
69 |
|
|
serializer.addRules(name); |
70 |
|
|
}); |
71 |
|
|
|
72 |
|
|
// Add font element if it's missing |
73 |
|
|
if (!serializer.rules["font"]) |
74 |
|
|
serializer.addRules("font[face|size|color|style]"); |
75 |
|
|
|
76 |
|
|
// Add the missing and depreacted align attribute for the serialization engine |
77 |
|
|
tinymce.each(alignElements.split(','), function(name) { |
78 |
|
|
var rule = serializer.rules[name], found; |
79 |
|
|
|
80 |
|
|
if (rule) { |
81 |
|
|
tinymce.each(rule.attribs, function(name, attr) { |
82 |
|
|
if (attr.name == 'align') { |
83 |
|
|
found = true; |
84 |
|
|
return false; |
85 |
|
|
} |
86 |
|
|
}); |
87 |
|
|
|
88 |
|
|
if (!found) |
89 |
|
|
rule.attribs.push({name : 'align'}); |
90 |
|
|
} |
91 |
|
|
}); |
92 |
|
|
|
93 |
|
|
// Listen for the onNodeChange event so that we can do special logic for the font size and font name drop boxes |
94 |
|
|
editor.onNodeChange.add(function(editor, control_manager) { |
95 |
|
|
var control, fontElm, fontName, fontSize; |
96 |
|
|
|
97 |
|
|
// Find font element get it's name and size |
98 |
|
|
fontElm = editor.dom.getParent(editor.selection.getNode(), 'font'); |
99 |
|
|
if (fontElm) { |
100 |
|
|
fontName = fontElm.face; |
101 |
|
|
fontSize = fontElm.size; |
102 |
|
|
} |
103 |
|
|
|
104 |
|
|
// Select/unselect the font name in droplist |
105 |
|
|
if (control = control_manager.get('fontselect')) { |
106 |
|
|
control.select(function(value) { |
107 |
|
|
return value == fontName; |
108 |
|
|
}); |
109 |
|
|
} |
110 |
|
|
|
111 |
|
|
// Select/unselect the font size in droplist |
112 |
|
|
if (control = control_manager.get('fontsizeselect')) { |
113 |
|
|
control.select(function(value) { |
114 |
|
|
var index = tinymce.inArray(fontSizes, value.fontSize); |
115 |
|
|
|
116 |
|
|
return index + 1 == fontSize; |
117 |
|
|
}); |
118 |
|
|
} |
119 |
|
|
}); |
120 |
|
|
}); |
121 |
|
|
}, |
122 |
|
|
|
123 |
|
|
getInfo : function() { |
124 |
|
|
return { |
125 |
|
|
longname : 'LegacyOutput', |
126 |
|
|
author : 'Moxiecode Systems AB', |
127 |
|
|
authorurl : 'http://tinymce.moxiecode.com', |
128 |
|
|
infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/legacyoutput', |
129 |
|
|
version : tinymce.majorVersion + "." + tinymce.minorVersion |
130 |
|
|
}; |
131 |
|
|
} |
132 |
|
|
}); |
133 |
|
|
|
134 |
|
|
// Register plugin |
135 |
|
|
tinymce.PluginManager.add('legacyoutput', tinymce.plugins.LegacyOutput); |
136 |
|
|
})(tinymce); |