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