Ticket #6103: 6103.patch

File 6103.patch, 4.0 KB (added by Tobiasz Cudnik, 14 years ago)
  • _source/plugins/styles/plugin.js

     
    110110
    111111        CKEDITOR.style.prototype =
    112112        {
    113                 apply : function( document )
     113                apply : function( document, config )
    114114                {
    115                         applyStyle.call( this, document, false );
     115                        applyStyle.call( this, document, false, config );
    116116                },
    117117
    118                 remove : function( document )
     118                remove : function( document, config )
    119119                {
    120                         applyStyle.call( this, document, true );
     120                        applyStyle.call( this, document, true, config );
    121121                },
    122122
    123123                applyToRange : function( range )
     
    13161316                return true;
    13171317        }
    13181318
    1319         function applyStyle( document, remove )
     1319        function applyStyle( document, remove, config )
    13201320        {
    13211321                var selection = document.getSelection(),
    13221322                        // Bookmark the range so we can re-select it after processing.
    13231323                        bookmarks = selection.createBookmarks(),
    1324                         ranges = selection.getRanges( true ),
     1324                        ranges = selection.getRanges( config.disableReadonlyStyling || this.type != CKEDITOR.STYLE_INLINE ),
    13251325                        func = remove ? this.removeFromRange : this.applyToRange,
    1326                         range;
     1326                        range, node;
    13271327
     1328                // Search for cke_nostyle elements and not fully selected readonly elements.
     1329                if ( !config.disableReadonlyStyling && this.type == CKEDITOR.STYLE_INLINE )
     1330                {
     1331                        for ( var i = 0; i < ranges.length; i++ )
     1332                        {
     1333                                range = ranges[ i ];
     1334
     1335                                var startContainer = range.startContainer,
     1336                                        endContainer = range.endContainer,
     1337                                        walkerRange = range.clone();
     1338
     1339                                // Use only fully selected readonly elements.
     1340                                var readOnly;
     1341                                if ( ( readOnly = startContainer.isReadOnly() ) )
     1342                                {
     1343                                        node = startContainer;
     1344
     1345                                        while ( readOnly.$ != parent.$ )
     1346                                        {
     1347                                                if ( node.getPrevious() )
     1348                                                {
     1349                                                        range.setStartAfter( readOnly );
     1350                                                        break;
     1351                                                }
     1352                                                node = node.getParent();
     1353                                        }
     1354                                }
     1355
     1356                                if ( ( readOnly = endContainer.isReadOnly() ) )
     1357                                {
     1358                                        node = endContainer;
     1359
     1360                                        while ( readOnly.$ != parent.$ )
     1361                                        {
     1362                                                if ( node.getNext() )
     1363                                                {
     1364                                                        range.setStartBefore( readOnly );
     1365                                                        break;
     1366                                                }
     1367                                                node = node.getParent();
     1368                                        }
     1369                                }
     1370
     1371                                if ( range.collapsed )
     1372                                        continue;
     1373
     1374                                // Looking for non-stylable element inside the range.
     1375                                var walker = new CKEDITOR.dom.walker( walkerRange );
     1376                                walker.evaluator = function( node )
     1377                                {
     1378                                        if ( node.type == CKEDITOR.NODE_ELEMENT
     1379                                                && node.hasAttribute( 'cke_nostyle' ) )
     1380                                        {
     1381                                                var newRange = range.clone();
     1382                                                range.setEndBefore( node );
     1383
     1384                                                // Drop collapsed range around read-only elements,
     1385                                                // it make sure the range list empty when selecting
     1386                                                // only non-editable elements.
     1387                                                if ( range.collapsed )
     1388                                                        ranges.splice( i--, 1 );
     1389
     1390                                                // Avoid creating invalid range.
     1391                                                if ( !( node.getPosition( walkerRange.endContainer ) & CKEDITOR.POSITION_CONTAINS ) )
     1392                                                {
     1393                                                        newRange.setStartAfter( node );
     1394                                                        if ( !newRange.collapsed )
     1395                                                                ranges.splice( i + 1, 0, newRange );
     1396                                                }
     1397
     1398                                                return true;
     1399                                        }
     1400
     1401                                        return false;
     1402                                };
     1403
     1404                                walker.next();
     1405                        }
     1406                }
     1407
    13281408                var iterator = ranges.createIterator();
    13291409                while ( ( range = iterator.getNextRange() ) )
    13301410                        func.call( this, range );
     
    13531433        if ( doc )
    13541434        {
    13551435                if ( this.state == CKEDITOR.TRISTATE_OFF )
    1356                         this.style.apply( doc );
     1436                        this.style.apply( doc, editor.config );
    13571437                else if ( this.state == CKEDITOR.TRISTATE_ON )
    1358                         this.style.remove( doc );
     1438                        this.style.remove( doc, editor.config );
    13591439        }
    13601440
    13611441        return !!doc;
     
    14151495};
    14161496
    14171497/**
     1498 * Disables styling of read only inline elements.
     1499 * @type Boolean
     1500 * @default false
     1501 * @example
     1502 * config.disableReadonlyStyling = true;
     1503 */
     1504CKEDITOR.config.disableReadonlyStyling = false;
     1505
     1506/**
    14181507 * The "styles definition set" to use in the editor. They will be used in the
    14191508 * styles combo and the Style selector of the div container. <br>
    14201509 * The styles may be defined in the page containing the editor, or can be
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy