-
Notifications
You must be signed in to change notification settings - Fork 3
/
Autoref.js
39 lines (32 loc) · 1.29 KB
/
Autoref.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
/*** Autoref ***/
// Insert auto-filled references in the 2010 Wikitext editor like you can in VE
// Documentation at [[en:w:User:BrandonXLF/Autoref]]
// By [[en:w:User:BrandonXLF]]
/* global getCitoidRef */
$.when(mw.loader.using('ext.wikiEditor'), mw.loader.getScript(
'https://en.wikipedia.org/w/index.php?title=User:BrandonXLF/Citoid.js&action=raw&ctype=text/javascript'
), $.ready).then(function() {
$('#wikiEditor-section-main [rel="reference"] > a').unbind().click(function() {
var pos = {
start: $('#wpTextbox1').textSelection('getCaretPosition'),
end: $('#wpTextbox1').textSelection('getCaretPosition') + $('#wpTextbox1').textSelection('getSelection').length
};
OO.ui.prompt($('<span>Enter a <abbr title="URL, DOI, ISBN, PMID, PMCID, or QID">source</abbr>:</span>'), {
textInput: {
placeholder: 'Leave blank for none'
}
}).done(function(source) {
$('#wpTextbox1').textSelection('setSelection', pos);
if (source === null) return;
if (source === '') {
$('#wpTextbox1').textSelection('encapsulateSelection', {pre: '<ref>', post: '</ref>'});
return;
}
getCitoidRef(source).then(function(ref) {
$('#wpTextbox1').textSelection('replaceSelection', '<ref>' + ref + '</ref>');
}, function(err) {
mw.notify(err, {type: 'error'});
});
});
});
});