Subversion-Projekte lars-tiefland.content-management

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
/**
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
					schema = editor.schema;
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 : 'justify'}},
38
 
39
					// Change the basic formatting elements to use deprecated element types
40
					bold : [
41
						{inline : 'b', remove : 'all'},
42
						{inline : 'strong', remove : 'all'},
43
						{inline : 'span', styles : {fontWeight : 'bold'}}
44
					],
45
					italic : [
46
						{inline : 'i', remove : 'all'},
47
						{inline : 'em', remove : 'all'},
48
						{inline : 'span', styles : {fontStyle : 'italic'}}
49
					],
50
					underline : [
51
						{inline : 'u', remove : 'all'},
52
						{inline : 'span', styles : {textDecoration : 'underline'}, exact : true}
53
					],
54
					strikethrough : [
55
						{inline : 'strike', remove : 'all'},
56
						{inline : 'span', styles : {textDecoration: 'line-through'}, exact : true}
57
					],
58
 
59
					// Change font size and font family to use the deprecated font element
60
					fontname : {inline : 'font', attributes : {face : '%value'}},
61
					fontsize : {
62
						inline : 'font',
63
						attributes : {
64
							size : function(vars) {
65
								return tinymce.inArray(fontSizes, vars.value) + 1;
66
							}
67
						}
68
					},
69
 
70
					// Setup font elements for colors as well
71
					forecolor : {inline : 'font', styles : {color : '%value'}},
72
					hilitecolor : {inline : 'font', styles : {backgroundColor : '%value'}}
73
				});
74
 
75
				// Check that deprecated elements are allowed if not add them
76
				tinymce.each('b,i,u,strike'.split(','), function(name) {
77
					schema.addValidElements(name + '[*]');
78
				});
79
 
80
				// Add font element if it's missing
81
				if (!schema.getElementRule("font"))
82
					schema.addValidElements("font[face|size|color|style]");
83
 
84
				// Add the missing and depreacted align attribute for the serialization engine
85
				tinymce.each(alignElements.split(','), function(name) {
86
					var rule = schema.getElementRule(name), found;
87
 
88
					if (rule) {
89
						if (!rule.attributes.align) {
90
							rule.attributes.align = {};
91
							rule.attributesOrder.push('align');
92
						}
93
					}
94
				});
95
 
96
				// Listen for the onNodeChange event so that we can do special logic for the font size and font name drop boxes
97
				editor.onNodeChange.add(function(editor, control_manager) {
98
					var control, fontElm, fontName, fontSize;
99
 
100
					// Find font element get it's name and size
101
					fontElm = editor.dom.getParent(editor.selection.getNode(), 'font');
102
					if (fontElm) {
103
						fontName = fontElm.face;
104
						fontSize = fontElm.size;
105
					}
106
 
107
					// Select/unselect the font name in droplist
108
					if (control = control_manager.get('fontselect')) {
109
						control.select(function(value) {
110
							return value == fontName;
111
						});
112
					}
113
 
114
					// Select/unselect the font size in droplist
115
					if (control = control_manager.get('fontsizeselect')) {
116
						control.select(function(value) {
117
							var index = tinymce.inArray(fontSizes, value.fontSize);
118
 
119
							return index + 1 == fontSize;
120
						});
121
					}
122
				});
123
			});
124
		},
125
 
126
		getInfo : function() {
127
			return {
128
				longname : 'LegacyOutput',
129
				author : 'Moxiecode Systems AB',
130
				authorurl : 'http://tinymce.moxiecode.com',
131
				infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/legacyoutput',
132
				version : tinymce.majorVersion + "." + tinymce.minorVersion
133
			};
134
		}
135
	});
136
 
137
	// Register plugin
138
	tinymce.PluginManager.add('legacyoutput', tinymce.plugins.LegacyOutput);
139
})(tinymce);