1/**
2 * Basic sample plugin inserting current date and time into CKEditor editing area.
3 */
4(function () {
5// Register the plugin with the editor.
6// http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.plugins.html
7CKEDITOR.plugins.add( 'shortcuts',
8{
9
10	// The plugin initialization logic goes inside this method.
11	// http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.pluginDefinition.html#init
12	init: function( editor )
13	{
14		// Define an editor command that inserts a timestamp.
15		// http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html#addCommand
16		editor.addCommand( 'ckgundoheader',
17			{
18				// Define a function that will be fired when the command is executed.
19				// http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.commandDefinition.html#exec
20				exec : function( editor )
21				{
22                     var text =   get_selected_text(editor);
23					// var timestamp = new Date();
24					// Insert the timestamp into the document.
25					// http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html#insertHtml
26                   editor.insertHtml( '<div>&nbsp;</div>' );
27					editor.insertHtml( '<div>' + text + '</div>' );
28				}
29			});
30
31		editor.addCommand( 'ckginsheaderone',
32			{
33
34				// Define a function that will be fired when the command is executed.
35				// http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.commandDefinition.html#exec
36				exec : function( editor )
37				{
38                    var text =  get_selected_text(editor);
39                    write_header(editor,text,"1");
40				}
41			});
42
43		editor.addCommand( 'ckginsheadertwo',
44			{
45				exec : function( editor )
46				{
47                    var text =  get_selected_text(editor);
48                    write_header(editor,text,"2");
49				}
50			}) ;
51
52        editor.addCommand( 'ckginsheaderthree',
53			{
54				exec : function( editor )
55				{
56                    var text =  get_selected_text(editor);
57                    write_header(editor,text,"3");
58				}
59			});
60
61		editor.addCommand( 'ckginsheaderfour',
62			{
63				exec : function( editor )
64				{
65                    var text =  get_selected_text(editor);
66                    write_header(editor,text,"4");
67				}
68			});
69
70		editor.addCommand( 'ckginsheaderfive',
71			{
72				exec : function( editor )
73				{
74                    var text =  get_selected_text(editor);
75                    write_header(editor,text,"5");
76				}
77			});
78
79		editor.addCommand( 'ckginscode',
80			{
81				exec : function( editor )
82				{
83                    var text =  get_selected_text(editor);
84                    editor.insertHtml( '<code>' +text + '</code>' );
85				}
86			});
87	}
88}
89 );
90 function get_selected_text(ed) {
91        var selection = ed.getSelection();
92        if(selection)   {
93             var text = selection.getSelectedText();
94             return text;
95         }
96            return "";
97 }
98
99 function write_header(ed,text,n) {
100       var h = 'h' + n +'>';
101       var o = '<'+h;
102       var c = '</'+h;
103
104       ed.insertHtml( '<div>' +o  +text +  c + '</div>' );
105 }
106
107})();
108