includes/clientside/tinymce/plugins/fullpage/editor_plugin_src.js
changeset 459 31c23016ab62
parent 395 fa4c5ecb7c9a
child 543 dffcbfbc4e59
equal deleted inserted replaced
458:c433348f3628 459:31c23016ab62
     1 /**
     1 /**
     2  * $Id: editor_plugin_src.js 520 2008-01-07 16:30:32Z spocke $
     2  * $Id: editor_plugin_src.js 593 2008-02-13 13:00:12Z spocke $
     3  *
     3  *
     4  * @author Moxiecode
     4  * @author Moxiecode
     5  * @copyright Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved.
     5  * @copyright Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved.
     6  */
     6  */
     7 
     7 
    27 
    27 
    28 			// Register buttons
    28 			// Register buttons
    29 			ed.addButton('fullpage', {title : 'fullpage.desc', cmd : 'mceFullPageProperties'});
    29 			ed.addButton('fullpage', {title : 'fullpage.desc', cmd : 'mceFullPageProperties'});
    30 
    30 
    31 			ed.onBeforeSetContent.add(t._setContent, t);
    31 			ed.onBeforeSetContent.add(t._setContent, t);
       
    32 			ed.onSetContent.add(t._setBodyAttribs, t);
    32 			ed.onGetContent.add(t._getContent, t);
    33 			ed.onGetContent.add(t._getContent, t);
    33 		},
    34 		},
    34 
    35 
    35 		getInfo : function() {
    36 		getInfo : function() {
    36 			return {
    37 			return {
    42 			};
    43 			};
    43 		},
    44 		},
    44 
    45 
    45 		// Private plugin internal methods
    46 		// Private plugin internal methods
    46 
    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 
    47 		_createSerializer : function() {
    73 		_createSerializer : function() {
    48 			return new tinymce.dom.Serializer({
    74 			return new tinymce.dom.Serializer({
    49 				dom : this.editor.dom,
    75 				dom : this.editor.dom,
    50 				apply_source_formatting : true
    76 				apply_source_formatting : true
    51 			});
    77 			});
    53 
    79 
    54 		_setContent : function(ed, o) {
    80 		_setContent : function(ed, o) {
    55 			var t = this, sp, ep, c = o.content;
    81 			var t = this, sp, ep, c = o.content;
    56 
    82 
    57 			// Parse out head, body and footer
    83 			// Parse out head, body and footer
       
    84 			c = c.replace(/<(\/?)BODY/gi, '<$1body');
    58 			sp = c.indexOf('<body');
    85 			sp = c.indexOf('<body');
    59 			if (sp == -1)
       
    60 				sp = c.indexOf('<BODY');
       
    61 
    86 
    62 			if (sp != -1) {
    87 			if (sp != -1) {
    63 				sp = c.indexOf('>', sp);
    88 				sp = c.indexOf('>', sp);
    64 				t.head = c.substring(0, sp + 1);
    89 				t.head = c.substring(0, sp + 1);
    65 
    90 
    67 				if (ep == -1)
    92 				if (ep == -1)
    68 					ep = c.indexOf('</body', ep);
    93 					ep = c.indexOf('</body', ep);
    69 
    94 
    70 				o.content = c.substring(sp + 1, ep);
    95 				o.content = c.substring(sp + 1, ep);
    71 				t.foot = c.substring(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);
    72 			} else {
   106 			} else {
    73 				t.head = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
   107 				t.head = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
    74 				t.head += '\n<html>\n<head>\n<title>Untitled document</title>\n</head>\n<body>\n';
   108 				t.head += '\n<html>\n<head>\n<title>Untitled document</title>\n</head>\n<body>\n';
    75 				t.foot = '\n</body>\n</html>';
   109 				t.foot = '\n</body>\n</html>';
    76 			}
   110 			}