2 * $Id: editor_plugin_src.js 126 2006-10-22 16:19:55Z spocke $
5 * @copyright Copyright © 2004-2006, 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://tinymce.moxiecode.com/tinymce/docs/plugin_fullpage.html',
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
)
131 content
= inst
.fullpageTopContent
+ content
+ "\n</body>\n</html>";
136 // Pass through to next handler in chain
140 // Private plugin internal methods
142 _addToHead : function(inst
) {
143 var doc
= inst
.getDoc();
144 var head
= doc
.getElementsByTagName("head")[0];
146 var h
= inst
.fullpageTopContent
;
147 var e
= doc
.createElement("body");
150 // Remove stuff we don't want
151 h
= h
.replace(/(\r|\n)/gi, '');
152 h
= h
.replace(/<\?[^\>]*\>/gi, '');
153 h
= h
.replace(/<\/?(!DOCTYPE|head|html)[^\>]*\>/gi, '');
154 h
= h
.replace(/<script(.*?)<\/script>/gi, '');
155 h
= h
.replace(/<title(.*?)<\/title>/gi, '');
156 h
= h
.replace(/<(meta|base)[^>]*>/gi, '');
158 // Make link and style elements into pre
159 h
= h
.replace(/<link([^>]*)\/>/gi, '<pre mce_type="link" $1></pre>');
160 //h = h.replace(/<style([^>]*)>(.*?)<\/style>/gi, '<pre mce_type="style" $1>$2</pre>');
163 h
= h
.replace(/<body/gi, '<div mce_type="body"');
166 // Now crapy MSIE can parse it
169 // Reset all body attributes
170 body
.vLink
= body
.aLink
= body
.link
= body
.text
= '';
171 body
.style
.cssText
= '';
173 // Delete all old links
174 nl
= head
.getElementsByTagName('link');
175 for (i
=0; i
<nl
.length
; i
++) {
176 if (tinyMCE
.getAttrib(nl
[i
], 'mce_head') == "true")
177 nl
[i
].parentNode
.removeChild(nl
[i
]);
181 nl
= e
.getElementsByTagName('pre');
182 for (i
=0; i
<nl
.length
; i
++) {
183 tmp
= tinyMCE
.getAttrib(nl
[i
], 'media');
184 if (tinyMCE
.getAttrib(nl
[i
], 'mce_type') == "link" && (tmp
== "" || tmp
== "screen" || tmp
== "all") && tinyMCE
.getAttrib(nl
[i
], 'rel') == "stylesheet") {
185 le
= doc
.createElement("link");
187 le
.rel
= "stylesheet";
188 le
.href
= tinyMCE
.getAttrib(nl
[i
], 'href');
189 le
.setAttribute("mce_head", "true");
191 head
.appendChild(le
);
195 // Add body attributes
196 nl
= e
.getElementsByTagName('div');
198 body
.style
.cssText
= tinyMCE
.getAttrib(nl
[0], 'style');
200 if ((tmp
= tinyMCE
.getAttrib(nl
[0], 'leftmargin')) != '' && body
.style
.marginLeft
== '')
201 body
.style
.marginLeft
= tmp
+ "px";
203 if ((tmp
= tinyMCE
.getAttrib(nl
[0], 'rightmargin')) != '' && body
.style
.marginRight
== '')
204 body
.style
.marginRight
= tmp
+ "px";
206 if ((tmp
= tinyMCE
.getAttrib(nl
[0], 'topmargin')) != '' && body
.style
.marginTop
== '')
207 body
.style
.marginTop
= tmp
+ "px";
209 if ((tmp
= tinyMCE
.getAttrib(nl
[0], 'bottommargin')) != '' && body
.style
.marginBottom
== '')
210 body
.style
.marginBottom
= tmp
+ "px";
212 body
.dir
= tinyMCE
.getAttrib(nl
[0], 'dir');
213 body
.vLink
= tinyMCE
.getAttrib(nl
[0], 'vlink');
214 body
.aLink
= tinyMCE
.getAttrib(nl
[0], 'alink');
215 body
.link
= tinyMCE
.getAttrib(nl
[0], 'link');
216 body
.text
= tinyMCE
.getAttrib(nl
[0], 'text');
218 if ((tmp
= tinyMCE
.getAttrib(nl
[0], 'background')) != '')
219 body
.style
.backgroundImage
= "url('" + tmp
+ "')";
221 if ((tmp
= tinyMCE
.getAttrib(nl
[0], 'bgcolor')) != '')
222 body
.style
.backgroundColor
= tmp
;
227 tinyMCE
.addPlugin("fullpage", TinyMCE_FullPagePlugin
);