forked from shokai/jQuery.editable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
51 lines (44 loc) · 1.25 KB
/
main.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
$(function(){
$('h1').editable('mouseover');
// double click
$('.name .editable').editable('dblclick', function(e){
alert(e.target.selector + ' : ' + e.value);
console.log(e.value);
});
// single click
$('.city .editable').editable('click', function(e){
console.log(e.value);
});
// click hold
$('.website .editable').editable('clickhold', function(e){
var a_tag = $('<a>').attr('href', e.value).text(e.value);
$('.website .editable').html(a_tag);
alert(e.value);
console.log(e.value);
});
// validation
$('.zip .editable').editable('click', function(e){
if(e.value.match(/^\d{3}\-\d{4}$/)){
alert(e.target.selector + ' : ' + e.value);
}
else{
$('.zip .editable').html(e.old_value);
alert(e.value + ' is not valid zip-code');
}
});
// edit button
var option = {trigger : $('.age .btn_edit'), action : 'click'};
$('.age .editable').editable(option, function(e){
if(!e.value.match(/^\d+$/)){
$('.age .editable').html(e.old_value);
alert(e.value + ' is not valid age');
}
else{
alert('save : '+e.value);
}
});
// textarea
$('.textarea .editable').editable({type: 'textarea', action: 'click'}, function(e){
console.log(e.value);
});
});