User:Crazycomputers/citations.js

//

/* * All of the citation template data. * * UGLY! I should fetch an XML document and parse that. It could be maintained * separately and is a lot easier on the eyes. But this will work for now. */ var cit_data = [ ['Book', 'book', ['last', 'first', 'authorlink', 'coauthors', 'editor', 'others', 'title', 'origdate', 'origyear', 'origmonth', 'url', 'format', 'accessdate', 'accessyear', 'accessmonth', 'edition', 'series', 'date', 'year', 'month', 'publisher', 'location', 'language', 'isbn', 'oclc', 'doi', 'id', 'pages', 'chapter', 'chapterurl', 'quote']],

['Journal (lastname, firstname)', 'journal', ['quotes', 'last', 'first', 'authorlink', 'coauthors', 'date', 'year', 'month', 'title', 'journal', 'volume', 'issue', 'pages', 'issn', 'pmid', 'doi', 'id', 'url', 'language', 'format', 'accessdate', 'laysummary', 'laysource', 'laydate', 'quote']],

['Journal (firstname lastname)', 'journal', ['quotes', 'author', 'date', 'year', 'month', 'title', 'journal', 'volume', 'issue', 'pages', 'issn', 'pmid', 'doi', 'id', 'url', 'language', 'format', 'accessdate', 'laysummary', 'laysource', 'laydate', 'quote']],

['Conference report or paper', 'conference', ['first', 'last', 'authorlink', 'coauthors', 'date', 'year', 'month', 'title', 'conference', 'conferenceurl', 'booktitle', 'editor', 'others', 'volume', 'edition', 'publisher', 'location', 'pages', 'url', 'format', 'accessdate', 'doi', 'id']],

['Encyclopedia', 'encyclopedia', ['last', 'first', 'author', 'authorlink', 'coauthors', 'editor', 'encyclopedia', 'title', 'url', 'accessdate', 'accessyear', 'accessmonth', 'edition', 'date', 'year', 'month', 'publisher', 'volume', 'location', 'id', 'doi', 'pages', 'quote']],

['News article', 'news', ['first', 'last', 'authorlink', 'author', 'coauthors', 'title', 'url', 'format', 'work', 'publisher', 'id', 'pages', 'page', 'date', 'accessdate', 'language', 'quote']],

['Website', 'web', ['url', 'title', 'accessdate', 'accessdaymonth', 'accessmonthday', 'accessyear', 'author', 'last', 'first', 'authorlink', 'coauthors', 'date', 'year', 'month', 'format', 'work', 'publisher', 'pages', 'language', 'doi', 'archiveurl', 'archivedate', 'quote']],

['Newsgroup posting', 'newsgroup', ['title', 'author', 'date', 'newsgroup', 'id', 'url', 'accessdate']],

['Paper, thesis, or dissertation', 'paper', ['author', 'title', 'version', 'publisher', 'date', 'url', 'format', 'accessdate']],

['Press release', 'press release', ['title', 'publisher', 'date', 'url', 'format', 'language', 'accessdate', 'quote']],

['Video', 'video', ['people', 'year', 'date', 'title', 'url', 'format', 'medium', 'publisher', 'location', 'accessdate', 'accessmonth', 'accessyear', 'time', 'quote']],

['Television/radio episode', 'episode', ['title', 'episodelink', 'series', 'serieslink', 'credits', 'network', 'station', 'city', 'airdate', 'began', 'ended', 'season', 'number', 'minutes', 'transcript', 'transcripturl']],

['Court case', 'court', ['litigants', 'vol', 'reporter', 'opinion', 'pinpoint', 'court', 'date', 'url']],

['Map', 'map', ['publisher', 'title', 'url', 'edition', 'year', 'cartography', 'scale', 'series', 'page', 'section', 'accessdate', 'accessmonth', 'accessyear', 'isbn', 'id']],

['Mailing list', 'mailing list', ['url', 'title', 'accessdate', 'last', 'first', 'author', 'authorlink', 'date', 'mailinglist', 'archiveurl', 'archivedate', 'quote']] ];

