applied my changes - initial import
[boxroom-stian.git] / public / javascripts / tiny_mce / plugins / fullpage / editor_plugin_src.js
blob332f5f2c8ab30c361ab076033dab463c650adf2c
1 /**
2 * $Id: editor_plugin_src.js 126 2006-10-22 16:19:55Z spocke $
4 * @author Moxiecode
5 * @copyright Copyright © 2004-2006, Moxiecode Systems AB, All rights reserved.
6 */
8 /* Import plugin specific language pack */
9 tinyMCE.importPluginLanguagePack('fullpage');
11 var TinyMCE_FullPagePlugin = {
12 getInfo : function() {
13 return {
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) {
23 switch (cn) {
24 case "fullpage":
25 return tinyMCE.getButtonHTML(cn, 'lang_fullpage_desc', '{$pluginurl}/images/fullpage.gif', 'mceFullPageProperties');
28 return "";
31 execCommand : function(editor_id, element, command, user_interface, value) {
32 // Handle commands
33 switch (command) {
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"});
45 return true;
47 case "mceFullPageUpdate":
48 TinyMCE_FullPagePlugin._addToHead(tinyMCE.getInstanceById(editor_id));
49 return true;
52 // Pass to next handler in chain
53 return false;
56 cleanup : function(type, content, inst) {
57 switch (type) {
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
63 if (pos != -1) {
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);
69 } else {
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", "");
81 // Xml encode it
82 title = title.replace(/&/g, '&amp;');
83 title = title.replace(/\"/g, '&quot;');
84 title = title.replace(/</g, '&lt;');
85 title = title.replace(/>/g, '&gt;');
87 tmp = '';
89 // Make default chunk
90 if (pi)
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';
95 tmp += '<head>\n';
96 tmp += '\t<title>' + title + '</title>\n';
97 tmp += '\t<meta http-equiv="Content-Type" content="text/html; charset=' + enc + '" />\n';
98 tmp += '</head>\n';
99 tmp += '<body';
101 if (ff != '' || fz != '') {
102 tmp += ' style="';
104 if (ds != '')
105 tmp += ds + ";";
107 if (ff != '')
108 tmp += 'font-family: ' + ff + ";";
110 if (fz != '')
111 tmp += 'font-size: ' + fz + ";";
113 tmp += '"';
116 if (dtc != '')
117 tmp += ' text="' + dtc + '"';
119 tmp += '>\n';
121 inst.fullpageTopContent = tmp;
125 this._addToHead(inst);
127 break;
129 case "get_from_editor":
130 if (inst.fullpageTopContent)
131 content = inst.fullpageTopContent + content + "\n</body>\n</html>";
133 break;
136 // Pass through to next handler in chain
137 return content;
140 // Private plugin internal methods
142 _addToHead : function(inst) {
143 var doc = inst.getDoc();
144 var head = doc.getElementsByTagName("head")[0];
145 var body = doc.body;
146 var h = inst.fullpageTopContent;
147 var e = doc.createElement("body");
148 var nl, i, le, tmp;
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>');
162 // Make body a div
163 h = h.replace(/<body/gi, '<div mce_type="body"');
164 h += '</div>';
166 // Now crapy MSIE can parse it
167 e.innerHTML = h;
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]);
180 // Add link elements
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');
197 if (nl.length > 0) {
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);