MediaWiki:RefToolbar.js: Versiyalar orasidagi farq

Kontent oʻchirildi Kontent qoʻshildi
Maintenance: mw:RL/MGU / mw:RL/JD - phab:T169385 - deprecated in jQuery 3.0
Tahrir izohi yoʻq
Qator 1:
/*jshint smarttabs:true, loopfunc:true,forin:false*/
/*global mw, $, importScript */
// ____________________________________________________________________________________________
// | |
// | refToolbar.js gadjetining 632049119 versiyasiga asoslangan |
// | (https://en.wikipedia.org/w/index.php?title=MediaWiki:RefToolbar.js&oldid=795320777) |
// |____________________________________________________________________________________________|
// TODO: make autodate an option in the CiteTemplate object, not a preference
 
Qator 265 ⟶ 270:
$(document).ready( function() {
switch( mw.config.get('wgUserLanguage') ) {
case 'deen': // German
importScript('MediaWiki:RefToolbarMessages-de.js');
break;
default: // English
importScript('MediaWiki:RefToolbarMessages-en.js');
break;
default:
importScript('MediaWiki:RefToolbarMessages-ru.js');
}
});
Qator 438 ⟶ 443:
// Function to get the page text
CiteTB.getPageText = function(callback) {
var section = $("input[name='wpSection']").val();
if ( section !== '' ) {
var postdata = {action:'query', prop:'revisions', rvprop:'content', pageids:mw.config.get('wgArticleId'), format:'json'};
if (CiteTB.getOption('expandtemplates')) {
postdata.rvexpandtemplates = '1';
}
$.get( mw.util.wikiScript( 'api' ),
postdata,
function(data) {
var pagetext = data.query.pages[mw.config.get('wgArticleId').toString()].revisions[0]['*'];
callback(pagetext);
},
'json'
);
} else {
if (CiteTB.getOption('expandtemplates')) {
CiteTB.expandtemplates($('#wpTextbox1').wikiEditor('getContents').text(), callback);
Qator 458 ⟶ 448:
callback($('#wpTextbox1').wikiEditor('getContents').text());
}
}
};
 
