forked from maccman/holla
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjquery.editable.js
More file actions
61 lines (44 loc) · 1.23 KB
/
Copy pathjquery.editable.js
File metadata and controls
61 lines (44 loc) · 1.23 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
(function($){
$.fn.startEditable = function(options){
if ( !options ) options = {};
var element = $(this);
var oldHTML = element.html();
if ( element.hasClass("editable") ) return;
element.addClass("editable");
var input;
if (options.textarea)
input = $("<textarea />");
else
input = $("<input type='text' />");
input.addClass("editable");
input.val(element.text());
element.bind("finish.edit", function(){
input.trigger("finish.edit");
});
input.bind("change blur finish.edit", function(){
var result = input.val();
input.remove();
element.html(oldHTML);
element.removeClass("editable");
element.trigger("value.edit", result);
});
input.bind("keydown", function(e){
var enter = (e.which == 13 && (!options.textarea || (e.metaKey || e.altKey)));
var escape = (e.which == 27);
if (enter || escape)
input.trigger("finish.edit");
});
element.empty();
element.append(input);
input.select();
return this;
}
$.fn.editable = function(options){
this.attr("title", "Click to edit");
this.bind("click start.edit", function(e){
e.preventDefault();
$(this).startEditable(options);
});
return this;
};
})(jQuery);