-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheditable_label.js
More file actions
48 lines (47 loc) · 1.55 KB
/
editable_label.js
File metadata and controls
48 lines (47 loc) · 1.55 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
isMobile = {
Android: function() {
return navigator.userAgent.match(/Android/i);
},
BlackBerry: function() {
return navigator.userAgent.match(/BlackBerry/i);
},
iOS: function() {
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
},
Opera: function() {
return navigator.userAgent.match(/Opera Mini/i);
},
Windows: function() {
return navigator.userAgent.match(/IEMobile/i);
},
any: function() {
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
}
};
function editable_label(label_class, input_class, options){
$("."+label_class).click(function(){
$("."+label_class).unbind('click');
var label = $(this);
var old_text = label.text()
$(this).replaceWith(
'<input id="temp_edit_input" type="text" value="'+label.text()+'" class="'+input_class+'">'
);
if('mask' in options){
$("#temp_edit_input").inputmask(options['mask'], {
placeholder:" ",
clearMaskOnLostFocus: true
});
};
$("#temp_edit_input").select();
$("#temp_edit_input").focusout(function(){
if($("#temp_edit_input").val() != ""){
label.text($("#temp_edit_input").val());
}
else{
label.text(old_text)
}
$("#temp_edit_input").replaceWith(label)
editable_label(label_class, input_class, options)
});
});
}