Ticket #7193: 7193_2.patch

File 7193_2.patch, 6.6 KB (added by Garry Yao, 14 years ago)
  • _source/plugins/fakeobjects/plugin.js

     
    1 /*
     1/*
    22Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
    33For licensing, see LICENSE.html or http://ckeditor.com/license
    44*/
    55
    66(function()
    77{
     8        function rebuildStyleSheets()
     9        {
     10                var map = this._.fakeClassMap,
     11                        fakeNamesRegex = [];
     12
     13                for ( var name in map )
     14                        fakeNamesRegex.push( name )
     15                if ( fakeNamesRegex.length )
     16                {
     17                        fakeNamesRegex= new RegExp( '(?:^|\\b)('+fakeNamesRegex.join( '|' ) + ')(?:$|\\b)','g' );
     18
     19
     20                        var sheets = this.document.$.styleSheets,
     21                                sheet, rules, count,rule, selector, style;
     22
     23                        // Walk through all the rules to refactor corresponding selectors.
     24                        for ( var i = 0; i < sheets.length; i++ )
     25                        {
     26                                sheet = sheets[ i ];
     27                                rules = sheet.cssRules || sheet.rules;
     28                                count = rules.length;
     29                                for ( var j = 0; j < count; j++ )
     30                                {
     31                                        rule = rules[ j ];
     32                                        selector = rule.selectorText;
     33                                        selector && ( selector = selector.toLowerCase().replace( fakeNamesRegex,
     34                                                function( match, name ) { return map[ name ]; } ));
     35
     36                                        // Replace existing rule with new selector.
     37                                        if ( selector != rule.selectorText )
     38                                        {
     39                                                style = rule.cssText.match( /\{([\s\S]*?)\}/ )[ 1 ];
     40                                                sheet[ sheet.deleteRule ? 'deleteRule' : 'removeRule' ].call( sheet, j );
     41                                                sheet.insertRule ? sheet.insertRule( selector + '{' + style + '}', j ) : sheet.addRule( selector, style, j );
     42                                                console.log(selector, style );
     43                                        }
     44                                }
     45                        }
     46                }
     47        }
     48
    849        var htmlFilterRules =
    950        {
    1051                elements :
     
    5697
    5798                        if ( htmlFilter )
    5899                                htmlFilter.addRules( htmlFilterRules );
     100
     101                        // Mapping from real element name to fake element selector, e.g. hr -> img.cke_hr
     102                        editor._.fakeClassMap = {};
     103
     104                        // Rebuild the content styles on any new added content to
     105                        // allow fake elements to receive styles assigned to their real type.
     106                        editor.on( 'contentDom', rebuildStyleSheets );
     107                        editor.on( 'insertHtml', rebuildStyleSheets, null, null, 1000 );
     108                        editor.on( 'insertElement', rebuildStyleSheets, null, null, 1000 );
    59109                }
    60110        });
    61111})();
     
    67117
    68118        var attributes =
    69119        {
    70                 'class' : className,
     120                'class' : [ className, realElement.getAttribute( 'class' ) ].join( ' ' ),
    71121                src : CKEDITOR.getUrl( 'images/spacer.gif' ),
    72122                'data-cke-realelement' : encodeURIComponent( realElement.getOuterHtml() ),
    73123                'data-cke-real-node-type' : realElement.type,
     
    82132        if ( isResizable )
    83133                attributes[ 'data-cke-resizable' ] = isResizable;
    84134
     135        this._.fakeClassMap[ realElementType ] = 'img.' + className;
    85136        return this.document.createElement( 'img', { attributes : attributes } );
    86137};
    87138
     
    97148
    98149        var attributes =
    99150        {
    100                 'class' : className,
     151                'class' : [ className, realElement.attributes[ 'class' ] ].join( ' ' ),
    101152                src : CKEDITOR.getUrl( 'images/spacer.gif' ),
    102153                'data-cke-realelement' : encodeURIComponent( html ),
    103154                'data-cke-real-node-type' : realElement.type,
     
    112163        if ( isResizable )
    113164                attributes[ 'data-cke-resizable' ] = isResizable;
    114165
     166        this._.fakeClassMap[ realElementType ] = 'img.' + className;
    115167        return new CKEDITOR.htmlParser.element( 'img', attributes );
    116168};
    117169
  • _source/plugins/wysiwygarea/plugin.js

     
    941941                                                                // Build the additional stuff to be included into <head>.
    942942                                                                var headExtra =
    943943                                                                        '<style type="text/css" data-cke-temp="1">' +
    944                                                                                 editor._.styles.join( '\n' ) +
     944                                                                                editor._.internalStyles.concat( editor._.styles ).join( '\n' ) +
    945945                                                                        '</style>';
    946946
    947947                                                                !fullPage && ( headExtra =
  • _source/core/editor.js

     
    423423
    424424                        this._.commands = {};
    425425                        this._.styles = [];
     426                        this._.internalStyles = [];
    426427
    427428                        /**
    428429                         * The DOM element that has been replaced by this editor instance. This
     
    531532                        this._.styles.push( css );
    532533                },
    533534
     535                addInternalCss : function( css )
     536                {
     537                        this._.internalStyles.push( css );
     538                },
     539
    534540                /**
    535541                 * Destroys the editor instance, releasing all resources used by it.
    536542                 * If the editor replaced an element, the element will be recovered.
  • _source/plugins/horizontalrule/plugin.js

     
    99
    1010(function()
    1111{
     12        // IE9 buggy on horizontal line that allows adding text into it, use fake instead. (#7193)
     13        var useFake = document.documentMode == 9;
     14
    1215        var horizontalruleCmd =
    1316        {
    1417                canUndo : false,    // The undo snapshot will be handled by 'insertElement'.
    1518                exec : function( editor )
    1619                {
    17                         editor.insertElement( editor.document.createElement( 'hr' ) );
     20                        var element =  editor.document.createElement( 'hr' );
     21                        useFake && ( element = editor.createFakeElement( element, 'cke_hr', 'hr' ) );
     22                        editor.insertElement( element );
    1823                }
    1924        };
    2025
     
    3136                                        label : editor.lang.horizontalrule,
    3237                                        command : pluginName
    3338                                });
    34                 }
    35         });
     39
     40                },
     41                afterInit : useFake ? function( editor )
     42                {
     43                        // Direct fake objects lang entry to plugin.
     44                        editor.lang.fakeobjects.hr = editor.lang.horizontalrule;
     45
     46                        // Add the style that renders the horizontal line.
     47                        editor.addInternalCss(
     48                                        'img.cke_hr' +
     49                                                        '{' +
     50                                                        'background-image: url(' + ( CKEDITOR.basePath + 'images/spacer.gif' ) + ');' +
     51                                                        'clear: both;' +
     52                                                        'display: block;' +
     53                                                        'float: none;' +
     54                                                        'width:100% !important; _width:99.9% !important;' +
     55                                                        'height: 0px !important;' +
     56                                                        'border-top: #808080 1px solid;' +
     57                                                        'border-bottom: #808080 1px solid;' +
     58                                                        '}' );
     59
     60                        // Register a filter to transform placeholders on data input.
     61                        var dataProcessor = editor.dataProcessor,
     62                                dataFilter = dataProcessor && dataProcessor.dataFilter;
     63                        dataFilter && dataFilter.addRules( { elements : { hr : function( element ) { return editor.createFakeParserElement( element, 'cke_hr', 'hr' ); } } } );
     64                } : null
     65        } );
    3666})();
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy