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