annotate WebContent/jscripts/tiny_mce/plugins/legacyoutput/editor_plugin_src.js @ 6:5bb7cc86069c

restlet.jar
author dwinter
date Wed, 14 Mar 2012 16:21:45 +0100
parents 0be9d53a6967
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1 /**
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
2 * editor_plugin_src.js
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
3 *
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
4 * Copyright 2009, Moxiecode Systems AB
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
5 * Released under LGPL License.
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
6 *
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
7 * License: http://tinymce.moxiecode.com/license
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
8 * Contributing: http://tinymce.moxiecode.com/contributing
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
9 *
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
10 * This plugin will force TinyMCE to produce deprecated legacy output such as font elements, u elements, align
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
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
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
12 *
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
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
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
14 * not apart of the newer specifications for HTML and XHTML.
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
15 */
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
16
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
17 (function(tinymce) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
18 // Override inline_styles setting to force TinyMCE to produce deprecated contents
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
19 tinymce.onAddEditor.addToTop(function(tinymce, editor) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
20 editor.settings.inline_styles = false;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
21 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
22
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
23 // Create the legacy ouput plugin
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
24 tinymce.create('tinymce.plugins.LegacyOutput', {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
25 init : function(editor) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
26 editor.onInit.add(function() {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
27 var alignElements = 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img',
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
28 fontSizes = tinymce.explode(editor.settings.font_size_style_values),
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
29 schema = editor.schema;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
30
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
31 // Override some internal formats to produce legacy elements and attributes
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
32 editor.formatter.register({
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
33 // Change alignment formats to use the deprecated align attribute
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
34 alignleft : {selector : alignElements, attributes : {align : 'left'}},
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
35 aligncenter : {selector : alignElements, attributes : {align : 'center'}},
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
36 alignright : {selector : alignElements, attributes : {align : 'right'}},
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
37 alignfull : {selector : alignElements, attributes : {align : 'justify'}},
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
38
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
39 // Change the basic formatting elements to use deprecated element types
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
40 bold : [
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
41 {inline : 'b', remove : 'all'},
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
42 {inline : 'strong', remove : 'all'},
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
43 {inline : 'span', styles : {fontWeight : 'bold'}}
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
44 ],
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
45 italic : [
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
46 {inline : 'i', remove : 'all'},
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
47 {inline : 'em', remove : 'all'},
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
48 {inline : 'span', styles : {fontStyle : 'italic'}}
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
49 ],
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
50 underline : [
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
51 {inline : 'u', remove : 'all'},
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
52 {inline : 'span', styles : {textDecoration : 'underline'}, exact : true}
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
53 ],
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
54 strikethrough : [
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
55 {inline : 'strike', remove : 'all'},
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
56 {inline : 'span', styles : {textDecoration: 'line-through'}, exact : true}
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
57 ],
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
58
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
59 // Change font size and font family to use the deprecated font element
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
60 fontname : {inline : 'font', attributes : {face : '%value'}},
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
61 fontsize : {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
62 inline : 'font',
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
63 attributes : {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
64 size : function(vars) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
65 return tinymce.inArray(fontSizes, vars.value) + 1;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
66 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
67 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
68 },
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
69
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
70 // Setup font elements for colors as well
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
71 forecolor : {inline : 'font', styles : {color : '%value'}},
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
72 hilitecolor : {inline : 'font', styles : {backgroundColor : '%value'}}
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
73 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
74
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
75 // Check that deprecated elements are allowed if not add them
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
76 tinymce.each('b,i,u,strike'.split(','), function(name) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
77 schema.addValidElements(name + '[*]');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
78 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
79
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
80 // Add font element if it's missing
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
81 if (!schema.getElementRule("font"))
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
82 schema.addValidElements("font[face|size|color|style]");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
83
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
84 // Add the missing and depreacted align attribute for the serialization engine
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
85 tinymce.each(alignElements.split(','), function(name) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
86 var rule = schema.getElementRule(name), found;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
87
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
88 if (rule) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
89 if (!rule.attributes.align) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
90 rule.attributes.align = {};
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
91 rule.attributesOrder.push('align');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
92 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
93 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
94 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
95
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
96 // Listen for the onNodeChange event so that we can do special logic for the font size and font name drop boxes
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
97 editor.onNodeChange.add(function(editor, control_manager) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
98 var control, fontElm, fontName, fontSize;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
99
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
100 // Find font element get it's name and size
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
101 fontElm = editor.dom.getParent(editor.selection.getNode(), 'font');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
102 if (fontElm) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
103 fontName = fontElm.face;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
104 fontSize = fontElm.size;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
105 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
106
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
107 // Select/unselect the font name in droplist
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
108 if (control = control_manager.get('fontselect')) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
109 control.select(function(value) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
110 return value == fontName;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
111 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
112 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
113
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
114 // Select/unselect the font size in droplist
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
115 if (control = control_manager.get('fontsizeselect')) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
116 control.select(function(value) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
117 var index = tinymce.inArray(fontSizes, value.fontSize);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
118
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
119 return index + 1 == fontSize;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
120 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
121 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
122 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
123 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
124 },
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
125
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
126 getInfo : function() {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
127 return {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
128 longname : 'LegacyOutput',
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
129 author : 'Moxiecode Systems AB',
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
130 authorurl : 'http://tinymce.moxiecode.com',
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
131 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/legacyoutput',
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
132 version : tinymce.majorVersion + "." + tinymce.minorVersion
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
133 };
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
134 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
135 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
136
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
137 // Register plugin
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
138 tinymce.PluginManager.add('legacyoutput', tinymce.plugins.LegacyOutput);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
139 })(tinymce);