LegacyInput.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /**
  2. * LegacyInput.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. tinymce.onAddEditor.add(function(tinymce, ed) {
  11. var filters, fontSizes, dom, settings = ed.settings;
  12. if (settings.inline_styles) {
  13. fontSizes = tinymce.explode(settings.font_size_legacy_values);
  14. function replaceWithSpan(node, styles) {
  15. tinymce.each(styles, function(value, name) {
  16. if (value)
  17. dom.setStyle(node, name, value);
  18. });
  19. dom.rename(node, 'span');
  20. };
  21. filters = {
  22. font : function(dom, node) {
  23. replaceWithSpan(node, {
  24. backgroundColor : node.style.backgroundColor,
  25. color : node.color,
  26. fontFamily : node.face,
  27. fontSize : fontSizes[parseInt(node.size) - 1]
  28. });
  29. },
  30. u : function(dom, node) {
  31. replaceWithSpan(node, {
  32. textDecoration : 'underline'
  33. });
  34. },
  35. strike : function(dom, node) {
  36. replaceWithSpan(node, {
  37. textDecoration : 'line-through'
  38. });
  39. }
  40. };
  41. function convert(editor, params) {
  42. dom = editor.dom;
  43. if (settings.convert_fonts_to_spans) {
  44. tinymce.each(dom.select('font,u,strike', params.node), function(node) {
  45. filters[node.nodeName.toLowerCase()](ed.dom, node);
  46. });
  47. }
  48. };
  49. ed.onPreProcess.add(convert);
  50. ed.onSetContent.add(convert);
  51. ed.onInit.add(function() {
  52. ed.selection.onSetContent.add(convert);
  53. });
  54. }
  55. });