2
* $Id: editor_plugin_src.js 232 2007-03-05 17:00:27Z spocke $
5
* @copyright Copyright ďż˝ 2004-2007, Moxiecode Systems AB, All rights reserved.
8
/* Import plugin specific language pack */
9
tinyMCE.importPluginLanguagePack('fullpage');
11
var TinyMCE_FullPagePlugin = {
12
getInfo : function() {
14
longname : 'Fullpage',
15
author : 'Moxiecode Systems AB',
16
authorurl : 'http://tinymce.moxiecode.com',
17
infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/fullpage',
18
version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion
22
getControlHTML : function(cn) {
25
return tinyMCE.getButtonHTML(cn, 'lang_fullpage_desc', '{$pluginurl}/images/fullpage.gif', 'mceFullPageProperties');
31
execCommand : function(editor_id, element, command, user_interface, value) {
34
case "mceFullPageProperties":
35
var template = new Array();
37
template['file'] = '../../plugins/fullpage/fullpage.htm';
38
template['width'] = 430;
39
template['height'] = 485 + (tinyMCE.isOpera ? 5 : 0);
41
template['width'] += tinyMCE.getLang('lang_fullpage_delta_width', 0);
42
template['height'] += tinyMCE.getLang('lang_fullpage_delta_height', 0);
44
tinyMCE.openWindow(template, {editor_id : editor_id, inline : "yes"});
47
case "mceFullPageUpdate":
48
TinyMCE_FullPagePlugin._addToHead(tinyMCE.getInstanceById(editor_id));
52
// Pass to next handler in chain
56
cleanup : function(type, content, inst) {
58
case "insert_to_editor":
59
var tmp = content.toLowerCase();
60
var pos = tmp.indexOf('<body'), pos2;
62
// Split page in header and body chunks
64
pos = tmp.indexOf('>', pos);
65
pos2 = tmp.lastIndexOf('</body>');
66
inst.fullpageTopContent = content.substring(0, pos + 1);
67
content = content.substring(pos + 1, pos2);
68
// tinyMCE.debug(inst.fullpageTopContent, content);
70
if (!inst.fullpageTopContent) {
71
var docType = tinyMCE.getParam("fullpage_default_doctype", '<!DOCTYPE html PUBLIC "-/'+'/W3C//DTD XHTML 1.0 Transitional/'+'/EN" "http:/'+'/www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
72
var enc = tinyMCE.getParam("fullpage_default_encoding", 'utf-8');
73
var title = tinyMCE.getParam("fullpage_default_title", 'Untitled document');
74
var lang = tinyMCE.getParam("fullpage_default_langcode", 'en');
75
var pi = tinyMCE.getParam("fullpage_default_xml_pi", true);
76
var ff = tinyMCE.getParam("fullpage_default_font_family", "");
77
var fz = tinyMCE.getParam("fullpage_default_font_size", "");
78
var ds = tinyMCE.getParam("fullpage_default_style", "");
79
var dtc = tinyMCE.getParam("fullpage_default_text_color", "");
82
title = title.replace(/&/g, '&');
83
title = title.replace(/\"/g, '"');
84
title = title.replace(/</g, '<');
85
title = title.replace(/>/g, '>');
91
tmp += '<?xml version="1.0" encoding="' + enc + '"?>\n';
93
tmp += docType + '\n';
94
tmp += '<html xmlns="http:/'+'/www.w3.org/1999/xhtml" lang="' + lang + '" xml:lang="' + lang + '">\n';
96
tmp += '\t<title>' + title + '</title>\n';
97
tmp += '\t<meta http-equiv="Content-Type" content="text/html; charset=' + enc + '" />\n';
101
if (ff != '' || fz != '') {
108
tmp += 'font-family: ' + ff + ";";
111
tmp += 'font-size: ' + fz + ";";
117
tmp += ' text="' + dtc + '"';
121
inst.fullpageTopContent = tmp;
125
this._addToHead(inst);
129
case "get_from_editor":
130
if (inst.fullpageTopContent && !tinyMCE.getParam("fullpage_hide_in_source_view", false)) {
131
content = content.replace(/(\s)?mce\_[a-z_]+\=[^\s>]+(\s|\>)/i, ''); // Remove internal stuff
132
content = inst.fullpageTopContent + content + "\n</body>\n</html>";
137
case "submit_content":
138
if (inst.fullpageTopContent && tinyMCE.getParam("fullpage_hide_in_source_view", false))
139
content = inst.fullpageTopContent + content + "\n</body>\n</html>";
144
// Pass through to next handler in chain
148
// Private plugin internal methods
150
_addToHead : function(inst) {
151
var doc = inst.getDoc();
152
var head = doc.getElementsByTagName("head")[0];
154
var h = inst.fullpageTopContent;
155
var e = doc.createElement("body");
158
// Remove stuff we don't want
159
h = h.replace(/(\r|\n)/gi, '');
160
h = h.replace(/<\?[^\>]*\>/gi, '');
161
h = h.replace(/<\/?(!DOCTYPE|head|html)[^\>]*\>/gi, '');
162
h = h.replace(/<script(.*?)<\/script>/gi, '');
163
h = h.replace(/<title(.*?)<\/title>/gi, '');
164
h = h.replace(/<(meta|base)[^>]*>/gi, '');
166
// Make link and style elements into pre
167
h = h.replace(/<link([^>]*)\/>/gi, '<pre mce_type="link" $1></pre>');
168
//h = h.replace(/<style([^>]*)>(.*?)<\/style>/gi, '<pre mce_type="style" $1>$2</pre>');
171
h = h.replace(/<body/gi, '<div mce_type="body"');
174
// Now crapy MSIE can parse it
177
// Reset all body attributes
178
body.vLink = body.aLink = body.link = body.text = '';
179
body.style.cssText = '';
181
// Delete all old links
182
nl = head.getElementsByTagName('link');
183
for (i=0; i<nl.length; i++) {
184
if (tinyMCE.getAttrib(nl[i], 'mce_head') == "true")
185
nl[i].parentNode.removeChild(nl[i]);
189
nl = e.getElementsByTagName('pre');
190
for (i=0; i<nl.length; i++) {
191
tmp = tinyMCE.getAttrib(nl[i], 'media');
192
if (tinyMCE.getAttrib(nl[i], 'mce_type') == "link" && (tmp == "" || tmp == "screen" || tmp == "all") && tinyMCE.getAttrib(nl[i], 'rel') == "stylesheet") {
193
le = doc.createElement("link");
195
le.rel = "stylesheet";
196
le.href = tinyMCE.getAttrib(nl[i], 'href');
197
le.setAttribute("mce_head", "true");
199
head.appendChild(le);
203
// Add body attributes
204
nl = e.getElementsByTagName('div');
206
body.style.cssText = tinyMCE.getAttrib(nl[0], 'style');
208
if ((tmp = tinyMCE.getAttrib(nl[0], 'leftmargin')) != '' && body.style.marginLeft == '')
209
body.style.marginLeft = tmp + "px";
211
if ((tmp = tinyMCE.getAttrib(nl[0], 'rightmargin')) != '' && body.style.marginRight == '')
212
body.style.marginRight = tmp + "px";
214
if ((tmp = tinyMCE.getAttrib(nl[0], 'topmargin')) != '' && body.style.marginTop == '')
215
body.style.marginTop = tmp + "px";
217
if ((tmp = tinyMCE.getAttrib(nl[0], 'bottommargin')) != '' && body.style.marginBottom == '')
218
body.style.marginBottom = tmp + "px";
220
body.dir = tinyMCE.getAttrib(nl[0], 'dir');
221
body.vLink = tinyMCE.getAttrib(nl[0], 'vlink');
222
body.aLink = tinyMCE.getAttrib(nl[0], 'alink');
223
body.link = tinyMCE.getAttrib(nl[0], 'link');
224
body.text = tinyMCE.getAttrib(nl[0], 'text');
226
if ((tmp = tinyMCE.getAttrib(nl[0], 'background')) != '')
227
body.style.backgroundImage = "url('" + tmp + "')";
229
if ((tmp = tinyMCE.getAttrib(nl[0], 'bgcolor')) != '')
230
body.style.backgroundColor = tmp;
235
tinyMCE.addPlugin("fullpage", TinyMCE_FullPagePlugin);