-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
158 lines (139 loc) · 4.42 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Online BibTex Viewer</title>
<link rel="stylesheet" type="text/css" href="./base.css">
</head>
<body>
<div id="debugDiv" contenteditable="false"></div>
<div id="bibx-out" data-type="bib" class="out"></div>
<h4>BibTex URL:</h4>
<input id="bibx-in" data-type="url" class="in bibtex" contenteditable="true" spellcheck="false"
value='https://raw.githubusercontent.com/rgolovanov/publications/master/golovanov.bib'/>
<h2>Output:</h2>
<fieldset>
<legend>HTML or plain text:</legend>
<select class="type">
<option value="html">HTML</option>
<option value="json">JSON</option>
<option value="string">Plain text</option>
</select>
</fieldset>
<fieldset>
<legend>Style:</legend>
<select class="style">
<option value="citation-gost">ГОСТ Р 7.0.5-2008</option>
<option value="citation-apa">APA</option>
<option value="csl">CSL-JSON</option>
<option value="bibtex">BibTeX</option>
<option value="bibtxt">Bib.TXT</option>
</select>
</fieldset>
<fieldset>
<legend>Language:</legend>
<select class="lang">
<option value="ru-RU">Русский</option>
<option value="en-US">English</option>
</select>
</fieldset>
<script type="text/javascript" src="https://code.jquery.com/jquery.min.js"></script>
<script type="text/javascript" src="https://cdn.rawgit.com/larsgw/citation.js/archive/citation.js/citation-0.3.4.min.js"></script>
<script class="code" type="text/javascript">
// jQuery elements
var $bibx_in = $('#bibx-in'),
$type = $('select.type'),
$styl = $('select.style'),
$lang = $('select.lang')
// Parse URL arguments to set controls
var url = new URL(window.location.href)
if(arg = url.searchParams.get('github_url')) {
$bibx_in.val('https://raw.githubusercontent.com' + arg)
}
else if(arg = url.searchParams.get('url')) {
$bibx_in.val(arg)
}
if(arg = url.searchParams.get('type')) {
$type.val(arg)
}
if(arg = url.searchParams.get('style')) {
$type.val(arg)
}
if(arg = url.searchParams.get('lang')) {
$lang.val(arg)
}
// Prepare url according to control's values
function cook_url() {
var newUrl = url.origin + url.pathname
newUrl += '?'
var bib_url = new URL($bibx_in.val())
newUrl += (bib_url.origin.search('raw.githubusercontent.com') != -1 ?
'github_url=' + bib_url.pathname :
'url=' + bib_url.href);
newUrl += '&type=' + $type.val();
newUrl += '&styl=' + $styl.val();
newUrl += '&lang=' + $lang.val();
return newUrl;
}
var Cite = require('citation-js')
// Register custom styles
async function custom_register(git_repo, custom_dict, cite_reg_func){
for (var key in custom_dict) {
if(custom_dict.hasOwnProperty(key)) {
await $.get(git_repo + custom_dict[key], function (response) {
cite_reg_func(key, response);
console.log('Register ' + key)
});
}
}
}
cite_github = 'https://raw.githubusercontent.com/citation-style-language/'
Promise.all([custom_register(cite_github + 'styles/master/',
{'gost' : 'gost-r-7-0-5-2008.csl'},
Cite.CSL.register.addTemplate),
custom_register(cite_github + 'locales/master/',
{'ru-RU' : 'locales-ru-RU.xml'},
Cite.CSL.register.addLocale)])
.then(function() {
console.log('Create cite')
// Set variables
var cite = new Cite()
var opt = {
format: 'string'
}
// Make shorter ref to function
var parseAsync = Cite.parse.input.async.chain
// Make a factory for callback
var callbackFactory = function (out) {
return function (data) {
out.html(cite.set(data).get(opt))
}
}
$(function(){
// Callbacks
var bibxCb = callbackFactory($('#bibx-out'))
// Declare function to update the output
function update() {
// Get user options
opt.type = $type.val()
opt.style = $styl.val()
opt.lang = $lang.val()
if (history.pushState) {
window.history.pushState('<empty>', '<empty>', cook_url());
} else {
document.location.href = cook_url();
}
// Set data (explicit parsing only recommended for async) and set html element to get output
parseAsync($bibx_in).then(bibxCb)
}
// Make output update when input is defocussed...
$('.in').on('blur', update)
// ... or a select tag has changed
$('select').on('change', update)
// Trigger update
update()
})
})
</script>
</body>
</html>