Line # Revision Author
1 8 ahitrov@rambler.ru /**
2 * $Id: editor_plugin_src.js 520 2008-01-07 16:30:32Z spocke $
3 *
4 * @author Moxiecode
5 * @copyright Copyright � 2004-2008, Moxiecode Systems AB, All rights reserved.
6 */
7
8 (function() {
9 tinymce.create('tinymce.plugins.InsertDateTime', {
10 init : function(ed, url) {
11 var t = this;
12
13 t.editor = ed;
14
15 ed.addCommand('mceInsertDate', function() {
16 var str = t._getDateTime(new Date(), ed.getParam("plugin_insertdate_dateFormat", ed.getLang('insertdatetime.date_fmt')));
17
18 ed.execCommand('mceInsertContent', false, str);
19 });
20
21 ed.addCommand('mceInsertTime', function() {
22 var str = t._getDateTime(new Date(), ed.getParam("plugin_insertdate_timeFormat", ed.getLang('insertdatetime.time_fmt')));
23
24 ed.execCommand('mceInsertContent', false, str);
25 });
26
27 ed.addButton('insertdate', {title : 'insertdatetime.insertdate_desc', cmd : 'mceInsertDate'});
28 ed.addButton('inserttime', {title : 'insertdatetime.inserttime_desc', cmd : 'mceInsertTime'});
29 },
30
31 getInfo : function() {
32 return {
33 longname : 'Insert date/time',
34 author : 'Moxiecode Systems AB',
35 authorurl : 'http://tinymce.moxiecode.com',
36 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/insertdatetime',
37 version : tinymce.majorVersion + "." + tinymce.minorVersion
38 };
39 },
40
41 // Private methods
42
43 _getDateTime : function(d, fmt) {
44 var ed = this.editor;
45
46 function addZeros(value, len) {
47 value = "" + value;
48
49 if (value.length < len) {
50 for (var i=0; i<(len-value.length); i++)
51 value = "0" + value;
52 }
53
54 return value;
55 };
56
57 fmt = fmt.replace("%D", "%m/%d/%y");
58 fmt = fmt.replace("%r", "%I:%M:%S %p");
59 fmt = fmt.replace("%Y", "" + d.getFullYear());
60 fmt = fmt.replace("%y", "" + d.getYear());
61 fmt = fmt.replace("%m", addZeros(d.getMonth()+1, 2));
62 fmt = fmt.replace("%d", addZeros(d.getDate(), 2));
63 fmt = fmt.replace("%H", "" + addZeros(d.getHours(), 2));
64 fmt = fmt.replace("%M", "" + addZeros(d.getMinutes(), 2));
65 fmt = fmt.replace("%S", "" + addZeros(d.getSeconds(), 2));
66 fmt = fmt.replace("%I", "" + ((d.getHours() + 11) % 12 + 1));
67 fmt = fmt.replace("%p", "" + (d.getHours() < 12 ? "AM" : "PM"));
68 fmt = fmt.replace("%B", "" + ed.getLang("insertdatetime.months_long").split(',')[d.getMonth()]);
69 fmt = fmt.replace("%b", "" + ed.getLang("insertdatetime.months_short").split(',')[d.getMonth()]);
70 fmt = fmt.replace("%A", "" + ed.getLang("insertdatetime.day_long").split(',')[d.getDay()]);
71 fmt = fmt.replace("%a", "" + ed.getLang("insertdatetime.day_short").split(',')[d.getDay()]);
72 fmt = fmt.replace("%%", "%");
73
74 return fmt;
75 }
76 });
77
78 // Register plugin
79 tinymce.PluginManager.add('insertdatetime', tinymce.plugins.InsertDateTime);
80 })();