maj du readme pour la 0.4.2
[mtweb] / web / libs / tiny_mce / plugins / insertdatetime / editor_plugin_src.js
1 /**\r
2  * editor_plugin_src.js\r
3  *\r
4  * Copyright 2009, Moxiecode Systems AB\r
5  * Released under LGPL License.\r
6  *\r
7  * License: http://tinymce.moxiecode.com/license\r
8  * Contributing: http://tinymce.moxiecode.com/contributing\r
9  */\r
10 \r
11 (function() {\r
12         tinymce.create('tinymce.plugins.InsertDateTime', {\r
13                 init : function(ed, url) {\r
14                         var t = this;\r
15 \r
16                         t.editor = ed;\r
17 \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
20 \r
21                                 ed.execCommand('mceInsertContent', false, str);\r
22                         });\r
23 \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
26 \r
27                                 ed.execCommand('mceInsertContent', false, str);\r
28                         });\r
29 \r
30                         ed.addButton('insertdate', {title : 'insertdatetime.insertdate_desc', cmd : 'mceInsertDate'});\r
31                         ed.addButton('inserttime', {title : 'insertdatetime.inserttime_desc', cmd : 'mceInsertTime'});\r
32                 },\r
33 \r
34                 getInfo : function() {\r
35                         return {\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
41                         };\r
42                 },\r
43 \r
44                 // Private methods\r
45 \r
46                 _getDateTime : function(d, fmt) {\r
47                         var ed = this.editor;\r
48 \r
49                         function addZeros(value, len) {\r
50                                 value = "" + value;\r
51 \r
52                                 if (value.length < len) {\r
53                                         for (var i=0; i<(len-value.length); i++)\r
54                                                 value = "0" + value;\r
55                                 }\r
56 \r
57                                 return value;\r
58                         };\r
59 \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
76 \r
77                         return fmt;\r
78                 }\r
79         });\r
80 \r
81         // Register plugin\r
82         tinymce.PluginManager.add('insertdatetime', tinymce.plugins.InsertDateTime);\r
83 })();