Ticket #3532: 3532.patch

File 3532.patch, 10.4 KB (added by Frederico Caldeira Knabben, 15 years ago)
  • _source/plugins/button/plugin.js

     
    2727 */
    2828CKEDITOR.ui.button = function( definition )
    2929{
    30         /**
    31          * The button label.
    32          * @name CKEDITOR.ui.button.prototype.label
    33          * @type String
    34          * @example
    35          */
    36         this.label = definition.label;
    37 
    38         /**
    39          * The button advisory title. It is usually displayed as the button tooltip.
    40          * If not defined, the label is used.
    41          * @name CKEDITOR.ui.button.prototype.title
    42          * @type String
    43          * @example
    44          */
    45         this.title = definition.title || definition.label;
    46 
    47         /**
    48          * The command name associated to the button. If no command is defined, the
    49          * "click" event is used.
    50          * @name CKEDITOR.ui.button.prototype.command
    51          * @type String
    52          * @example
    53          */
    54         this.command = definition.command;
    55 
    56         this.className = definition.className || ( definition.command && 'cke_button_' + definition.command ) || '';
    57 
    58         this.icon = definition.icon;
    59         this.iconOffset = definition.iconOffset;
    60 
    61         /**
    62          * The function to be called when the user clicks the button. If not
    63          * defined, the "command" property is required, and the command gets
    64          * executed on click.
    65          * @function
    66          * @name CKEDITOR.ui.button.prototype.click
    67          * @example
    68          */
    69         this.click = definition.click || function( editor )
     30        // Copy all definition properties to this object.
     31        CKEDITOR.tools.extend( this, definition,
     32                // Set defaults.
    7033                {
    71                         editor.execCommand( definition.command );
    72                 };
     34                        title           : definition.label,
     35                        className       : definition.className || ( definition.command && 'cke_button_' + definition.command ) || '',
     36                        click           : definition.click || function( editor )
     37                                {
     38                                        editor.execCommand( definition.command );
     39                                }
     40                });
    7341
    7442        this._ = {};
    7543};
     
    11886                                this.button.click( editor );
    11987                        }
    12088                };
     89               
     90                var clickFn = CKEDITOR.tools.addFunction( instance.execute, instance );
    12191
    12292                var index = CKEDITOR.ui.button._.instances.push( instance ) - 1;
    12393
     
    176146                output.push(
    177147                                ' onkeydown="return CKEDITOR.ui.button._.keydown(', index, ', event);"' +
    178148                                ' onfocus="return CKEDITOR.ui.button._.focus(', index, ', event);"' +
    179                                 ' onclick="return CKEDITOR.ui.button._.click(', index, ', event);">' +
     149                                ' onclick="CKEDITOR.tools.callFunction(', clickFn, ', this); return false;">' +
    180150                                        '<span class="cke_icon"' );
    181151
    182152                if ( this.icon )
     
    187157
    188158                output.push(
    189159                                        '></span>' +
    190                                         '<span class="cke_label">', this.label, '</span>' +
     160                                        '<span class="cke_label">', this.label, '</span>' );
     161
     162                if ( this.hasArrow )
     163                {
     164                        output.push(
     165                                        '<span class="cke_buttonarrow"></span>' );
     166                }
     167
     168                output.push(
    191169                        '</a>',
    192170                        '</span>' );
    193171
     172                if ( this.onRender )
     173                        this.onRender();
     174
    194175                return instance;
    195176        },
    196177
     
    213194{
    214195        instances : [],
    215196
    216         click : function( index )
    217         {
    218                 CKEDITOR.ui.button._.instances[ index ].execute();
    219                 return false;
    220         },
    221 
    222197        keydown : function( index, ev )
    223198        {
    224199                var instance = CKEDITOR.ui.button._.instances[ index ];
  • _source/plugins/panelbutton/plugin.js

     
    1919 */
    2020CKEDITOR.UI_PANELBUTTON = 4;
    2121
    22 CKEDITOR.ui.panelButton = CKEDITOR.tools.createClass(
     22(function()
    2323{
    24         $ : function( definition )
     24        var clickFn = function( editor )
    2525        {
    26                 // Copy all definition properties to this object.
    27                 CKEDITOR.tools.extend( this, definition,
    28                         // Set defaults.
    29                         {
    30                                 title : definition.label,
    31                                 modes : { wysiwyg : 1 }
    32                         });
     26                var _ = this._;
    3327
    34                 // We don't want the panel definition in this object.
    35                 var panelDefinition = this.panel;
    36                 delete this.panel;
     28                if ( _.state == CKEDITOR.TRISTATE_DISABLED )
     29                        return;
    3730
    38                 this.document = ( panelDefinition
    39                                                         && panelDefinition.parent
    40                                                         && panelDefinition.parent.getDocument() )
    41                                                 || CKEDITOR.document;
    42                 this._ =
    43                 {
    44                         panelDefinition : panelDefinition
    45                 };
    46         },
     31                this.createPanel( editor );
    4732
    48         statics :
    49         {
    50                 handler :
     33                if ( _.on )
    5134                {
    52                         create : function( definition )
    53                         {
    54                                 return new CKEDITOR.ui.panelButton( definition );
    55                         }
     35                        _.panel.hide();
     36                        return;
    5637                }
    57         },
    5838
    59         proto :
    60         {
    61                 render : function( editor, output )
    62                 {
    63                         var id = this._.id = 'cke_' + CKEDITOR.tools.getNextNumber();
     39                _.panel.showBlock( this._.id, this.document.getById( this._.id ), 4 );
     40        };
    6441
    65                         var instance =
    66                         {
    67                                 id : id,
    68                                 focus : function()
    69                                 {
    70                                         var element = CKEDITOR.document.getById( id );
    71                                         element.focus();
    72                                 },
    73                                 execute : function()
    74                                 {
    75                                         this.button.click( editor );
    76                                 }
    77                         };
    7842
    79                         var clickFn = CKEDITOR.tools.addFunction( function( $element )
    80                                 {
    81                                         var _ = this._;
     43        CKEDITOR.ui.panelButton = CKEDITOR.tools.createClass(
     44        {
     45                base : CKEDITOR.ui.button,
    8246
    83                                         if ( _.state == CKEDITOR.TRISTATE_DISABLED )
    84                                                 return;
     47                $ : function( definition )
     48                {
     49                        // We don't want the panel definition in this object.
     50                        var panelDefinition = definition.panel;
     51                        delete definition.panel;
    8552
    86                                         this.createPanel( editor );
     53                        this.base( definition );
    8754
    88                                         if ( _.on )
    89                                         {
    90                                                 _.panel.hide();
    91                                                 return;
    92                                         }
     55                        this.document = ( panelDefinition
     56                                                                && panelDefinition.parent
     57                                                                && panelDefinition.parent.getDocument() )
     58                                                        || CKEDITOR.document;
     59                       
     60                        this.hasArrow = true;
    9361
    94                                         _.panel.showBlock( this._.id, new CKEDITOR.dom.element( $element ), 4 );
    95                                 },
    96                                 this );
    97                         var keyDownFn = CKEDITOR.tools.addFunction( function( ev, element ){
     62                        this.click = clickFn;
    9863
    99                                 ev = new CKEDITOR.dom.event( ev );
     64                        this._ =
     65                        {
     66                                panelDefinition : panelDefinition
     67                        };
     68                },
    10069
    101                                 var keystroke = ev.getKeystroke();
    102                                 switch ( keystroke )
     70                statics :
     71                {
     72                        handler :
     73                        {
     74                                create : function( definition )
    10375                                {
    104                                         case 13 :       // ENTER
    105                                         case 32 :       // SPACE
    106                                         case 40 :       // ARROW-DOWN
    107                                                 // Show panel
    108                                                 CKEDITOR.tools.callFunction( clickFn, element );
    109                                                 break;
    110                                         default :
    111                                                 // Delegate the default behavior to toolbar button key handling.
    112                                                 instance.onkey( instance,  keystroke );
     76                                        return new CKEDITOR.ui.panelButton( definition );
    11377                                }
    114 
    115                                 // Avoid subsequent focus grab on editor document.
    116                                 ev.preventDefault();
    117                         });
    118 
    119                         var label = this.label || '';
    120 
    121                         var classes = 'cke_off';
    122 
    123                         if ( this.className )
    124                                 classes += ' ' + this.className;
    125 
    126                         editor.on( 'mode', function()
    127                                 {
    128                                         this.setState( this.modes[ editor.mode ] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED );
    129                                 },
    130                                 this );
    131 
    132                         output.push(
    133                                 '<span class="cke_button">',
    134                                 '<a id="', id, '"' +
    135                                         ' class="', classes, '" href="javascript:void(\'', ( this.title || '' ).replace( "'", '' ), '\')"' +
    136                                         ' title="', this.title, '"' +
    137                                         ' tabindex="-1"' +
    138                                         ' hidefocus="true"' );
    139 
    140                         // Some browsers don't cancel key events in the keydown but in the
    141                         // keypress.
    142                         // TODO: Check if really needed for Gecko+Mac.
    143                         if ( CKEDITOR.env.opera || ( CKEDITOR.env.gecko && CKEDITOR.env.mac ) )
    144                         {
    145                                 output.push(
    146                                         ' onkeypress="return false;"' );
    14778                        }
    148 
    149                         // With Firefox, we need to force the button to redraw, otherwise it
    150                         // will remain in the focus state.
    151                         if ( CKEDITOR.env.gecko )
    152                         {
    153                                 output.push(
    154                                         ' onblur="this.style.cssText = this.style.cssText;"' );
    155                         }
    156 
    157                         output.push(
    158                                         ' onkeydown="CKEDITOR.tools.callFunction( ', keyDownFn, ', event, this );"' +
    159                                         ' onclick="CKEDITOR.tools.callFunction(', clickFn, ', this); return false;">' +
    160                                                 '<span class="cke_icon"></span>' +
    161                                                 '<span class="cke_label">', this.label, '</span>' +
    162                                                 '<span class="cke_buttonarrow"></span>' +
    163                                 '</a>' +
    164                                 '</span>' );
    165 
    166                         return instance;
    16779                },
    16880
    169                 createPanel : function( editor )
     81                proto :
    17082                {
    171                         var _ = this._;
     83                        createPanel : function( editor )
     84                        {
     85                                var _ = this._;
    17286
    173                         if ( _.panel )
    174                                 return;
     87                                if ( _.panel )
     88                                        return;
    17589
    176                         var panelDefinition = this._.panelDefinition || {},
    177                                 panelParentElement = panelDefinition.parent || CKEDITOR.document.getBody(),
    178                                 panel = this._.panel = new CKEDITOR.ui.floatPanel( editor, panelParentElement, panelDefinition ),
    179                                 me = this;
     90                                var panelDefinition = this._.panelDefinition || {},
     91                                        panelParentElement = panelDefinition.parent || CKEDITOR.document.getBody(),
     92                                        panel = this._.panel = new CKEDITOR.ui.floatPanel( editor, panelParentElement, panelDefinition ),
     93                                        me = this;
    18094
    181                         panel.onShow = function()
    182                                 {
    183                                         if ( me.className )
    184                                                 this.element.getFirst().addClass( me.className + '_panel' );
     95                                panel.onShow = function()
     96                                        {
     97                                                if ( me.className )
     98                                                        this.element.getFirst().addClass( me.className + '_panel' );
    18599
    186                                         me.setState( CKEDITOR.TRISTATE_ON );
     100                                                _.oldState = me._.state;
     101                                                me.setState( CKEDITOR.TRISTATE_ON );
    187102
    188                                         _.on = 1;
     103                                                _.on = 1;
    189104
    190                                         if ( me.onOpen )
    191                                                 me.onOpen();
    192                                 };
     105                                                if ( me.onOpen )
     106                                                        me.onOpen();
     107                                        };
    193108
    194                         panel.onHide = function()
    195                                 {
    196                                         if ( me.className )
    197                                                 this.element.getFirst().removeClass( me.className + '_panel' );
     109                                panel.onHide = function()
     110                                        {
     111                                                if ( me.className )
     112                                                        this.element.getFirst().removeClass( me.className + '_panel' );
    198113
    199                                         me.setState( CKEDITOR.TRISTATE_OFF );
     114                                                me.setState( _.oldState );
    200115
    201                                         _.on = 0;
     116                                                _.on = 0;
    202117
    203                                         if ( me.onClose )
    204                                                 me.onClose();
    205                                 };
     118                                                if ( me.onClose )
     119                                                        me.onClose();
     120                                        };
    206121
    207                         panel.onEscape = function()
    208                                 {
    209                                         panel.hide();
    210                                         me.document.getById( _.id ).focus();
    211                                 };
     122                                panel.onEscape = function()
     123                                        {
     124                                                panel.hide();
     125                                                me.document.getById( _.id ).focus();
     126                                        };
    212127
    213128
    214                         if ( this.onBlock )
    215                                 this.onBlock( panel, _.id );
    216                 },
     129                                if ( this.onBlock )
     130                                        this.onBlock( panel, _.id );
     131                        }
     132                }
     133        });
    217134
    218                 setState : CKEDITOR.ui.button.prototype.setState
    219         }
    220 });
     135})();
     136 No newline at end of file
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy