Ticket #3532: 3532.patch
File 3532.patch, 10.4 KB (added by , 14 years ago) |
---|
-
_source/plugins/button/plugin.js
27 27 */ 28 28 CKEDITOR.ui.button = function( definition ) 29 29 { 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. 70 33 { 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 }); 73 41 74 42 this._ = {}; 75 43 }; … … 118 86 this.button.click( editor ); 119 87 } 120 88 }; 89 90 var clickFn = CKEDITOR.tools.addFunction( instance.execute, instance ); 121 91 122 92 var index = CKEDITOR.ui.button._.instances.push( instance ) - 1; 123 93 … … 176 146 output.push( 177 147 ' onkeydown="return CKEDITOR.ui.button._.keydown(', index, ', event);"' + 178 148 ' 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;">' + 180 150 '<span class="cke_icon"' ); 181 151 182 152 if ( this.icon ) … … 187 157 188 158 output.push( 189 159 '></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( 191 169 '</a>', 192 170 '</span>' ); 193 171 172 if ( this.onRender ) 173 this.onRender(); 174 194 175 return instance; 195 176 }, 196 177 … … 213 194 { 214 195 instances : [], 215 196 216 click : function( index )217 {218 CKEDITOR.ui.button._.instances[ index ].execute();219 return false;220 },221 222 197 keydown : function( index, ev ) 223 198 { 224 199 var instance = CKEDITOR.ui.button._.instances[ index ]; -
_source/plugins/panelbutton/plugin.js
19 19 */ 20 20 CKEDITOR.UI_PANELBUTTON = 4; 21 21 22 CKEDITOR.ui.panelButton = CKEDITOR.tools.createClass( 22 (function() 23 23 { 24 $ : function( definition)24 var clickFn = function( editor ) 25 25 { 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._; 33 27 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; 37 30 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 ); 47 32 48 statics : 49 { 50 handler : 33 if ( _.on ) 51 34 { 52 create : function( definition ) 53 { 54 return new CKEDITOR.ui.panelButton( definition ); 55 } 35 _.panel.hide(); 36 return; 56 37 } 57 },58 38 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 }; 64 41 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 };78 42 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, 82 46 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; 85 52 86 this.createPanel( editor);53 this.base( definition ); 87 54 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; 93 61 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; 98 63 99 ev = new CKEDITOR.dom.event( ev ); 64 this._ = 65 { 66 panelDefinition : panelDefinition 67 }; 68 }, 100 69 101 var keystroke = ev.getKeystroke(); 102 switch ( keystroke ) 70 statics : 71 { 72 handler : 73 { 74 create : function( definition ) 103 75 { 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 ); 113 77 } 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 the141 // 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;"' );147 78 } 148 149 // With Firefox, we need to force the button to redraw, otherwise it150 // 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;167 79 }, 168 80 169 createPanel : function( editor )81 proto : 170 82 { 171 var _ = this._; 83 createPanel : function( editor ) 84 { 85 var _ = this._; 172 86 173 if ( _.panel )174 return;87 if ( _.panel ) 88 return; 175 89 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; 180 94 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' ); 185 99 186 me.setState( CKEDITOR.TRISTATE_ON ); 100 _.oldState = me._.state; 101 me.setState( CKEDITOR.TRISTATE_ON ); 187 102 188 _.on = 1;103 _.on = 1; 189 104 190 if ( me.onOpen )191 me.onOpen();192 };105 if ( me.onOpen ) 106 me.onOpen(); 107 }; 193 108 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' ); 198 113 199 me.setState( CKEDITOR.TRISTATE_OFF);114 me.setState( _.oldState ); 200 115 201 _.on = 0;116 _.on = 0; 202 117 203 if ( me.onClose )204 me.onClose();205 };118 if ( me.onClose ) 119 me.onClose(); 120 }; 206 121 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 }; 212 127 213 128 214 if ( this.onBlock ) 215 this.onBlock( panel, _.id ); 216 }, 129 if ( this.onBlock ) 130 this.onBlock( panel, _.id ); 131 } 132 } 133 }); 217 134 218 setState : CKEDITOR.ui.button.prototype.setState 219 } 220 }); 135 })(); 136 No newline at end of file