tagging as ATutor 1.5.4-release
[atutor.git] / jscripts / tiny_mce / plugins / insertdatetime / editor_plugin_src.js
1 /**\r
2  * $RCSfile: editor_plugin_src.js,v $\r
3  * $Revision: 1.22 $\r
4  * $Date: 2006/02/10 16:29:39 $\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('insertdatetime', 'en,tr,cs,el,fr_ca,it,ko,sv,zh_cn,fa,fr,de,pl,pt_br,nl,da,he,nb,ru,ru_KOI8-R,ru_UTF-8,nn,fi,es,cy,is,pl');\r
12 \r
13 var TinyMCE_InsertDateTimePlugin = {\r
14         getInfo : function() {\r
15                 return {\r
16                         longname : 'Insert date/time',\r
17                         author : 'Moxiecode Systems',\r
18                         authorurl : 'http://tinymce.moxiecode.com',\r
19                         infourl : 'http://tinymce.moxiecode.com/tinymce/docs/plugin_insertdatetime.html',\r
20                         version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion\r
21                 };\r
22         },\r
23 \r
24         /**\r
25          * Returns the HTML contents of the insertdate, inserttime controls.\r
26          */\r
27         getControlHTML : function(cn) {\r
28                 switch (cn) {\r
29                         case "insertdate":\r
30                                 return tinyMCE.getButtonHTML(cn, 'lang_insertdate_desc', '{$pluginurl}/images/insertdate.gif', 'mceInsertDate');\r
31 \r
32                         case "inserttime":\r
33                                 return tinyMCE.getButtonHTML(cn, 'lang_inserttime_desc', '{$pluginurl}/images/inserttime.gif', 'mceInsertTime');\r
34                 }\r
35 \r
36                 return "";\r
37         },\r
38 \r
39         /**\r
40          * Executes the mceInsertDate command.\r
41          */\r
42         execCommand : function(editor_id, element, command, user_interface, value) {\r
43                 /* Adds zeros infront of value */\r
44                 function addZeros(value, len) {\r
45                         value = "" + value;\r
46 \r
47                         if (value.length < len) {\r
48                                 for (var i=0; i<(len-value.length); i++)\r
49                                         value = "0" + value;\r
50                         }\r
51 \r
52                         return value;\r
53                 }\r
54 \r
55                 /* Returns the date object in the specified format */\r
56                 function getDateTime(date, format) {\r
57                         format = tinyMCE.regexpReplace(format, "%D", "%m/%d/%y");\r
58                         format = tinyMCE.regexpReplace(format, "%r", "%I:%M:%S %p");\r
59                         format = tinyMCE.regexpReplace(format, "%Y", "" + date.getFullYear());\r
60                         format = tinyMCE.regexpReplace(format, "%y", "" + date.getYear());\r
61                         format = tinyMCE.regexpReplace(format, "%m", addZeros(date.getMonth()+1, 2));\r
62                         format = tinyMCE.regexpReplace(format, "%d", addZeros(date.getDate(), 2));\r
63                         format = tinyMCE.regexpReplace(format, "%H", "" + addZeros(date.getHours(), 2));\r
64                         format = tinyMCE.regexpReplace(format, "%M", "" + addZeros(date.getMinutes(), 2));\r
65                         format = tinyMCE.regexpReplace(format, "%S", "" + addZeros(date.getSeconds(), 2));\r
66                         format = tinyMCE.regexpReplace(format, "%I", "" + ((date.getHours() + 11) % 12 + 1));\r
67                         format = tinyMCE.regexpReplace(format, "%p", "" + (date.getHours() < 12 ? "AM" : "PM"));\r
68                         format = tinyMCE.regexpReplace(format, "%B", "" + tinyMCE.getLang("lang_inserttime_months_long")[date.getMonth()]);\r
69                         format = tinyMCE.regexpReplace(format, "%b", "" + tinyMCE.getLang("lang_inserttime_months_short")[date.getMonth()]);\r
70                         format = tinyMCE.regexpReplace(format, "%A", "" + tinyMCE.getLang("lang_inserttime_day_long")[date.getDay()]);\r
71                         format = tinyMCE.regexpReplace(format, "%a", "" + tinyMCE.getLang("lang_inserttime_day_short")[date.getDay()]);\r
72                         format = tinyMCE.regexpReplace(format, "%%", "%");\r
73 \r
74                         return format;\r
75                 }\r
76 \r
77                 // Handle commands\r
78                 switch (command) {\r
79                         case "mceInsertDate":\r
80                                 tinyMCE.execInstanceCommand(editor_id, 'mceInsertContent', false, getDateTime(new Date(), tinyMCE.getParam("plugin_insertdate_dateFormat", tinyMCE.getLang('lang_insertdate_def_fmt'))));\r
81                                 return true;\r
82 \r
83                         case "mceInsertTime":\r
84                                 tinyMCE.execInstanceCommand(editor_id, 'mceInsertContent', false, getDateTime(new Date(), tinyMCE.getParam("plugin_insertdate_timeFormat", tinyMCE.getLang('lang_inserttime_def_fmt'))));\r
85                                 return true;\r
86                 }\r
87 \r
88                 // Pass to next handler in chain\r
89                 return false;\r
90         }\r
91 };\r
92 \r
93 tinyMCE.addPlugin("insertdatetime", TinyMCE_InsertDateTimePlugin);\r