-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathjquery.expandable.js
53 lines (45 loc) · 1.08 KB
/
jquery.expandable.js
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
/*!
* jQuery Expandable Input Plugin v1.0
* https://github.com/armmer1/expandable-input
*
* Copyright 2014, Nattawat Nonsung
*/
/**
* Use immediately Invoked Function Expression to
* - Prevent conflicting with other libary on alias $
* - Scope varaible to be private
*/
(function( $ ) {
$.fn.expandable = function(options) {
// Define default setting
var settings = $.extend({
width: 150,
duration: 300
}, options );
var width = this.outer();
this.on("focus", function(){
// $(this).css({width: settings.width});
$(this).animate({
width: settings.width
}, settings.duration, function(){
// callback function
});
});
this.on("blur", function(){
$(this).animate({
width: width
}, settings.duration, function(){
// callback function
});
});
if(settings.action && typeof(settings.action) == "function"){
this.on('keypress', function(e) {
if (e.which === 13) { // press enter
settings.action($(this).val());
}
});
}
// Return jQuery so that it's chainable
return this;
};
}( jQuery ));