e59900ded0c7c71f65e800e0f4761b070ca9c007
2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
3 For licensing, see LICENSE.html or http://ckeditor.com/license
7 * @fileOverview Defines the {@link CKEDITOR.focusManager} class, which is used
8 * to handle the focus on editor instances..
12 * Creates a focusManager class instance.
13 * @class Manages the focus activity in an editor instance. This class is to be
14 * used mainly by UI elements coders when adding interface elements that need
15 * to set the focus state of the editor.
16 * @param {CKEDITOR.editor} editor The editor instance.
18 * var focusManager = <b>new CKEDITOR.focusManager( editor )</b>;
19 * focusManager.focus();
21 CKEDITOR
.focusManager = function( editor
)
23 if ( editor
.focusManager
)
24 return editor
.focusManager
;
27 * Indicates that the editor instance has focus.
30 * alert( CKEDITOR.instances.editor1.focusManager.hasFocus ); // e.g "true"
32 this.hasFocus
= false;
35 * Object used to hold private stuff.
46 CKEDITOR
.focusManager
.prototype =
49 * Used to indicate that the editor instance has the focus.<br />
51 * Note that this function will not explicitelly set the focus in the
52 * editor (for example, making the caret blinking on it). Use
53 * {@link CKEDITOR.editor#focus} for it instead.
55 * var editor = CKEDITOR.instances.editor1;
56 * <b>editor.focusManager.focus()</b>;
61 clearTimeout( this._
.timer
);
65 // If another editor has the current focus, we first "blur" it. In
66 // this way the events happen in a more logical sequence, like:
67 // "focus 1" > "blur 1" > "focus 2"
69 // "focus 1" > "focus 2" > "blur 1"
70 if ( CKEDITOR
.currentInstance
)
71 CKEDITOR
.currentInstance
.focusManager
.forceBlur();
73 var editor
= this._
.editor
;
75 editor
.container
.getChild( 1 ).addClass( 'cke_focus' );
78 editor
.fire( 'focus' );
83 * Used to indicate that the editor instance has lost the focus.<br />
85 * Note that this functions acts asynchronously with a delay of 100ms to
86 * avoid subsequent blur/focus effects. If you want the "blur" to happen
87 * immediately, use the {@link #forceBlur} function instead.
89 * var editor = CKEDITOR.instances.editor1;
90 * <b>editor.focusManager.blur()</b>;
94 var focusManager
= this;
96 if ( focusManager
._
.timer
)
97 clearTimeout( focusManager
._
.timer
);
99 focusManager
._
.timer
= setTimeout(
102 delete focusManager
._
.timer
;
103 focusManager
.forceBlur();
109 * Used to indicate that the editor instance has lost the focus. Unlike
110 * {@link #blur}, this function is synchronous, marking the instance as
111 * "blured" immediately.
113 * var editor = CKEDITOR.instances.editor1;
114 * <b>editor.focusManager.forceBlur()</b>;
116 forceBlur : function()
120 var editor
= this._
.editor
;
122 editor
.container
.getChild( 1 ).removeClass( 'cke_focus' );
124 this.hasFocus
= false;
125 editor
.fire( 'blur' );
131 * Fired when the editor instance receives the input focus.
132 * @name CKEDITOR.editor#focus
134 * @param {CKEDITOR.editor} editor The editor instance.
136 * editor.on( 'focus', function( e )
138 * alert( 'The editor named ' + e.editor.name + ' is now focused' );
143 * Fired when the editor instance loses the input focus.
144 * @name CKEDITOR.editor#blur
146 * @param {CKEDITOR.editor} editor The editor instance.
148 * editor.on( 'blur', function( e )
150 * alert( 'The editor named ' + e.editor.name + ' lost the focus' );