c5b63a04c4d7c31d57a9f50655ed22afb8d19931.svn-base
3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.html or http://ckeditor.com/license
*/
/**
* @fileOverview Defines the {@link CKEDITOR.focusManager} class, which is used
* to handle the focus on editor instances..
*/
/**
* Creates a focusManager class instance.
* @class Manages the focus activity in an editor instance. This class is to be
* used mainly by UI elements coders when adding interface elements that need
* to set the focus state of the editor.
* @param {CKEDITOR.editor} editor The editor instance.
* @example
* var focusManager = <b>new CKEDITOR.focusManager( editor )</b>;
* focusManager.focus();
*/
CKEDITOR.focusManager = function( editor )
{
if ( editor.focusManager )
return editor.focusManager;
/**
* Indicates that the editor instance has focus.
* @type Boolean
* @example
* alert( CKEDITOR.instances.editor1.focusManager.hasFocus ); // e.g "true"
*/
this.hasFocus = false;
/**
* Object used to hold private stuff.
* @private
*/
this._ =
{
editor : editor
};
return this;
};
CKEDITOR.focusManager.prototype =
{
/**
* Used to indicate that the editor instance has the focus.<br />
* <br />
* Note that this function will not explicitelly set the focus in the
* editor (for example, making the caret blinking on it). Use
* {@link CKEDITOR.editor#focus} for it instead.
* @example
* var editor = CKEDITOR.instances.editor1;
* <b>editor.focusManager.focus()</b>;
*/
focus : function()
{
if ( this._.timer )
clearTimeout( this._.timer );
if ( !this.hasFocus )
{
// If another editor has the current focus, we first "blur" it. In
// this way the events happen in a more logical sequence, like:
// "focus 1" > "blur 1" > "focus 2"
// ... instead of:
// "focus 1" > "focus 2" > "blur 1"
if ( CKEDITOR.currentInstance )
CKEDITOR.currentInstance.focusManager.forceBlur();
var editor = this._.editor;
editor.container.getChild( 1 ).addClass( 'cke_focus' );
this.hasFocus = true;
editor.fire( 'focus' );
}
},
/**
* Used to indicate that the editor instance has lost the focus.<br />
* <br />
* Note that this functions acts asynchronously with a delay of 100ms to
* avoid subsequent blur/focus effects. If you want the "blur" to happen
* immediately, use the {@link #forceBlur} function instead.
* @example
* var editor = CKEDITOR.instances.editor1;
* <b>editor.focusManager.blur()</b>;
*/
blur : function()
{
var focusManager = this;
if ( focusManager._.timer )
clearTimeout( focusManager._.timer );
focusManager._.timer = setTimeout(
function()
{
delete focusManager._.timer;
focusManager.forceBlur();
}
, 100 );
},
/**
* Used to indicate that the editor instance has lost the focus. Unlike
* {@link #blur}, this function is synchronous, marking the instance as
* "blured" immediately.
* @example
* var editor = CKEDITOR.instances.editor1;
* <b>editor.focusManager.forceBlur()</b>;
*/
forceBlur : function()
{
if ( this.hasFocus )
{
var editor = this._.editor;
editor.container.getChild( 1 ).removeClass( 'cke_focus' );
this.hasFocus = false;
editor.fire( 'blur' );
}
}
};
/**
* Fired when the editor instance receives the input focus.
* @name CKEDITOR.editor#focus
* @event
* @param {CKEDITOR.editor} editor The editor instance.
* @example
* editor.on( 'focus', function( e )
* {
* alert( 'The editor named ' + e.editor.name + ' is now focused' );
* });
*/
/**
* Fired when the editor instance loses the input focus.
* @name CKEDITOR.editor#blur
* @event
* @param {CKEDITOR.editor} editor The editor instance.
* @example
* editor.on( 'blur', function( e )
* {
* alert( 'The editor named ' + e.editor.name + ' lost the focus' );
* });
*/