User:V111P/js/webRef.js: Difference between revisions

Content deleted Content added
page title can change
MM/DD/YYYY date support for U.S. date button and sites with language set to en-US ; trans-title param if lang is not en
Line 1:
// v. 20142015-0503-1706; en.wikipedia.org/wiki/User:V111P/js/WebRef
window.webRef = window.webRef || {}; // object used to communicate with webRefSetup
window.webRef.getRef = (function () {
Line 35:
templateName: 'Cite web',
title: 'title',
transTitle: 'trans-title', // the title translated to English
work: 'work',
date: 'date',
Line 52 ⟶ 53:
dateFormatRetrieved: '%YYYY%-%MM%-%DD%' // %D% or %DD%, %M% or %MM% or %MMM%, %YY% or %YYYY%
};
var altDateFormatIsUSFormat = true; // LOCALIZE. True in the case of the English Wikipedia
 
 
var msgs = webRef.idToText = webRef.msgs = webRef.msgs || webRef.idToText || {};
var msgs_default = { // LOCALIZE
programName: 'WebRef',
monthWarning: 'Check month!',
monthWarningTitle: 'Was the date in the MM/DD/YY(YY) or DD/MM/YY(YY) format?',
quoteUsedWarning: 'Quotation!',
quoteUsedWarningTitle: 'The selected text on the page was used for the value of the "quote"Quote parameter.',
setupButton: 'Site setup',
hideButton: 'Close',
Line 83 ⟶ 86:
 
aboutSiteH: 'About the site',
aboutSiteSectionIntro: 'You can fill this information, but data that is automatically filled doesn\'t need saving in the configuration. Using en as the language code for sites in English will hide the language parameter in the Cite web template. Use en-US if the date is in the MM/DD/YY(YY) format, with the month number instead of its name used in the date.',
siteName_L: 'Site name (can be a wikilink):',
lang_L: 'Language code for the site:',
Line 137 ⟶ 140:
 
var codeTextArea;
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 refDocData = window.webRef.refDocData = {
Line 306 ⟶ 310:
 
 
function dateFormatter(dateStr, format, dontCheckUSuseUSFormatIfUnclear) { // format is optional
var formattedDate = '';
var monthStr = '';
Line 349 ⟶ 353:
else if (year < 100)
year = '19' + year; // 1900+ otherwise :)
 
if ((!dontCheckUS && langsiteLang == 'en-US') || dateParts[2] > 12) { // American style date
var lang = metaContent ? metaContent['misc html-lang'] : '';
if ((!dontCheckUS && lang == 'en-US') || dateParts[2] > 12) { // American style date
month = dateParts[1];
day = dateParts[2];
}
else {
if (!siteLang || siteLang == 'en')
day = dateParts[1];
month monthWarningNeeded = dateParts[2]true;
if (useUSFormatIfUnclear) {
month = dateParts[1];
day = dateParts[2];
}
else {
day = dateParts[1];
month = dateParts[2];
}
}
day = ('0' + day).slice(-2);
Line 370 ⟶ 381:
 
 
function formatDateParams(format, useUSFormatIfUnclear) {
var t = templateParams;
var trimCollapse = aux.collapseWhitespace;
Line 397 ⟶ 408:
 
if (userDate) {
monthWarningNeeded = false;
formatted = dateFormatter(userDate, format, trueuseUSFormatIfUnclear);
if (formatted) {
var dateParamPos = templStr.indexOf('| ' + paramName + ' =') - 1;
Line 403 ⟶ 415:
var pos = (dateParamPos > 0 ? dateParamPos : templStr.indexOf('|') - 1);
templStr = templStr.slice(0, pos) + '\n| ' + paramName + ' = ' + formatted + templStr.slice(pos);
if (monthWarningNeeded)
addWarning(msgs.monthWarning, msgs.monthWarningTitle);
}
else
Line 585 ⟶ 599:
id: (templateParams.altDateFormat ? 'altDateFormatButton' : ''),
onclick: function () {
formatDateParams(templateParams.altDateFormat, altDateFormatIsUSFormat);
}
},
Line 646 ⟶ 660:
css: {display: 'none'}
}));
docFrag.appendChild(dom.newEl('span', {id: 'warnings'}));
id: 'warnings',
css: {backgroundColor: 'green'}
}));
 
refFrame.frame = dom.byId('ref00ref');
Line 859 ⟶ 870:
return text;
}
 
 
function addWarning(label, title) {
var warnSpan = dom.byId('warnings', refFrame.doc);
var warnSepar = dom.byId('warningsSeparator', refFrame.doc).style.display = 'none';
warnSepar.style.display = 'inline';
warnSpan.appendChild(dom.textNode(' '));
warnSpan.appendChild(dom.newEl('span', {
text: label,
title: title,
css: {backgroundColor: 'green'}
}));
}
 
 
function clearWarnings() {
var warnSpan = dom.byId('warnings', refFrame.doc);
var warnSepar = dom.byId('warningsSeparator', refFrame.doc).style.display = 'inline';
warnSpan.innerHTML = '';
warnSepar.style.display = 'none';
}
 
 
 
function go() {
var t = templateParams;
var title, date, lang, langParam, quote, selection, work, publisher;
 
metaContent = window.webRef.metaContent = getMetaContent();
Line 875 ⟶ 908:
return sO || {};
})();
langsiteLang = siteObj.lang || '';
 
clearWarnings();
id:var 'warnings', = [];
 
title = cleanParam(searchFor('title'));
monthWarningNeeded = false;
date = searchFor('date');
if (monthWarningNeeded) { // set in dateFormatter() if not clear whether the date is MM/DD/YYYY or DD/MM/YYYY
warnings.push([msgs.monthWarning, msgs.monthWarningTitle]);
}
 
langParam = '';
if (siteLang.search(/^en-US/i) == 0) siteLang = 'en-US';
lang = siteObj.lang;
lang = (siteLang == 'en-US' ? 'en' : siteLang);
if (!lang) {
lang = autoSearchFor('lang') || '';
Line 891 ⟶ 934:
quote = '| ' + t.quote + ' = ';
selection = getSelectedText();
var warnSpan = dom.byId('warnings', refFrame.doc);
if (selection) {
quote += cleanParam(selection);
warnSpanwarnings.title =push([msgs.quoteUsedWarning, msgs.quoteUsedWarningTitle]);
dom.byId('warningsSeparator', refFrame.doc).style.display = 'inline';
warnSpan.innerHTML = msgs.quoteUsedWarning;
warnSpan.title = msgs.quoteUsedWarningTitle;
}
 
else {
for (var i = 0; i < warnings.length; i++) {
dom.byId('warningsSeparator', refFrame.doc).style.display = 'none';
addWarning(warnings[i][0], warnings[i][1]);
warnSpan.innerHTML = '';
}
 
Line 909 ⟶ 949:
+ t.templateName
+ '\n| ' + t.title + ' = ' + title
+ (!lang || lang == langToIgnore ? '' : '\n| ' + t.transTitle + ' = ') // translated title
+ authorParams()
+ '\n| ' + t.work + ' = ' + work
+ '\n| ' + t.date + ' = ' + searchFor('date')
+ '\n| ' + t.accessDate + ' = ' + getTodaysDateStr()
+ '\n| ' + t.url + ' = ' + decodeURI(___location.href) + '\n'