plugin.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1.  CKEDITOR.plugins.add('einserttime',
  2. {
  3. init: function(editor)
  4. {
  5. //plugin code goes here
  6. var pluginName = 'einserttime';
  7. //CKEDITOR.dialog.add(pluginName, this.path + 'dialogs/flvPlayer.js');
  8. editor.addCommand(pluginName,{exec:function(editor){
  9. editor.insertHtml(eDoInsertTime());
  10. }});
  11. editor.ui.addButton('einserttime',
  12. {
  13. label: '当前时间',
  14. command: pluginName,
  15. icon: this.path + 'images/inserttime.gif'
  16. });
  17. }
  18. });
  19. function efunformatTime(date, format) {
  20. var hh = ('0' + date.getHours()).slice(-2),
  21. ii = ('0' + date.getMinutes()).slice(-2),
  22. ss = ('0' + date.getSeconds()).slice(-2);
  23. format = format || 'hh:ii:ss';
  24. return format.replace(/hh/ig, hh).replace(/ii/ig, ii).replace(/ss/ig, ss);
  25. }
  26. function efunformatDate(date, format) {
  27. var yyyy = ('000' + date.getFullYear()).slice(-4),
  28. yy = yyyy.slice(-2),
  29. mm = ('0' + (date.getMonth()+1)).slice(-2),
  30. dd = ('0' + date.getDate()).slice(-2);
  31. format = format || 'yyyy-mm-dd';
  32. return format.replace(/yyyy/ig, yyyy).replace(/yy/ig, yy).replace(/mm/ig, mm).replace(/dd/ig, dd);
  33. }
  34. function eDoInsertTime(){
  35. var date = new Date;
  36. var datetimestr='';
  37. datetimestr=efunformatDate(date,'')+' '+efunformatTime(date,'');
  38. return datetimestr;
  39. }