forked from filebrowser/filebrowser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
98 lines (85 loc) 路 2.28 KB
/
app.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
$(document).ready(function() {
$(document).pjax('a', '#container');
});
$(document).on('ready pjax:success', function() {
$('.scroll').perfectScrollbar();
$("#preview").click(function(e) {
e.preventDefault();
var preview = $("#preview-area"),
editor = $('.editor textarea');
if ($(this).data("previewing") == "true") {
preview.hide();
editor.fadeIn();
$(this).data("previewing", "false");
notification({
text: "You've gone into editing mode.",
type: 'information',
timeout: 2000
});
} else {
var converter = new showdown.Converter(),
text = editor.val(),
html = converter.makeHtml(text);
editor.hide();
preview.html(html).fadeIn();
$(this).data("previewing", "true");
notification({
text: "You've gone into preview mode.",
type: 'information',
timeout: 2000
});
}
return false;
});
$('form').submit(function(event) {
event.preventDefault();
var data = JSON.stringify($(this).serializeJSON()),
url = $(this).attr('action'),
button = $(this).find("input[type=submit]:focus");
$.ajax({
type: 'POST',
url: url,
data: data,
beforeSend: function(xhr) {
xhr.setRequestHeader('X-Regenerate', button.data("regenerate"));
},
dataType: 'json',
encode: true,
}).done(function(data) {
notification({
text: button.data("message"),
type: 'success',
timeout: 5000
});
}).fail(function(data) {
notification({
text: 'Something went wrong.',
type: 'error'
});
console.log(data);
});
});
$("#logout").click(function(e) {
e.preventDefault();
jQuery.ajax({
type: "GET",
url: "/admin",
async: false,
username: "logmeout",
password: "123456",
headers: {
"Authorization": "Basic xxx"
}
})
.fail(function() {
window.location = "/";
});
return false;
});
$(".add").click(function(e) {
e.preventDefault();
fieldset = $(this).closest("fieldset");
fieldset.append("<input name=\"" + fieldset.attr("name") + "\" id=\"" + fieldset.attr("name") + "\" value=\"\"></input><br>");
return false;
});
});