PageRenderTime 27ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/BlogEngine/BlogEngine.NET/editors/tiny_mce_3_4_3_1/plugins/legacyoutput/editor_plugin_src.js

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