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