blob: 5f7f3575cc63daa997dca3878983787c766edea3 (
plain) (
blame)
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
/**
* jQuery TextExt Plugin
* http://textextjs.com
*
* @version 1.3.1
* @copyright Copyright (C) 2011 Alex Gorbatchev. All rights reserved.
* @license MIT License
*/
(function($)
{
/**
* Focus plugin displays a visual effect whenever user sets focus
* into the text area.
*
* @author agorbatchev
* @date 2011/08/18
* @id TextExtFocus
*/
function TextExtFocus() {};
$.fn.textext.TextExtFocus = TextExtFocus;
$.fn.textext.addPlugin('focus', TextExtFocus);
var p = TextExtFocus.prototype,
/**
* Focus plugin only has one option and that is its HTML template. It could be
* changed when passed to the `$().textext()` function. For example:
*
* $('textarea').textext({
* plugins: 'focus',
* html: {
* focus: "<span/>"
* }
* })
*
* @author agorbatchev
* @date 2011/08/18
* @id TextExtFocus.options
*/
/**
* HTML source that is used to generate markup required for the focus effect.
*
* @name html.focus
* @default '<div class="text-focus"/>'
* @author agorbatchev
* @date 2011/08/18
* @id TextExtFocus.options.html.focus
*/
OPT_HTML_FOCUS = 'html.focus',
/**
* Focus plugin dispatches or reacts to the following events.
*
* @author agorbatchev
* @date 2011/08/17
* @id TextExtFocus.events
*/
/**
* Focus plugin reacts to the `focus` event and shows the markup generated from
* the `html.focus` option.
*
* @name focus
* @author agorbatchev
* @date 2011/08/18
* @id TextExtFocus.events.focus
*/
/**
* Focus plugin reacts to the `blur` event and hides the effect.
*
* @name blur
* @author agorbatchev
* @date 2011/08/18
* @id TextExtFocus.events.blur
*/
DEFAULT_OPTS = {
html : {
focus : '<div class="text-focus"/>'
}
}
;
/**
* Initialization method called by the core during plugin instantiation.
*
* @signature TextExtFocus.init(core)
*
* @param core {TextExt} Instance of the TextExt core class.
*
* @author agorbatchev
* @date 2011/08/18
* @id TextExtFocus.init
*/
p.init = function(core)
{
var self = this;
self.baseInit(core, DEFAULT_OPTS);
self.core().wrapElement().append(self.opts(OPT_HTML_FOCUS));
self.on({
blur : self.onBlur,
focus : self.onFocus
});
self._timeoutId = 0;
};
//--------------------------------------------------------------------------------
// Event handlers
/**
* Reacts to the `blur` event and hides the focus effect with a slight delay which
* allows quick refocusing without effect blinking in and out.
*
* @signature TextExtFocus.onBlur(e)
*
* @param e {Object} jQuery event.
*
* @author agorbatchev
* @date 2011/08/08
* @id TextExtFocus.onBlur
*/
p.onBlur = function(e)
{
var self = this;
clearTimeout(self._timeoutId);
self._timeoutId = setTimeout(function()
{
self.getFocus().hide();
},
100);
};
/**
* Reacts to the `focus` event and shows the focus effect.
*
* @signature TextExtFocus.onFocus
*
* @param e {Object} jQuery event.
* @author agorbatchev
* @date 2011/08/08
* @id TextExtFocus.onFocus
*/
p.onFocus = function(e)
{
var self = this;
clearTimeout(self._timeoutId);
self.getFocus().show();
};
//--------------------------------------------------------------------------------
// Core functionality
/**
* Returns focus effect HTML element.
*
* @signature TextExtFocus.getFocus()
*
* @author agorbatchev
* @date 2011/08/08
* @id TextExtFocus.getFocus
*/
p.getFocus = function()
{
return this.core().wrapElement().find('.text-focus');
};
})(jQuery);
|