]>
Commit | Line | Data |
---|---|---|
eaa92715 IB |
1 | /**\r |
2 | * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.\r | |
3 | * For licensing, see LICENSE.md or http://ckeditor.com/license\r | |
4 | */\r | |
5 | \r | |
6 | /**\r | |
7 | * @fileOverview The "div" plugin. It wraps the selected block level elements with a 'div' element with specified styles and attributes.\r | |
8 | *\r | |
9 | */\r | |
10 | \r | |
11 | ( function() {\r | |
12 | CKEDITOR.plugins.add( 'div', {\r | |
13 | requires: 'dialog',\r | |
14 | // jscs:disable maximumLineLength\r | |
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%\r | |
16 | // jscs:enable maximumLineLength\r | |
17 | icons: 'creatediv', // %REMOVE_LINE_CORE%\r | |
18 | hidpi: true, // %REMOVE_LINE_CORE%\r | |
19 | init: function( editor ) {\r | |
20 | if ( editor.blockless )\r | |
21 | return;\r | |
22 | \r | |
23 | var lang = editor.lang.div,\r | |
24 | allowed = 'div(*)';\r | |
25 | \r | |
26 | if ( CKEDITOR.dialog.isTabEnabled( editor, 'editdiv', 'advanced' ) )\r | |
27 | allowed += ';div[dir,id,lang,title]{*}';\r | |
28 | \r | |
29 | editor.addCommand( 'creatediv', new CKEDITOR.dialogCommand( 'creatediv', {\r | |
30 | allowedContent: allowed,\r | |
31 | requiredContent: 'div',\r | |
32 | contextSensitive: true,\r | |
33 | contentTransformations: [\r | |
34 | [ 'div: alignmentToStyle' ]\r | |
35 | ],\r | |
36 | refresh: function( editor, path ) {\r | |
37 | var context = editor.config.div_wrapTable ? path.root : path.blockLimit;\r | |
38 | this.setState( 'div' in context.getDtd() ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED );\r | |
39 | }\r | |
40 | } ) );\r | |
41 | \r | |
42 | editor.addCommand( 'editdiv', new CKEDITOR.dialogCommand( 'editdiv', { requiredContent: 'div' } ) );\r | |
43 | editor.addCommand( 'removediv', {\r | |
44 | requiredContent: 'div',\r | |
45 | exec: function( editor ) {\r | |
46 | var selection = editor.getSelection(),\r | |
47 | ranges = selection && selection.getRanges(),\r | |
48 | range,\r | |
49 | bookmarks = selection.createBookmarks(),\r | |
50 | walker,\r | |
51 | toRemove = [];\r | |
52 | \r | |
53 | function findDiv( node ) {\r | |
54 | var div = CKEDITOR.plugins.div.getSurroundDiv( editor, node );\r | |
55 | if ( div && !div.data( 'cke-div-added' ) ) {\r | |
56 | toRemove.push( div );\r | |
57 | div.data( 'cke-div-added' );\r | |
58 | }\r | |
59 | }\r | |
60 | \r | |
61 | for ( var i = 0; i < ranges.length; i++ ) {\r | |
62 | range = ranges[ i ];\r | |
63 | if ( range.collapsed )\r | |
64 | findDiv( selection.getStartElement() );\r | |
65 | else {\r | |
66 | walker = new CKEDITOR.dom.walker( range );\r | |
67 | walker.evaluator = findDiv;\r | |
68 | walker.lastForward();\r | |
69 | }\r | |
70 | }\r | |
71 | \r | |
72 | for ( i = 0; i < toRemove.length; i++ )\r | |
73 | toRemove[ i ].remove( true );\r | |
74 | \r | |
75 | selection.selectBookmarks( bookmarks );\r | |
76 | }\r | |
77 | } );\r | |
78 | \r | |
79 | editor.ui.addButton && editor.ui.addButton( 'CreateDiv', {\r | |
80 | label: lang.toolbar,\r | |
81 | command: 'creatediv',\r | |
82 | toolbar: 'blocks,50'\r | |
83 | } );\r | |
84 | \r | |
85 | if ( editor.addMenuItems ) {\r | |
86 | editor.addMenuItems( {\r | |
87 | editdiv: {\r | |
88 | label: lang.edit,\r | |
89 | command: 'editdiv',\r | |
90 | group: 'div',\r | |
91 | order: 1\r | |
92 | },\r | |
93 | \r | |
94 | removediv: {\r | |
95 | label: lang.remove,\r | |
96 | command: 'removediv',\r | |
97 | group: 'div',\r | |
98 | order: 5\r | |
99 | }\r | |
100 | } );\r | |
101 | \r | |
102 | if ( editor.contextMenu ) {\r | |
103 | editor.contextMenu.addListener( function( element ) {\r | |
104 | if ( !element || element.isReadOnly() )\r | |
105 | return null;\r | |
106 | \r | |
107 | \r | |
108 | if ( CKEDITOR.plugins.div.getSurroundDiv( editor ) ) {\r | |
109 | return {\r | |
110 | editdiv: CKEDITOR.TRISTATE_OFF,\r | |
111 | removediv: CKEDITOR.TRISTATE_OFF\r | |
112 | };\r | |
113 | }\r | |
114 | \r | |
115 | return null;\r | |
116 | } );\r | |
117 | }\r | |
118 | }\r | |
119 | \r | |
120 | CKEDITOR.dialog.add( 'creatediv', this.path + 'dialogs/div.js' );\r | |
121 | CKEDITOR.dialog.add( 'editdiv', this.path + 'dialogs/div.js' );\r | |
122 | }\r | |
123 | } );\r | |
124 | \r | |
125 | CKEDITOR.plugins.div = {\r | |
126 | getSurroundDiv: function( editor, start ) {\r | |
127 | var path = editor.elementPath( start );\r | |
128 | return editor.elementPath( path.blockLimit ).contains( function( node ) {\r | |
129 | // Avoid read-only (i.e. contenteditable="false") divs (#11083).\r | |
130 | return node.is( 'div' ) && !node.isReadOnly();\r | |
131 | }, 1 );\r | |
132 | }\r | |
133 | };\r | |
134 | } )();\r |