]> git.immae.eu Git - perso/Immae/Projets/packagist/ludivine-ckeditor-component.git/blob - sources/plugins/div/plugin.js
Add audio, color and fonts
[perso/Immae/Projets/packagist/ludivine-ckeditor-component.git] / sources / plugins / div / plugin.js
1 /**
2 * @license Copyright (c) 2003-2017, 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,az,bg,bn,bs,ca,cs,cy,da,de,de-ch,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,oc,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 contentTransformations: [
34 [ 'div: alignmentToStyle' ]
35 ],
36 refresh: function( editor, path ) {
37 var context = editor.config.div_wrapTable ? path.root : path.blockLimit;
38 this.setState( 'div' in context.getDtd() ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED );
39 }
40 } ) );
41
42 editor.addCommand( 'editdiv', new CKEDITOR.dialogCommand( 'editdiv', { requiredContent: 'div' } ) );
43 editor.addCommand( 'removediv', {
44 requiredContent: 'div',
45 exec: function( editor ) {
46 var selection = editor.getSelection(),
47 ranges = selection && selection.getRanges(),
48 range,
49 bookmarks = selection.createBookmarks(),
50 walker,
51 toRemove = [];
52
53 function findDiv( node ) {
54 var div = CKEDITOR.plugins.div.getSurroundDiv( editor, node );
55 if ( div && !div.data( 'cke-div-added' ) ) {
56 toRemove.push( div );
57 div.data( 'cke-div-added' );
58 }
59 }
60
61 for ( var i = 0; i < ranges.length; i++ ) {
62 range = ranges[ i ];
63 if ( range.collapsed )
64 findDiv( selection.getStartElement() );
65 else {
66 walker = new CKEDITOR.dom.walker( range );
67 walker.evaluator = findDiv;
68 walker.lastForward();
69 }
70 }
71
72 for ( i = 0; i < toRemove.length; i++ )
73 toRemove[ i ].remove( true );
74
75 selection.selectBookmarks( bookmarks );
76 }
77 } );
78
79 editor.ui.addButton && editor.ui.addButton( 'CreateDiv', {
80 label: lang.toolbar,
81 command: 'creatediv',
82 toolbar: 'blocks,50'
83 } );
84
85 if ( editor.addMenuItems ) {
86 editor.addMenuItems( {
87 editdiv: {
88 label: lang.edit,
89 command: 'editdiv',
90 group: 'div',
91 order: 1
92 },
93
94 removediv: {
95 label: lang.remove,
96 command: 'removediv',
97 group: 'div',
98 order: 5
99 }
100 } );
101
102 if ( editor.contextMenu ) {
103 editor.contextMenu.addListener( function( element ) {
104 if ( !element || element.isReadOnly() )
105 return null;
106
107
108 if ( CKEDITOR.plugins.div.getSurroundDiv( editor ) ) {
109 return {
110 editdiv: CKEDITOR.TRISTATE_OFF,
111 removediv: CKEDITOR.TRISTATE_OFF
112 };
113 }
114
115 return null;
116 } );
117 }
118 }
119
120 CKEDITOR.dialog.add( 'creatediv', this.path + 'dialogs/div.js' );
121 CKEDITOR.dialog.add( 'editdiv', this.path + 'dialogs/div.js' );
122 }
123 } );
124
125 CKEDITOR.plugins.div = {
126 getSurroundDiv: function( editor, start ) {
127 var path = editor.elementPath( start );
128 return editor.elementPath( path.blockLimit ).contains( function( node ) {
129 // Avoid read-only (i.e. contenteditable="false") divs (#11083).
130 return node.is( 'div' ) && !node.isReadOnly();
131 }, 1 );
132 }
133 };
134 } )();