// Autofill a template from an ID (ISBN, DOI, PMID, URL)
CiteTB.initAutofill = function() {
var elemid = $(this).attr('id');
Qator 488 ⟶ 477:
var i,j, coauthors;
$('.'+cl+'title').val(data.title);
// Fill in authors
if ($('.'+cl+'last-incr-1').length != 0) {
if (data.authors && data.authors.length > 0) {
var classes = $('.'+cl+'last-incr-1').eq(0).attr('class').split(/\s+/);
if ($('.'+cl+'last-incr-1').length != 0) {
var group = false;
var pattclasses = /cite-[^-]*?$('.'+cl+'last-incr-1').eq(0).*attr('class').split(/\s+/);
var group = false;
for (var c=0; c<classes.length; c++) {
ifvar (patt.exec(classes = /cite-[c^-]*?-incr-(.*)) {/
groupfor (var c=0; patt.exec(c<classes[.length; c]++)[1]; {
if (patt.exec(classes[c])) {
break;
group = patt.exec(classes[c])[1];
}
break;
}
}
$('.'+cl+'last-incr-1').val(data.authors[0][0])
}
$('.'+cl+'first-incr-1').val(data.authors[0][1])
$('.'+cl+'last-incr-1').val(data.authors[0][0])
elemid = '#cite-incr-'+template+'-'+group;
for $('.'+cl+'first-incr-1').val(var i=2; i<data.authors.length+[0][1; i++]) {
elemid = '#cite-incr-'+template+'-'+group;
$(elemid).click();
$for ('.'+cl+'last-incr-'+var i=2; i.toString()).val(<data.authors[.length+1; i-1][0]++) {
$(elemid).click();
$('.'+cl+'firstlast-incr-'+i.toString()).val(data.authors[i-1][10])
$('.'+cl+'first-incr-'+i.toString()).val(data.authors[i-1][1])
}
}
} else if ($('.'+cl+'author-incr-1').length != 0) {
var classes =} else if ($('.'+cl+'author-incr-1').eq(length != 0).attr('class').split(/\s+/); {
var classes = $('.'+cl+'author-incr-1').eq(0).attr('class').split(/\s+/);
var group = false;
var group = false;
var patt = /cite-[^-]*?-incr-(.*)/
for (var c=0; c<classes.length; c++) {
if (patt.exec(classes[c])) {
group = patt.exec(classes[c])[1];
break;
}
}
$('.'+cl+'author-incr-1').val(data.authors[0].join(', '))
elemid = '#cite-incr-'+template+'-'+group;
for (var i=2; i<data.authors.length+1; i++) {
$(elemid).click();
$('.'+cl+'author-incr-'+i.toString()).val(data.authors[i-1].join(', '))
}
} else if ($('.'+cl+'last1').length != 0) {
for(i=0; data.authors && i<data.authors.length; i++) {
if ($('.'+cl+'last'+(i+1)).length) {
$('.'+cl+'last'+(i+1)).val(data.authors[i][0]);
$('.'+cl+'first'+(i+1)).val(data.authors[i][1]);
} else {
coauthors = [];
for(j=i; j<data.authors.length; j++) {
coauthors.push(data.authors[j].join(', '));
}
$('.'+cl+'coauthors').val(coauthors.join('; '));
break;
}
}
} else if($('.'+cl+'author1').length !== 0) {
for(i=0; data.authors && i<data.authors.length; i++) {
if ($('.'+cl+'author'+(i+1)).length) {
$('.'+cl+'author'+(i+1)).val(data.authors[i].join(', '));
} else {
coauthors = [];
for(j=i; j<data.authors.length; j++) {
coauthors.push(data.authors[j].join(', '));
}
$('.'+cl+'coauthors').val(coauthors.join('; '));
break;
}
}
$('.'+cl+'coauthors').val(coauthors.join('; '));
break;
}
}
} else if($('.'+cl+'author1').length !== 0) {
for(i=0; data.authors && i<data.authors.length; i++) {
if ($('.'+cl+'author'+(i+1)).length) {
$('.'+cl+'author'+(i+1)).val(data.authors[i].join(', '));
} else {
var coauthorsauthors = [];
for(j=i=0; jdata.authors && i<data.authors.length; ji++) {
coauthorsauthors.push(data.authors[ji].join(', '));
}
$('.'+cl+'coauthorsauthors').val(coauthorsauthors.join('; '));
break;
}
}
} else {
var authors = [];
for(i=0; data.authors && i<data.authors.length; i++) {
authors.push(data.authors[i].join(', '));
}
$('.'+cl+'authors').val(authors.join('; '));
}
 
if (type === 'pmid' || type === 'doi') {
if (data.date && (data.fulldate || !$('.'+cl+'month').length)) {
var DT = new Date(data.date);
var useday = /\d{4}-\d{2}-\d{2}/.test(data.date);
Qator 574 ⟶ 567:
$('.'+cl+'issue').val(data.issue);
$('.'+cl+'pages').val(data.pages);
if (type === 'pmid' && data.doi) {
$('.'+cl+'doi').val(data.doi);
}
} else if (type === 'isbn') {
$('.'+cl+'publisher').val(data.publisher);
Qator 579 ⟶ 575:
$('.'+cl+'year').val(data.year);
$('.'+cl+'edition').val(data.edition);
} else if (type === 'url') {
if (data.date) {
var DT = new Date(data.date);
var useday = /\d{4}-\d{2}-\d{2}/.test(data.date) && template !== 'book';
var usemonth = /\d{4}-\d{2}/.test(data.date) && template !== 'book';
var yearOrDate = (template === 'book') ? 'year' : 'date';
$('.'+cl+yearOrDate).val(CiteTB.formatDate(DT, useday, usemonth));
}
$('.'+cl+'journal').val(data.journal);
$('.'+cl+'volume').val(data.volume);
$('.'+cl+'issue').val(data.issue);
$('.'+cl+'pages').val(data.pages);
$('.'+cl+'publisher').val(data.publisher);
$('.'+cl+'edition').val(data.edition);
$('.'+cl+'isbn').val(data.isbn);
$('.'+cl+'issn').val(data.issn);
$('.'+cl+'doi').val(data.doi);
// "en-US" isn't a valid value for the language parameter
if (data.language && data.language !== 'ru-RU' ) {
$('.'+cl+'language').val(data.language);
}
$('.'+cl+'chapter').val(data.chapter);
}
};
Qator 807 ⟶ 825:
// Returns a string quoted as necessary for name/group attributes
CiteTB.getQuotedString = function(s) {
var sp = /\s/.test(s); // spaces
var sq = /\'/.test(s); // single quotes
var dq = /\"/.test(s); // double quotes
if (!sp && !sq && !dq) { // NoAlways quotes necessaryfor non-latin alphabet
return '"'+s+'"';
} else if (!dq) { // Can use double quotes
return '"'+s+'"';
Qator 817 ⟶ 834:
return "'"+s+"'";
} else { // Has double and single quotes
s = s.replace(/\"/g, '\"'');
return '"'+s+'"';
}