2f954dc1155f150917a5b95dc0d73b9c5a1196e9
2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
3 For licensing, see LICENSE.html or http://ckeditor.com/license
7 * @fileOverview The "div" plugin. It wraps the selected block level elements with a 'div' element with specified styles and attributes.
13 CKEDITOR
.plugins
.add( 'div',
15 requires
: [ 'editingblock', 'domiterator', 'styles' ],
17 init : function( editor
)
19 var lang
= editor
.lang
.div
;
21 editor
.addCommand( 'creatediv', new CKEDITOR
.dialogCommand( 'creatediv' ) );
22 editor
.addCommand( 'editdiv', new CKEDITOR
.dialogCommand( 'editdiv' ) );
23 editor
.addCommand( 'removediv',
25 exec : function( editor
)
27 var selection
= editor
.getSelection(),
28 ranges
= selection
&& selection
.getRanges(),
30 bookmarks
= selection
.createBookmarks(),
34 function findDiv( node
)
36 var path
= new CKEDITOR
.dom
.elementPath( node
),
37 blockLimit
= path
.blockLimit
,
38 div
= blockLimit
.is( 'div' ) && blockLimit
;
40 if ( div
&& !div
.data( 'cke-div-added' ) )
43 div
.data( 'cke-div-added' );
47 for ( var i
= 0 ; i
< ranges
.length
; i
++ )
50 if ( range
.collapsed
)
51 findDiv( selection
.getStartElement() );
54 walker
= new CKEDITOR
.dom
.walker( range
);
55 walker
.evaluator
= findDiv
;
60 for ( i
= 0 ; i
< toRemove
.length
; i
++ )
61 toRemove
[ i
].remove( true );
63 selection
.selectBookmarks( bookmarks
);
67 editor
.ui
.addButton( 'CreateDiv',
73 if ( editor
.addMenuItems
)
88 command
: 'removediv',
94 if ( editor
.contextMenu
)
96 editor
.contextMenu
.addListener( function( element
, selection
)
98 if ( !element
|| element
.isReadOnly() )
101 var elementPath
= new CKEDITOR
.dom
.elementPath( element
),
102 blockLimit
= elementPath
.blockLimit
;
104 if ( blockLimit
&& blockLimit
.getAscendant( 'div', true ) )
107 editdiv
: CKEDITOR
.TRISTATE_OFF
,
108 removediv
: CKEDITOR
.TRISTATE_OFF
117 CKEDITOR
.dialog
.add( 'creatediv', this.path
+ 'dialogs/div.js' );
118 CKEDITOR
.dialog
.add( 'editdiv', this.path
+ 'dialogs/div.js' );