annotate static/js/tiny_mce/plugins/legacyoutput/editor_plugin_src.js @ 327:a1bf6cf49720

Modified the implementation of the avatar tag to look for an attribute 'user_profile' on the user object. If present, this is assumed to be the profile. This improves the performance of the member list and some forum views.
author Brian Neal <bgneal@gmail.com>
date Tue, 22 Feb 2011 02:11:26 +0000
parents 88b2b9cb8c1f
children 6c182ceb7147
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@312 29 serializer = editor.serializer;
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@312 37 alignfull : {selector : alignElements, attributes : {align : 'full'}},
bgneal@312 38
bgneal@312 39 // Change the basic formatting elements to use deprecated element types
bgneal@312 40 bold : {inline : 'b'},
bgneal@312 41 italic : {inline : 'i'},
bgneal@312 42 underline : {inline : 'u'},
bgneal@312 43 strikethrough : {inline : 'strike'},
bgneal@312 44
bgneal@312 45 // Change font size and font family to use the deprecated font element
bgneal@312 46 fontname : {inline : 'font', attributes : {face : '%value'}},
bgneal@312 47 fontsize : {
bgneal@312 48 inline : 'font',
bgneal@312 49 attributes : {
bgneal@312 50 size : function(vars) {
bgneal@312 51 return tinymce.inArray(fontSizes, vars.value) + 1;
bgneal@312 52 }
bgneal@312 53 }
bgneal@312 54 },
bgneal@312 55
bgneal@312 56 // Setup font elements for colors as well
bgneal@312 57 forecolor : {inline : 'font', styles : {color : '%value'}},
bgneal@312 58 hilitecolor : {inline : 'font', styles : {backgroundColor : '%value'}}
bgneal@312 59 });
bgneal@312 60
bgneal@312 61 // Force parsing of the serializer rules
bgneal@312 62 serializer._setup();
bgneal@312 63
bgneal@312 64 // Check that deprecated elements are allowed if not add them
bgneal@312 65 tinymce.each('b,i,u,strike'.split(','), function(name) {
bgneal@312 66 var rule = serializer.rules[name];
bgneal@312 67
bgneal@312 68 if (!rule)
bgneal@312 69 serializer.addRules(name);
bgneal@312 70 });
bgneal@312 71
bgneal@312 72 // Add font element if it's missing
bgneal@312 73 if (!serializer.rules["font"])
bgneal@312 74 serializer.addRules("font[face|size|color|style]");
bgneal@312 75
bgneal@312 76 // Add the missing and depreacted align attribute for the serialization engine
bgneal@312 77 tinymce.each(alignElements.split(','), function(name) {
bgneal@312 78 var rule = serializer.rules[name], found;
bgneal@312 79
bgneal@312 80 if (rule) {
bgneal@312 81 tinymce.each(rule.attribs, function(name, attr) {
bgneal@312 82 if (attr.name == 'align') {
bgneal@312 83 found = true;
bgneal@312 84 return false;
bgneal@312 85 }
bgneal@312 86 });
bgneal@312 87
bgneal@312 88 if (!found)
bgneal@312 89 rule.attribs.push({name : 'align'});
bgneal@312 90 }
bgneal@312 91 });
bgneal@312 92
bgneal@312 93 // Listen for the onNodeChange event so that we can do special logic for the font size and font name drop boxes
bgneal@312 94 editor.onNodeChange.add(function(editor, control_manager) {
bgneal@312 95 var control, fontElm, fontName, fontSize;
bgneal@312 96
bgneal@312 97 // Find font element get it's name and size
bgneal@312 98 fontElm = editor.dom.getParent(editor.selection.getNode(), 'font');
bgneal@312 99 if (fontElm) {
bgneal@312 100 fontName = fontElm.face;
bgneal@312 101 fontSize = fontElm.size;
bgneal@312 102 }
bgneal@312 103
bgneal@312 104 // Select/unselect the font name in droplist
bgneal@312 105 if (control = control_manager.get('fontselect')) {
bgneal@312 106 control.select(function(value) {
bgneal@312 107 return value == fontName;
bgneal@312 108 });
bgneal@312 109 }
bgneal@312 110
bgneal@312 111 // Select/unselect the font size in droplist
bgneal@312 112 if (control = control_manager.get('fontsizeselect')) {
bgneal@312 113 control.select(function(value) {
bgneal@312 114 var index = tinymce.inArray(fontSizes, value.fontSize);
bgneal@312 115
bgneal@312 116 return index + 1 == fontSize;
bgneal@312 117 });
bgneal@312 118 }
bgneal@312 119 });
bgneal@312 120 });
bgneal@312 121 },
bgneal@312 122
bgneal@312 123 getInfo : function() {
bgneal@312 124 return {
bgneal@312 125 longname : 'LegacyOutput',
bgneal@312 126 author : 'Moxiecode Systems AB',
bgneal@312 127 authorurl : 'http://tinymce.moxiecode.com',
bgneal@312 128 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/legacyoutput',
bgneal@312 129 version : tinymce.majorVersion + "." + tinymce.minorVersion
bgneal@312 130 };
bgneal@312 131 }
bgneal@312 132 });
bgneal@312 133
bgneal@312 134 // Register plugin
bgneal@312 135 tinymce.PluginManager.add('legacyoutput', tinymce.plugins.LegacyOutput);
bgneal@312 136 })(tinymce);