includes/clientside/tinymce/plugins/fullpage/editor_plugin_src.js
changeset 459 31c23016ab62
parent 395 fa4c5ecb7c9a
child 543 dffcbfbc4e59
--- a/includes/clientside/tinymce/plugins/fullpage/editor_plugin_src.js	Fri Feb 22 12:51:53 2008 -0500
+++ b/includes/clientside/tinymce/plugins/fullpage/editor_plugin_src.js	Sun Feb 24 12:50:52 2008 -0500
@@ -1,5 +1,5 @@
 /**
- * $Id: editor_plugin_src.js 520 2008-01-07 16:30:32Z spocke $
+ * $Id: editor_plugin_src.js 593 2008-02-13 13:00:12Z spocke $
  *
  * @author Moxiecode
  * @copyright Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved.
@@ -29,6 +29,7 @@
 			ed.addButton('fullpage', {title : 'fullpage.desc', cmd : 'mceFullPageProperties'});
 
 			ed.onBeforeSetContent.add(t._setContent, t);
+			ed.onSetContent.add(t._setBodyAttribs, t);
 			ed.onGetContent.add(t._getContent, t);
 		},
 
@@ -44,6 +45,31 @@
 
 		// Private plugin internal methods
 
+		_setBodyAttribs : function(ed, o) {
+			var bdattr, i, len, kv, k, v, t, attr = this.head.match(/body(.*?)>/i);
+
+			if (attr && attr[1]) {
+				bdattr = attr[1].match(/\s*(\w+\s*=\s*".*?"|\w+\s*=\s*'.*?'|\w+\s*=\s*\w+|\w+)\s*/g);
+
+				for(i = 0, len = bdattr.length; i < len; i++) {
+					kv = bdattr[i].split('=');
+					k = kv[0].replace(/\s/,'');
+					v = kv[1];
+
+					if (v) {
+						v = v.replace(/^\s+/,'').replace(/\s+$/,'');
+						t = v.match(/^["'](.*)["']$/);
+
+						if (t)
+							v = t[1];
+					} else
+						v = k;
+
+					ed.dom.setAttrib(ed.getBody(), 'style', v);
+				}
+			}
+		},
+
 		_createSerializer : function() {
 			return new tinymce.dom.Serializer({
 				dom : this.editor.dom,
@@ -55,9 +81,8 @@
 			var t = this, sp, ep, c = o.content;
 
 			// Parse out head, body and footer
+			c = c.replace(/<(\/?)BODY/gi, '<$1body');
 			sp = c.indexOf('<body');
-			if (sp == -1)
-				sp = c.indexOf('<BODY');
 
 			if (sp != -1) {
 				sp = c.indexOf('>', sp);
@@ -69,6 +94,15 @@
 
 				o.content = c.substring(sp + 1, ep);
 				t.foot = c.substring(ep);
+
+				function low(s) {
+					return s.replace(/<\/?[A-Z]+/g, function(a) {
+						return a.toLowerCase();
+					})
+				};
+
+				t.head = low(t.head);
+				t.foot = low(t.foot);
 			} else {
 				t.head = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
 				t.head += '\n<html>\n<head>\n<title>Untitled document</title>\n</head>\n<body>\n';