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