annotate static/js/tiny_mce/plugins/legacyoutput/editor_plugin_src.js @ 645:99f7917702ca

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