bgneal@183: /** bgneal@183: * editor_plugin_src.js bgneal@183: * bgneal@183: * Copyright 2009, Moxiecode Systems AB bgneal@183: * Released under LGPL License. bgneal@183: * bgneal@183: * License: http://tinymce.moxiecode.com/license bgneal@183: * Contributing: http://tinymce.moxiecode.com/contributing bgneal@183: * bgneal@183: * This plugin will force TinyMCE to produce deprecated legacy output such as font elements, u elements, align bgneal@183: * 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: * bgneal@183: * 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: * not apart of the newer specifications for HTML and XHTML. bgneal@183: */ bgneal@183: bgneal@183: (function(tinymce) { bgneal@183: // Override inline_styles setting to force TinyMCE to produce deprecated contents bgneal@183: tinymce.onAddEditor.addToTop(function(tinymce, editor) { bgneal@183: editor.settings.inline_styles = false; bgneal@183: }); bgneal@183: bgneal@183: // Create the legacy ouput plugin bgneal@183: tinymce.create('tinymce.plugins.LegacyOutput', { bgneal@183: init : function(editor) { bgneal@183: editor.onInit.add(function() { bgneal@183: var alignElements = 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img', bgneal@183: fontSizes = tinymce.explode(editor.settings.font_size_style_values), bgneal@183: serializer = editor.serializer; bgneal@183: bgneal@183: // Override some internal formats to produce legacy elements and attributes bgneal@183: editor.formatter.register({ bgneal@183: // Change alignment formats to use the deprecated align attribute bgneal@183: alignleft : {selector : alignElements, attributes : {align : 'left'}}, bgneal@183: aligncenter : {selector : alignElements, attributes : {align : 'center'}}, bgneal@183: alignright : {selector : alignElements, attributes : {align : 'right'}}, bgneal@183: alignfull : {selector : alignElements, attributes : {align : 'full'}}, bgneal@183: bgneal@183: // Change the basic formatting elements to use deprecated element types bgneal@183: bold : {inline : 'b'}, bgneal@183: italic : {inline : 'i'}, bgneal@183: underline : {inline : 'u'}, bgneal@183: strikethrough : {inline : 'strike'}, bgneal@183: bgneal@183: // Change font size and font family to use the deprecated font element bgneal@183: fontname : {inline : 'font', attributes : {face : '%value'}}, bgneal@183: fontsize : { bgneal@183: inline : 'font', bgneal@183: attributes : { bgneal@183: size : function(vars) { bgneal@183: return tinymce.inArray(fontSizes, vars.value) + 1; bgneal@183: } bgneal@183: } bgneal@183: }, bgneal@183: bgneal@183: // Setup font elements for colors as well bgneal@183: forecolor : {inline : 'font', styles : {color : '%value'}}, bgneal@217: hilitecolor : {inline : 'font', styles : {backgroundColor : '%value'}} bgneal@183: }); bgneal@183: bgneal@183: // Force parsing of the serializer rules bgneal@183: serializer._setup(); bgneal@183: bgneal@183: // Check that deprecated elements are allowed if not add them bgneal@183: tinymce.each('b,i,u,strike'.split(','), function(name) { bgneal@183: var rule = serializer.rules[name]; bgneal@183: bgneal@183: if (!rule) bgneal@183: serializer.addRules(name); bgneal@183: }); bgneal@183: bgneal@183: // Add font element if it's missing bgneal@183: if (!serializer.rules["font"]) bgneal@183: serializer.addRules("font[face|size|color|style]"); bgneal@183: bgneal@183: // Add the missing and depreacted align attribute for the serialization engine bgneal@183: tinymce.each(alignElements.split(','), function(name) { bgneal@183: var rule = serializer.rules[name], found; bgneal@183: bgneal@183: if (rule) { bgneal@183: tinymce.each(rule.attribs, function(name, attr) { bgneal@183: if (attr.name == 'align') { bgneal@183: found = true; bgneal@183: return false; bgneal@183: } bgneal@183: }); bgneal@183: bgneal@183: if (!found) bgneal@183: rule.attribs.push({name : 'align'}); bgneal@183: } bgneal@183: }); bgneal@183: bgneal@183: // Listen for the onNodeChange event so that we can do special logic for the font size and font name drop boxes bgneal@183: editor.onNodeChange.add(function(editor, control_manager) { bgneal@183: var control, fontElm, fontName, fontSize; bgneal@183: bgneal@183: // Find font element get it's name and size bgneal@183: fontElm = editor.dom.getParent(editor.selection.getNode(), 'font'); bgneal@183: if (fontElm) { bgneal@183: fontName = fontElm.face; bgneal@183: fontSize = fontElm.size; bgneal@183: } bgneal@183: bgneal@183: // Select/unselect the font name in droplist bgneal@183: if (control = control_manager.get('fontselect')) { bgneal@183: control.select(function(value) { bgneal@183: return value == fontName; bgneal@183: }); bgneal@183: } bgneal@183: bgneal@183: // Select/unselect the font size in droplist bgneal@183: if (control = control_manager.get('fontsizeselect')) { bgneal@183: control.select(function(value) { bgneal@183: var index = tinymce.inArray(fontSizes, value.fontSize); bgneal@183: bgneal@183: return index + 1 == fontSize; bgneal@183: }); bgneal@183: } bgneal@183: }); bgneal@183: }); bgneal@183: }, bgneal@183: bgneal@183: getInfo : function() { bgneal@183: return { bgneal@183: longname : 'LegacyOutput', bgneal@183: author : 'Moxiecode Systems AB', bgneal@183: authorurl : 'http://tinymce.moxiecode.com', bgneal@183: infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/legacyoutput', bgneal@183: version : tinymce.majorVersion + "." + tinymce.minorVersion bgneal@183: }; bgneal@183: } bgneal@183: }); bgneal@183: bgneal@183: // Register plugin bgneal@183: tinymce.PluginManager.add('legacyoutput', tinymce.plugins.LegacyOutput); bgneal@183: })(tinymce);