Content deleted Content added
Copy button |
Compact & Copy button, etc.; not decoding the url |
||
Line 1:
// v.
window.webRef = window.webRef || {}; // object used to communicate with webRefSetup
window.webRef.getRef = (function () {
Line 38:
work: 'work',
date: 'date',
accessDate: '
url: 'url',
publisher: 'publisher',
Line 46:
last: 'last',
first: 'first',
coauthors: 'coauthors', // not
authorWikiArticle: 'authorlink',
dateFormat: '%D% %MMM% %YYYY%', // %M% -> Feb is 2; %MM% -> Feb is 02; %MMM% -> Feb is monthNumToName[1]
altDateFormat: '%MMM% %D%, %YYYY%', // %D% or %DD%, %M% or %MM% or %MMM%, %YY% or %YYYY%.
dateFormatRetrieved: '
barV: '| ', // bar and spaces around it (but no newlines) for Vertical format
barVsameLine: ' | ', // (e.g. first name is on the same line as last name even in vertical mode)
barH: ' |', // ... for Horizontal format
eqV: ' = ', // equal sign and spaces around it (but no newline) for Vertical format
eqH: '=', // ... for Horizontal format
urlEqH: '= ' // a space before the URL helps with line wrapping
};
var barV = tp.barV, barH = tp.barH, eqV = tp.eqV, eqH = tp.eqH;
var altDateFormatIsUSFormat = true; // LOCALIZE. True in the case of the English Wikipedia
Line 64 ⟶ 72:
setupButton: 'Site setup',
hideButton: 'Close',
copyButton: 'Copy',
compactCopyButton: 'Compact & Copy',
compactSelectButton : 'Compact & Select',
copyFailed: ' Copying failed!',
reloadButton: 'Reload',
formatNamesPromptButton: 'Authors',
formatNamesPrompt: 'Enter the author names (separated by commas) to be formatted and inserted into the template:',
singleMultiLineButton: '
formatDatePromptButton: 'Date formatter',
formatDatePrompt: 'Enter the date to be formatted and inserted into the template:',
Line 384 ⟶ 394:
function formatDateParams(format, useUSFormatIfUnclear) {
▲ var t = templateParams;
var trimCollapse = aux.collapseWhitespace;
var strt = '\\|\\s*';
var end = '\\s*=\\s*([^|}]
var oldVal = codeTextArea.value;
var val;
val = formatDateParam(oldVal, format,
if (val === null) return; // user pressed Cancel
if (
val = formatDateParam(val, format,
if (val != oldVal) {
codeTextArea.value = val;
Line 406 ⟶ 416:
if (dateInTemplate || noPrompt)
userDate = dateInTemplate;
else {
if (promptResponse === null) // user pressed Cancel
return null;
userDate = trimCollapse(promptResponse);
}▼
if (userDate) {
Line 413 ⟶ 427:
formatted = dateFormatter(userDate, format, useUSFormatIfUnclear);
if (formatted) {
var
if (pos < 0) pos = templStr.indexOf('|');
templStr = templStr.replace(dateParamRe, '');
if (monthWarningNeeded)
addWarning(msgs.monthWarning, msgs.monthWarningTitle);
Line 431 ⟶ 446:
function formatNamesPrompt() {
var val = codeTextArea.value;
var names = '';
var authorParamNames = [
for (var n = 1; n <= 9; n++) {
authorParamNames.push(
authorParamNames.push(
}
var strt = '\\|\\s*';
var end = '\\s*=\\s*([^|}]+)';
names = (val.match(strt +
for (var n = 0; n <= 9; n++)
names += (val.match(strt +
.replace(/ /g, '_') + ','; if (
names += (val.match(strt +
names = names.replace(/\s+/g, ' ').replace(/\s?,\s?/g, ',')
.replace(/,,+/g, ',').replace(/^,|,$/g, '').replace(/,/g, ', ');
Line 454 ⟶ 468:
var namesNewParams = authorParams(nameFormatter(userAuthors));
if (namesNewParams) {
var
if (
for (var n = 0; n < authorParamNames.length; n++)
val = val.replace(new RegExp(strt + authorParamNames[n] + end), '');
val = val.slice(0, pos) + namesNewParams + val.slice(pos);
codeTextArea.value = val;
Line 489 ⟶ 502:
function authorParams(
var str = '';
var nl = '\n
if (!authorsArr && siteObj.authorName) {
if (siteObj.authorWikiArticle)
str += nl +
}
else if ((
if (additionalNotAnAuthor) { // to remove e.g. "CNN" from "James Smith, CNN"
var i = authorsArr.length;
if (authorsArr[i][0] === additionalNotAnAuthor && !authorsArr[i][1])
if ( authorsArr.length == 1 && !authorsArr[0][1] ) // only 1 author without a first name
str = nl + t.last + ' = ' + last1;▼
str
else { // use the 'last' and 'first' params
var num = (i > 0 || authorsArr.length > 1 ? String(i + 1) : ''); // omit number if only 1 author
str += tp.barVsameLine + tp.first + num + eqV + authorsArr[i][1];
}▼
}
else▼
▲ for (var i = 1; i < authors.length; i++) {
▲ if (authors[i][0]) {
▲ if (authors[i][1])
▲ }
▲ }
▲ if (i > 1)
▲ }
▲ }
▲ else if (co) {
}
return str;
Line 547 ⟶ 540:
var val = aux.trimStr(codeTextArea.value);
var nowMulti = (val.indexOf('\n') > -1) && !toMulti;
if ( toMulti === false || (!toMulti && nowMulti) ) {
val = val.replace(/\n/g, ' ')
.replace(/\s*\|\s*([^|= ]+)\s*=\s*/g, barH + '$1' + eqH)
// a space after |url= helps with line wrapping :
val = val.replace(/\s*\|\s*([^|= ]+)\s*=\s*/g, '\n' + barV + '$1' + eqV ).replace(/\s*}}/, '\n}}')
.replace( // move the "last" and "first" parameters on one line
new RegExp('(\\|\\s*' +
'$1 $2'
);
Line 589 ⟶ 584:
var buttons = [
{
id: copyButtonSupported ? '
onclick: function () {
var
val = val.replace(new RegExp('\\s*\\|\\s*' + tp.quote + '\\s*=\\s*(\\||})'), '$1') // rm empty quote
ta.focus();▼
.replace(new RegExp('\\s*\\|\\s*' + tp.lang + '\\s*=\\s*(\\||})'), '$1') // rm empty lang
ta.select();▼
.replace(/\s+}}\s*$/, '}}'); // remove spaces before and after final }}
codeTextArea.value = val;
singleMultiLine(false);
if (copyButtonSupported) {
var copyFailed = !refFrame.doc.queryCommandEnabled('copy');
Line 612:
},
{
id: (
onclick: function () {
formatDateParams(
}
},
Line 811:
function dateToString(day, month, year, format) { // month is 0..11
day = +day; month = +month; year = +year;
return ((format ||
.replace(/%DD%/, (day > 9 ? '' : '0') + day)
.replace(/%D%/, day)
Line 828:
today.getMonth(),
today.getFullYear(),
(
);
}
Line 910:
function go() {
var title, date, lang, langParam, quote, selection, work, publisher;
Line 945 ⟶ 944:
}
if (!lang || lang != langToIgnore) // add the param only if lang is not langToIgnore
langParam =
quote =
selection = getSelectedText();
if (selection) {
Line 962 ⟶ 961:
codeTextArea.value = '<ref name="' + makeRefName(title) + '">{{'
+
+ '\n
+ (!lang || lang == langToIgnore ? '' : '\n
+ authorParams(null, work)
+ '\n
+ '\n
+ '\n
+ '\n
+ (publisher ?
+ langParam
+ quote
|