Ticket #4548: 4548_4.patch

File 4548_4.patch, 12.9 KB (added by Garry Yao, 14 years ago)
  • _source/plugins/drupalpagebreak/plugin.js

     
     1/*
     2Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     3For licensing, see LICENSE.html or http://ckeditor.com/license
     4*/
     5
     6/**
     7 * @file Insert a Drupal page breakl(fake comment) into the body, split up contents when necessary.
     8 */
     9
     10CKEDITOR.plugins.add( 'drupalpagebreak',
     11{
     12        init : function( editor )
     13        {
     14                editor.addCommand( 'insertDrupalPageBreak',
     15                {
     16                        exec : function( editor )
     17                        {
     18                                var placeholder = CKEDITOR.dom.element.createFromHtml( '<cke:comment></cke:comment>' ),
     19                                        range = new CKEDITOR.dom.range( editor.document );
     20                                editor.insertElement( placeholder );
     21                                range.selectNodeContents( placeholder );
     22                                range.select( true );
     23                                editor.insertHtml( '<!--break-->' );
     24                               
     25                        }
     26                } );
     27               
     28                editor.ui.addButton( 'DrupalPageBreak',
     29                        {
     30                                label : editor.lang.drupalPageBreak,
     31                                command : 'insertDrupalPageBreak'
     32                        });
     33        },
     34
     35        requires : [ 'fakecomment' ]
     36});
  • _source/plugins/fakecomment/plugin.js

     
     1/*
     2Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     3For licensing, see LICENSE.html or http://ckeditor.com/license
     4*/
     5
     6/**
     7 * @file Comment place holder plugin which create a fake object to represent HTML
     8 * comments in certain patterns.
     9 */
     10
     11CKEDITOR.plugins.add( 'fakecomment',
     12{
     13        requires  : [ 'htmldataprocessor','fakeobjects' ],
     14        init : function( editor )
     15        {
     16                // Add the style that renders our placeholder.
     17                editor.addCss(
     18                        'img.cke_comment' +
     19                        '{' +
     20                                'background-image: url(' + CKEDITOR.getUrl( this.path + 'images/placeholder.gif' ) + ');' +
     21                            '-webkit-background-size: 20px 20px;' +
     22                            '-o-background-size: 20px 20px;' +
     23                                'background-position: center center;' +
     24                                'background-repeat: no-repeat;' +
     25                                'display: inline;' +
     26                                'width: 20px;' +
     27                                'vertical-align: middle;' +
     28                                'border: #999999 1px dotted;' +
     29                        '}' );
     30        },
     31
     32        // There's currently no gurantee on registration order, this make sure
     33        // the registration will come after the default ones in 'htmldataprocessor'.
     34        afterInit : function( editor )
     35        {
     36                var dataProcessor = editor.dataProcessor,
     37                        dataFilter = dataProcessor.dataFilter,
     38                        htmlFilter = dataProcessor.htmlFilter,
     39                        // Borrow the comment output filters to restore them.
     40                        commentFilters = htmlFilter._.comment,
     41                        filter = commentFilters && ( commentFilters.filter || commentFilters[ 0 ] ),
     42                        config = editor.config,
     43                        fakeComments = config.fakeComments || [] ;
     44
     45                if( ! ( fakeComments && fakeComments.length ) )
     46                        return;
     47
     48                var fakeComment,
     49                    // Used when 'displayName' is not presented in comment definition.
     50                        defaultDisplayName = 'cke:comment',
     51                        allFakeWrapperTagNames = {},
     52                        allFakeCommentPatterns = [];
     53
     54                for ( var i = 0; i < fakeComments.length; i++ )
     55                {
     56                        fakeComment = fakeComments[ i ];
     57                        if( fakeComment.displayName )
     58                                allFakeWrapperTagNames[ fakeComment.displayName ] = 1;
     59                        else if( !( defaultDisplayName in allFakeWrapperTagNames ) )
     60                                allFakeWrapperTagNames[ defaultDisplayName ] = 1;
     61
     62                        fakeComment.pattern && allFakeCommentPatterns.push(
     63                                [ fakeComment.pattern,
     64                                  fakeComment.displayName || defaultDisplayName ] );
     65                }
     66
     67                // Create fake objects for all fake comments.
     68                dataFilter.addRules(
     69                        {
     70                                comment : function( value )
     71                                {
     72                                        var data = filter ? filter( value ) : value,
     73                                                fakeWrapper, fakeElement,
     74                                                pattern,
     75                                                fakeCommentName;
     76
     77                                        // Instance of CKEDITOR.htmlParser.cdata is expected.
     78                                        if ( data.value )
     79                                        {
     80                                                for ( var i = 0; i < allFakeCommentPatterns.length; i++ )
     81                                                {
     82                                                        pattern = allFakeCommentPatterns[ i ];
     83                                                        // Is it actually a comment and match the desired pattern?
     84                                                        data.value.replace( /<!--([\s\S]*?)-->/, function( match, content )
     85                                                        {
     86                                                                if( content.match( pattern[ 0 ] ) )
     87                                                                {
     88                                                                        fakeCommentName = pattern[ 1 ];
     89                                                                        fakeWrapper = new CKEDITOR.htmlParser.element( fakeCommentName, {} );
     90                                                                        fakeWrapper.add( data );
     91                                                                        fakeElement = editor.createFakeParserElement(
     92                                                                                        fakeWrapper,
     93                                                                                        'cke_comment cke_fc_' + CKEDITOR.tools.escapeCssSelector( fakeCommentName ),
     94                                                                                        fakeCommentName,
     95                                                                                        false );
     96
     97                                                                        // Comment content specific style.
     98                                                                        fakeElement.attributes.style = CKEDITOR.tools.clone( pattern.styles );
     99                                                                        allFakeWrapperTagNames[ fakeCommentName ] = 1;
     100                                                                }
     101                                                        } );
     102
     103                                                        if ( fakeElement )
     104                                                                return fakeElement;
     105                                                }
     106                                        }
     107                                        return value;
     108                                }
     109                        } );
     110
     111                // Reveal the real comments under cover on output.
     112                htmlFilter.addRules(
     113                {
     114                        elements :
     115                        {
     116                                '$' : function( element )
     117                                {
     118                                        // Drop the wrapper element.
     119                                        if ( element.name in allFakeWrapperTagNames )
     120                                        {
     121                                                delete element.name;
     122                                        }
     123                                }
     124                        }
     125                } );
     126
     127        }
     128} );
     129
     130/**
     131 * A list of comment definition which will be converted to fake element in wysiwyg mode.
     132 * @name CKEDITOR.config.fakeComments
     133 * @type Array
     134 * @default []
     135 * @example
     136 * CKEDITOR.config.fakeComments =
     137 * [
     138 *      {
     139 *              pattern : /^break$/,
     140 *              styles :
     141 *              {
     142 *                      display : 'block'
     143 *              },
     144 *              displayName : 'page-break'
     145 *      }
     146 * ];
     147 */
  • _source/plugins/wysiwygarea/plugin.js

     
    5858
    5959                        var element = evt.data,
    6060                                elementName = element.getName(),
    61                                 isBlock = CKEDITOR.dtd.$block[ elementName ];
     61                                dtd = CKEDITOR.dtd,
     62                                isBlock = dtd.$block[ elementName ] || !dtd[ elementName ];
    6263
    6364                        var selection = this.getSelection(),
    6465                                ranges = selection.getRanges();
     
    8485                                var current, dtd;
    8586                                if ( isBlock )
    8687                                {
    87                                         while( ( current = range.getCommonAncestor( false, true ) )
    88                                                         && ( dtd = CKEDITOR.dtd[ current.getName() ] )
    89                                                         && !( dtd && dtd [ elementName ] ) )
    90                                         {
    91                                                 // If we're in an empty block which indicate a new paragraph,
    92                                                 // simply replace it with the inserting block.(#3664)
    93                                                 if ( range.checkStartOfBlock()
    94                                                         && range.checkEndOfBlock() )
    95                                                 {
    96                                                         range.setStartBefore( current );
    97                                                         range.collapse( true );
    98                                                         current.remove();
    99                                                 }
    100                                                 else
    101                                                         range.splitBlock();
    102                                         }
     88                                while( ( current = range.getCommonAncestor( false, true ) )
     89                                                && ( dtd = CKEDITOR.dtd[ current.getName() ] )
     90                                                && !( dtd && dtd [ elementName ] ) )
     91                                {
     92                                        // If we're in an empty block which indicate a new paragraph,
     93                                        // simply replace it with the inserting block.(#3664)
     94                                        if ( range.checkStartOfBlock()
     95                                                && range.checkEndOfBlock() )
     96                                        {
     97                                                range.setStartBefore( current );
     98                                                range.collapse( true );
     99                                                current.remove();
     100                                        }
     101                                        else
     102                                                range.splitBlock();
     103                                }
    103104                                }
    104105
    105106                                // Insert the new node.
  • _source/core/dom/elementpath.js

     
    1 /*
     1/*
    22Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
    33For licensing, see LICENSE.html or http://ckeditor.com/license
    44*/
    55
    66(function()
    77{
    8         // Elements that may be considered the "Block boundary" in an element path.
    9         var pathBlockElements = { address:1,blockquote:1,dl:1,h1:1,h2:1,h3:1,h4:1,h5:1,h6:1,p:1,pre:1,li:1,dt:1,de:1 };
    108
    119        // Elements that may be considered the "Block limit" in an element path.
    1210        var pathBlockLimitElements = { body:1,div:1,table:1,tbody:1,tr:1,td:1,th:1,caption:1,form:1 };
     
    4846
    4947                                if ( !blockLimit )
    5048                                {
    51                                         if ( !block && pathBlockElements[ elementName ] )
     49                                        if ( !block && e.isBlockBoundary() )
    5250                                                block = e;
    5351
    5452                                        if ( pathBlockLimitElements[ elementName ] )
  • _source/lang/en.js

     
    5555        unlink                  : 'Unlink',
    5656        undo                    : 'Undo',
    5757        redo                    : 'Redo',
     58        drupalPageBreak : 'Drupal Page Break',
    5859
     60
    5961        // Common messages and labels.
    6062        common :
    6163        {
  • _source/plugins/fakeobjects/plugin.js

     
    55
    66(function()
    77{
    8         var htmlFilterRules =
    9         {
    10                 elements :
    11                 {
    12                         $ : function( element )
    13                         {
    14                                 var realHtml = element.attributes._cke_realelement,
    15                                         realFragment = realHtml && new CKEDITOR.htmlParser.fragment.fromHtml( decodeURIComponent( realHtml ) ),
    16                                         realElement = realFragment && realFragment.children[ 0 ];
    17 
    18                                 if ( realElement )
    19                                 {
    20                                         // If we have width/height in the element, we must move it into
    21                                         // the real element.
    22 
    23                                         var style = element.attributes.style;
    24 
    25                                         if ( style )
    26                                         {
    27                                                 // Get the width from the style.
    28                                                 var match = /(?:^|\s)width\s*:\s*(\d+)/.exec( style ),
    29                                                         width = match && match[1];
    30 
    31                                                 // Get the height from the style.
    32                                                 match = /(?:^|\s)height\s*:\s*(\d+)/.exec( style );
    33                                                 var height = match && match[1];
    34 
    35                                                 if ( width )
    36                                                         realElement.attributes.width = width;
    37 
    38                                                 if ( height )
    39                                                         realElement.attributes.height = height;
    40                                         }
    41                                 }
    42 
    43                                 return realElement;
    44                         }
    45                 }
    46         };
    47 
    488        CKEDITOR.plugins.add( 'fakeobjects',
    499        {
    5010                requires : [ 'htmlwriter' ],
     
    5515                                htmlFilter = dataProcessor && dataProcessor.htmlFilter;
    5616
    5717                        if ( htmlFilter )
    58                                 htmlFilter.addRules( htmlFilterRules );
    59                 }
    60         });
     18                                htmlFilter.addRules(
     19                                {
     20                                        elements :
     21                                        {
     22                                                $ : CKEDITOR.editor.restoreParserElement
     23                                        }
     24                                } );
     25                }
     26        });
    6127})();
    6228
    6329CKEDITOR.editor.prototype.createFakeElement = function( realElement, className, realElementType, isResizable )
     
    10975        var html = decodeURIComponent( fakeElement.getAttribute( '_cke_realelement' ) );
    11076        return CKEDITOR.dom.element.createFromHtml( html, this.document );
    11177};
     78
     79CKEDITOR.editor.restoreParserElement = function( fakeElement )
     80{
     81        var realHtml = fakeElement.attributes._cke_realelement,
     82                realFragment = realHtml && new CKEDITOR.htmlParser.fragment.fromHtml( decodeURIComponent( realHtml ) ),
     83                realElement = realFragment && realFragment.children[ 0 ];
     84
     85        if ( realElement )
     86        {
     87                // If we have width/height in the fakeElement, we must move it into
     88                // the real fakeElement.
     89
     90                var style = fakeElement.attributes.style;
     91
     92                if ( style )
     93                {
     94                        // Get the width from the style.
     95                        var match = /(?:^|\s)width\s*:\s*(\d+)/.exec( style ),
     96                                width = match && match[1];
     97
     98                        // Get the height from the style.
     99                        match = /(?:^|\s)height\s*:\s*(\d+)/.exec( style );
     100                        var height = match && match[1];
     101
     102                        if ( width )
     103                                realElement.attributes.width = width;
     104
     105                        if ( height )
     106                                realElement.attributes.height = height;
     107                }
     108        }
     109
     110        return realElement;
     111}
  • _source/core/htmlparser/fragment.js

     
    107107                        // body (if fixForBody).
    108108                        if ( fixForBody && !target.type )
    109109                        {
    110                                 var elementName, realElementName;
     110                                var elementName, realElement;
    111111                                if ( element.attributes
    112                                          && ( realElementName =
    113                                                   element.attributes[ '_cke_real_element_type' ] ) )
    114                                         elementName = realElementName;
    115                                 else
    116                                         elementName =  element.name;
    117                                 if ( !( elementName in CKEDITOR.dtd.$body ) )
     112                                         && element.attributes[ '_cke_real_element_type' ] )
     113                                        realElement = CKEDITOR.editor.restoreParserElement( element );
     114
     115                                elementName =  realElement ?
     116                                               ( realElement.isUnknown ?    // Don't fix for unknown elements.
     117                                                 '' : realElement.name ) : element.name;
     118
     119                                if ( elementName && !( elementName in CKEDITOR.dtd.$body ) )
    118120                                {
    119121                                        var savedCurrent = currentNode;
    120122
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy