2 * editor_plugin_src.js
\r
4 * Copyright 2009, Moxiecode Systems AB
\r
5 * Released under LGPL License.
\r
7 * License: http://tinymce.moxiecode.com/license
\r
8 * Contributing: http://tinymce.moxiecode.com/contributing
\r
12 tinymce.create('tinymce.plugins.InsertDateTime', {
\r
13 init : function(ed, url) {
\r
18 ed.addCommand('mceInsertDate', function() {
\r
19 var str = t._getDateTime(new Date(), ed.getParam("plugin_insertdate_dateFormat", ed.getLang('insertdatetime.date_fmt')));
\r
21 ed.execCommand('mceInsertContent', false, str);
\r
24 ed.addCommand('mceInsertTime', function() {
\r
25 var str = t._getDateTime(new Date(), ed.getParam("plugin_insertdate_timeFormat", ed.getLang('insertdatetime.time_fmt')));
\r
27 ed.execCommand('mceInsertContent', false, str);
\r
30 ed.addButton('insertdate', {title : 'insertdatetime.insertdate_desc', cmd : 'mceInsertDate'});
\r
31 ed.addButton('inserttime', {title : 'insertdatetime.inserttime_desc', cmd : 'mceInsertTime'});
\r
34 getInfo : function() {
\r
36 longname : 'Insert date/time',
\r
37 author : 'Moxiecode Systems AB',
\r
38 authorurl : 'http://tinymce.moxiecode.com',
\r
39 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/insertdatetime',
\r
40 version : tinymce.majorVersion + "." + tinymce.minorVersion
\r
46 _getDateTime : function(d, fmt) {
\r
47 var ed = this.editor;
\r
49 function addZeros(value, len) {
\r
52 if (value.length < len) {
\r
53 for (var i=0; i<(len-value.length); i++)
\r
54 value = "0" + value;
\r
60 fmt = fmt.replace("%D", "%m/%d/%y");
\r
61 fmt = fmt.replace("%r", "%I:%M:%S %p");
\r
62 fmt = fmt.replace("%Y", "" + d.getFullYear());
\r
63 fmt = fmt.replace("%y", "" + d.getYear());
\r
64 fmt = fmt.replace("%m", addZeros(d.getMonth()+1, 2));
\r
65 fmt = fmt.replace("%d", addZeros(d.getDate(), 2));
\r
66 fmt = fmt.replace("%H", "" + addZeros(d.getHours(), 2));
\r
67 fmt = fmt.replace("%M", "" + addZeros(d.getMinutes(), 2));
\r
68 fmt = fmt.replace("%S", "" + addZeros(d.getSeconds(), 2));
\r
69 fmt = fmt.replace("%I", "" + ((d.getHours() + 11) % 12 + 1));
\r
70 fmt = fmt.replace("%p", "" + (d.getHours() < 12 ? "AM" : "PM"));
\r
71 fmt = fmt.replace("%B", "" + ed.getLang("insertdatetime.months_long").split(',')[d.getMonth()]);
\r
72 fmt = fmt.replace("%b", "" + ed.getLang("insertdatetime.months_short").split(',')[d.getMonth()]);
\r
73 fmt = fmt.replace("%A", "" + ed.getLang("insertdatetime.day_long").split(',')[d.getDay()]);
\r
74 fmt = fmt.replace("%a", "" + ed.getLang("insertdatetime.day_short").split(',')[d.getDay()]);
\r
75 fmt = fmt.replace("%%", "%");
\r
82 tinymce.PluginManager.add('insertdatetime', tinymce.plugins.InsertDateTime);
\r