JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.6.1
[ckeditor.git] / _source / plugins / horizontalrule / plugin.js
1 /*\r
2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license\r
4 */\r
5 \r
6 /**\r
7  * @file Horizontal Rule plugin.\r
8  */\r
9 \r
10 (function()\r
11 {\r
12         var horizontalruleCmd =\r
13         {\r
14                 canUndo : false,    // The undo snapshot will be handled by 'insertElement'.\r
15                 exec : function( editor )\r
16                 {\r
17                         var hr = editor.document.createElement( 'hr' ),\r
18                                 range = new CKEDITOR.dom.range( editor.document );\r
19 \r
20                         editor.insertElement( hr );\r
21 \r
22                         // If there's nothing or a non-editable block followed by, establish a new paragraph\r
23                         // to make sure cursor is not trapped.\r
24                         range.moveToPosition( hr, CKEDITOR.POSITION_AFTER_END );\r
25                         var next = hr.getNext();\r
26                         if ( !next || next.type == CKEDITOR.NODE_ELEMENT && !next.isEditable() )\r
27                                 range.fixBlock( true, editor.config.enterMode == CKEDITOR.ENTER_DIV ? 'div' : 'p'  );\r
28 \r
29                         range.select();\r
30                 }\r
31         };\r
32 \r
33         var pluginName = 'horizontalrule';\r
34 \r
35         // Register a plugin named "horizontalrule".\r
36         CKEDITOR.plugins.add( pluginName,\r
37         {\r
38                 init : function( editor )\r
39                 {\r
40                         editor.addCommand( pluginName, horizontalruleCmd );\r
41                         editor.ui.addButton( 'HorizontalRule',\r
42                                 {\r
43                                         label : editor.lang.horizontalrule,\r
44                                         command : pluginName\r
45                                 });\r
46                 }\r
47         });\r
48 })();\r