Ticket #6305: 6305.patch

File 6305.patch, 3.4 KB (added by Garry Yao, 13 years ago)
  • _source/plugins/liststyle/dialogs/liststyle.js

     
    1 /*
     1/*
    22 * Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
    33 * For licensing, see LICENSE.html or http://ckeditor.com/license
    44 */
    55
    66(function()
    77{
    8         function getListElement( editor, listTag )
    9         {
    10                 var range;
    11                 try { range  = editor.getSelection().getRanges()[ 0 ]; }
    12                 catch( e ) { return null; }
    13 
    14                 range.shrink( CKEDITOR.SHRINK_TEXT );
    15                 return range.getCommonAncestor().getAscendant( listTag, 1 );
    16         }
    17 
    188        var mapListStyle = {
    199                'a' : 'lower-alpha',
    2010                'A' : 'upper-alpha',
     
    7868                                onShow: function()
    7969                                {
    8070                                        var editor = this.getParentEditor(),
    81                                                 element = getListElement( editor, 'ul' );
     71                                                element = CKEDITOR.plugins.liststyle.getSelectedList( editor, 'ul' );
    8272
    8373                                        element && this.setupContent( element );
    8474                                },
    8575                                onOk: function()
    8676                                {
    8777                                        var editor = this.getParentEditor(),
    88                                                 element = getListElement( editor, 'ul' );
     78                                                element = CKEDITOR.plugins.liststyle.getSelectedList( editor, 'ul' );
    8979
    9080                                        element && this.commitContent( element );
    9181                                }
     
    177167                                onShow: function()
    178168                                {
    179169                                        var editor = this.getParentEditor(),
    180                                                 element = getListElement( editor, 'ol' );
     170                                                element = CKEDITOR.plugins.liststyle.getSelectedList( editor, 'ol' );
    181171
    182172                                        element && this.setupContent( element );
    183173                                },
    184174                                onOk: function()
    185175                                {
    186176                                        var editor = this.getParentEditor(),
    187                                                 element = getListElement( editor, 'ol' );
     177                                                element = CKEDITOR.plugins.liststyle.getSelectedList( editor, 'ol' );
    188178
    189179                                        element && this.commitContent( element );
    190180                                }
  • _source/plugins/liststyle/plugin.js

     
    4343                        {
    4444                                editor.contextMenu.addListener( function( element, selection )
    4545                                        {
    46                                                 if ( !element || element.isReadOnly() )
    47                                                         return null;
    48 
    49                                                 while ( element )
    50                                                 {
    51                                                         var name = element.getName();
    52                                                         if ( name == 'ol' )
    53                                                                 return { numberedlist: CKEDITOR.TRISTATE_OFF };
    54                                                         else if ( name == 'ul' )
    55                                                                 return { bulletedlist: CKEDITOR.TRISTATE_OFF };
    56 
    57                                                         element = element.getParent();
    58                                                 }
    59                                                 return null;
    60                                         });
    61                         }
    62                 }
     46                                                return CKEDITOR.plugins.liststyle.getSelectedList( editor, 'ol' ) ? { numberedlist: CKEDITOR.TRISTATE_OFF } :
     47                                                           CKEDITOR.plugins.liststyle.getSelectedList( editor, 'ul' ) ? { bulletedlist: CKEDITOR.TRISTATE_OFF } : null;
     48                                        });
     49                        }
     50                },
     51                getSelectedList :        function( editor, listTag )
     52                {
     53                        try
     54                        {
     55                                var selection = editor.getSelection(),
     56                                                start= selection.getStartElement(),
     57                                                range = selection.getRanges()[ 0 ];
     58                        }
     59                        catch( e ) { return null; }
     60
     61                        if ( !start || start.isReadOnly() )
     62                                return null;
     63
     64                        range.shrink( CKEDITOR.SHRINK_TEXT );
     65                        return range.getCommonAncestor().getAscendant( listTag, 1 );
     66                }
    6367        };
    6468
    6569        CKEDITOR.plugins.add( 'liststyle', CKEDITOR.plugins.liststyle );
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy