PageRenderTime 45ms CodeModel.GetById 29ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/static/scripts/tiny_mce/plugins/fullpage/editor_plugin_src.js

http://n23.googlecode.com/
JavaScript | 140 lines | 99 code | 30 blank | 11 comment | 15 complexity | 8841a568f97ff8da1128b0610d44b9ac MD5 | raw file
  1/**
  2 * $Id: editor_plugin_src.js 827 2008-04-29 15:02:42Z spocke $
  3 *
  4 * @author Moxiecode
  5 * @copyright Copyright Š 2004-2008, Moxiecode Systems AB, All rights reserved.
  6 */
  7
  8(function() {
  9	tinymce.create('tinymce.plugins.FullPagePlugin', {
 10		init : function(ed, url) {
 11			var t = this;
 12
 13			t.editor = ed;
 14
 15			// Register commands
 16			ed.addCommand('mceFullPageProperties', function() {
 17				ed.windowManager.open({
 18					file : url + '/fullpage.htm',
 19					width : 430 + parseInt(ed.getLang('fullpage.delta_width', 0)),
 20					height : 495 + parseInt(ed.getLang('fullpage.delta_height', 0)),
 21					inline : 1
 22				}, {
 23					plugin_url : url,
 24					head_html : t.head
 25				});
 26			});
 27
 28			// Register buttons
 29			ed.addButton('fullpage', {title : 'fullpage.desc', cmd : 'mceFullPageProperties'});
 30
 31			ed.onBeforeSetContent.add(t._setContent, t);
 32			ed.onSetContent.add(t._setBodyAttribs, t);
 33			ed.onGetContent.add(t._getContent, t);
 34		},
 35
 36		getInfo : function() {
 37			return {
 38				longname : 'Fullpage',
 39				author : 'Moxiecode Systems AB',
 40				authorurl : 'http://tinymce.moxiecode.com',
 41				infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/fullpage',
 42				version : tinymce.majorVersion + "." + tinymce.minorVersion
 43			};
 44		},
 45
 46		// Private plugin internal methods
 47
 48		_setBodyAttribs : function(ed, o) {
 49			var bdattr, i, len, kv, k, v, t, attr = this.head.match(/body(.*?)>/i);
 50
 51			if (attr && attr[1]) {
 52				bdattr = attr[1].match(/\s*(\w+\s*=\s*".*?"|\w+\s*=\s*'.*?'|\w+\s*=\s*\w+|\w+)\s*/g);
 53
 54				for(i = 0, len = bdattr.length; i < len; i++) {
 55					kv = bdattr[i].split('=');
 56					k = kv[0].replace(/\s/,'');
 57					v = kv[1];
 58
 59					if (v) {
 60						v = v.replace(/^\s+/,'').replace(/\s+$/,'');
 61						t = v.match(/^["'](.*)["']$/);
 62
 63						if (t)
 64							v = t[1];
 65					} else
 66						v = k;
 67
 68					ed.dom.setAttrib(ed.getBody(), 'style', v);
 69				}
 70			}
 71		},
 72
 73		_createSerializer : function() {
 74			return new tinymce.dom.Serializer({
 75				dom : this.editor.dom,
 76				apply_source_formatting : true
 77			});
 78		},
 79
 80		_setContent : function(ed, o) {
 81			var t = this, sp, ep, c = o.content, v, st = '';
 82
 83			// Parse out head, body and footer
 84			c = c.replace(/<(\/?)BODY/gi, '<$1body');
 85			sp = c.indexOf('<body');
 86
 87			if (sp != -1) {
 88				sp = c.indexOf('>', sp);
 89				t.head = c.substring(0, sp + 1);
 90
 91				ep = c.indexOf('</body', sp);
 92				if (ep == -1)
 93					ep = c.indexOf('</body', ep);
 94
 95				o.content = c.substring(sp + 1, ep);
 96				t.foot = c.substring(ep);
 97
 98				function low(s) {
 99					return s.replace(/<\/?[A-Z]+/g, function(a) {
100						return a.toLowerCase();
101					})
102				};
103
104				t.head = low(t.head);
105				t.foot = low(t.foot);
106			} else {
107				t.head = '';
108				if (ed.getParam('fullpage_default_xml_pi'))
109					t.head += '<?xml version="1.0" encoding="' + ed.getParam('fullpage_default_encoding', 'ISO-8859-1') + '" ?>\n';
110
111				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">');
112				t.head += '\n<html>\n<head>\n<title>' + ed.getParam('fullpage_default_title', 'Untitled document') + '</title>\n';
113
114				if (v = ed.getParam('fullpage_default_encoding'))
115					t.head += '<meta http-equiv="Content-Type" content="' + v + '" />\n';
116
117				if (v = ed.getParam('fullpage_default_font_family'))
118					st += 'font-family: ' + v + ';';
119
120				if (v = ed.getParam('fullpage_default_font_size'))
121					st += 'font-size: ' + v + ';';
122
123				if (v = ed.getParam('fullpage_default_text_color'))
124					st += 'color: ' + v + ';';
125
126				t.head += '</head>\n<body' + (st ? ' style="' + st + '"' : '') + '>\n';
127				t.foot = '\n</body>\n</html>';
128			}
129		},
130
131		_getContent : function(ed, o) {
132			var t = this;
133
134			o.content = tinymce.trim(t.head) + '\n' + tinymce.trim(o.content) + '\n' + tinymce.trim(t.foot);
135		}
136	});
137
138	// Register plugin
139	tinymce.PluginManager.add('fullpage', tinymce.plugins.FullPagePlugin);
140})();