annotate media/js/tiny_mce/plugins/legacyoutput/editor_plugin_src.js @ 217:237710206167

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