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