Ticket #2885: 2885_12.patch

File 2885_12.patch, 21.0 KB (added by Garry Yao, 14 years ago)
  • _source/core/config.js

     
    198198         * @type String
    199199         * @example
    200200         */
    201         plugins : 'about,basicstyles,blockquote,button,clipboard,colorbutton,colordialog,contextmenu,elementspath,enterkey,entities,filebrowser,find,flash,font,format,forms,horizontalrule,htmldataprocessor,image,indent,justify,keystrokes,link,list,maximize,newpage,pagebreak,pastefromword,pastetext,popup,preview,print,removeformat,resize,save,scayt,smiley,showblocks,sourcearea,stylescombo,table,tabletools,specialchar,tab,templates,toolbar,undo,wysiwygarea,wsc',
     201        plugins : 'about,basicstyles,blockquote,button,clipboard,colorbutton,colordialog,contextmenu,div,elementspath,enterkey,entities,filebrowser,find,flash,font,format,forms,horizontalrule,htmldataprocessor,image,indent,justify,keystrokes,link,list,maximize,newpage,pagebreak,pastefromword,pastetext,popup,preview,print,removeformat,resize,save,scayt,smiley,showblocks,sourcearea,stylescombo,table,tabletools,specialchar,tab,templates,toolbar,undo,wysiwygarea,wsc',
    202202
    203203        /**
    204204         * List of additional plugins to be loaded. This is a tool setting which
  • _source/skins/v2/icons.css

     
    307307{
    308308        background-position: 0 -1040px;
    309309}
     310
     311.cke_skin_v2 .cke_button_creatediv .cke_icon
     312{
     313        background-position: 0 -1168px;
     314}
     315
     316.cke_skin_v2 .cke_button_editdiv .cke_icon
     317{
     318        background-position: 0 -1184px;
     319}
     320
     321.cke_skin_v2 .cke_button_removediv .cke_icon
     322{
     323        background-position: 0 -1200px;
     324}
  • _source/skins/kama/icons.css

     
    283283        background-position: 0 -1152px;
    284284}
    285285
     286.cke_skin_kama .cke_button_creatediv .cke_icon
     287{
     288        background-position: 0 -1168px;
     289}
     290.cke_skin_kama .cke_button_editdiv .cke_icon
     291{
     292        background-position: 0 -1184px;
     293}
     294.cke_skin_kama .cke_button_removediv .cke_icon
     295{
     296        background-position: 0 -1200px;
     297}
     298
    286299.cke_skin_kama .cke_button_flash .cke_icon
    287300{
    288301        background-position: 0 -592px;
     
    307320{
    308321        background-position: 0 -1040px;
    309322}
     323.cke_skin_office2003 .cke_button_editdiv .cke_icon
     324{
     325        background-position: 0 -1184px;
     326}
  • _source/plugins/div/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 * @fileOverview The "div" plugin. It wraps the selected block level elements with a 'div' element with specified styles and attributes.
     8 *
     9 */
     10
     11(function()
     12{
     13        CKEDITOR.plugins.add( 'div',
     14        {
     15                requires : [ 'editingblock', 'domiterator' ],
     16
     17                init : function( editor )
     18                {
     19                        var lang = editor.lang.div;
     20
     21                        editor.addCommand( 'creatediv', new CKEDITOR.dialogCommand( 'creatediv' ) );
     22                        editor.addCommand( 'editdiv', new CKEDITOR.dialogCommand( 'editdiv' ) );
     23                        editor.addCommand( 'removediv',
     24                                {
     25                                        exec : function( editor )
     26                                        {
     27                                                var selection = editor.getSelection(),
     28                                                        ranges = selection && selection.getRanges(),
     29                                                        range,
     30                                                        bookmarks = selection.createBookmarks(),
     31                                                        walker,
     32                                                        toRemove = [];
     33
     34                                                function findDiv( node )
     35                                                {
     36                                                        var path = new CKEDITOR.dom.elementPath( node ),
     37                                                                blockLimit = path.blockLimit,
     38                                                                div = blockLimit.is( 'div' ) && blockLimit;
     39
     40                                                        if ( div && !div.getAttribute( '_cke_div_added' ) )
     41                                                        {
     42                                                                toRemove.push( div );
     43                                                                div.setAttribute( '_cke_div_added' );
     44                                                        }
     45                                                }
     46
     47                                                for ( var i = 0 ; i < ranges.length ; i++ )
     48                                                {
     49                                                        range = ranges[ i ];
     50                                                        if( range.collapsed )
     51                                                                findDiv( selection.getStartElement() );
     52                                                        else
     53                                                        {
     54                                                                walker = new CKEDITOR.dom.walker( range );
     55                                                                walker.evaluator = findDiv;
     56                                                                walker.lastForward();
     57                                                        }
     58                                                }
     59
     60                                                for ( var i = 0 ; i < toRemove.length ; i++ )
     61                                                        toRemove[ i ].remove( true );
     62
     63                                                selection.selectBookmarks( bookmarks );
     64                                        }
     65                                } );
     66                               
     67                        editor.ui.addButton( 'CreateDiv',
     68                        {
     69                                label : lang.toolbar,
     70                                command :'creatediv'
     71                        } );
     72
     73                        if ( editor.addMenuItems )
     74                        {
     75                                editor.addMenuItems(
     76                                        {
     77                                                editdiv :
     78                                                {
     79                                                        label : lang.edit,
     80                                                        command : 'editdiv',
     81                                                        group : 'div',
     82                                                        order : 1
     83                                                },
     84
     85                                                removediv:
     86                                                {
     87                                                        label : lang.remove,
     88                                                        command : 'removediv',
     89                                                        group : 'div',
     90                                                        order : 5
     91                                                }
     92                                        } );
     93
     94                                if ( editor.contextMenu )
     95                                {
     96                                        editor.contextMenu.addListener( function( element, selection )
     97                                                {
     98                                                        if ( !element )
     99                                                                return null;
     100
     101                                                        var elementPath = new CKEDITOR.dom.elementPath( element ),
     102                                                                blockLimit = elementPath.blockLimit;
     103
     104                                                        if ( blockLimit && blockLimit.getAscendant( 'div', true ) )
     105                                                        {
     106                                                                return {
     107                                                                        editdiv : CKEDITOR.TRISTATE_OFF,
     108                                                                        removediv : CKEDITOR.TRISTATE_OFF
     109                                                                }
     110                                                        }
     111
     112                                                        return null;
     113                                                } );
     114                                }
     115                        }
     116                       
     117                        CKEDITOR.dialog.add( 'creatediv', this.path + 'dialogs/div.js' );
     118                        CKEDITOR.dialog.add( 'editdiv', this.path + 'dialogs/div.js' );
     119                }
     120        } );
     121})();
  • _source/plugins/menu/plugin.js

     
    381381        'form,' +
    382382        'tablecell,tablecellproperties,tablerow,tablecolumn,table,'+
    383383        'anchor,link,image,flash,' +
    384         'checkbox,radio,textfield,hiddenfield,imagebutton,button,select,textarea';
     384        'checkbox,radio,textfield,hiddenfield,imagebutton,button,select,textarea,div';
  • _source/core/dtd.js

     
    6666                 */
    6767                $block : block,
    6868
     69                /**
     70                 * List of block limit elements.
     71                 * @type Object
     72                 * @example
     73                 */
     74                $blockLimit : { body:1,div:1,td:1,th:1,caption:1,form:1 },
     75
    6976                $body : X({script:1}, block),
    7077
    7178                $cdata : {script:1,style:1},
  • _source/plugins/toolbar/plugin.js

     
    364364        ['Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'],
    365365        '/',
    366366        ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
    367         ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
     367        ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote','CreateDiv'],
    368368        ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
    369369        ['Link','Unlink','Anchor'],
    370370        ['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'],
  • _source/lang/en.js

     
    566566                tag_div : 'Normal (DIV)'
    567567        },
    568568
     569        div :
     570        {
     571                title                           : 'Create Div Container',
     572                toolbar                         : 'Create Div Container',
     573                cssClassInputLabel      : 'Stylesheet Classes',
     574                styleSelectLabel        : 'Style',
     575                IdInputLabel            : 'Id',
     576                languageCodeInputLabel  : ' Language Code',
     577                inlineStyleInputLabel   : 'Inline Style',
     578                advisoryTitleInputLabel : 'Advisory Title',
     579                langDirLabel            : 'Language Direction',
     580                langDirLTRLabel         : 'Left to Right (LTR)',
     581                langDirRTLLabel         : 'Right to Left (RTL)',
     582                edit                            : 'Edit Div',
     583                remove                          : 'Remove Div'
     584        },
     585
    569586        font :
    570587        {
    571588                label : 'Font',
  • _source/plugins/div/dialogs/div.js

     
     1/*
     2 * Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     3 * For licensing, see LICENSE.html or http://ckeditor.com/license
     4 */
     5
     6(function()
     7{
     8       
     9        /**
     10         * Add to collection with DUP examination.
     11         * @param {Object} collection
     12         * @param {Object} element
     13         * @param {Object} database
     14         */
     15        function addSafely( collection, element, database )
     16        {
     17                // 1. IE doesn't support customData on text nodes;
     18                // 2. Text nodes never get chance to appear twice;
     19                if ( !element.is || !element.getCustomData( 'block_processed' ) )
     20                {
     21                        element.is && CKEDITOR.dom.element.setMarker( database, element, 'block_processed', true );
     22                        collection.push( element );
     23                }
     24        }
     25       
     26        function getNonEmptyChildren( element )
     27        {
     28                var retval = [];
     29                var children = element.getChildren();
     30                for( var i = 0 ; i < children.count() ; i++ )
     31                {
     32                        var child = children.getItem( i );
     33                        if( ! ( child.type === CKEDITOR.NODE_TEXT
     34                                && /^[ \t\n\r]+$/.test( child.getText() ) ) )
     35                                retval.push( child );
     36                }
     37                return retval;
     38        }
     39
     40
     41        /**
     42         * Dialog reused by both 'creatediv' and 'editdiv' commands.
     43         * @param {Object} editor
     44         * @param {String} command      The command name which indicate what the current command is.
     45         */
     46        function divDialog( editor, command )
     47        {
     48                // Definition of elements at which div operation should stopped.
     49                var divLimitDefinition = ( function(){
     50                       
     51                        // Customzie from specialize blockLimit elements
     52                        var definition = CKEDITOR.tools.extend( {}, CKEDITOR.dtd.$blockLimit );
     53
     54                        // Exclude 'div' itself.
     55                        delete definition.div;
     56
     57                        // Exclude 'td' and 'th' when 'wrapping table'
     58                        if( editor.config.div_wrapTable )
     59                        {
     60                                delete definition.td;
     61                                delete definition.th;
     62                        }
     63                        return definition;
     64                })();
     65               
     66                // DTD of 'div' element
     67                var dtd = CKEDITOR.dtd.div;
     68               
     69                /**
     70                 * Get the first div limit element on the element's path.
     71                 * @param {Object} element
     72                 */
     73                function getDivLimitElement( element )
     74                {
     75                        var pathElements = new CKEDITOR.dom.elementPath( element ).elements;
     76                        var divLimit;
     77                        for ( var i = 0; i < pathElements.length ; i++ )
     78                        {
     79                                if ( pathElements[ i ].getName() in divLimitDefinition )
     80                                {
     81                                        divLimit = pathElements[ i ];
     82                                        break;
     83                                }
     84                        }
     85                        return divLimit;
     86                }
     87               
     88                /**
     89                 * Init all fields' setup/commit function.
     90                 * @memberof divDialog
     91                 */
     92                function setupFields()
     93                {
     94                        this.foreach( function( field )
     95                        {
     96                                // Exclude layout container elements
     97                                if( /^(?!vbox|hbox)/.test( field.type ) )
     98                                {
     99                                        if ( !field.setup )
     100                                        {
     101                                                // Read the dialog fields values from the specified
     102                                                // element attributes.
     103                                                field.setup = function( element )
     104                                                {
     105                                                        field.setValue( element.getAttribute( field.id ) || '' );
     106                                                };
     107                                        }
     108                                        if ( !field.commit )
     109                                        {
     110                                                // Set element attributes assigned by the dialog
     111                                                // fields.
     112                                                field.commit = function( element )
     113                                                {
     114                                                        var fieldValue = this.getValue();
     115                                                        // ignore default element attribute values
     116                                                        if ( 'dir' == field.id && element.getComputedStyle( 'direction' ) == fieldValue )
     117                                                                return true;
     118                                                        if ( fieldValue )
     119                                                                element.setAttribute( field.id, fieldValue );
     120                                                        else
     121                                                                element.removeAttribute( field.id );
     122                                                };
     123                                        }
     124                                }
     125                        } );
     126                }
     127               
     128                /**
     129                 * Wrapping 'div' element around appropriate blocks among the selected ranges.
     130                 * @param {Object} editor
     131                 */
     132                function createDiv( editor )
     133                {
     134                        // new adding containers OR detected pre-existed containers.
     135                        var containers = [];
     136                        // node markers store.
     137                        var database = {};
     138                        // All block level elements which contained by the ranges.
     139                        var containedBlocks = [], block;
     140
     141                        // Get all ranges from the selection.
     142                        var selection = editor.document.getSelection();
     143                        var ranges = selection.getRanges();
     144                        var bookmarks = selection.createBookmarks();
     145                        var i, iterator;
     146
     147                        // Calcualte a default block tag if we need to create blocks.
     148                        var blockTag = editor.config.enterMode == CKEDITOR.ENTER_DIV ? 'div' : 'p';
     149
     150                        // collect all included elements from dom-iterator
     151                        for( i = 0 ; i < ranges.length ; i++ )
     152                        {
     153                                iterator = ranges[ i ].createIterator();
     154                                while( ( block = iterator.getNextParagraph() ) )
     155                                {
     156                                        // include contents of blockLimit elements.
     157                                        if( block.getName() in divLimitDefinition )
     158                                        {
     159                                                var j, childNodes = block.getChildren();
     160                                                for ( j = 0 ; j < childNodes.count() ; j++ )
     161                                                        addSafely( containedBlocks, childNodes.getItem( j ) , database );
     162                                        }
     163                                        else
     164                                        {
     165                                                // Bypass dtd disallowed elements.
     166                                                while( !dtd[ block.getName() ] && block.getName() != 'body' )
     167                                                        block = block.getParent();
     168                                                addSafely( containedBlocks, block, database );
     169                                        }
     170                                }
     171                        }
     172
     173                        CKEDITOR.dom.element.clearAllMarkers( database );
     174
     175                        var blockGroups = groupByDivLimit( containedBlocks );
     176                        var ancestor, blockEl, divElement;
     177
     178                        for( i = 0 ; i < blockGroups.length ; i++ )
     179                        {
     180                                var currentNode = blockGroups[ i ][ 0 ];
     181
     182                                // Calculate the common parent node of all contained elements.
     183                                ancestor = currentNode.getParent();
     184                                for ( var j = 1 ; j < blockGroups[ i ].length; j++ )
     185                                        ancestor = ancestor.getCommonAncestor( blockGroups[ i ][ j ] );
     186
     187                                divElement = new CKEDITOR.dom.element( 'div', editor.document );
     188                               
     189                                // Normalize the blocks in each group to a common parent.
     190                                for( var j = 0; j < blockGroups[ i ].length ; j++ )
     191                                {
     192                                        currentNode = blockGroups[ i ][ j ];
     193
     194                                        while( !currentNode.getParent().equals( ancestor ) )
     195                                                currentNode = currentNode.getParent();
     196
     197                                        // This could introduce some duplicated elements in array.
     198                                        blockGroups[ i ][ j ] = currentNode;
     199                                }
     200
     201                                // Wrapped blocks counting
     202                                var fixedBlock = null;
     203                                for ( var j = 0 ; j < blockGroups[ i ].length ; j++ )
     204                                {
     205                                        currentNode = blockGroups[ i ][ j ];
     206
     207                                        // Avoid DUP elements introduced by grouping.
     208                                        if ( !( currentNode.getCustomData && currentNode.getCustomData( 'block_processed' ) ) )
     209                                        {
     210                                                currentNode.is && CKEDITOR.dom.element.setMarker( database, currentNode, 'block_processed', true );
     211
     212                                                // Establish new container, wrapping all elements in this group.
     213                                                if ( j == 0 )
     214                                                        divElement.insertBefore( currentNode );
     215
     216                                                divElement.append( currentNode );
     217                                        }
     218                                }
     219
     220                                CKEDITOR.dom.element.clearAllMarkers( database );
     221                                containers.push( divElement );
     222                        }
     223
     224                        selection.selectBookmarks( bookmarks );
     225                        return containers;
     226                }
     227
     228                function getDiv( editor )
     229                {
     230                        var path = new CKEDITOR.dom.elementPath( editor.getSelection().getStartElement() ),
     231                                blockLimit = path.blockLimit,
     232                                div = blockLimit && blockLimit.getAscendant( 'div', true );
     233                        return div;
     234                }
     235                /**
     236                 * Divide a set of nodes to different groups by their path's blocklimit element.
     237                 * Note: the specified nodes should be in source order naturally, which mean they are supposed to producea by following class:
     238                 *  * CKEDITOR.dom.range.Iterator
     239                 *  * CKEDITOR.dom.domWalker
     240                 *  @return {Array []} the grouped nodes
     241                 */
     242                function groupByDivLimit( nodes )
     243                {
     244                        var groups = [],
     245                                lastDivLimit = null,
     246                                path, block;
     247                        for ( var i = 0 ; i < nodes.length ; i++ )
     248                        {
     249                                block = nodes[i];
     250                                var limit = getDivLimitElement( block );
     251                                if ( !limit.equals( lastDivLimit ) )
     252                                {
     253                                        lastDivLimit = limit ;
     254                                        groups.push( [] ) ;
     255                                }
     256                                groups[ groups.length - 1 ].push( block ) ;
     257                        }
     258                        return groups;
     259                }
     260               
     261                /**
     262                 * Hold a collection of created block container elements. 
     263                 */
     264                var containers = [];
     265                /**
     266                 * @type divDialog
     267                 */
     268                return {
     269                        title : editor.lang.div.title,
     270                        minWidth : 400,
     271                        minHeight : 165,
     272                        contents :
     273                        [
     274                        {
     275                                id :'info',
     276                                label :editor.lang.common.generalTab,
     277                                title :editor.lang.common.generalTab,
     278                                elements :
     279                                [
     280                                        {
     281                                                type :'hbox',
     282                                                widths : [ '50%', '50%' ],
     283                                                children :
     284                                                [
     285                                                        {
     286                                                                id :'elementStyle',
     287                                                                type :'select',
     288                                                                style :'width: 100%;',
     289                                                                label :editor.lang.div.styleSelectLabel,
     290                                                                'default' : '',
     291                                                                items : [],
     292                                                                setup : function( element )
     293                                                                {
     294                                                                        this.setValue( element.$.style.cssText || '' );
     295                                                                },
     296                                                                commit: function( element )
     297                                                                {
     298                                                                        if ( this.getValue() )
     299                                                                                element.$.style.cssText = this.getValue();
     300                                                                        else
     301                                                                                element.removeAttribute( 'style' );
     302                                                                }
     303                                                        },
     304                                                        {
     305                                                                id :'class',
     306                                                                type :'text',
     307                                                                label :editor.lang.common.cssClass,
     308                                                                'default' : ''
     309                                                        }
     310                                                ]
     311                                        }
     312                                ]
     313                        },
     314                        {
     315                                        id :'advanced',
     316                                        label :editor.lang.common.advancedTab,
     317                                        title :editor.lang.common.advancedTab,
     318                                        elements :
     319                                        [
     320                                        {
     321                                                type :'vbox',
     322                                                padding :1,
     323                                                children :
     324                                                [
     325                                                        {
     326                                                                type :'hbox',
     327                                                                widths : [ '50%', '50%' ],
     328                                                                children :
     329                                                                [
     330                                                                        {
     331                                                                                type :'text',
     332                                                                                id :'id',
     333                                                                                label :editor.lang.common.id,
     334                                                                                'default' : ''
     335                                                                        },
     336                                                                        {
     337                                                                                type :'text',
     338                                                                                id :'lang',
     339                                                                                label :editor.lang.link.langCode,
     340                                                                                'default' : ''
     341                                                                        }
     342                                                                ]
     343                                                        },
     344                                                        {
     345                                                                type :'hbox',
     346                                                                children :
     347                                                                [
     348                                                                                {
     349                                                                                        type :'text',
     350                                                                                        id :'style',
     351                                                                                        style :'width: 100%;',
     352                                                                                        label :editor.lang.common.cssStyle,
     353                                                                                        'default' : ''
     354                                                                                }
     355                                                                ]
     356                                                        },
     357                                                        {
     358                                                                type :'hbox',
     359                                                                children :
     360                                                                [
     361                                                                                {
     362                                                                                        type :'text',
     363                                                                                        id :'title',
     364                                                                                        style :'width: 100%;',
     365                                                                                        label :editor.lang.common.advisoryTitle,
     366                                                                                        'default' : ''
     367                                                                                }
     368                                                                ]
     369                                                        },
     370                                                        {
     371                                                                type :'select',
     372                                                                id :'dir',
     373                                                                style :'width: 100%;',
     374                                                                label :editor.lang.common.langDir,
     375                                                                'default' : '',
     376                                                                items :
     377                                                                [
     378                                                                        [
     379                                                                                editor.lang.common.langDirLtr,
     380                                                                                'ltr'
     381                                                                        ],
     382                                                                        [
     383                                                                                editor.lang.common.langDirRtl,
     384                                                                                'rtl'
     385                                                                        ]
     386                                                                ]
     387                                                        }
     388                                                ]
     389                                        }
     390                                        ]
     391                                }
     392                        ],
     393                        onLoad : function()
     394                        {
     395                                setupFields.call(this);
     396                        },
     397                        onShow : function()
     398                        {
     399                                // Whether always create new container regardless of existed
     400                                // ones.
     401                                if ( command == 'editdiv' )
     402                                {
     403                                        // Try to discover the containers that already existed in
     404                                        // ranges
     405                                        var div = getDiv( editor );
     406                                        // update dialog field values
     407                                        div && this.setupContent( this._element = div );
     408                                }
     409                        },
     410                        onOk : function()
     411                        {
     412                                if( command == 'editdiv' )
     413                                        containers = [ this._element ];
     414                                else
     415                                        containers = createDiv( editor, true );
     416                               
     417                                // Update elements attributes
     418                                for( var i = 0 ; i < containers.length ; i++ )
     419                                        this.commitContent( containers[ i ] );
     420                                this.hide();
     421                        }
     422                };
     423        }
     424       
     425        CKEDITOR.dialog.add( 'creatediv', function( editor )
     426                {
     427                        return divDialog( editor, 'creatediv' );
     428                } );
     429        CKEDITOR.dialog.add( 'editdiv', function( editor )
     430                {
     431                        return divDialog( editor, 'editdiv' );
     432                } );
     433} )();
     434
     435/*
     436 * @name CKEDITOR.config.div_wrapTable
     437 * Whether to wrap the whole table instead of indivisual cells when created 'div' in table cell.
     438 * @type Boolean
     439 * @default false
     440 * @example config.div_wrapTable = true;
     441 */
  • _source/skins/office2003/icons.css

     
    307307{
    308308        background-position: 0 -1040px;
    309309}
     310
     311.cke_skin_office2003 .cke_button_creatediv .cke_icon
     312{
     313        background-position: 0 -1168px;
     314}
     315
     316.cke_skin_office2003 .cke_button_editdiv .cke_icon
     317{
     318        background-position: 0 -1184px;
     319}
     320
     321.cke_skin_office2003 .cke_button_removediv .cke_icon
     322{
     323        background-position: 0 -1200px;
     324}
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy