annotate static/js/tiny_mce/plugins/insertdatetime/editor_plugin_src.js @ 1170:b213e4b333bb

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