2 Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license
\r
7 * @fileOverview Defines the {@link CKEDITOR.focusManager} class, which is used
\r
8 * to handle the focus on editor instances..
\r
12 * Manages the focus activity in an editor instance. This class is to be used
\r
13 * mainly by UI elements coders when adding interface elements to CKEditor.
\r
15 * @param {CKEDITOR.editor} editor The editor instance.
\r
18 CKEDITOR.focusManager = function( editor )
\r
20 if ( editor.focusManager )
\r
21 return editor.focusManager;
\r
24 * Indicates that the editor instance has focus.
\r
27 * alert( CKEDITOR.instances.editor1.focusManager.hasFocus ); // e.g "true"
\r
29 this.hasFocus = false;
\r
32 * Object used to hold private stuff.
\r
43 CKEDITOR.focusManager.prototype =
\r
46 * Indicates that the editor instance has the focus.
\r
48 * This function is not used to set the focus in the editor. Use
\r
49 * {@link CKEDITOR.editor#focus} for it instead.
\r
51 * var editor = CKEDITOR.instances.editor1;
\r
52 * <b>editor.focusManager.focus()</b>;
\r
57 clearTimeout( this._.timer );
\r
59 if ( !this.hasFocus )
\r
61 // If another editor has the current focus, we first "blur" it. In
\r
62 // this way the events happen in a more logical sequence, like:
\r
63 // "focus 1" > "blur 1" > "focus 2"
\r
65 // "focus 1" > "focus 2" > "blur 1"
\r
66 if ( CKEDITOR.currentInstance )
\r
67 CKEDITOR.currentInstance.focusManager.forceBlur();
\r
69 var editor = this._.editor;
\r
71 editor.container.getChild( 1 ).addClass( 'cke_focus' );
\r
73 this.hasFocus = true;
\r
74 editor.fire( 'focus' );
\r
79 * Indicates that the editor instance has lost the focus. Note that this
\r
80 * functions acts asynchronously with a delay of 100ms to avoid subsequent
\r
81 * blur/focus effects. If you want the "blur" to happen immediately, use
\r
82 * the {@link #forceBlur} function instead.
\r
84 * var editor = CKEDITOR.instances.editor1;
\r
85 * <b>editor.focusManager.blur()</b>;
\r
89 var focusManager = this;
\r
91 if ( focusManager._.timer )
\r
92 clearTimeout( focusManager._.timer );
\r
94 focusManager._.timer = setTimeout(
\r
97 delete focusManager._.timer;
\r
98 focusManager.forceBlur();
\r
104 * Indicates that the editor instance has lost the focus. Unlike
\r
105 * {@link #blur}, this function is synchronous, marking the instance as
\r
106 * "blured" immediately.
\r
108 * var editor = CKEDITOR.instances.editor1;
\r
109 * <b>editor.focusManager.forceBlur()</b>;
\r
111 forceBlur : function()
\r
113 if ( this.hasFocus )
\r
115 var editor = this._.editor;
\r
117 editor.container.getChild( 1 ).removeClass( 'cke_focus' );
\r
119 this.hasFocus = false;
\r
120 editor.fire( 'blur' );
\r
126 * Fired when the editor instance receives the input focus.
\r
127 * @name CKEDITOR.editor#focus
\r
129 * @param {CKEDITOR.editor} editor The editor instance.
\r
133 * Fired when the editor instance loses the input focus.
\r
134 * @name CKEDITOR.editor#blur
\r
136 * @param {CKEDITOR.editor} editor The editor instance.
\r