User:Fredddie/script/CustomRefToolbar.js

/*

Many, many thanks to User:Mr.Z-man for his creation of the excellent RefToolbar gadget. I have only modified his work; I have not created a new gadget, as he did, from scratch. If you're using RefToolbar, this modification, or have modified it for your own use, you owe a great debt of gratitude to Mr.Z-man for all his hard work, which continues. Thank you, good sir!



/*

Change log: 2016-02-25 Update new parameter names. 2014-06-30 Add "agency" parameter to web template. 2014-06-10 Add UN doc template. 2014-06-04 Added cite interview template. Updated all labels for dialog boxes to include "(custom)". Tried to override default options, but "expandtemplates" still doesn't work. Turned off "modal" as a test; while it doesn't allow me to leave the form and edit the document, it does bypass graying out the entire screen; easier to see edit area. 2014-06-03 Added the code that parses the information; customized it to include a space before the pipe. 2014-06-02 Updated to include new incrementing features of RefToolbar; removed "coauthors" everywhere. 2014-05-25 Added autofill to DOI fields; added the deprecated "coauthors" field which is still being populated by autofill tools, along with a tooltip about not using it. Made all fields on patent template show; it's so short there's no reason not to show them all. 2014-05-25 Finalized modifications and wrote documentation.



// Custom RefToolbar $('head').one('reftoolbarbase', function { if (typeof CiteTB === 'undefined') return;

// Set default options CiteTB.Options = { "date format" : ", ", "autodate fields" : ['date', 'access-date', 'archive-date'], "months" : ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'], "modal" : false, "autoparse" : true, "expandtemplates" : true, };

// Set user options

CiteTB.UserOptions['date format'] = ", "; CiteTB.UserOptions['autodate fields'] = ['date', 'access-date', 'archive-date']; CiteTB.UserOptions['autoparse'] = true;

// Cite template definitions new citeTemplate('cite map', 'map',  [ // Basic fields      {"field": "first", "autofillprop":"first-incr", 'increment_group':'author'}, 	  {"field": "last", "autofillprop":"last-incr", 'increment_group':'author', 'increment_button':true},	  {"field": "title", "autofillprop":"title"},      {"field": "url"},      {"field": "date", "autofillprop":"year"},	  {"field": "publisher", "autofillprop":"publisher"},      {"field": "location", "autofillprop":"location"},	  {"field": "isbn", "autofillid":"isbn"},      {"field": "cartography",},      {"field": "edition", "autofillprop":"edition"},      {"field": "access-date", "autofillprop":"date"},      {"field": "ref", "tooltip":"cite-ref-tooltip"},

],  [ // Expanded fields {"field": "author", 'increment_group':'author_alt', 'increment_button':true}, {"field": "author-link", "tooltip":"cite-author-link-tooltip", 'increment_group':'authorlink', 'increment_button':true}, {"field": "archive-url"}, {"field": "archive-date", "autofillprop":"date"}, {"field": "dead-url"}, {"field": "page", "tooltip":"cite-page-tooltip"}, {"field": "pages", "autofillprop":"pages", "tooltip":"cite-pages-tooltip"}, {"field": "language"}, {"field": "trans-title"}, {"field": "format"}, {"field": "scale"}, {"field": "series"}, {"field": "section"}, {"field": "sections"}, {"field": "inset"}, {"field": "type"}, {"field": "via"},

]);

new citeTemplate('cite IowaDOT map', 'iowadotmap',  [ // Basic fields      {"field": "year", "autofillprop":"year"},      {"field": "month"},      {"field": "access-date", "autofillprop":"date"},      {"field": "link"},

],  [ // Expanded fields {"field": "inset"}, {"field": "scale"}, {"field": "section"}, {"field": "sections"}, {"field": "ref", "tooltip":"cite-ref-tooltip"}, ]);

// Cite template headings, field labels, and tooltips

mw.usability.addMessages( { 'cite-dialog-map' : 'Map citation (custom)', 'cite-dialog-iowadotmap' : 'IowaDOT map citation (custom)',

'cite-increment-alt' : 'Add another',	// Alt text for field increment button, not specific to a particular field

'cite-author-link-tooltip' : 'If the author has a Wikipedia article, the name of the article', 'cite-body-tooltip' : "A=General Assembly; S=Security Council; T=Secretariat; E=Economic and Social Council; H=Human Rights Campaign", 'cite-subject-link-tooltip' : 'If the subject has a Wikipedia article, the name of the article', 'cite-type-tooltip' : "A=Agenda item; D=Document; M=Meeting; R=Resolution; S=Summary Report; V=Verbatim Report", 'cite-others-tooltip' : "Use for translators, photographers, illustrators, etc. List last name followed by a comma and a space, then first name followed by their role in parentheses; if more than one, separate with semicolons",

'cite-access-date-label' : 'Access date', 'cite-archive-date-label' : 'Archive date', 'cite-archive-url-label' : 'Archive URL', 'cite-cartography-label' : 'Cartography by', 'cite-dead-url-label' : "Dead url?", 'cite-docid-label' : 'Doc ID', 'cite-document_number-label' : 'Document number', 'cite-edition-label' : 'Edition', 'cite-inset-label' : 'Inset', 'cite-map-label' : 'Map', 'cite-map-url-label' : 'Map URL', 'cite-number-label' : 'Number', 'cite-others-label' : 'Others', 'cite-pubdate-label' : 'Publication date', 'cite-scale-label' : 'Scale', 'cite-section-label' : 'Section', 'cite-sections-label' : 'Sections', 'cite-series-label' : 'Series', 'cite-status-label' : 'Status', 'cite-subject-link-label' : "Subject's article", 'cite-trans-title-label' : 'Translated title', 'cite-type-label' : 'Type', }); });

// REF FUNCTIONS - hoping to customize this to add a space before the pipe // Actually assemble a ref from user input if(typeof CiteTB !== 'undefined') { CiteTB.getRef = function(inneronly, forinsert) { var i; var template = CiteTB.getOpenTemplate; var templatename = template.templatename; var res = ''; var refobj = {'shorttag':false}; if (!inneronly) { var group = $('#cite-'+CiteTB.escStr(template.shortform)+'-group').val; var refname = $('#cite-'+CiteTB.escStr(template.shortform)+'-name').val; res += ''; } var content =''; res+=content; refobj.content = content; if (!inneronly) { res+= ' '; } if (forinsert) { CiteTB.mainRefList.push(refobj); } return res; }; }