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