tagging as ATutor 1.5.4-release
[atutor.git] / jscripts / tiny_mce / plugins / preview / editor_plugin_src.js
1 /**\r
2  * $RCSfile: editor_plugin_src.js,v $\r
3  * $Revision: 1.23 $\r
4  * $Date: 2006/03/20 12:03:44 $\r
5  *\r
6  * @author Moxiecode\r
7  * @copyright Copyright © 2004-2006, Moxiecode Systems AB, All rights reserved.\r
8  */\r
9 \r
10 /* Import plugin specific language pack */\r
11 tinyMCE.importPluginLanguagePack('preview', 'en,tr,cs,de,el,fr_ca,it,ko,pt,sv,zh_cn,fa,fr,pl,pt_br,nl,da,he,nb,hu,ru,ru_KOI8-R,ru_UTF-8,nn,es,cy,is,zh_tw,zh_tw_utf8,sk');\r
12 \r
13 var TinyMCE_PreviewPlugin = {\r
14         getInfo : function() {\r
15                 return {\r
16                         longname : 'Preview',\r
17                         author : 'Moxiecode Systems',\r
18                         authorurl : 'http://tinymce.moxiecode.com',\r
19                         infourl : 'http://tinymce.moxiecode.com/tinymce/docs/plugin_preview.html',\r
20                         version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion\r
21                 };\r
22         },\r
23 \r
24         /**\r
25          * Returns the HTML contents of the preview control.\r
26          */\r
27         getControlHTML : function(cn) {\r
28                 switch (cn) {\r
29                         case "preview":\r
30                                 return tinyMCE.getButtonHTML(cn, 'lang_preview_desc', '{$pluginurl}/images/preview.gif', 'mcePreview');\r
31                 }\r
32 \r
33                 return "";\r
34         },\r
35 \r
36         /**\r
37          * Executes the mcePreview command.\r
38          */\r
39         execCommand : function(editor_id, element, command, user_interface, value) {\r
40                 // Handle commands\r
41                 switch (command) {\r
42                         case "mcePreview":\r
43                                 var previewPage = tinyMCE.getParam("plugin_preview_pageurl", null);\r
44                                 var previewWidth = tinyMCE.getParam("plugin_preview_width", "550");\r
45                                 var previewHeight = tinyMCE.getParam("plugin_preview_height", "600");\r
46 \r
47                                 // Use a custom preview page\r
48                                 if (previewPage) {\r
49                                         var template = new Array();\r
50 \r
51                                         template['file'] = previewPage;\r
52                                         template['width'] = previewWidth;\r
53                                         template['height'] = previewHeight;\r
54 \r
55                                         tinyMCE.openWindow(template, {editor_id : editor_id, resizable : "yes", scrollbars : "yes", inline : "yes", content : tinyMCE.getContent(), content_css : tinyMCE.getParam("content_css")});\r
56                                 } else {\r
57                                         var win = window.open("", "mcePreview", "menubar=no,toolbar=no,scrollbars=yes,resizable=yes,left=20,top=20,width=" + previewWidth + ",height="  + previewHeight);\r
58                                         var html = "";\r
59                                         var c = tinyMCE.getContent();\r
60                                         var pos = c.indexOf('<body'), pos2;\r
61 \r
62                                         if (pos != -1) {\r
63                                                 pos = c.indexOf('>', pos);\r
64                                                 pos2 = c.lastIndexOf('</body>');\r
65                                                 c = c.substring(pos + 1, pos2);\r
66                                         }\r
67 \r
68                                         html += tinyMCE.getParam('doctype');\r
69                                         html += '<html xmlns="http://www.w3.org/1999/xhtml">';\r
70                                         html += '<head>';\r
71                                         html += '<title>' + tinyMCE.getLang('lang_preview_desc') + '</title>';\r
72                                         html += '<base href="' + tinyMCE.settings['base_href'] + '" />';\r
73                                         html += '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';\r
74                                         html += '<link href="' + tinyMCE.getParam("content_css") + '" rel="stylesheet" type="text/css" />';\r
75                                         html += '</head>';\r
76                                         html += '<body dir="' + tinyMCE.getParam("directionality") + '">';\r
77                                         html += c;\r
78                                         html += '</body>';\r
79                                         html += '</html>';\r
80 \r
81                                         win.document.write(html);\r
82                                         win.document.close();\r
83                                 }\r
84 \r
85                                 return true;\r
86                 }\r
87 \r
88                 return false;\r
89         }\r
90 };\r
91 \r
92 tinyMCE.addPlugin("preview", TinyMCE_PreviewPlugin);\r