Ticket #5909: 5909_2.patch

File 5909_2.patch, 5.1 KB (added by Tobiasz Cudnik, 14 years ago)
  • _source/plugins/toolbar/plugin.js

     
    433433        ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
    434434        ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote','CreateDiv'],
    435435        ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
     436        ['BidiLtr', 'BidiRtl'],
    436437        ['Link','Unlink','Anchor'],
    437438        ['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'],
    438439        '/',
  • _source/lang/en.js

     
    744744        },
    745745
    746746        toolbarCollapse : 'Collapse Toolbar',
    747         toolbarExpand   : 'Expand Toolbar'
     747        toolbarExpand   : 'Expand Toolbar',
     748
     749        bidiswitch :
     750        {
     751                ltr :"Switch to LTR text direction",
     752                rtl : "Switch to RTL text direction"
     753        }
    748754};
  • _source/core/config.js

     
    243243         * @type String
    244244         * @example
    245245         */
    246         plugins : 'about,a11yhelp,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,liststyle,maximize,newpage,pagebreak,pastefromword,pastetext,popup,preview,print,removeformat,resize,save,scayt,smiley,showblocks,showborders,sourcearea,stylescombo,table,tabletools,specialchar,tab,templates,toolbar,undo,wysiwygarea,wsc',
     246        plugins : 'about,a11yhelp,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,liststyle,maximize,newpage,pagebreak,pastefromword,pastetext,popup,preview,print,removeformat,resize,save,scayt,smiley,showblocks,showborders,sourcearea,stylescombo,table,tabletools,specialchar,tab,templates,toolbar,undo,wysiwygarea,wsc,bidiswitch',
    247247
    248248        /**
    249249         * List of additional plugins to be loaded. This is a tool setting which
  • _source/plugins/bidiswitch/plugin.js

     
     1/*
     2Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
     3For licensing, see LICENSE.html or http://ckeditor.com/license
     4*/
     5(function(){
     6
     7        function onSelectionChange( evt )
     8        {
     9                var command = evt.editor.getCommand( 'rtlSwitch' );
     10                command.state = getState( evt.editor, evt.data.path, 'rtl' );
     11                command.fire( 'state' );
     12
     13                command = evt.editor.getCommand( 'ltrSwitch' );
     14                command.state = getState( evt.editor, evt.data.path, 'ltr' );
     15                command.fire( 'state' );
     16        }
     17       
     18        function getState( editor, path, dir )
     19        {
     20                var firstBlock = path.block || path.blockLimit;
     21
     22                if ( !firstBlock || firstBlock.getName() == 'body' )
     23                        return CKEDITOR.TRISTATE_OFF;
     24
     25                return ( firstBlock.getAttribute( 'dir' ) == dir ) ?
     26                        CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF;
     27        }
     28
     29        function bidiCommand( dir )
     30        {
     31                return function( editor )
     32                {
     33                        var selection = editor.getSelection(),
     34                                enterMode = editor.config.enterMode,
     35                                ranges = editor.getSelection().getRanges();
     36
     37                        // Creates bookmarks for selection, as we may split some blocks.
     38                        var bookmarks = selection.createBookmarks();
     39
     40                        if ( ranges )
     41                        {
     42                                var iterator,
     43                                        block;
     44
     45                                for ( var i = ranges.length - 1 ; i >= 0 ; i-- )
     46                                {
     47                                        iterator = ranges[ i ].createIterator();
     48                                        iterator.enlargeBr = enterMode != CKEDITOR.ENTER_BR;
     49
     50                                        while ( ( block = iterator.getNextParagraph( enterMode == CKEDITOR.ENTER_P ? 'p' : 'div' ) ) )
     51                                        {
     52                                                if ( block.hasAttribute( 'dir' ) && block.getAttribute( 'dir' ).toLowerCase()  == dir )
     53                                                        block.removeAttribute( 'dir' );
     54                                                else
     55                                                        block.setAttribute( 'dir', dir );
     56                                        }
     57                                }
     58
     59                                editor.focus();
     60                                editor.forceNextSelectionCheck();
     61                                // Restore selection position.
     62                                selection.selectBookmarks( bookmarks );
     63                        }
     64                };
     65        }
     66
     67        CKEDITOR.plugins.add( 'bidiswitch',
     68        {
     69                requires : [ 'styles', 'button' ],
     70
     71                init : function( editor )
     72                {
     73                        // All buttons use the same code to register. So, to avoid
     74                        // duplications, let's use this tool function.
     75                        var addButtonCommand = function( buttonName, buttonLabel, commandName, commandExec )
     76                        {
     77                                editor.addCommand( commandName, new CKEDITOR.command( editor, { exec : commandExec }) );
     78
     79                                editor.ui.addButton( buttonName,
     80                                        {
     81                                                label : buttonLabel,
     82                                                command : commandName
     83                                        });
     84                        };
     85
     86                        var lang = editor.lang.bidiswitch;
     87
     88                        addButtonCommand( 'BidiRtl', lang.rtl, 'rtlSwitch', bidiCommand( 'rtl' ) );
     89                        addButtonCommand( 'BidiLtr', lang.ltr, 'ltrSwitch', bidiCommand( 'ltr' ) );
     90
     91                        editor.on( 'selectionChange', onSelectionChange );
     92                }
     93        });
     94       
     95})();
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy