/static/scripts/tiny_mce/plugins/fullpage/editor_plugin_src.js

http://n23.googlecode.com/ · JavaScript · 140 lines · 99 code · 30 blank · 11 comment · 15 complexity · 8841a568f97ff8da1128b0610d44b9ac MD5 · raw file

  1. /**
  2. * $Id: editor_plugin_src.js 827 2008-04-29 15:02:42Z spocke $
  3. *
  4. * @author Moxiecode
  5. * @copyright Copyright Š 2004-2008, Moxiecode Systems AB, All rights reserved.
  6. */
  7. (function() {
  8. tinymce.create('tinymce.plugins.FullPagePlugin', {
  9. init : function(ed, url) {
  10. var t = this;
  11. t.editor = ed;
  12. // Register commands
  13. ed.addCommand('mceFullPageProperties', function() {
  14. ed.windowManager.open({
  15. file : url + '/fullpage.htm',
  16. width : 430 + parseInt(ed.getLang('fullpage.delta_width', 0)),
  17. height : 495 + parseInt(ed.getLang('fullpage.delta_height', 0)),
  18. inline : 1
  19. }, {
  20. plugin_url : url,
  21. head_html : t.head
  22. });
  23. });
  24. // Register buttons
  25. ed.addButton('fullpage', {title : 'fullpage.desc', cmd : 'mceFullPageProperties'});
  26. ed.onBeforeSetContent.add(t._setContent, t);
  27. ed.onSetContent.add(t._setBodyAttribs, t);
  28. ed.onGetContent.add(t._getContent, t);
  29. },
  30. getInfo : function() {
  31. return {
  32. longname : 'Fullpage',
  33. author : 'Moxiecode Systems AB',
  34. authorurl : 'http://tinymce.moxiecode.com',
  35. infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/fullpage',
  36. version : tinymce.majorVersion + "." + tinymce.minorVersion
  37. };
  38. },
  39. // Private plugin internal methods
  40. _setBodyAttribs : function(ed, o) {
  41. var bdattr, i, len, kv, k, v, t, attr = this.head.match(/body(.*?)>/i);
  42. if (attr && attr[1]) {
  43. bdattr = attr[1].match(/\s*(\w+\s*=\s*".*?"|\w+\s*=\s*'.*?'|\w+\s*=\s*\w+|\w+)\s*/g);
  44. for(i = 0, len = bdattr.length; i < len; i++) {
  45. kv = bdattr[i].split('=');
  46. k = kv[0].replace(/\s/,'');
  47. v = kv[1];
  48. if (v) {
  49. v = v.replace(/^\s+/,'').replace(/\s+$/,'');
  50. t = v.match(/^["'](.*)["']$/);
  51. if (t)
  52. v = t[1];
  53. } else
  54. v = k;
  55. ed.dom.setAttrib(ed.getBody(), 'style', v);
  56. }
  57. }
  58. },
  59. _createSerializer : function() {
  60. return new tinymce.dom.Serializer({
  61. dom : this.editor.dom,
  62. apply_source_formatting : true
  63. });
  64. },
  65. _setContent : function(ed, o) {
  66. var t = this, sp, ep, c = o.content, v, st = '';
  67. // Parse out head, body and footer
  68. c = c.replace(/<(\/?)BODY/gi, '<$1body');
  69. sp = c.indexOf('<body');
  70. if (sp != -1) {
  71. sp = c.indexOf('>', sp);
  72. t.head = c.substring(0, sp + 1);
  73. ep = c.indexOf('</body', sp);
  74. if (ep == -1)
  75. ep = c.indexOf('</body', ep);
  76. o.content = c.substring(sp + 1, ep);
  77. t.foot = c.substring(ep);
  78. function low(s) {
  79. return s.replace(/<\/?[A-Z]+/g, function(a) {
  80. return a.toLowerCase();
  81. })
  82. };
  83. t.head = low(t.head);
  84. t.foot = low(t.foot);
  85. } else {
  86. t.head = '';
  87. if (ed.getParam('fullpage_default_xml_pi'))
  88. t.head += '<?xml version="1.0" encoding="' + ed.getParam('fullpage_default_encoding', 'ISO-8859-1') + '" ?>\n';
  89. t.head += ed.getParam('fullpage_default_doctype', '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
  90. t.head += '\n<html>\n<head>\n<title>' + ed.getParam('fullpage_default_title', 'Untitled document') + '</title>\n';
  91. if (v = ed.getParam('fullpage_default_encoding'))
  92. t.head += '<meta http-equiv="Content-Type" content="' + v + '" />\n';
  93. if (v = ed.getParam('fullpage_default_font_family'))
  94. st += 'font-family: ' + v + ';';
  95. if (v = ed.getParam('fullpage_default_font_size'))
  96. st += 'font-size: ' + v + ';';
  97. if (v = ed.getParam('fullpage_default_text_color'))
  98. st += 'color: ' + v + ';';
  99. t.head += '</head>\n<body' + (st ? ' style="' + st + '"' : '') + '>\n';
  100. t.foot = '\n</body>\n</html>';
  101. }
  102. },
  103. _getContent : function(ed, o) {
  104. var t = this;
  105. o.content = tinymce.trim(t.head) + '\n' + tinymce.trim(o.content) + '\n' + tinymce.trim(t.foot);
  106. }
  107. });
  108. // Register plugin
  109. tinymce.PluginManager.add('fullpage', tinymce.plugins.FullPagePlugin);
  110. })();