annotate WebContent/jscripts/tiny_mce/plugins/insertdatetime/editor_plugin_src.js @ 8:11baadcdd2c8

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