X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Fpagebreak%2Fplugin.js;h=ac7653f3af90d76baa26d89e2bdce2d13e2695a6;hb=f0610347140239143439a511ee2bd48cb784f470;hp=b73fbcf82296247b5164ad00b40dd31526c65db1;hpb=e7789c1ad838194d45eeee6ac2eb6e55f5cf35a1;p=ckeditor.git diff --git a/_source/plugins/pagebreak/plugin.js b/_source/plugins/pagebreak/plugin.js index b73fbcf..ac7653f 100644 --- a/_source/plugins/pagebreak/plugin.js +++ b/_source/plugins/pagebreak/plugin.js @@ -1,5 +1,5 @@ /* -Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved. +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ @@ -22,31 +22,66 @@ CKEDITOR.plugins.add( 'pagebreak', command : 'pagebreak' }); + var cssStyles = [ + '{' , + 'background: url(' + CKEDITOR.getUrl( this.path + 'images/pagebreak.gif' ) + ') no-repeat center center;' , + 'clear: both;' , + 'width:100%; _width:99.9%;' , + 'border-top: #999999 1px dotted;' , + 'border-bottom: #999999 1px dotted;' , + 'padding:0;' , + 'height: 5px;' , + 'cursor: default;' , + '}' + ].join( '' ).replace(/;/g, ' !important;' ); // Increase specificity to override other styles, e.g. block outline. + // Add the style that renders our placeholder. - editor.addCss( - 'img.cke_pagebreak' + - '{' + - 'background-image: url(' + CKEDITOR.getUrl( this.path + 'images/pagebreak.gif' ) + ');' + - 'background-position: center center;' + - 'background-repeat: no-repeat;' + - 'clear: both;' + - 'display: block;' + - 'float: none;' + - 'width: 100%;' + - 'border-top: #999999 1px dotted;' + - 'border-bottom: #999999 1px dotted;' + - 'height: 5px;' + - 'page-break-after: always;' + - - '}' ); + editor.addCss( 'div.cke_pagebreak' + cssStyles ); + + // Opera needs help to select the page-break. + CKEDITOR.env.opera && editor.on( 'contentDom', function() + { + editor.document.on( 'click', function( evt ) + { + var target = evt.data.getTarget(); + if ( target.is( 'div' ) && target.hasClass( 'cke_pagebreak') ) + editor.getSelection().selectElement( target ); + }); + }); }, afterInit : function( editor ) { - // Register a filter to displaying placeholders after mode change. + var label = editor.lang.pagebreakAlt; + // Register a filter to displaying placeholders after mode change. var dataProcessor = editor.dataProcessor, - dataFilter = dataProcessor && dataProcessor.dataFilter; + dataFilter = dataProcessor && dataProcessor.dataFilter, + htmlFilter = dataProcessor && dataProcessor.htmlFilter; + + if ( htmlFilter ) + { + htmlFilter.addRules( + { + attributes : { + 'class' : function( value, element ) + { + var className = value.replace( 'cke_pagebreak', '' ); + if ( className != value ) + { + var span = CKEDITOR.htmlParser.fragment.fromHtml( ' ' ); + element.children.length = 0; + element.add( span ); + var attrs = element.attributes; + delete attrs[ 'aria-label' ]; + delete attrs.contenteditable; + delete attrs.title; + } + return className; + } + } + }, 5 ); + } if ( dataFilter ) { @@ -62,7 +97,15 @@ CKEDITOR.plugins.add( 'pagebreak', childStyle = child && ( child.name == 'span' ) && child.attributes.style; if ( childStyle && ( /page-break-after\s*:\s*always/i ).test( style ) && ( /display\s*:\s*none/i ).test( childStyle ) ) - return editor.createFakeParserElement( element, 'cke_pagebreak', 'div' ); + { + attributes.contenteditable = "false"; + attributes[ 'class' ] = "cke_pagebreak"; + attributes[ 'data-cke-display-name' ] = "pagebreak"; + attributes[ 'aria-label' ] = label; + attributes[ 'title' ] = label; + + element.children.length = 0; + } } } }); @@ -76,28 +119,46 @@ CKEDITOR.plugins.pagebreakCmd = { exec : function( editor ) { - // Create the element that represents a print break. - var breakObject = CKEDITOR.dom.element.createFromHtml( '
 
' ); + var label = editor.lang.pagebreakAlt; - // Creates the fake image used for this element. - breakObject = editor.createFakeElement( breakObject, 'cke_pagebreak', 'div' ); + // Create read-only element that represents a print break. + var pagebreak = CKEDITOR.dom.element.createFromHtml( + '
' + + '
', editor.document ); - var ranges = editor.getSelection().getRanges(); + var ranges = editor.getSelection().getRanges( true ); - for ( var range, i = 0 ; i < ranges.length ; i++ ) + editor.fire( 'saveSnapshot' ); + + for ( var range, i = ranges.length - 1 ; i >= 0; i-- ) { range = ranges[ i ]; - if ( i > 0 ) - breakObject = breakObject.clone( true ); + if ( i < ranges.length -1 ) + pagebreak = pagebreak.clone( true ); range.splitBlock( 'p' ); - range.insertNode( breakObject ); + range.insertNode( pagebreak ); if ( i == ranges.length - 1 ) { - range.moveToPosition( breakObject, CKEDITOR.POSITION_AFTER_END ); + var next = pagebreak.getNext(); + range.moveToPosition( pagebreak, CKEDITOR.POSITION_AFTER_END ); + + // If there's nothing or a non-editable block followed by, establish a new paragraph + // to make sure cursor is not trapped. + if ( !next || next.type == CKEDITOR.NODE_ELEMENT && !next.isEditable() ) + range.fixBlock( true, editor.config.enterMode == CKEDITOR.ENTER_DIV ? 'div' : 'p' ); + range.select(); } } + + editor.fire( 'saveSnapshot' ); } };