-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
83 lines (74 loc) · 2.63 KB
/
script.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
var bibdata_warn_color = 'darkorange';
function checkSourceCompleted(response) {
var status_div = jQuery('#bibdataform__status');
var source_input = jQuery('#bibdataform__source');
var pageid_input = jQuery('#bibdataform__pageid');
status_div.css('color', 'green');
status_div.html('BibTeX seems ok!');
eval('var result = ' + response);
if(result.msg.length > 0) {
status_div.css('color', bibdata_warn_color);
status_div.html(result.msg);
return;
}
pageid_input.val(result.pageid);
if(!result.has_doi) {
status_div.css('color', bibdata_warn_color);
status_div.html('BibTeX source does not seem to contain the doi!');
}
if(!result.has_abstract) {
if(!result.has_doi) {
status_div.html(status_div.html().substr(0, status_div.html().length-1)
+ ', nor the abstract!');
} else {
status_div.css('color', bibdata_warn_color);
status_div.html('BibTeX source does not seem to contain the abstract!');
}
}
}
function checkPageIdCompleted(response) {
var pageid_input = jQuery('#bibdataform__pageid');
if(response == "true") {
pageid_input.css('color', 'green');
} else {
pageid_input.css('color', 'red');
}
}
function checkSourceAjax() {
var status_div = jQuery('#bibdataform__status');
var source_input = jQuery('#bibdataform__source');
var targetns = jQuery('[name="targetns"]');
status_div.html('Please wait while parsing BibTeX...');
jQuery.post(DOKU_BASE + 'lib/plugins/bibdata/ajax/checkBibtex.php',
{source: encodeURIComponent(source_input.val()),
targetns: encodeURIComponent(targetns.val())},
checkSourceCompleted);
}
function checkPageIdAjax() {
var pageid_input = jQuery('#bibdataform__pageid');
var targetns = jQuery('[name="targetns"]');
jQuery.post(DOKU_BASE + 'lib/plugins/bibdata/ajax/checkPageId.php',
{pageid: encodeURIComponent(pageid_input.val()),
targetns: encodeURIComponent(targetns.val())},
checkPageIdCompleted);
}
function installFormCheck()
{
var source_input = jQuery('#bibdataform__source');
var pageid_input = jQuery('#bibdataform__pageid');
if(source_input.length > 0) {
jQuery(source_input).change(checkSourceAjax);
}
if(pageid_input.length > 0) {
jQuery(pageid_input).keyup(checkPageIdAjax);
}
}
function redirectOnSuccess() {
var success_div = jQuery('#bibdataform__success');
if(success_div.length > 0) {
var dest = success_div.attr('href');
setTimeout(function() {window.location = dest;}, 3000);
}
}
jQuery(installFormCheck);
jQuery(redirectOnSuccess);