Content deleted Content added
Compact & Copy button, etc.; not decoding the url |
YMD date button; removing <ref name="..." |
||
Line 1:
// v.
window.webRef = window.webRef || {}; // object used to communicate with webRefSetup
window.webRef.getRef = (function () {
Line 31:
// these words are used when spliting names in the case of multipe article authors
var andWords = ['and']; // LOCALIZE by adding the word(s) for "and" in the local lang
var dateFormatMDY = '%MMM% %D%, %YYYY%';
var dateFormatDMY = '%D% %MMM% %YYYY%';
var dateFormatYMD = '%YYYY%-%MM%-%DD%';
var dateFormatDefault = dateFormatDMY;
var templateParams = { // LOCALIZE
Line 48 ⟶ 56:
coauthors: 'coauthors', // not used
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: '', //Leave empty to use default format (dateFormat or altDateFormat)
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)
Line 56 ⟶ 61:
eqV: ' = ', // equal sign and spaces around it (but no newline) for Vertical format
eqH: '=', // ... for Horizontal format
};
var barV = tp.barV, barH = tp.barH, eqV = tp.eqV, eqH = tp.eqH;
var msgs = webRef.idToText = webRef.msgs = webRef.msgs || webRef.idToText || {};
Line 75 ⟶ 78:
copyButton: 'Copy',
compactCopyButton: 'Compact & Copy',
copyFailed: ' Copying failed!',
reloadButton: 'Reload',
formatNamesPromptButton: 'Authors',
formatNamesPrompt: 'Enter the author names (separated by commas if more than one author) to be formatted and inserted into the template:',
dmy: 'DMY',
mdy: 'MDY',
ymd: 'YMD',
refName: 'RefName',
singleMultiLineButton: 'Horiz./Vertical',
couldntParse: 'Sorry, I couldn\'t parse that.',
Line 154 ⟶ 158:
var siteLang; // used for date formatting if equals en-US and month is represented as a number
var monthWarningNeeded; // set in dateFormatter if not clear if date is in U.S. format or not
var siteDateIsUS = false;
var refDocData = window.webRef.refDocData = {
Line 326 ⟶ 331:
var monthStr = '';
var month;
format = format || dateFormatDefault;
for (var m in monthNameToNum) {
Line 398 ⟶ 404:
var end = '\\s*=\\s*([^|}]*)';
var oldVal = codeTextArea.value;
var val = formatDateParam(oldVal, format, tp.date);▼
var val;▼
▲ val = formatDateParam(oldVal, format, tp.date);
▲ if (tp.accessDate && tp.dateFormatRetrieved == '')
▲ val = formatDateParam(val, format, tp.accessDate, true);
if (val != oldVal) {
codeTextArea.value = val;
Line 409 ⟶ 413:
}
function formatDateParam(templStr, format, paramName
var dateParamRe = new RegExp(strt + paramName + end);
var dateInTemplate = trimCollapse((templStr.match(dateParamRe) || ['', ''])[1]);
if (dateInTemplate)
else {▼
}▼
if (userDate) {▼
monthWarningNeeded = false;
if (
var pos = templStr.search(dateParamRe);
if (pos < 0) pos = templStr.indexOf('|');
if (pos < 0) pos = 0;
templStr = templStr.replace(dateParamRe, '');
templStr = templStr.slice(0, pos) + '\n'
+ barV + paramName + eqV + if (monthWarningNeeded)
addWarning(msgs.monthWarning, msgs.monthWarningTitle);
}
else
alert(msgs.programName + ':\n' + msgs.couldntParse + '\n' +
}
return templStr;
Line 521 ⟶ 516:
str = nl + tp.author + eqV + authorsArr[0][0]; // use the 'author' param
else { // use the 'last' and 'first' params
}
}
Line 608 ⟶ 603:
},
{
id: '
onclick: function () { formatDateParams(dateFormatDMY); }
},
{
id: 'mdy',
onclick: function () { formatDateParams(dateFormatMDY); }
▲ },
id: 'ymd',
onclick: function () { formatDateParams(dateFormatYMD); }
},▼
id: 'refName',
onclick: function () {
var val, oldVal = codeTextArea.value;
val = oldVal.replace(/^<ref name="[^"]*"/, '<ref');
if (val == oldVal)
val = val.replace(/^<ref/, '<ref name=""');
codeTextArea.value = val;
}
},
Line 653 ⟶ 660:
br();
for (var i = 0; i < buttons.length; i++) {
docFrag.appendChild(dom.newEl('button', {▼
continue;
text: msgs[buttons[i].id],▼
onclick: buttons[i].onclick▼
}));▼
dom.text(' ', docFrag);▼
▲ }
▲ }
}
dom.text('| ', docFrag);
docFrag.appendChild(dom.newEl('a', {
Line 811 ⟶ 821:
function dateToString(day, month, year, format) { // month is 0..11
day = +day; month = +month; year = +year;
return
.replace(/%DD%/, (day > 9 ? '' : '0') + day)
.replace(/%D%/, day)
Line 818 ⟶ 828:
.replace(/%M%/, (month + 1))
.replace(/%YYYY%/, year)
.replace(/%YY%/, year % 100
}
Line 828 ⟶ 838:
today.getMonth(),
today.getFullYear(),
(
);
}
Line 844 ⟶ 854:
}
return siteName;
}
Line 928 ⟶ 933:
title = cleanParam(searchFor('title'));
monthWarningNeeded = false;
date = searchFor('date');
Line 960 ⟶ 966:
publisher = siteObj.publisher || '';
codeTextArea.value = '<ref
+ tp.templateName
+ '\n' + barV + tp.title + eqV + title
|