PageRenderTime 38ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/BlogEngine/BlogEngine.NET/editors/tiny_mce_3_4_3_1/plugins/insertdatetime/editor_plugin_src.js

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