]>
git.immae.eu Git - perso/Immae/Projets/packagist/connexionswing-ckeditor-component.git/blob - sources/plugins/pagebreak/plugin.js
2 * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
3 * For licensing, see LICENSE.md or http://ckeditor.com/license
7 * @fileOverview Horizontal Page Break
13 // Register a plugin named "pagebreak".
14 CKEDITOR
.plugins
.add( 'pagebreak', {
15 requires: 'fakeobjects',
16 // jscs:disable maximumLineLength
17 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%
18 // jscs:enable maximumLineLength
19 icons: 'pagebreak,pagebreak-rtl', // %REMOVE_LINE_CORE%
20 hidpi: true, // %REMOVE_LINE_CORE%
23 'background:url(' + CKEDITOR
.getUrl( this.path
+ 'images/pagebreak.gif' ) + ') no-repeat center center;' +
26 'border-top:#999 1px dotted;' +
27 'border-bottom:#999 1px dotted;' +
31 ).replace( /;/g
, ' !important;' ); // Increase specificity to override other styles, e.g. block outline.
33 // Add the style that renders our placeholder.
34 CKEDITOR
.addCss( 'div.cke_pagebreak{' + cssStyles
+ '}' );
37 init: function( editor
) {
38 if ( editor
.blockless
)
41 // Register the command.
42 editor
.addCommand( 'pagebreak', CKEDITOR
.plugins
.pagebreakCmd
);
44 // Register the toolbar button.
45 editor
.ui
.addButton
&& editor
.ui
.addButton( 'PageBreak', {
46 label: editor
.lang
.pagebreak
.toolbar
,
51 // Webkit based browsers needs help to select the page-break.
52 CKEDITOR
.env
.webkit
&& editor
.on( 'contentDom', function() {
53 editor
.document
.on( 'click', function( evt
) {
54 var target
= evt
.data
.getTarget();
55 if ( target
.is( 'div' ) && target
.hasClass( 'cke_pagebreak' ) )
56 editor
.getSelection().selectElement( target
);
61 afterInit: function( editor
) {
62 // Register a filter to displaying placeholders after mode change.
63 var dataProcessor
= editor
.dataProcessor
,
64 dataFilter
= dataProcessor
&& dataProcessor
.dataFilter
,
65 htmlFilter
= dataProcessor
&& dataProcessor
.htmlFilter
,
66 styleRegex
= /page-break-after\s*:\s*always/i,
67 childStyleRegex
= /display\s*:\s*none/i;
69 function upcastPageBreak( element
) {
70 CKEDITOR
.tools
.extend( element
.attributes
, attributesSet( editor
.lang
.pagebreak
.alt
), true );
72 element
.children
.length
= 0;
76 htmlFilter
.addRules( {
78 'class': function( value
, element
) {
79 var className
= value
.replace( 'cke_pagebreak', '' );
80 if ( className
!= value
) {
81 var span
= CKEDITOR
.htmlParser
.fragment
.fromHtml( '<span style="display: none;"> </span>' ).children
[ 0 ];
82 element
.children
.length
= 0;
84 var attrs
= element
.attributes
;
85 delete attrs
[ 'aria-label' ];
86 delete attrs
.contenteditable
;
92 }, { applyToAll: true, priority: 5 } );
96 dataFilter
.addRules( {
98 div: function( element
) {
99 // The "internal form" of a pagebreak is pasted from clipboard.
100 // ACF may have distorted the HTML because "internal form" is
101 // different than "data form". Make sure that element remains valid
102 // by re-upcasting it (#11133).
103 if ( element
.attributes
[ 'data-cke-pagebreak' ] )
104 upcastPageBreak( element
);
106 // Check for "data form" of the pagebreak. If both element and
107 // descendants match, convert them to internal form.
108 else if ( styleRegex
.test( element
.attributes
.style
) ) {
109 var child
= element
.children
[ 0 ];
111 if ( child
&& child
.name
== 'span' && childStyleRegex
.test( child
.attributes
.style
) )
112 upcastPageBreak( element
);
121 // TODO Much probably there's no need to expose this object as public object.
122 CKEDITOR
.plugins
.pagebreakCmd
= {
123 exec: function( editor
) {
124 // Create read-only element that represents a print break.
125 var pagebreak
= editor
.document
.createElement( 'div', {
126 attributes: attributesSet( editor
.lang
.pagebreak
.alt
)
129 editor
.insertElement( pagebreak
);
134 styles: '!page-break-after'
137 match: function( element
) {
138 var parent
= element
.parent
;
139 return parent
&& parent
.name
== 'div' && parent
.styles
&& parent
.styles
[ 'page-break-after' ];
144 requiredContent: 'div{page-break-after}'
147 // Returns an object representing all the attributes
148 // of the "internal form" of the pagebreak element.
149 function attributesSet( label
) {
152 'class': 'cke_pagebreak',
153 contenteditable: 'false',
154 'data-cke-display-name': 'pagebreak',
155 'data-cke-pagebreak': 1,
156 style: 'page-break-after: always',