]> git.immae.eu Git - perso/Immae/Projets/packagist/connexionswing-ckeditor-component.git/blob - sources/plugins/div/plugin.js
Initial commit
[perso/Immae/Projets/packagist/connexionswing-ckeditor-component.git] / sources / plugins / div / plugin.js
1 /**
2 * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
3 * For licensing, see LICENSE.md or http://ckeditor.com/license
4 */
5
6 /**
7 * @fileOverview The "div" plugin. It wraps the selected block level elements with a 'div' element with specified styles and attributes.
8 *
9 */
10
11 ( function() {
12 CKEDITOR.plugins.add( 'div', {
13 requires: 'dialog',
14 // jscs:disable maximumLineLength
15 lang: 'af,ar,bg,bn,bs,ca,cs,cy,da,de,el,en,en-au,en-ca,en-gb,eo,es,et,eu,fa,fi,fo,fr,fr-ca,gl,gu,he,hi,hr,hu,id,is,it,ja,ka,km,ko,ku,lt,lv,mk,mn,ms,nb,nl,no,pl,pt,pt-br,ro,ru,si,sk,sl,sq,sr,sr-latn,sv,th,tr,tt,ug,uk,vi,zh,zh-cn', // %REMOVE_LINE_CORE%
16 // jscs:enable maximumLineLength
17 icons: 'creatediv', // %REMOVE_LINE_CORE%
18 hidpi: true, // %REMOVE_LINE_CORE%
19 init: function( editor ) {
20 if ( editor.blockless )
21 return;
22
23 var lang = editor.lang.div,
24 allowed = 'div(*)';
25
26 if ( CKEDITOR.dialog.isTabEnabled( editor, 'editdiv', 'advanced' ) )
27 allowed += ';div[dir,id,lang,title]{*}';
28
29 editor.addCommand( 'creatediv', new CKEDITOR.dialogCommand( 'creatediv', {
30 allowedContent: allowed,
31 requiredContent: 'div',
32 contextSensitive: true,
33 refresh: function( editor, path ) {
34 var context = editor.config.div_wrapTable ? path.root : path.blockLimit;
35 this.setState( 'div' in context.getDtd() ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED );
36 }
37 } ) );
38
39 editor.addCommand( 'editdiv', new CKEDITOR.dialogCommand( 'editdiv', { requiredContent: 'div' } ) );
40 editor.addCommand( 'removediv', {
41 requiredContent: 'div',
42 exec: function( editor ) {
43 var selection = editor.getSelection(),
44 ranges = selection && selection.getRanges(),
45 range,
46 bookmarks = selection.createBookmarks(),
47 walker,
48 toRemove = [];
49
50 function findDiv( node ) {
51 var div = CKEDITOR.plugins.div.getSurroundDiv( editor, node );
52 if ( div && !div.data( 'cke-div-added' ) ) {
53 toRemove.push( div );
54 div.data( 'cke-div-added' );
55 }
56 }
57
58 for ( var i = 0; i < ranges.length; i++ ) {
59 range = ranges[ i ];
60 if ( range.collapsed )
61 findDiv( selection.getStartElement() );
62 else {
63 walker = new CKEDITOR.dom.walker( range );
64 walker.evaluator = findDiv;
65 walker.lastForward();
66 }
67 }
68
69 for ( i = 0; i < toRemove.length; i++ )
70 toRemove[ i ].remove( true );
71
72 selection.selectBookmarks( bookmarks );
73 }
74 } );
75
76 editor.ui.addButton && editor.ui.addButton( 'CreateDiv', {
77 label: lang.toolbar,
78 command: 'creatediv',
79 toolbar: 'blocks,50'
80 } );
81
82 if ( editor.addMenuItems ) {
83 editor.addMenuItems( {
84 editdiv: {
85 label: lang.edit,
86 command: 'editdiv',
87 group: 'div',
88 order: 1
89 },
90
91 removediv: {
92 label: lang.remove,
93 command: 'removediv',
94 group: 'div',
95 order: 5
96 }
97 } );
98
99 if ( editor.contextMenu ) {
100 editor.contextMenu.addListener( function( element ) {
101 if ( !element || element.isReadOnly() )
102 return null;
103
104
105 if ( CKEDITOR.plugins.div.getSurroundDiv( editor ) ) {
106 return {
107 editdiv: CKEDITOR.TRISTATE_OFF,
108 removediv: CKEDITOR.TRISTATE_OFF
109 };
110 }
111
112 return null;
113 } );
114 }
115 }
116
117 CKEDITOR.dialog.add( 'creatediv', this.path + 'dialogs/div.js' );
118 CKEDITOR.dialog.add( 'editdiv', this.path + 'dialogs/div.js' );
119 }
120 } );
121
122 CKEDITOR.plugins.div = {
123 getSurroundDiv: function( editor, start ) {
124 var path = editor.elementPath( start );
125 return editor.elementPath( path.blockLimit ).contains( function( node ) {
126 // Avoid read-only (i.e. contenteditable="false") divs (#11083).
127 return node.is( 'div' ) && !node.isReadOnly();
128 }, 1 );
129 }
130 };
131 } )();