0
|
1 |
/**
|
|
2 |
* $Id: editor_plugin_src.js 1029 2009-02-24 22:32:21Z 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 |
if (o.source_view && ed.getParam('fullpage_hide_in_source_view'))
|
|
86 |
return;
|
|
87 |
|
|
88 |
// Parse out head, body and footer
|
|
89 |
c = c.replace(/<(\/?)BODY/gi, '<$1body');
|
|
90 |
sp = c.indexOf('<body');
|
|
91 |
|
|
92 |
if (sp != -1) {
|
|
93 |
sp = c.indexOf('>', sp);
|
|
94 |
t.head = c.substring(0, sp + 1);
|
|
95 |
|
|
96 |
ep = c.indexOf('</body', sp);
|
|
97 |
if (ep == -1)
|
|
98 |
ep = c.indexOf('</body', ep);
|
|
99 |
|
|
100 |
o.content = c.substring(sp + 1, ep);
|
|
101 |
t.foot = c.substring(ep);
|
|
102 |
|
|
103 |
function low(s) {
|
|
104 |
return s.replace(/<\/?[A-Z]+/g, function(a) {
|
|
105 |
return a.toLowerCase();
|
|
106 |
})
|
|
107 |
};
|
|
108 |
|
|
109 |
t.head = low(t.head);
|
|
110 |
t.foot = low(t.foot);
|
|
111 |
} else {
|
|
112 |
t.head = '';
|
|
113 |
if (ed.getParam('fullpage_default_xml_pi'))
|
|
114 |
t.head += '<?xml version="1.0" encoding="' + ed.getParam('fullpage_default_encoding', 'ISO-8859-1') + '" ?>\n';
|
|
115 |
|
|
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">');
|
|
117 |
t.head += '\n<html>\n<head>\n<title>' + ed.getParam('fullpage_default_title', 'Untitled document') + '</title>\n';
|
|
118 |
|
|
119 |
if (v = ed.getParam('fullpage_default_encoding'))
|
|
120 |
t.head += '<meta http-equiv="Content-Type" content="' + v + '" />\n';
|
|
121 |
|
|
122 |
if (v = ed.getParam('fullpage_default_font_family'))
|
|
123 |
st += 'font-family: ' + v + ';';
|
|
124 |
|
|
125 |
if (v = ed.getParam('fullpage_default_font_size'))
|
|
126 |
st += 'font-size: ' + v + ';';
|
|
127 |
|
|
128 |
if (v = ed.getParam('fullpage_default_text_color'))
|
|
129 |
st += 'color: ' + v + ';';
|
|
130 |
|
|
131 |
t.head += '</head>\n<body' + (st ? ' style="' + st + '"' : '') + '>\n';
|
|
132 |
t.foot = '\n</body>\n</html>';
|
|
133 |
}
|
|
134 |
},
|
|
135 |
|
|
136 |
_getContent : function(ed, o) {
|
|
137 |
var t = this;
|
|
138 |
|
|
139 |
if (!o.source_view || !ed.getParam('fullpage_hide_in_source_view'))
|
|
140 |
o.content = tinymce.trim(t.head) + '\n' + tinymce.trim(o.content) + '\n' + tinymce.trim(t.foot);
|
|
141 |
}
|
|
142 |
});
|
|
143 |
|
|
144 |
// Register plugin
|
|
145 |
tinymce.PluginManager.add('fullpage', tinymce.plugins.FullPagePlugin);
|
|
146 |
})(); |