1/** 2 * Basic sample plugin inserting current date and time into CKEditor editing area. 3 */ 4 5// Register the plugin with the editor. 6// http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.plugins.html 7CKEDITOR.plugins.add( 'signature', 8{ 9 // The plugin initialization logic goes inside this method. 10 // http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.pluginDefinition.html#init 11 init: function( editor ) 12 { 13 var lang = editor.lang.signature; 14 if(!lang) lang = CKEDITOR.lang['default']['signature']; 15 16 // Define an editor command that inserts a timestamp. 17 // http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html#addCommand 18 editor.addCommand( 'insertSignature', 19 { 20 numbersToTwoDigits : function(n) 21 { 22 if(n < 10) n = '0' + n; 23 return(n); 24 }, 25 // Define a function that will be fired when the command is executed. 26 // http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.commandDefinition.html#exec 27 exec : function( editor ) 28 { 29 var user_name = oDokuWiki_FCKEditorInstance.fckgUserName; 30 var email = oDokuWiki_FCKEditorInstance.fckgUserMail; 31 32 var d = new Date(); 33 var date_str = d.getFullYear() + '/' 34 + this.numbersToTwoDigits(d.getMonth() +1) + '/' 35 + this.numbersToTwoDigits(d.getDate()) 36 + ' ' + this.numbersToTwoDigits(d.getHours()) 37 + ':' + this.numbersToTwoDigits(d.getMinutes()); 38 var mail = '— <i><a href="mailto:' + email+'">' + user_name +'</a> ' + date_str +'</i>—'; 39 40 // Insert the timestamp into the document. 41 // http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html#insertHtml 42 editor.insertHtml(mail); 43 } 44 }); 45 // Create a toolbar button that executes the plugin command. 46 // http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.ui.html#addButton 47 editor.ui.addButton( 'Signature', 48 { 49 // Toolbar button tooltip. 50 label: lang.ToolTip, // 'Insert signature', 51 // Reference to the plugin command name. 52 command: 'insertSignature', 53 // Button's icon file path. 54 icon: this.path + 'images/sig.png' 55 } ); 56 } 57} );