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