* Removed the Kevin Roth rich text editor and replaced it with TinyMCE.
[citadel.git] / webcit / tiny_mce / plugins / insertdatetime / editor_plugin_src.js
1 /* Import plugin specific language pack */
2 tinyMCE.importPluginLanguagePack('insertdatetime', 'cs,el,en,fr_ca,it,ko,sv,zh_cn,fa,fr,de,pl,pt_br,nl');
3
4 function TinyMCE_insertdatetime_getInfo() {
5         return {
6                 longname : 'Insert date/time',
7                 author : 'Moxiecode Systems',
8                 authorurl : 'http://tinymce.moxiecode.com',
9                 infourl : 'http://tinymce.moxiecode.com/tinymce/docs/plugin_insertdatetime.html',
10                 version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion
11         };
12 };
13
14 /**
15  * Returns the HTML contents of the insertdate, inserttime controls.
16  */
17 function TinyMCE_insertdatetime_getControlHTML(control_name) {
18         switch (control_name) {
19                 case "insertdate":
20                         return '<a href="javascript:tinyMCE.execInstanceCommand(\'{$editor_id}\',\'mceInsertDate\');" onmousedown="return false;"><img id="{$editor_id}_insertdate" src="{$pluginurl}/images/insertdate.gif" title="{$lang_insertdate_desc}" width="20" height="20" class="mceButtonNormal" onmouseover="tinyMCE.switchClass(this,\'mceButtonOver\');" onmouseout="tinyMCE.restoreClass(this);" onmousedown="tinyMCE.restoreAndSwitchClass(this,\'mceButtonDown\');" /></a>';
21
22                 case "inserttime":
23                         return '<a href="javascript:tinyMCE.execInstanceCommand(\'{$editor_id}\',\'mceInsertTime\');" onmousedown="return false;"><img id="{$editor_id}_inserttime" src="{$pluginurl}/images/inserttime.gif" title="{$lang_inserttime_desc}" width="20" height="20" class="mceButtonNormal" onmouseover="tinyMCE.switchClass(this,\'mceButtonOver\');" onmouseout="tinyMCE.restoreClass(this);" onmousedown="tinyMCE.restoreAndSwitchClass(this,\'mceButtonDown\');" /></a>';
24         }
25
26         return "";
27 }
28
29 /**
30  * Executes the mceInsertDate command.
31  */
32 function TinyMCE_insertdatetime_execCommand(editor_id, element, command, user_interface, value) {
33         /* Adds zeros infront of value */
34         function addZeros(value, len) {
35                 value = "" + value;
36
37                 if (value.length < len) {
38                         for (var i=0; i<(len-value.length); i++)
39                                 value = "0" + value;
40                 }
41
42                 return value;
43         }
44
45         /* Returns the date object in the specified format */
46         function getDateTime(date, format) {
47                 format = tinyMCE.regexpReplace(format, "%D", "%m/%d/%y");
48                 format = tinyMCE.regexpReplace(format, "%r", "%I:%M:%S %p");
49                 format = tinyMCE.regexpReplace(format, "%Y", "" + date.getFullYear());
50                 format = tinyMCE.regexpReplace(format, "%y", "" + date.getYear());
51                 format = tinyMCE.regexpReplace(format, "%m", addZeros(date.getMonth()+1, 2));
52                 format = tinyMCE.regexpReplace(format, "%d", addZeros(date.getDate(), 2));
53                 format = tinyMCE.regexpReplace(format, "%H", "" + addZeros(date.getHours(), 2));
54                 format = tinyMCE.regexpReplace(format, "%M", "" + addZeros(date.getMinutes(), 2));
55                 format = tinyMCE.regexpReplace(format, "%S", "" + addZeros(date.getSeconds(), 2));
56                 format = tinyMCE.regexpReplace(format, "%I", "" + (date.getHours() < 12 ? (date.getHours()+1) : 24-date.getHours()));
57                 format = tinyMCE.regexpReplace(format, "%p", "" + (date.getHours() < 12 ? "AM" : "PM"));
58                 format = tinyMCE.regexpReplace(format, "%B", "" + tinyMCE.getLang("lang_inserttime_months_long")[date.getMonth()]);
59                 format = tinyMCE.regexpReplace(format, "%b", "" + tinyMCE.getLang("lang_inserttime_months_short")[date.getMonth()]);
60                 format = tinyMCE.regexpReplace(format, "%A", "" + tinyMCE.getLang("lang_inserttime_day_long")[date.getDay()]);
61                 format = tinyMCE.regexpReplace(format, "%a", "" + tinyMCE.getLang("lang_inserttime_day_short")[date.getDay()]);
62                 format = tinyMCE.regexpReplace(format, "%%", "%");
63
64                 return format;
65         }
66
67         // Handle commands
68         switch (command) {
69                 case "mceInsertDate":
70                         tinyMCE.execInstanceCommand(editor_id, 'mceInsertContent', false, getDateTime(new Date(), tinyMCE.getParam("plugin_insertdate_dateFormat", tinyMCE.getLang('lang_insertdate_def_fmt'))));
71                         return true;
72
73                 case "mceInsertTime":
74                         tinyMCE.execInstanceCommand(editor_id, 'mceInsertContent', false, getDateTime(new Date(), tinyMCE.getParam("plugin_insertdate_timeFormat", tinyMCE.getLang('lang_inserttime_def_fmt'))));
75                         return true;
76         }
77
78         // Pass to next handler in chain
79         return false;
80 }