1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
|
/**
* $Id: editor_plugin_src.js 126 2006-10-22 16:19:55Z spocke $
*
* @author Moxiecode
* @copyright Copyright 2004-2006, Moxiecode Systems AB, All rights reserved.
*/
/* Import plugin specific language pack */
tinyMCE.importPluginLanguagePack('fullpage');
var TinyMCE_FullPagePlugin = {
getInfo : function() {
return {
longname : 'Fullpage',
author : 'Moxiecode Systems AB',
authorurl : 'http://tinymce.moxiecode.com',
infourl : 'http://tinymce.moxiecode.com/tinymce/docs/plugin_fullpage.html',
version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion
};
},
getControlHTML : function(cn) {
switch (cn) {
case "fullpage":
return tinyMCE.getButtonHTML(cn, 'lang_fullpage_desc', '{$pluginurl}/images/fullpage.gif', 'mceFullPageProperties');
}
return "";
},
execCommand : function(editor_id, element, command, user_interface, value) {
// Handle commands
switch (command) {
case "mceFullPageProperties":
var template = new Array();
template['file'] = '../../plugins/fullpage/fullpage.htm';
template['width'] = 430;
template['height'] = 485 + (tinyMCE.isOpera ? 5 : 0);
template['width'] += tinyMCE.getLang('lang_fullpage_delta_width', 0);
template['height'] += tinyMCE.getLang('lang_fullpage_delta_height', 0);
tinyMCE.openWindow(template, {editor_id : editor_id, inline : "yes"});
return true;
case "mceFullPageUpdate":
TinyMCE_FullPagePlugin._addToHead(tinyMCE.getInstanceById(editor_id));
return true;
}
// Pass to next handler in chain
return false;
},
cleanup : function(type, content, inst) {
switch (type) {
case "insert_to_editor":
var tmp = content.toLowerCase();
var pos = tmp.indexOf('<body'), pos2;
// Split page in header and body chunks
if (pos != -1) {
pos = tmp.indexOf('>', pos);
pos2 = tmp.lastIndexOf('</body>');
inst.fullpageTopContent = content.substring(0, pos + 1);
content = content.substring(pos + 1, pos2);
// tinyMCE.debug(inst.fullpageTopContent, content);
} else {
if (!inst.fullpageTopContent) {
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">');
var enc = tinyMCE.getParam("fullpage_default_encoding", 'utf-8');
var title = tinyMCE.getParam("fullpage_default_title", 'Untitled document');
var lang = tinyMCE.getParam("fullpage_default_langcode", 'en');
var pi = tinyMCE.getParam("fullpage_default_xml_pi", true);
var ff = tinyMCE.getParam("fullpage_default_font_family", "");
var fz = tinyMCE.getParam("fullpage_default_font_size", "");
var ds = tinyMCE.getParam("fullpage_default_style", "");
var dtc = tinyMCE.getParam("fullpage_default_text_color", "");
// Xml encode it
title = title.replace(/&/g, '&');
title = title.replace(/\"/g, '"');
title = title.replace(/</g, '<');
title = title.replace(/>/g, '>');
tmp = '';
// Make default chunk
if (pi)
tmp += '<?xml version="1.0" encoding="' + enc + '"?>\n';
tmp += docType + '\n';
tmp += '<html xmlns="http:/'+'/www.w3.org/1999/xhtml" lang="' + lang + '" xml:lang="' + lang + '">\n';
tmp += '<head>\n';
tmp += '\t<title>' + title + '</title>\n';
tmp += '\t<meta http-equiv="Content-Type" content="text/html; charset=' + enc + '" />\n';
tmp += '</head>\n';
tmp += '<body';
if (ff != '' || fz != '') {
tmp += ' style="';
if (ds != '')
tmp += ds + ";";
if (ff != '')
tmp += 'font-family: ' + ff + ";";
if (fz != '')
tmp += 'font-size: ' + fz + ";";
tmp += '"';
}
if (dtc != '')
tmp += ' text="' + dtc + '"';
tmp += '>\n';
inst.fullpageTopContent = tmp;
}
}
this._addToHead(inst);
break;
case "get_from_editor":
if (inst.fullpageTopContent)
content = inst.fullpageTopContent + content + "\n</body>\n</html>";
break;
}
// Pass through to next handler in chain
return content;
},
// Private plugin internal methods
_addToHead : function(inst) {
var doc = inst.getDoc();
var head = doc.getElementsByTagName("head")[0];
var body = doc.body;
var h = inst.fullpageTopContent;
var e = doc.createElement("body");
var nl, i, le, tmp;
// Remove stuff we don't want
h = h.replace(/(\r|\n)/gi, '');
h = h.replace(/<\?[^\>]*\>/gi, '');
h = h.replace(/<\/?(!DOCTYPE|head|html)[^\>]*\>/gi, '');
h = h.replace(/<script(.*?)<\/script>/gi, '');
h = h.replace(/<title(.*?)<\/title>/gi, '');
h = h.replace(/<(meta|base)[^>]*>/gi, '');
// Make link and style elements into pre
h = h.replace(/<link([^>]*)\/>/gi, '<pre mce_type="link" $1></pre>');
//h = h.replace(/<style([^>]*)>(.*?)<\/style>/gi, '<pre mce_type="style" $1>$2</pre>');
// Make body a div
h = h.replace(/<body/gi, '<div mce_type="body"');
h += '</div>';
// Now crapy MSIE can parse it
e.innerHTML = h;
// Reset all body attributes
body.vLink = body.aLink = body.link = body.text = '';
body.style.cssText = '';
// Delete all old links
nl = head.getElementsByTagName('link');
for (i=0; i<nl.length; i++) {
if (tinyMCE.getAttrib(nl[i], 'mce_head') == "true")
nl[i].parentNode.removeChild(nl[i]);
}
// Add link elements
nl = e.getElementsByTagName('pre');
for (i=0; i<nl.length; i++) {
tmp = tinyMCE.getAttrib(nl[i], 'media');
if (tinyMCE.getAttrib(nl[i], 'mce_type') == "link" && (tmp == "" || tmp == "screen" || tmp == "all") && tinyMCE.getAttrib(nl[i], 'rel') == "stylesheet") {
le = doc.createElement("link");
le.rel = "stylesheet";
le.href = tinyMCE.getAttrib(nl[i], 'href');
le.setAttribute("mce_head", "true");
head.appendChild(le);
}
}
// Add body attributes
nl = e.getElementsByTagName('div');
if (nl.length > 0) {
body.style.cssText = tinyMCE.getAttrib(nl[0], 'style');
if ((tmp = tinyMCE.getAttrib(nl[0], 'leftmargin')) != '' && body.style.marginLeft == '')
body.style.marginLeft = tmp + "px";
if ((tmp = tinyMCE.getAttrib(nl[0], 'rightmargin')) != '' && body.style.marginRight == '')
body.style.marginRight = tmp + "px";
if ((tmp = tinyMCE.getAttrib(nl[0], 'topmargin')) != '' && body.style.marginTop == '')
body.style.marginTop = tmp + "px";
if ((tmp = tinyMCE.getAttrib(nl[0], 'bottommargin')) != '' && body.style.marginBottom == '')
body.style.marginBottom = tmp + "px";
body.dir = tinyMCE.getAttrib(nl[0], 'dir');
body.vLink = tinyMCE.getAttrib(nl[0], 'vlink');
body.aLink = tinyMCE.getAttrib(nl[0], 'alink');
body.link = tinyMCE.getAttrib(nl[0], 'link');
body.text = tinyMCE.getAttrib(nl[0], 'text');
if ((tmp = tinyMCE.getAttrib(nl[0], 'background')) != '')
body.style.backgroundImage = "url('" + tmp + "')";
if ((tmp = tinyMCE.getAttrib(nl[0], 'bgcolor')) != '')
body.style.backgroundColor = tmp;
}
}
};
tinyMCE.addPlugin("fullpage", TinyMCE_FullPagePlugin);
|