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