// Ditto this. var cit_fields = [ ['General', [ ['title', 'Title'], ['episodelink', 'Episode Wikipedia article'], ['url', 'Link to source'], ['date', 'Date of publication'], ['month', 'OR: Month of publication'], ['year', 'AND: Year of publication'], ['origdate', 'Date of original publication'], ['origmonth', 'OR: Month of original publication'], ['origyear', 'AND: Year of original publication'], ['booktitle', 'Title of Proceedings'], ['chapter', 'Chapter title'], ['chapterurl', 'Link to specific chapter'], ['conference', 'Conference title'], ['conferenceurl', 'Conference website'], ['credits', 'Episode credits'], ['edition', 'Edition'], ['editor', 'Editor'], ['encyclopedia', 'Encyclopedia'], ['isbn', 'ISBN'], ['issue', 'Issue'], ['laysummary', 'Lay summary'], ['laydate', 'Date of lay summary publication'], ['laysource', 'Source of lay summary'], ['litigants', 'Litigants'], ['mailinglist', 'Mailing list'], ['medium', 'Medium'], ['minutes', 'Minute being cited'], ['newsgroup', 'Newsgroup'], ['season', 'Episode season'], ['number', 'Episode number'], ['oclc', 'OCLC ID'], ['opinion', 'Opinion number'], ['others', 'Others'], ['page', 'Page (one)'], ['pages', 'OR: Pages (multiple)'], ['people', 'People'], ['pinpoint', 'Pinpoint'], ['pmid', 'PubMed ID'], ['reporter', 'Reporter'], ['vol', 'Reporter volume'], ['scale', 'Map scale'], ['section', 'Map coordinates'], ['series', 'Series'], ['serieslink', 'Series Wikipedia article'], ['time', 'Time of cited scene'], ['version', 'Version'], ['volume', 'Volume'], ['work', 'Work'], ]],	['Publisher', [ ['publisher', 'Publisher'], ['journal', 'Journal'], ['issn', 'International Standard Serial Number'], ['location', 'Location'], ]],	['Date of access', [ ['accessdate', 'Access date'], ['accessdaymonth', 'Access date (day, month)'], ['accessmonthday', 'Access date (month, day)'], ['accessmonth', 'Access month'], ['accessyear', 'Access year'] ]],	['Archive copy', [ ['archiveurl', 'Archive URL'], ['archivedate', 'Date archived'] ]],	['Author', [ ['first', 'First name'], ['last', 'Last name'], ['author', 'Name'], ['authorlink', 'Wikipedia article'], ['coauthors', 'Co-authors'], ['cartography', 'Cartography preparation by'], ['court', 'Court'], ]],	['Broadcast information', [ ['station', 'Station'], ['city', 'Location of station (city)'], ['airdate', 'Date aired'], ['began', 'OR: Date began'], ['ended', 'AND: Date ended'], ['network', 'Network'], ['transcripturl', 'Transcript URL'], ['transcript', 'OR: Transcript (if no URL)'], ]],	['Miscellaneous', [ ['doi', 'Digital object identifier'], ['format', 'Data format'], ['id', 'Unique ID'], ['language', 'Language'], ['quote', 'Relevant quote'], ['quotes', 'Quotes around title?'], ]], ];

var cit_installed; var cit_popupDiv; var cit_dropdown; var cit_region;

var cit_type; var cit_entries; var cit_output;

function cit_install { if (cit_installed) { return; }	var toolbar = document.getElementById('toolbar'); if (!toolbar) { return; }	var img = document.createElement('img'); img.id = 'mw-editbutton-cit-cite'; img.className = 'mw-toolbar-editbutton'; img.width = 23; img.height = 22; img.border = 0; img.src = '/skins-1.5/common/images/button_bold.png'; img.alt = 'Cite a source'; img.title = 'Cite a source'; img.style.cursor = 'pointer'; img.onclick = cit_toggleDiv; toolbar.appendChild(img); var div = cit_popupDiv = document.createElement('div'); div.className = "messagebox"; div.style.backgroundColor = '#e6ffe6'; div.style.border = '1px solid #008000'; div.style.display = 'none'; var e = document.createElement('h2'); e.appendChild(document.createTextNode('Citation editor')); div.appendChild(e); e = cit_dropdown = document.createElement('select'); for (var i = 0; i < cit_data.length; i++) { var type = cit_data[i]; var opt = document.createElement('option'); opt.appendChild(document.createTextNode(type[0])); e.appendChild(opt); }	e.selectedIndex = -1; e.onchange = cit_typeSelected; div.appendChild(e); div.appendChild(cit_region = document.createElement('div')); toolbar.parentNode.insertBefore(div, toolbar.nextSibling); cit_installed = true; }

$(cit_install);

function cit_toggleDiv { cit_popupDiv.style.display = cit_popupDiv.style.display ? '' : 'none'; return false; }

function cit_typeSelected { var r = cit_region; while (r.firstChild) { r.removeChild(r.firstChild); }	if (cit_dropdown.selectedIndex == -1) { return; }	var type = cit_type = cit_data[cit_dropdown.selectedIndex]; cit_entries = []; var fs = type[2]; var filter = []; for (var i = 0; i < fs.length; i++) { filter[fs[i]] = 1; }	var table = document.createElement('table'); table.style.border = 'none'; table.style.backgroundColor = 'inherit'; var tbody = document.createElement('tbody'); table.appendChild(tbody); for (var i = 0; i < cit_fields.length; i++) { var group = cit_fields[i]; var group_fields = group[1]; var header = false; for (var j = 0; j < group_fields.length; j++) { if (filter[group_fields[j][0]]) { var tr; var td; if (!header) { tr = document.createElement('tr'); td = document.createElement('td'); tr.appendChild(td); td.colSpan = 2; var h = document.createElement('h3'); h.appendChild(document.createTextNode(group[0])); td.appendChild(h); tbody.appendChild(tr); header = true; }				tr = document.createElement('tr'); td = document.createElement('td'); tr.appendChild(td); td.style.textAlign = 'right'; td.appendChild(document.createTextNode(group_fields[j][1] + ':')); td = document.createElement('td'); tr.appendChild(td); var entry = document.createElement('input'); entry.name = entry.id = 'cit-entry-' + group_fields[j][0]; entry.size = 100; entry.cit_field = group_fields[j][0]; cit_entries.push(entry); td.appendChild(entry); tbody.appendChild(tr); }		}	}	var tr = document.createElement('tr'); var td = document.createElement('td'); tr.appendChild(td); td.colSpan = 2; var gen = document.createElement('button'); td.appendChild(gen); gen.appendChild(document.createTextNode('Generate citation')); gen.onclick = cit_generate; tbody.appendChild(tr); tr = document.createElement('tr'); td = document.createElement('td'); tr.appendChild(td); td.colSpan = 2; var out = cit_output = document.createElement('textarea'); out.rows = 4; out.cols = 100; td.appendChild(out); tbody.appendChild(tr); r.appendChild(table); }

function cit_generate { var t = ""; cit_output.value = t; }

//