2 * editor_plugin_src.js
\r
4 * Copyright 2009, Moxiecode Systems AB
\r
5 * Released under LGPL License.
\r
7 * License: http://tinymce.moxiecode.com/license
\r
8 * Contributing: http://tinymce.moxiecode.com/contributing
\r
12 tinymce.create('tinymce.plugins.FullPagePlugin', {
\r
13 init : function(ed, url) {
\r
18 // Register commands
\r
19 ed.addCommand('mceFullPageProperties', function() {
\r
20 ed.windowManager.open({
\r
21 file : url + '/fullpage.htm',
\r
22 width : 430 + parseInt(ed.getLang('fullpage.delta_width', 0)),
\r
23 height : 495 + parseInt(ed.getLang('fullpage.delta_height', 0)),
\r
32 ed.addButton('fullpage', {title : 'fullpage.desc', cmd : 'mceFullPageProperties'});
\r
34 ed.onBeforeSetContent.add(t._setContent, t);
\r
35 ed.onSetContent.add(t._setBodyAttribs, t);
\r
36 ed.onGetContent.add(t._getContent, t);
\r
39 getInfo : function() {
\r
41 longname : 'Fullpage',
\r
42 author : 'Moxiecode Systems AB',
\r
43 authorurl : 'http://tinymce.moxiecode.com',
\r
44 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/fullpage',
\r
45 version : tinymce.majorVersion + "." + tinymce.minorVersion
\r
49 // Private plugin internal methods
\r
51 _setBodyAttribs : function(ed, o) {
\r
52 var bdattr, i, len, kv, k, v, t, attr = this.head.match(/body(.*?)>/i);
\r
54 if (attr && attr[1]) {
\r
55 bdattr = attr[1].match(/\s*(\w+\s*=\s*".*?"|\w+\s*=\s*'.*?'|\w+\s*=\s*\w+|\w+)\s*/g);
\r
58 for(i = 0, len = bdattr.length; i < len; i++) {
\r
59 kv = bdattr[i].split('=');
\r
60 k = kv[0].replace(/\s/,'');
\r
64 v = v.replace(/^\s+/,'').replace(/\s+$/,'');
\r
65 t = v.match(/^["'](.*)["']$/);
\r
72 ed.dom.setAttrib(ed.getBody(), 'style', v);
\r
78 _createSerializer : function() {
\r
79 return new tinymce.dom.Serializer({
\r
80 dom : this.editor.dom,
\r
81 apply_source_formatting : true
\r
85 _setContent : function(ed, o) {
\r
86 var t = this, sp, ep, c = o.content, v, st = '';
\r
88 // Ignore raw updated if we already have a head, this will fix issues with undo/redo keeping the head/foot separate
\r
89 if (o.format == 'raw' && t.head)
\r
92 if (o.source_view && ed.getParam('fullpage_hide_in_source_view'))
\r
95 // Parse out head, body and footer
\r
96 c = c.replace(/<(\/?)BODY/gi, '<$1body');
\r
97 sp = c.indexOf('<body');
\r
100 sp = c.indexOf('>', sp);
\r
101 t.head = c.substring(0, sp + 1);
\r
103 ep = c.indexOf('</body', sp);
\r
105 ep = c.indexOf('</body', ep);
\r
107 o.content = c.substring(sp + 1, ep);
\r
108 t.foot = c.substring(ep);
\r
111 return s.replace(/<\/?[A-Z]+/g, function(a) {
\r
112 return a.toLowerCase();
\r
116 t.head = low(t.head);
\r
117 t.foot = low(t.foot);
\r
120 if (ed.getParam('fullpage_default_xml_pi'))
\r
121 t.head += '<?xml version="1.0" encoding="' + ed.getParam('fullpage_default_encoding', 'ISO-8859-1') + '" ?>\n';
\r
123 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">');
\r
124 t.head += '\n<html>\n<head>\n<title>' + ed.getParam('fullpage_default_title', 'Untitled document') + '</title>\n';
\r
126 if (v = ed.getParam('fullpage_default_encoding'))
\r
127 t.head += '<meta http-equiv="Content-Type" content="' + v + '" />\n';
\r
129 if (v = ed.getParam('fullpage_default_font_family'))
\r
130 st += 'font-family: ' + v + ';';
\r
132 if (v = ed.getParam('fullpage_default_font_size'))
\r
133 st += 'font-size: ' + v + ';';
\r
135 if (v = ed.getParam('fullpage_default_text_color'))
\r
136 st += 'color: ' + v + ';';
\r
138 t.head += '</head>\n<body' + (st ? ' style="' + st + '"' : '') + '>\n';
\r
139 t.foot = '\n</body>\n</html>';
\r
143 _getContent : function(ed, o) {
\r
146 if (!o.source_view || !ed.getParam('fullpage_hide_in_source_view'))
\r
147 o.content = tinymce.trim(t.head) + '\n' + tinymce.trim(o.content) + '\n' + tinymce.trim(t.foot);
\r
152 tinymce.PluginManager.add('fullpage', tinymce.plugins.FullPagePlugin);
\r