User:D'Ranged 1/Sandbox 1

/*

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 {

// 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 book', 'book2',  [ // Basic fields      {"field": "title", "autofillprop":"title"},      {"field": "date", "autofillprop":"year"},	  {"field": "first", "autofillprop":"first-incr", 'increment_group':'author'}, 	  {"field": "last", "autofillprop":"last-incr", 'increment_group':'author', 'increment_button':true},	  {"field": "author-link", "tooltip":"cite-author-link-tooltip", 'increment_group':'authorlink', 'increment_button':true},      {"field": "author", 'increment_group':'author_alt', 'increment_button':true},      {"field": "isbn", "autofillid":"isbn"},      {"field": "access-date", "autofillprop":"date"},      {"field": "url"},      {"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": "publisher", "autofillprop":"publisher"}, {"field": "location", "autofillprop":"location"}, {"field": "edition", "autofillprop":"edition"}, {"field": "type"}, {"field": "quote"}, {"field": "asin"}, ],  [ // Expanded fields {"field": "editor-first", "increment_group":"editor"}, {"field": "editor-last", "increment_group":"editor", "increment_button":true}, {"field": "editor-link", "tooltip":"cite-editor-link-tooltip", 'increment_group':'editorlink', 'increment_button':true}, {"field": "others", "tooltip":"cite-others-tooltip"}, {"field": "format"}, {"field": "year"}, {"field": "language"}, {"field": "trans-title"}, {"field": "chapter"}, {"field": "ref", "tooltip":"cite-ref-tooltip"}, ]);

new citeTemplate('cite interview', 'interview2',  [ // Basic fields      {"field": "title", "autofillprop":"title"},      {"field": "date", "autofillprop":"year"},	  {"field": "first", "autofillprop":"first-incr", 'increment_group':'author'}, 	  {"field": "last", "autofillprop":"last-incr", 'increment_group':'author', 'increment_button':true},	  {"field": "subject-link", "tooltip":"cite-subject-link-tooltip", 'increment_group':'authorlink', 'increment_button':true},      {"field": "subject", 'increment_group':'author_alt', 'increment_button':true},      {"field": "interviewer"},      {"field": "program"},      {"field": "callsign"},      {"field": "access-date", "autofillprop":"date"},      {"field": "url"},      {"field": "archive-url"},      {"field": "archive-date", "autofillprop":"date"},      {"field": "dead-url"},      {"field": "publisher", "autofillprop":"publisher"}, {"field": "city", "autofillprop":"location"}, {"field": "type"}, {"field": "quote"}, ],  [ // Expanded fields {"field": "others", "tooltip":"cite-others-tooltip"}, {"field": "page", "tooltip":"cite-page-tooltip"}, {"field": "pages", "autofillprop":"pages", "tooltip":"cite-pages-tooltip"}, {"field": "format"}, {"field": "year"}, {"field": "language"}, {"field": "trans-title"}, {"field": "ref", "tooltip":"cite-ref-tooltip"}, {"field": "id"}, ]);

new citeTemplate('cite journal', 'journal2',  [ // Basic fields      {"field": "title", "autofillprop":"title"},      {"field": "date", "autofillprop":"date"},	  {"field": "first", "autofillprop":"first-incr", 'increment_group':'author'}, 	  {"field": "last", "autofillprop":"last-incr", 'increment_group':'author', 'increment_button':true},	  {"field": "author-link", "tooltip":"cite-author-link-tooltip", 'increment_group':'authorlink', 'increment_button':true},      {"field": "author", 'increment_group':'author_alt', 'increment_button':true},      {"field": "access-date"},      {"field": "doi", "autofillid":"doi"},      {"field": "journal", "autofillprop":"journal"},      {"field": "volume", "autofillprop":"volume"},      {"field": "series"},      {"field": "issue", "autofillprop":"issue"},      {"field": "page", "tooltip":"cite-page-tooltip"},      {"field": "pages", "autofillprop":"pages", "tooltip":"cite-pages-tooltip"}, {"field": "pmid", "autofillid":"pmid"}, {"field": "pmc"}, {"field": "url"}, {"field": "archive-url"}, {"field": "archive-date", "autofillprop":"date"}, {"field": "dead-url"}, ],  [ // Expanded fields {"field": "editor-first", "increment_group":"editor"}, {"field": "editor<N>-last", "increment_group":"editor", "increment_button":true}, {"field": "editor<N>-link", "tooltip":"cite-editor-link-tooltip", 'increment_group':'editorlink', 'increment_button':true}, {"field": "others", "tooltip":"cite-others-tooltip"}, {"field": "language"}, {"field": "trans-title"}, {"field": "publisher"}, {"field": "location"}, {"field": "format"}, {"field": "year"}, {"field": "issn"}, {"field": "oclc"}, {"field": "bibcode"}, {"field": "id"}, {"field": "quote"}, {"field": "at", "tooltip":"cite-at-tooltip"}, {"field": "ref", "tooltip":"cite-ref-tooltip"}, {"field": "postscript", "tooltip":"cite-postscript-tooltip"}, ]);

new citeTemplate('cite news', 'news2',  [ // Basic fields	  {"field": "title", "autofillprop":"title"},      {"field": "date", "autofillprop":"date"},	  {"field": "first<N>", "autofillprop":"first-incr", 'increment_group':'author'}, 	  {"field": "last<N>", "autofillprop":"last-incr", 'increment_group':'author', 'increment_button':true},	  {"field": "author<N>-link", "tooltip":"cite-author-link-tooltip", 'increment_group':'authorlink', 'increment_button':true},      {"field": "author<N>", 'increment_group':'author_alt', 'increment_button':true},      {"field": "access-date"},      {"field": "work", "tooltip":"cite-work-tooltip", "autofillprop":"journal"},      {"field": "url"},      {"field": "archive-url"},      {"field": "archive-date", "autofillprop":"date"},      {"field": "dead-url"},      {"field": "agency"}   ],   [ // Expanded fields      {"field": "editor<N>-first", "increment_group":"editor"}, {"field": "editor<N>-last", "increment_group":"editor", "increment_button":true}, {"field": "editor<N>-link", "tooltip":"cite-editor-link-tooltip", 'increment_group':'editorlink', 'increment_button':true}, {"field": "others", "tooltip":"cite-others-tooltip"}, {"field": "language"}, {"field": "trans-title"}, {"field": "page", "tooltip":"cite-page-tooltip"}, {"field": "pages", "autofillprop":"pages", "tooltip":"cite-pages-tooltip"}, {"field": "format"}, {"field": "location"}, {"field": "quote"}, {"field": "doi", "autofillid":"doi"}, ]);

new citeTemplate('cite patent', 'patent',  [ // Basic fields      {"field": "country"},      {"field": "number"}, 	  {"field": "title", "autofillprop":"title"},      {"field": "status"},      {"field": "pubdate"},      {"field": "gdate"},      {"field": "fdate"},      {"field": "assign1"},      {"field": "invent1"},      {"field": "invent2"},      {"field": "invent3"},      {"field": "invent4"},      {"field": "assign2"},   ],   [ // Expanded fields   ]);

new citeTemplate('UN document', 'UN doc',  [ // Basic fields      {"field": "docid"},      {"field": "body", "tooltip":"cite-body-tooltip"},      {"field": "type", "tooltip":"cite-type-tooltip"},	  {"field": "session"},      {"field": "resolution_number"},      {"field": "document_number"},      {"field": "title"},      {"field": "page"},      {"field": "pages"},      {"field": "date"},      {"field": "year"},      {"field": "meeting"},      {"field": "meetingtime"},      {"field": "speakername"},      {"field": "speakernation"},      {"field": "language"},      {"field": "access-date", "autofillprop":"date"},   ],   [ // Expanded fields   ]); new citeTemplate('cite web', 'web2',  [ // Basic fields      {"field": "title", "autofillprop":"title"},      {"field": "date", "autofillprop":"date"},	  {"field": "first<N>", "autofillprop":"first-incr", 'increment_group':'author'}, 	  {"field": "last<N>", "autofillprop":"last-incr", 'increment_group':'author', 'increment_button':true},	  {"field": "author<N>-link", "tooltip":"cite-author-link-tooltip", 'increment_group':'authorlink', 'increment_button':true},	  {"field": "author<N>", 'increment_group':'author_alt', 'increment_button':true},      {"field": "access-date"},      {"field": "website", "tooltip": "cite-work-tooltip", "autofillprop":"journal"},      {"field": "url"},      {"field": "archive-url"},      {"field": "archive-date", "autofillprop":"date"},      {"field": "dead-url"},      {"field": "format"},      {"field": "year"},      {"field": "publisher"},      {"field": "location"}, {"field": "language"}, {"field": "trans-title"}, {"field": "quote"}, {"field": "doi", "autofillid":"doi"}, {"field": "agency"}, ],  [ // Expanded fields {"field": "editor<N>-first", "increment_group":"editor"}, {"field": "editor<N>-last", "increment_group":"editor", "increment_button":true}, {"field": "editor<N>-link", "tooltip":"cite-editor-link-tooltip", 'increment_group':'editorlink', 'increment_button':true}, {"field": "others", "tooltip":"cite-others-tooltip"}, {"field": "page", "tooltip":"cite-page-tooltip"}, {"field": "pages", "autofillprop":"pages", "tooltip":"cite-pages-tooltip"} ]);

// Cite template headings, field labels, and tooltips

mw.usability.addMessages( { 'cite-dialog-book2' : 'Book citation (custom)', 'cite-dialog-interview2' : 'Interview citation (custom)', 'cite-dialog-journal2' : 'Journal citation (custom)', 'cite-dialog-news2' : 'News citation (custom)', 'cite-dialog-patent' : 'Patent citation (custom)', 'cite-dialog-UN doc' : 'UN document', 'cite-dialog-web2' : 'Web 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 semi-colons",

'cite-access-date-label' : 'Access date', 'cite-archive-date-label' : 'Archive date', 'cite-archive-url-label' : 'Archive URL', 'cite-asin-label' : 'ASIN', 'cite-assign1-label' : 'Assignee 1', 'cite-assign2-label' : 'Assignee 2', 'cite-body-label' : 'Body', 'cite-country-label' : 'Country', 'cite-dead-url-label' : "Dead url?", 'cite-docid-label' : 'Doc ID', 'cite-document_number-label' : 'Document number', 'cite-fdate-label' : 'Filing date', 'cite-gdate-label' : 'Grant date', 'cite-invent1-label' : 'Inventor 1', 'cite-invent2-label' : 'Inventor 2', 'cite-invent3-label' : 'Inventor 3', 'cite-invent4-label' : 'Inventor 4', 'cite-meeting-label' : 'Meeting number', 'cite-meetingtime-label' : 'Meeting time', 'cite-number-label' : 'Number', 'cite-others-label' : 'Others', 'cite-pubdate-label' : 'Publication date', 'cite-resolution_number-label' : 'Resolution number', 'cite-session-label' : 'Session number', 'cite-speakername-label' : 'Speaker name', 'cite-speakernation-label' : 'Speaker nation', '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 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 += '<ref'; if (refname) { refname = $.trim(refname); res+=' name='+CiteTB.getQuotedString(refname); refobj.refname = refname; }   if (group) { group = $.trim(group); res+=' group='+CiteTB.getQuotedString(group); refobj.refgroup = group; }   res+='>'; } var content =''; res+=content; refobj.content = content; if (!inneronly) { res+= ' '; } if (forinsert) { CiteTB.mainRefList.push(refobj); } return res; };