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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
function fixedEncodeURIComponent (str) {
return encodeURIComponent(str).replace(/[!'()]/g, escape).replace(/\*/g, "%2A");
}
(function($) {
$(function() {
$(window).bind('hashchange', function(e) {
var hash = window.location.hash;
$('.highlight_line').removeClass("highlight_line");
if (hash.match(/^#n\d+$/) === null) {
return;
}
var line = $(hash).parent().parent();
line.addClass("highlight_line");
});
$(window).trigger('hashchange');
var lexer_source = [];
for (var key in window.lexers) {
lexer_source.push({ label: window.lexers[key], value: key });
}
$('#language').autocomplete({
source: lexer_source,
select: function(event, ui) {
window.location = window.paste_base + '/' + fixedEncodeURIComponent(ui.item.value);
}
});
$('#language-toggle').click(function() {
setTimeout(function() {
$('#language').focus();
}, 0);
});
$('[rel="tooltip"]').tooltip({
placement: 'bottom'
});
$('#history-all').bind('change', function() {
$('.delete-history').prop('checked', $(this).is(':checked'));
});
window.lines_wrapped = true;
$('#linewrap').click(function() {
if (window.lines_wrapped == true) {
$(".highlight > pre").css("white-space", "pre");
} else {
$(".highlight > pre").css("white-space", "pre-wrap");
}
window.lines_wrapped = !window.lines_wrapped;
});
// check file size before uploading if browser support html5
if (window.File && window.FileList) {
function checkFileUpload(evt) {
var sum = 0;
var files = evt.target.files;
// TODO: check all forms, not only the one we are called from
for (var i = 0; i < files.length; i++) {
var f = evt.target.files[i];
sum += f.size;
}
if (sum > max_upload_size) {
document.getElementById('upload_button').innerHTML = "File(s) too big";
document.getElementById('upload_button').disabled = true;
} else {
document.getElementById('upload_button').innerHTML = "Upload it!";
document.getElementById('upload_button').disabled = false;
}
}
$('.file-upload').bind('change', checkFileUpload);
}
if (typeof $.tablesorter !== 'undefined') {
// source: https://projects.archlinux.org/archweb.git/tree/sitestatic/archweb.js
$.tablesorter.addParser({
id: 'filesize',
re: /^(\d+(?:\.\d+)?)(bytes?|[KMGTPEZY]i?B|B)$/,
is: function(s) {
return this.re.test(s);
},
format: function(s) {
var matches = this.re.exec(s);
if (!matches) {
return 0;
}
var size = parseFloat(matches[1]),
suffix = matches[2];
switch(suffix) {
/* intentional fall-through at each level */
case 'YB':
case 'YiB':
size *= 1024;
case 'ZB':
case 'ZiB':
size *= 1024;
case 'EB':
case 'EiB':
size *= 1024;
case 'PB':
case 'PiB':
size *= 1024;
case 'TB':
case 'TiB':
size *= 1024;
case 'GB':
case 'GiB':
size *= 1024;
case 'MB':
case 'MiB':
size *= 1024;
case 'KB':
case 'KiB':
size *= 1024;
}
return size;
},
type: 'numeric'
});
$.tablesorter.addParser({
// set a unique id
id: 'mydate',
re: /t=([0-9]+)$/,
is: function(s) {
// return false so this parser is not auto detected
return false;
},
format: function(s) {
var matches = this.re.exec(s);
if (!matches) {
return 0;
}
//console.log(s, matches);
return matches[1];
},
type: 'numeric'
});
$("#upload_history:has(tbody tr)").tablesorter({
headers: {
0: {sorter: false},
4: {sorter: "mydate"},
},
sortList: [[4,1]],
});
}
});
})(jQuery);
|