Ticket #7584: 7584.patch

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

     
    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; }
    138
    14                 range.shrink( CKEDITOR.SHRINK_TEXT );
    15                 return range.getCommonAncestor().getAscendant( listTag, 1 );
    16         }
    17 
    189        var mapListStyle = {
    1910                'a' : 'lower-alpha',
    2011                'A' : 'upper-alpha',
     
    2819
    2920        function listStyle( editor, startupPage )
    3021        {
     22                function targetElement()
     23                {
     24                        var range  = editor.getSelection().getRanges()[ 0 ];
     25                        range.shrink( CKEDITOR.SHRINK_TEXT );
     26                        var root = range.getCommonAncestor().getAscendant( startupPage == 'bulletedListStyle' ? 'ul' : 'ol', 1 );
     27
     28                        // Is list fully selected? Then list root mode.
     29                        if ( range.checkBoundaryOfElement( root, CKEDITOR.START ) && range.checkBoundaryOfElement( root, CKEDITOR.END ) )
     30                                return root;
     31                        // Otherwise it's in list item mode.
     32                        else
     33                        {
     34                                var path = new CKEDITOR.dom.elementPath( range.startContainer );
     35                                var elements = path.elements, element;
     36                                for ( var i = 0; i < elements.length; i++ )
     37                                {
     38                                        element = elements[ i ];
     39                                        if ( element.is( 'li' ) && element.getParent().equals( root ) )
     40                                                return element;
     41                                }
     42                        }
     43                }
     44
    3145                var lang = editor.lang.list;
    3246                if ( startupPage == 'bulletedListStyle' )
    3347                {
     
    7791                                ],
    7892                                onShow: function()
    7993                                {
    80                                         var editor = this.getParentEditor(),
    81                                                 element = getListElement( editor, 'ul' );
    82 
    83                                         element && this.setupContent( element );
     94                                        this.element = targetElement();
     95                                        this.setupContent( this.element );
    8496                                },
    8597                                onOk: function()
    8698                                {
    87                                         var editor = this.getParentEditor(),
    88                                                 element = getListElement( editor, 'ul' );
    89 
    90                                         element && this.commitContent( element );
     99                                        this.commitContent( this.element );
     100                                },
     101                                onHide : function()
     102                                {
     103                                        delete this.element;
    91104                                }
    92105                        };
    93106                }
     
    137150                                                                                validate : CKEDITOR.dialog.validate.integer( lang.validateStartNumber ),
    138151                                                                                setup : function( element )
    139152                                                                                {
    140                                                                                         var value = element.getAttribute( 'start' ) || 1;
     153                                                                                        var value = element.getAttribute( element.is( 'li' ) ? 'value' : 'start' ) || 1;
    141154                                                                                        value && this.setValue( value );
    142155                                                                                },
    143156                                                                                commit : function( element )
    144157                                                                                {
    145                                                                                         element.setAttribute( 'start', this.getValue() );
     158                                                                                        element.setAttribute( element.is( 'li' ) ? 'value' : 'start', this.getValue() );
    146159                                                                                }
    147160                                                                        },
    148161                                                                        {
     
    176189                                ],
    177190                                onShow: function()
    178191                                {
    179                                         var editor = this.getParentEditor(),
    180                                                 element = getListElement( editor, 'ol' );
    181 
    182                                         element && this.setupContent( element );
     192                                        this.element = targetElement();
     193                                        this.setupContent( this.element );
    183194                                },
    184195                                onOk: function()
    185196                                {
    186                                         var editor = this.getParentEditor(),
    187                                                 element = getListElement( editor, 'ol' );
    188 
    189                                         element && this.commitContent( element );
     197                                        this.commitContent( this.element );
     198                                },
     199                                onHide : function()
     200                                {
     201                                        delete this.element;
    190202                                }
    191203                        };
    192204                }
  • _source/plugins/menu/plugin.js

     
    114114                                if ( item.onClick )
    115115                                        item.onClick();
    116116                                else if ( item.command )
    117                                         this.editor.execCommand( item.command );
     117                                        this.editor.execCommand( item.command, { fromMenu : item.name } );
    118118                        },
    119119
    120120                        onEscape : function( keystroke )
  • _source/lang/en.js

     
    207207        // List style dialog
    208208        list:
    209209        {
    210                 numberedTitle           : 'Numbered List Properties',
    211                 bulletedTitle           : 'Bulleted List Properties',
     210                numberedTitle           : 'Numbered List',
     211                bulletedTitle           : 'Bulleted List',
     212                listRoot                : 'List Properties',
     213                listItem                : 'List Item Properties',
    212214                type                            : 'Type',
    213215                start                           : 'Start',
    214216                validateStartNumber                             :'List start number must be a whole number.',
  • _source/plugins/liststyle/plugin.js

     
    1010                requires : [ 'dialog' ],
    1111                init : function( editor )
    1212                {
     13                        function anchoredList()
     14                        {
     15                                var sel = editor.getSelection(),
     16                                        element = sel && sel.getStartElement(),
     17                                        path = new CKEDITOR.dom.elementPath( element ).elements;
     18
     19                                for ( var i = 0; i < path.length; i++ )
     20                                {
     21                                        element = path[ i ];
     22                                        if ( element.getName() in { ol : 1, ul : 1 } )
     23                                                return element;
     24                                }
     25                        }
     26
     27                        editor.addCommand( 'listStyleEdit',
     28                        {
     29                                exec : function( editor, data )
     30                                {
     31                                        var list = anchoredList();
     32                                        if ( data.fromMenu == 'list_root' )
     33                                                editor.getSelection().selectElement( list );
     34                                       
     35                                        editor.openDialog( list.is( 'ol' )? 'numberedListStyle' : 'bulletedListStyle' );
     36                                }
     37                        });
     38
    1339                        editor.addCommand( 'numberedListStyle', new CKEDITOR.dialogCommand( 'numberedListStyle' ) );
    1440                        CKEDITOR.dialog.add( 'numberedListStyle', this.path + 'dialogs/liststyle.js' );
    1541                        editor.addCommand( 'bulletedListStyle', new CKEDITOR.dialogCommand( 'bulletedListStyle' ) );
    1642                        CKEDITOR.dialog.add( 'bulletedListStyle', this.path + 'dialogs/liststyle.js' );
    1743
     44                        function subMenu()
     45                        {
     46                                return {
     47                                        list_root : CKEDITOR.TRISTATE_OFF,
     48                                        list_item : CKEDITOR.TRISTATE_OFF
     49                                };
     50                        }
     51
    1852                        // If the "menu" plugin is loaded, register the menu items.
    1953                        if ( editor.addMenuItems )
    2054                        {
     
    2761                                                {
    2862                                                        label : editor.lang.list.numberedTitle,
    2963                                                        group : 'list',
    30                                                         command: 'numberedListStyle'
     64                                                        getItems : subMenu
    3165                                                },
    3266                                                bulletedlist :
    3367                                                {
    3468                                                        label : editor.lang.list.bulletedTitle,
    3569                                                        group : 'list',
    36                                                         command: 'bulletedListStyle'
     70                                                        getItems : subMenu
     71                                                },
     72                                                list_root :
     73                                                {
     74                                                        label : editor.lang.list.listRoot,
     75                                                        group : 'list',
     76                                                        command: 'listStyleEdit',
     77                                                        order : 5
     78                                                },
     79                                                list_item :
     80                                                {
     81                                                        label : editor.lang.list.listItem,
     82                                                        group : 'list',
     83                                                        command: 'listStyleEdit',
     84                                                        order : 10
    3785                                                }
    3886                                        });
    3987                        }
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy