-
-
Notifications
You must be signed in to change notification settings - Fork 162
/
js.js
51 lines (41 loc) · 1.16 KB
/
js.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
var g_changing = false,
g_saved = '';
function nl2br(value) {
return (value + "").replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, "$1<br>$2")
}
function fieldSave(id, value, dataTarget) {
g_changing = (g_saved!=value);
if (!g_changing){
$(this).parent().html(g_saved);
return
};
$("#save").show();
$.post(
"", { fieldname: id, content: value, target: dataTarget },
function(a) {}
).always(
function() {
window.location.reload();
}
)
}
function onEdit() {
if (g_changing) return;
var $this = $(this),
title = $this.attr('title'),
id = $this.attr('id'),
target= $this.data('target'),
value = $this.hasClass('editable') ? ["", ""] : ["nl2br(", ")"];
g_saved = $this.html();
title = title ? '"'+title+'"' : '';
value = value.join('this.value');
var fBlur = 'fieldSave.call(this, '+[ "'"+id+"'", value, "'"+target+"'"].join(',')+')';
$this.html('<textarea '+title+' id="'+id+'_field" onblur="'+fBlur+'">'+$this.html()+"</textarea>");
$this.children(":first").focus();
autosize($("textarea")),
g_changing = true;
}
function onReady() {
$("span.editText").click(onEdit);
}
$(document).ready(onReady);