User:Ansumang/reference.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | Documentation for this user script can be added at User:Ansumang/reference. |
// <pre><nowiki>
// A reference toolbar in the edit toolbox to Cite
// {{Cite web}}, {{Cite news}}, {{Cite book}}, {{Cite journal}}
// Credit goes to [[User:Mr.Z-man/refToolbar.js]]
// and [[User:Odie5533/SnipManager.user.js]]
window.SnippetManagerWrapper = function() {
if (typeof(smConfig) == 'undefined') { window.smConfig = new Object(); }
if (typeof(smConfig['smColumns']) == 'undefined') { window.smConfig['smColumns'] = 1; }
if (typeof(smConfig['smTextWidth']) == 'undefined') { window.smConfig['smTextWidth'] = '100px'; }
if (typeof(smConfig['smSingleForm']) == 'undefined') { window.smConfig['smSingleForm'] = true; }
if (typeof(smConfig['smMenus']) == 'undefined') {
window.smConfig['smMenus'] = { '+Citations ∨': { 'Web':'Cite web', 'News':'Cite news',
'Book':'Cite book', 'Journal':'Cite journal' },
};
}
if (typeof(smConfig['smForms']) == 'undefined') {
window.smConfig['smForms'] = {
'Cite web' : [ { 'prepend':'<ref>{{Cite web', 'append':'}}</ref>', 'description':'This template is used to cite online sources in Wikipedia articles. For help, see <a href="/wiki/Wikipedia:CITE" title="" class="mw-redirect">Wikipedia:cite sources</a>.' },
{'title':'<strong>Title:</strong>', 'code':'title', 'help':'Title of the web article'},
{'title':'<strong>URL:</strong>', 'code':'url', 'help':'URL of the web source'},
{'title':'Last name:', 'code':'last', 'help':'Last name of the author'},
{'title':'First name:', 'code':'first', 'help':'First name of the author'},
{'title':'Publication date:', 'code':'date', 'help':'Date the article was published'},
{'title':'Access date:', 'code':'accessdate', 'defeval':'smGetTime()', 'help':'Full date when item was accessed, in ISO 8601 YYYY-MM-DD format, for example "accessdate = 2009-03-13". Must not be wikilinked.'},
{'title':'Format:', 'code':'format', 'help':'e.g. PDF. HTML is implied'},
{'title':'Work:', 'code':'work', 'help':'If this item is part of a larger "work", such as a book, periodical or website, write the name of that work.'},
{'title':'Publisher:', 'code':'publisher', 'help':'Publisher, if any—for example if the website is hosted by a government service, educational institution, or company'},
{'title':'Pages:', 'code':'pages', 'help':'pp. 5–7: first page and optional last page. This is for listing the pages relevant to the citation, not the total number of pages in the book.'},
{'title':'Language:', 'code':'language', 'help':'The language in which the source is written (don\'t specify "English" as this is the default).'},
{'title':'Archive url:', 'code':'archiveurl', 'help':'The URL of an archived copy of the page, if (or in case) the url becomes unavailable. Typically used to refer to services like WebCite and The Internet Archive. Requires archivedate.'},
{'title':'Archive date:', 'code':'archivedate', 'help':'Date when the item was archived (requires archiveurl), in ISO 8601 YYYY-MM-DD format, e.g. 2006-02-17. Must not be wikilinked.'},
{'title':'Quote:', 'code':'quote', 'help':'Relevant quote from online item.'}
],
'Cite news' : [ { 'prepend':'<ref>{{cite news', 'append':'}}</ref>' },
{'title':'<strong>Title:</strong>', 'code':'title', 'help':'required, rest is optional. Note that title must be on one line in order for the hyperlink to display properly. Do not enclose it in quotations marks, italics or other formatting, must be in lowercase.'},
{'title':'URL:', 'code':'url', 'help':'Link to the news item if available online (note this is not for a link to the main web page of the work of publisher, but only to a copy of the item specified in title). Start the url with the communications protocol e.g. http:// or just //. '},
{'title':'Last name:', 'code':'last', 'help':'Last name of the author'},
{'title':'First name:', 'code':'first', 'help':'First name of the author'},
{'title':'Publication date:', 'code':'date', 'help':'Date the article was published.'},
{'title':'Format:', 'code':'format', 'help':'e.g. PDF. HTML is implied. Specify as "fee required" if free access is no longer available. Specify as "Reprint" if you use a full original version but not hosted by the original publisher.'},
{'title':'Agency:', 'code':'agency', 'help':'The news agency (wire service) that provided the content, e.g. Associated Press, Reuters, etc. Spell out and link the full name.'},
{'title':'Work:', 'code':'work', 'help':'The publication that ran the item, e.g. Newsweek. Can also be used for the name of a column or subpart of an issue. Do not italicize.'},
{'title':'Publisher:', 'code':'publisher', 'help':'The company or organization that publishes the news source. Not necessary for major publications like The New York Times, but may add credibility for local papers that are part of a family of publications like Dainik Jagaran or DNA.'},
{'title':'Identifier:', 'code':'id', 'help':'A unique identifier, used if none of the above are applicable. In this case, you need to specify the kind of identifier you are using, preferably with a template like {{ASIN}} or {{ISSN}}. (Use one of the more specialized parameters if possible; they are linked automatically. In other words, don\'t use id = ISBN 1-111-22222-9 anymore. Use isbn = 1-111-22222-9.)'},
{'title':'Page:', 'code':'page', 'help':'The page(s) on which the article is found. page inserts the abbreviation "p." before the number; pages inserts "pp." Use only one of these parameters. If numbers are entered for both, pages overrides page.'},
{'title':'Access date:', 'code':'accessdate', 'defeval':'smGetTime()', 'help':'Full date when item was accessed, in ISO 8601 YYYY-MM-DD format, for example "accessdate = 2009-03-13". Must not be wikilinked.'},
{'title':'Language:', 'code':'language', 'help':'The language in which the source is written (don\'t specify "English" as this is the default).'},
{'title':'Archive url:', 'code':'archiveurl', 'help':'URL of the archive location of the item; this is for archives (such archive.org and WebCite); for back-issues and the like that are on file at the publisher\'s site, use the "url" parameter (requires archivedate).'},
{'title':'Archive date:', 'code':'archivedate', 'help':'Date when the item was archived (requires archiveurl), in ISO 8601 YYYY-MM-DD format, e.g. 2006-02-17. Must not be wikilinked.'},
{'title':'Quote:', 'code':'quote', 'help':'Relevant quotation. Adding a quotation can help locate online copies of the item using a text search, especially if the original link goes dead.'},
],
'Cite book' : [ { 'prepend':'<ref>{{cite book', 'append':'}}</ref>' },
{'title':'Last name:', 'code':'last', 'help':'Surname of author. Don\'t wikilink (use authorlink instead).'},
{'title':'First name:', 'code':'first', 'help':'First name(s) of author, including title(s) (e.g. Firstname Middlename or Firstname M. or Dr. Firstname M., Snr.). Don\'t wikilink (use authorlink instead). '},
{'title':'Author link:', 'code':'authorlink', 'help':'Title of Wikipedia article about author. Article should already exist. Must not be wikilinked itself. Do not use this on its own, but along with "author" or "first" and "last".'},
{'title':'Coauthors:', 'code':'coauthors', 'help':'Full name of additional author or authors, separated by ", " (e.g. Khuswant Singh, APJ Abdul Kalam).'},
{'title':'Editor:', 'code':'editor', 'help':'Name of editor/editors. Do not Wikilink any values in the editor field but use "editor-link" instead. The template automatically adds "ed." after the editor\'s name unless the "chapter" parameter is used in which case the template adds "in" before the editor\'s name which appears after the chapter and before the title.'},
{'title':'title:', 'code':'title', 'help':'Title of book. This is the only required parameter. Can be wikilinked only to an existing Wikipedia article. Do not use italics.'},
{'title':'URL:', 'code':'url', 'help':'URL of an online location where the book can be found. Cannot be used if you wikilinked title. If applicable, can point to the specific page(s) referenced.'},
{'title':'Format:', 'code':'format', 'help':'Format, e.g. PDF. HTML implied if not specified.'},
{'title':'Access date:', 'code':'accessdate', 'defeval':'smGetTime()', 'help':'Full date when url was accessed. Required when url field is used. Must not be wikilinked.'},
{'title':'Edition:', 'code':'edition', 'help':'When the book has more than one edition. e.g.: "2nd." (note that " ed." is placed after this field, so edition=2nd produces "2nd ed.").'},
{'title':'Series:', 'code':'series', 'help':'When the book is part of a series of publications'},
{'title':'Publication date:', 'code':'date', 'help':'Full date of publication edition being referenced, in the same format as the main text of the article. Must not be wikilinked.'},
{'title':'Orig publication year:', 'code':'origyear', 'help':'Original publication year, for display alongside the date or year. For clarity, please specify as much information as possible, for instance "First published 1859" or "Composed 1904". This parameter only displays if there is a value for "year" or "date".'},
{'title':'Publisher:', 'code':'publisher', 'help':'Publisher should not include corporate designation such as "Ltd" or "Inc". '},
{'title':'Location:', 'code':'location', 'help':'Geographical place of publication.'},
{'title':'Language:', 'code':'language', 'help':'The language the book is written in, if it is not English. The template automatically puts parentheses around the text and adds "in" before the language name.'},
{'title':'ISBN:', 'code':'isbn', 'help':'International Standard Book Number such as 1-111-22222-9. Note that "isbn", like all field names, must be in lowercase.'},
{'title':'OCLC:', 'code':'oclc', 'help':'Online Computer Library Center ID number, such as 3185581'},
{'title':'Pages:', 'code':'pages', 'help':'"|pages= 5–7" produces pp. 5–7, while "|page= 5" produces p. 5. The "pp." notation indicating multiple pages, and "p." notation indicating a single page, are placed automatically when you choose between the plural (pages) or singular (page) form of the parameter. These parameters are for listing the pages relevant to the citation, not the total number of pages in the book.'},
{'title':'Chapter:', 'code':'chapter', 'help':'The chapter of the book, written in full. Punctuation other than quotes should be included in the value passed to the parameter, e.g. chapter = Meet Dick and Jane. produces "Meet Dick and Jane." ahead of title.'},
{'title':'Chapter URL:', 'code':'chapterurl', 'help':'URL of an individual chapter of online book. Should be at the same site as url, if any.'},
{'title':'Quote:', 'code':'quote', 'help':'Relevant quote from the book.'},
{'title':'Link Ref:', 'code':'ref', 'help':'use this parameter to make the reference linkable. The variable is placed after the # in a hyperlink (the fragment identifier). Such a linkable reference can be made the target of wikilinks to full references, especially useful in short citations like shortened notes and author-date referencing. See an example for using ref field in citation templates below.'},
],
'Cite journal' : [ { 'prepend':'<ref>{{cite journal', 'append':'}}</ref>' },
{'title':'Last name:', 'code':'last', 'help':'last works with first to produce last, first'},
{'title':'First name:', 'code':'first', 'help':'last works with first to produce last, first'},
{'title':'Author Wikilink:', 'code':'authorlink', 'help':'authorlink works either with author or with last & first to link to the appropriate article (interwiki link)'},
{'title':'Coauthors:', 'code':'coauthors', 'help':'allows additional authors'},
{'title':'Title:', 'code':'title', 'help':'Title of article. This is the only required parameter. All other parameters are optional.'},
{'title':'Journal:', 'code':'journal', 'help':'Name of the journal or periodical.'},
{'title':'Publication date:', 'code':'date', 'help':'January 1, 2006. Full date of publication.'},
{'title':'Publication year:', 'code':'year', 'help':'2006. Year of publication (ignored if the date field is used).'},
{'title':'Publication month:', 'code':'month', 'help':'January. Month of publication (ignored if the date field is used, or if the year field is not used).'},
{'title':'Volume:', 'code':'volume', 'help':'Volume number of the journal in which the article is found'},
{'title':'Issue:', 'code':'issue', 'help':'Journal\'s issue number, or issue name.'},
{'title':'Series:', 'code':'series', 'help':'According to the 14th edition of Chicago Manual of Style p. 576, "As in the case of book series, some journals have attained such longevity that they have begun a new series of volumes or issues. Identification of the series (n.s., 2d ser., 3d ser., ser. b) must be made in citations to these journals."'},
{'title':'Pages:', 'code':'pages', 'help':'45–47: first page, and optional last page (separated by an en dash –). Manually prepend with p. or pp. if desired.'},
{'title':'Publisher:', 'code':'publisher', 'help':'Publisher of journal or periodical; should not include corporate designation such as "Ltd" or "Inc". Only include if ISSN and DOI are unavailable.'},
{'title':'Location:', 'code':'location', 'help':'Place of publication for journal or periodical.'},
{'title':'ISSN:', 'code':'issn', 'help':'The publication\'s International Standard Serial Number such as 1111-2220. Only include if a DOI is unavailable.'},
{'title':'PMID:', 'code':'pmid', 'help':'The document\'s PubMed Unique Identifier, such as 15128012'},
{'title':'PMC:', 'code':'pmc', 'help':'The document\'s PubMed Central article number for full-text free repository of an article, such as 246835'},
{'title':'DOI:', 'code':'doi', 'help':'A digital object identifier for the document, such as 10.1130/0091-7613(1990)018<1153:TAFSIA>2.3.CO;2.'},
{'title':'Bibcode:', 'code':'bibcode', 'help':'The document\'s bibcode in the Astrophysics Data System, e.g., 1924MNRAS..84..308E'},
{'title':'OCLC:', 'code':'oclc', 'help':'The periodical\'s Online Computer Library Center ID number, such as 3185581'},
{'title':'Id:', 'code':'id', 'help':'A unique identifier, used if none of the above are applicable. In this case, you need to specify the kind of identifier you are using, preferably with a template like {{US patent}}, {{MR}} / {{MathSciNet}}, {{Zbl}}, {{arXiv}} or {{JFM}}. (Use one of the more specialized parameters if possible; they are linked automatically. For example pmid = 15128012.)'},
{'title':'URL:', 'code':'url', 'help':'This should point to, in descending order of preference: 1. A free online version of the full text 2. An online version of the full text, for which subscription is required 3. An abstract or information page, if no DOI or PMID record is available. If a DOI or PMID is available, the URL should only be specified if it would point to a different page to that which a DOI or PMID would redirect to.'},
{'title':'Language:', 'code':'language', 'help':'Language, e.g. Finnish. (English is default and should not be specified.)'},
{'title':'Format:', 'code':'format', 'help':'Format, e.g. PDF. Don\'t specify for HTML (implied as default). Specify as "fee required" if free access no longer available. Specify as "Reprint" if a full original version but not hosted by the original publisher.'},
{'title':'Access date:', 'code':'accessdate', 'defeval':'smGetTime()', 'help':'Full date when URL was last checked.'},
{'title':'Lay summary URL:', 'code':'laysummary', 'help':'URL of a lay summary, which could be in a popular science magazine or newspaper. '},
{'title':'Lay source:', 'code':'laysource', 'help':'Name of the source, e.g. The Guardian (UK newspaper) or New Scientist.'},
{'title':'Lay summary date:', 'code':'laydate', 'help':'Date of publication or, where this is not available, date of retrieval of the lay summary.'},
{'title':'Quote:', 'code':'quote', 'help':'Relevant excerpt from the journal.'}
],
};
}
if (smConfig['smCustomForms'] != 'undefined') {
for (key in smConfig['smCustomForms']) {
smConfig['smForms'][key] = smConfig['smCustomForms'][key];
}
}
window.smRibbon = new Ribbon('smRibbon',{
"Rows":"1",
"defaultItemImage":"/media/wikipedia/commons/thumb/4/40/Feather.svg/20px-Feather.svg.png",
"MainClass":"HStrip",
"GroupClass":"HStripB",
"LeftClass":"HStripL",
"CenterClass":"HStripP",
"CenterImageClass":"HStripPC",
"RightClass":"HStripR",
"SingleClass":"HStripLR",
"SelectedClass":"selected",
"HoverClass":"hover",
"ItemHoverClass":"hover",
"GapClass":"HStripS",
"MenuBarClass":"HMenuParent",
"MenuClass":"HMenuItem",
"onItem":"'smExecuteCode(\\'' + item.code + '\\',\\'' + item.value + '\\')'",
"Menu":[
{
"Name":"References",
"Groups":["Citations"],
"show":"", "onShow":"", "onHide":""
},
],
"Groups":
{
"Citations":
{
"Name":"Citations",
"onClick":"",
"Tabs":
[
{
"Image":"/media/wikipedia/commons/thumb/4/40/Feather.svg/60px-Feather.svg.png",
"Items":["Web","Book","News","Journal"],
"ItemCodes":["Cite web","Cite book","Cite news","Cite journal"]
}
]
},
}
},'');
// Taken from [[User:Mr.Z-man/refToolbar.js]]
// All credit for this function goes to him
window.smGetTime = function() {
var time = new Date();
var nowdate = time.getUTCDate();
if (nowdate<10) { nowdate = "0"+ nowdate.toString(); }
var nowmonth = time.getUTCMonth()+1;
if (nowmonth<10) { nowmonth = "0"+ nowmonth.toString(); }
var nowyear = time.getUTCFullYear();
newtime = nowyear + '-' + nowmonth + '-' + nowdate;
return (newtime);
}
window.smVisibleMenu = 0;
// Creates the menu on the page
function createMenu() {
var toolbar = document.getElementById('toolbar');
if (!toolbar)
toolbar = document.getElementById('wikiEditor-ui-toolbar');
if (toolbar) {
// everything is added to the sm_panel
var sm_panel = document.createElement('div');
sm_panel.id = 'snipmanager-panel';
//toolbar.insertBefore(sm_panel, toolbar.childNodes[0]);
toolbar.appendChild(sm_panel);
window.smFormPanel = document.createElement('div');
smFormPanel.id = 'snipmanager-form-panel';
smFormPanel.style.clear = 'both';
var ribbonStrip = document.createElement('div');
ribbonStrip.className = 'HStrip';
var ribbonMenu = document.createElement('div');
ribbonMenu.className = 'HMenu';
sm_panel.appendChild(ribbonMenu);
sm_panel.appendChild(ribbonStrip);
sm_panel.appendChild(smFormPanel);
smRibbon.configuration.Menu[0].Default='true';
smRibbon.Initialize(ribbonStrip,ribbonMenu);
smRibbon.state = 'load';
smRibbon.Render();
}
}
// closes the form that calls it (called from the Close Form button)
window.smCloseForm = function(sender) {
var formFieldSet = sender;
while (formFieldSet.className != 'smForm')
formFieldSet = formFieldSet.parentNode;
formFieldSet.parentNode.removeChild(formFieldSet);
}
function smCompileTemplate(formFieldSet) {
var templTable = formFieldSet.getElementsByTagName('table')[0];
var inputs = templTable.getElementsByTagName('input');
var formName = formFieldSet.formName;
var form = smConfig['smForms'][formName];
var insertText = new Array(form[0]['prepend']);
for (var i in inputs) {
var inp = inputs[i];
if (inp.value && inp.value.length > 0) {
if (inp.className == "%ref") {
insertText[0] = insertText[0].replace(/<ref>/,'<ref name="' + inp.value + '">');
continue;
}
insertText.push('|' + inp.className + '=' + inp.value);
}
}
insertText.push(form[0]['append']);
return insertText.join('');
}
function smInsertTags(insert_text) {
if (typeof(wikEdUseWikEd) != 'undefined' && wikEdUseWikEd) {
/* wikiEd's insertTags has bugs when inserting at the end of a line */
insert_text = insert_text.replace(/&/g, '&');
insert_text = insert_text.replace(/</g, '<');
insert_text = insert_text.replace(/>/g, '>');
WikEdFrameExecCommand('inserthtml', insert_text);
} else {
insertTags(insert_text, '', '');
}
}
// adds the template to the edit box using insertTags
// called from the add template button on the form
window.smAddTemplate = function(sender) {
var formFieldSet = sender;
while (formFieldSet.className != 'smForm')
formFieldSet = formFieldSet.parentNode;
var insert_text = smCompileTemplate(formFieldSet);
smInsertTags(insert_text);
}
// compiles a template and displays an html preview
// called from the preview button on a form
window.smPreviewTemplate = function(sender) {
var formFieldSet = sender;
while (formFieldSet.className != 'smForm')
formFieldSet = formFieldSet.parentNode;
var formDivs = formFieldSet.getElementsByTagName('div');
var previewDiv;
for (var i = 0; i < formDivs.length; i++) {
if (formDivs[i].className == 'formPreview') {
previewDiv = formDivs[i];
break;
}
}
if (!previewDiv) {
alert('No preview div found');
return;
}
var templateCode = smCompileTemplate(formFieldSet);
if (templateCode.indexOf('</ref>') != -1)
templateCode = templateCode.replace(/<\/?ref.*?>/g, '');
smWikiPreview(templateCode, function(content) { previewDiv.innerHTML = content; });
}
// Replaces %s tokens in a string with replacements
function sprintf(haystack, replacements) {
for (var i = 1; i < replacements.length; i++) {
var sub = eval(replacements[i]);
haystack = haystack.replace('%s', sub);
}
return haystack;
}
// Called when a button is clicked
// code refers to a form or function
// and name is the name of the form displayed at the top of the form
window.smExecuteCode = function(code, name) {
var form = smConfig['smForms'][code];
if (!form || !form['length'] || form['length'] < 1) {
return;
}
if (form[0]['inserttext']) {
smInsertTags(form[0]['inserttext'], '', '');
} else if (form[0]['httplink']) {
window.open(form[0]['httplink']);
} else if (form[0]['httpeval']) {
var url = sprintf(form[0]['httpeval'][0], form[0]['httpeval']);
window.open(url);
} else if (form[0]['inserteval']) {
var text = sprintf(form[0]['inserteval'][0], form[0]['inserteval']);
smInsertTags(text, '', '');
} else if (form[0]['evaluate']) {
eval(form[0]['evaluate']);
} else {
smShowForm(code, name);
}
}
// Display a template form in the div
window.smShowForm = function(formName, title) {
// If the smSingleForm option is set, close all previously open forms
if (smConfig['smSingleForm']) {
for (var i = 0; i < smFormPanel.childNodes.length; i++) {
smFormPanel.removeChild(smFormPanel.childNodes[i]);
}
}
// Creates a fieldset and adds it to the form panel
var form = smConfig['smForms'][formName];
var formFields = smGetFormFields(form);
var fieldSet = document.createElement('fieldset');
fieldSet.formName = formName;
smFormPanel.appendChild(fieldSet);
var legend = document.createElement('legend');
fieldSet.appendChild(legend);
fieldSet.className = 'smForm'; //class is used to find the fieldset by
// crawling up from a button node
legend.innerHTML = '<a href="http://en.wikipedia.org/wiki/Template:'+formName+'" target="_blank">'+title+'</a>';
if (typeof(form[0]['description']) != 'undefined') {
var formDesc = document.createElement('div');
formDesc.innerHTML = form[0]['description'];
fieldSet.appendChild(formDesc);
}
// Creates the table for all the text fields
var table = document.createElement('table');
table.cellspacing = 5;
fieldSet.appendChild(table);
var maxcols = smConfig['smColumns'];
var col = 99;
var currentTr = 0;
// loop creates the table cells going from left to right maxcols
// and then top to bottom
for (var i = 0; i < formFields.length; i++) {
if (col++ >= maxcols) {
col = 1;
currentTr = document.createElement('tr');
table.appendChild(currentTr);
}
var td1 = document.createElement('td');
td1.innerHTML = formFields[i]['title'];
var td2 = document.createElement('td');
var textField = createTextField(formFields[i]['code']);
if (formFields[i]['defeval']) {
textField.value = eval(formFields[i]['defeval']);
} else if (formFields[i]['default']) {
textField.value = formFields[i]['default'];
}
textField.title = formFields[i]['help'];
td2.appendChild(textField);
// each field has two TDs: one for the title and one for the text field
currentTr.appendChild(td1);
currentTr.appendChild(td2);
}
// buttons are added to the bottom of the fieldset as a table
var buttonTable = document.createElement('table');
buttonTable.style.width = "100%";
fieldSet.appendChild(buttonTable);
var buttonRow = document.createElement('tr');
buttonTable.appendChild(buttonRow);
var addTemplateButton = addOption("smAddTemplate(this)", "Add Template");
buttonRow.appendChild(document.createElement('td').appendChild(addTemplateButton));
var previewTemplateButton = addOption("smPreviewTemplate(this)", "Preview Template");
buttonRow.appendChild(document.createElement('td').appendChild(previewTemplateButton));
var closeButton = addOption("smCloseForm(this)", "Close Form");
buttonRow.appendChild(document.createElement('td').appendChild(closeButton));
var previewPanel = document.createElement('div');
previewPanel.className = 'formPreview';
fieldSet.appendChild(previewPanel);
}
// Takes a form template and
// returns an array of the fields which have values filled
// Called when showing a form
function smGetFormFields(form) {
var formFields = new Array();
for (var i in form) {
if (!form[i]['title'] || !form[i]['code']) continue;
formFields.push(form[i]);
}
return formFields;
}
// Creates a text field for display on the form
// Called while showing a form
function createTextField(id) {
var inp = document.createElement('input');
inp.type = 'text';
inp.className = id;
inp.tabIndex = 1;
inp.style.width = smConfig['smTextWidth'];
return inp;
}
// Creates a button for display on the form
// Called when showing a form
function addOption(script, text) {
option = document.createElement('input');
option.setAttribute('type', 'button');
option.setAttribute('onclick', script);
option.setAttribute('value', text);
option.setAttribute('tabIndex', 1);
return option;
}
// simple wrapper function for wiki markup preview
// give it the markup and a function(content)
// and it will call the function with the returned preview's HTML content
// Note this function uses wgPageName and sajax_init_object, so must be called
// from within the page's JS scope
window.smWikiPreview = function(wiki_markup, func) {
var form = document.editform;
var addr = mw.config.get('wgServer') + mw.config.get('wgScript') + "?title=" + wgPageName + "&action=submit&wpPreview=true&live=true";
var qwxmlhttp = sajax_init_object(null);
qwxmlhttp.overrideMimeType('text/xml');
qwxmlhttp.open('POST', addr, true);
var boundary = '--(fR*3briuStOum6#v)--';
qwxmlhttp.setRequestHeader('Content-type','multipart/form-data; boundary=' + boundary);
qwxmlhttp.onload = function(event) {
var content = unescape(qwxmlhttp.responseText.replace(/>/g,">").replace(/</g,"<").replace(/&/g,"&").replace(/"/g,'"'));
var match = /<hr \/><\/div>([\w\W\n]*)<\/preview>/.exec(content);
func(match[1]);
};
var postData = '--' + boundary + '\nContent-Disposition: form-data; name="wpTextbox1"\n\n' + wiki_markup + '\n--' + boundary;
qwxmlhttp.send(postData);
}
// The following code is from http://code.google.com/p/jribbon/
// It is listed as GNU GPL, both on the Google Code page and on
// the author's website at http://www.openwebstudio.com/
// WebCite archive: http://www.webcitation.org/5gpjSnfj8
function Ribbon(callerobj,Config) {
this.configuration = Config;
this.caller = callerobj;
this.target = null;
this.menutarget = null;
this.selected = null;
this.state=null;
this.Editors = new Array();
function RibbonEditor(editor,helper)
{
this.cEditor = editor;
this.cHelper = helper;
this.RibbonTab = false;
this.RibbonMenu = false;
}
this.Initialize = function (target,menutarget,editorIndex)
{
this.target = target;
this.menutarget = menutarget;
if (this.selected==null&&this.configuration.Menu!=undefined)
{
for (var i=0;i<this.configuration.Menu.length;i++)
{
if (this.configuration.Menu[i].Default!=undefined && this.configuration.Menu[i].Default.toUpperCase() == 'TRUE')
{
this.selected = this.configuration.Menu[i];
i = this.configuration.Menu.length+1;
}
}
}
this.Render(editorIndex);
}
this.Regenerate = function(txtobj) {
this.Render(txtobj.EditorIndex);
}
this.Toggle = function(groupname,txtobj) {
var canLoad = true;
if (typeof this.Editors[groupname] != 'undefined')
{
if (txtobj.id == this.Editors[groupname].cEditor.id)
{
canLoad = false;
}
else
this.Remove(this.Editors[groupname].cEditor);
}
if (canLoad) this.Editors[groupname]=this.Generate(txtobj);
}
this.Remove = function(txtobj) {
if (typeof txtobj.EditorIndex != 'undefined' && txtobj.EditorIndex != null)
{
var rEditor = this.Editors[txtobj.EditorIndex];
this.Editors[txtobj.EditorIndex]=null;
txtobj.EditorIndex = null;
txtobj.onkeydown=false;
txtobj.setAttribute('isLoaded','false');
txtobj.parentNode.removeChild(rEditor.RibbonTab);
txtobj.parentNode.removeChild(rEditor.RibbonMenu);
rEditor.RibbonTab = false;
rEditor.RibbonMenu = false;
}
}
this.Generate = function(txtobj) {
var randomnumber=Math.floor(Math.random()*32767)
//this.HelpTabID='RibbonHelp' + randomnumber;
var editorIndex = 0;
var rEditor = new RibbonEditor(txtobj,'RibbonHelp' + randomnumber);
this.Editors.push(rEditor);
editorIndex=this.Editors.length-1;
txtobj.EditorIndex = editorIndex;
var override=true;
var rtext = true;
var isLoadedObj = txtobj.getAttribute('isLoaded');
if (typeof isLoadedObj=='undefined' || isLoadedObj==null)
isLoadedObj = false;
else
if (isLoadedObj =='false')
isLoaded=false;
else
isLoaded=true;
if(isLoadedObj==true)
rtext=false;
if(rtext){
txtobj.setAttribute('isLoaded','true');
var dv=document.createElement('div');
dv.className=this.configuration.MainClass;
txtobj.parentNode.insertBefore(dv,txtobj);
var dvm = document.createElement('div');
this.Initialize(dv,dvm,editorIndex);
txtobj.parentNode.insertBefore(dvm,dv);
rEditor.RibbonTab = dv;
rEditor.RibbonMenu = dvm;
}
return rEditor;
}
this.onItemClick = function (input,group,tab,item)
{
if (!isNaN(input))
input = this.Editors[input].Editor();
tab = eval('this.configuration.Groups.' + group + '.Tabs[' + tab + ']');
if (tab!=undefined && tab!=null)
{
item = tab.ItemEditor[item];
}
return false;
}
var txtClip = '';
var txtPasteItem = null;
this.onMenu = function (menuindex,editorIndex)
{
if (this.configuration.Menu!=undefined&&this.configuration.Menu.length > menuindex)
{
this.selected = this.configuration.Menu[menuindex];
if (this.selected.onShow!=undefined && this.selected.onShow.length>0)
{
eval(this.selected.onShow);
}
}
this.Render(editorIndex);
}
this.onMenuHover = function (o)
{
o.xclassName = o.className;
if (o.className!=this.configuration.SelectedClass)
o.className= this.configuration.HoverClass;
}
this.onMenuBlur = function (o)
{
o.className=o.xclassName;
}
this.onItemHover = function (o,group,iindex,tindex,editorIndex)
{
o.xclassName = o.className;
o.className=this.configuration.ItemHoverClass;
if (group!=undefined && group!=null)
{
var helptxt = eval('this.configuration.Groups.' + group + '.Tabs[' + tindex + '].ItemHelp[' + iindex + ']');
if (helptxt!=null && this.Editors[editorIndex]!=null && typeof this.Editors[editorIndex].Helper != 'undefined' && this.Editors[editorIndex].Helper !=null && this.Editors[editorIndex].Helper() != null)
this.Editors[editorIndex].Helper().innerHTML = helptxt;
}
}
this.onItemBlur = function (o,group,iindex,tindex)
{
o.className=o.xclassName;
}
this.Render = function (editorIndex)
{
arr = new Array();
if (this.menutarget!=null && this.configuration!=null)
{
if (this.configuration.Menu!=null && this.configuration.Menu.length > 0)
this.renderMenu(arr,editorIndex);
this.menutarget.innerHTML = arr.join('');
}
arr = new Array();
if (this.target!=null && this.configuration!=null && this.selected!=null)
{
var groups = this.selected.Groups;
arr.push('<table cellpadding=0 cellspacing=0>');
if (groups!=null && groups.length > 0)
{
arr.push('<TR>');
for (var i=0;i<groups.length;i++)
{
//RENDER GROUP
var group = false;
eval('group=this.configuration.Groups.' + groups[i]);
this.renderGroup(this.configuration.Rows,group,arr,editorIndex);
if (i<groups.length-1)
{
arr.push('<TD class="' + this.configuration.GapClass + '"></TD>');
}
}
arr.push('</TR>');
arr.push('<TR>');
for (var i=0;i<groups.length;i++)
{
//RENDER FOOTER
this.renderGroupFooter(this.configuration.Rows,eval('this.configuration.Groups.' + groups[i]),arr,editorIndex);
if (i<groups.length-1)
{
arr.push('<TD class="' + this.configuration.GapClass + '"></TD>');
}
}
arr.push('</TR>');
}
arr.push('</table>');
this.target.innerHTML = arr.join('');
}
}
this.renderGroupFooter = function (rows,group,arr,editorIndex)
{
colspan = 0;
if (group.Tabs != null && group.Tabs.length > 0)
{
for (var tti = 0; tti < group.Tabs.length; tti++)
{
tabcolumns = 0;
itemcounter = 0;
if (group.Tabs[tti].Columns!=undefined)
tabcolumns=1;
else
{
if (group.Tabs[tti].Image!=undefined && group.Tabs[tti].Image.length > 0)
{ itemcounter++;itemcounter++; }
if (group.Tabs[tti].ImageMap!=undefined && group.Tabs[tti].ImageMap.length > 0)
itemcounter++;
if (group.Tabs[tti].Items!=undefined)
itemcounter = itemcounter + group.Tabs[tti].Items.length;
tabcolumns = parseInt(itemcounter / rows);
if (itemcounter / rows > tabcolumns)
tabcolumns++;
}
colspan = colspan + tabcolumns;
}
}
if (colspan > 0)
{
arr.push('<td class="' + this.configuration.GroupClass + '" colspan=' + colspan + '>' + group.Name + '</td>');
}
}
this.renderMenu = function (arr,editorIndex)
{
if (this.configuration.Menu != null && this.configuration.Menu.length > 0)
{
arr.push('<div class="' + this.configuration.MenuBarClass + '">');
for (var mnuI = 0; mnuI < this.configuration.Menu.length; mnuI++)
{
if (this.state!=null && this.configuration.Menu[mnuI].show==this.state || this.configuration.Menu[mnuI].show=='')
this.renderMenuItem(this.configuration.Menu[mnuI],mnuI,arr,editorIndex);
}
arr.push('</div>');
}
}
this.renderMenuItem = function (group,index,arr,editorIndex)
{
arr.push('<div ' + (this.selected!=null&&group.Name==this.selected.Name?'class="' + this.configuration.SelectedClass+'"':'class=' + this.configuration.MenuClass + '"') + ' onclick="' + this.caller + '.onMenu(' + index + ',' + (editorIndex==null?'null':editorIndex) + ');" onmouseover="' + this.caller + '.onMenuHover(this);" onmouseout="' + this.caller + '.onMenuBlur(this);">' + group.Name + '</div>');
}
this.renderGroup = function (rows,group,arr,editorIndex)
{
if (group.Tabs != null && group.Tabs.length > 0)
{
for (var tabI = 0; tabI < group.Tabs.length; tabI++)
{
group.Tabs[tabI].Index=tabI;
this.renderTab(rows,group,group.Tabs[tabI],(tabI==0?true:false),(tabI==group.Tabs.length-1?true:false),arr,editorIndex,tabI);
}
}
}
this.renderTab = function (rows,group,tab,firsttab,lasttab,arr,editorIndex)
{
var thisEditorIndex = -1;
var classname = '';
var isLastTab = lasttab;
var crow = 0;
if (tab.Image!=undefined && tab.Image.length > 0)
{ crow+=2;
if (tab.ImageMap!=undefined && tab.ImageMap.length > 0)
crow++;
}
if ((tab.Columns==undefined && rows-crow < (tab.Items!=undefined?tab.Items.length:0)) || tab.Columns!=undefined && rows-crow < tab.Columns )
{
lasttab=false;
}
crow = 0;
if (editorIndex!=undefined)
thisEditorIndex = editorIndex;
if (lasttab && firsttab)
classname = this.configuration.SingleClass;
else if (lasttab)
classname = this.configuration.RightClass;
else if (firsttab)
classname = this.configuration.LeftClass;
else
classname = this.configuration.CenterClass;
if (tab.Items==undefined || tab.Items.length == 0)
classname = this.configuration.CenterImageClass;
var tdc = '<div>';
var tde = '</div>';
var tc = 'div';
if (tab!=null)
{
var style = '';
if (tab.Style!=undefined)
style = ' style="' + tab.Style + '" ';
if (tab.Image!=undefined && tab.Image.length > 0)
{
arr.push('<td class="' + classname + '"' + style + '>' + tdc);
crow = crow + 2;
if (tab.ImageMap!=undefined && tab.ImageMap.length > 0)
{
arr.push('<img src="' + tab.Image + '" border=0 useMap="' + tab.ImageMap + '">');
crow++;
}
else
{
arr.push('<img src="' + tab.Image + '">');
}
if (crow == rows)
{ arr.push(tde + '</td>'); crow = 0; }
}
else
{
//tdc = '<UL>';
//tde = '</UL>';
//tc = 'li';
}
if (tab.Columns!=undefined)
{
arr.push('<td class="' + classname + '"' + style + '>');
if (tab.Help==undefined || tab.Help.toUpperCase()!='TRUE')
{
arr.push('<div class="' + tab.ColumnClass + '">');
arr.push('<table width=100% border=0 cellpadding=0 cellspacing=0>');
}
else
{
if (editorIndex!=undefined)
{
var chelper=this.Editors[editorIndex].cHelper;
arr.push('<div class="' + tab.ColumnClass + '" id="' + chelper + '">');
arr.push(tab.DefaultHelp);
}
}
}
if (tab.Items!=undefined && tab.Items.length > 0)
{
for (var ti = 0;tab.Items!=undefined && ti < tab.Items.length; ti++)
{
lasttab=false;
if (tab.Columns==undefined && isLastTab && rows-crow > tab.Items.length-ti-1)
lasttab=true;
if (lasttab && firsttab)
classname = this.configuration.SingleClass;
else if (lasttab)
classname = this.configuration.RightClass;
else if (firsttab && tab.Columns==undefined)
classname = this.configuration.LeftClass;
else
classname = this.configuration.CenterClass;
if (tab.Columns!=undefined)
{
if (crow==0)
{arr.push('<tr>');}
if (crow >=0)
{arr.push('<td class="' + classname + '">' + tdc); }
classname = this.configuration.CenterClass;
}
else
{
if (crow==0)
{arr.push('<td class="' + classname + '"' + style + '>' + tdc); }
}
var item = new function() {
this.value = tab.Items[ti];
this.code = tab.ItemCodes[ti];
}
var onclick = '';
var onclickparameters = '()';
if (tab.onclick==undefined||tab.onclick==null||tab.onclick.length==0)
{
if (this.configuration.onItem!=undefined && this.configuration.onItem!=null)
{
onclick= eval(this.configuration.onItem);
onclickparameters = '(' + thisEditorIndex + ')';
}
}
else
{
onclick= eval(tab.onclick);
onclickparameters = '(' + thisEditorIndex + ')';
}
//onclick = onclick.replace(' ','_').replace('-','_').replace('\'','_');
if (editorIndex!=undefined && tab.ItemEditor!=undefined && tab.ItemEditor!=null && tab.ItemEditor.length == tab.Items.length)
{
if (tab.ItemEditor[ti]!=null && (tab.ItemEditor[ti].length != undefined || tab.ItemEditor[ti].Text != undefined))
{
onclick = this.caller + '.onItemClick';
onclickparameters = '(' + editorIndex + ',\'' + group.Abbr + '\',' + tab.Index + ',' + ti + ')';
}
}
/*else
{
if (eval('!window.' + onclick) && this.configuration.debug!=undefined)
alert('The Ribbon control requires a definition for function: ' + onclick);
}*/
var image = null;
if (this.configuration.defaultItemImage!=undefined)
image = this.configuration.defaultItemImage;
if (tab.ItemImages!=undefined && tab.ItemImages[ti].length > 0)
image = tab.ItemImages[ti];
onclickparameters = '';
if (tab.ItemHelp==undefined)
arr.push('<' + tc + ' onclick="' + onclick + onclickparameters + '" onmouseover="' + this.caller + '.onItemHover(this);" onmouseout="' + this.caller + '.onItemBlur(this);">' + (image!=null?'<img src=' + image + '>':'') + tab.Items[ti] + '</' + tc + '>');
else
arr.push('<' + tc + ' onclick="' + onclick + onclickparameters + '" onmouseover="' + this.caller + '.onItemHover(this,\'' + group.Abbr + '\',' + ti + ',' + tab.Index + ',' + thisEditorIndex + ');" onmouseout="' + this.caller + '.onItemBlur(this,\'' + group.Name + '\',' + ti + ',' + tab.Index + ');">' + (image!=null?'<img src=' + image + '>':'') + tab.Items[ti] + '</' + tc + '>');
crow++;
if (tab.Columns!=undefined)
{ arr.push(tde + '</td>'); }
if (crow == rows && tab.Columns==undefined)
{ arr.push(tde + '</td>'); crow = 0; firsttab=false;}
else if (tab.Columns!=undefined && crow==tab.Columns)
{ arr.push('</tr>'); crow = 0; firsttab=false; }
}
}
if (crow!=0 && tab.Columns==undefined)
arr.push(tde + '</td>');
else if (tab.Columns!=undefined)
{
if (tab.Help==undefined || tab.Help.toUpperCase()!='TRUE')
{
var bcrow = false;
while (crow != tab.Columns && crow > 0)
{
bcrow=true;
arr.push('<td> </td>');
crow++;
}
if (bcrow)
arr.push('</tr>');
arr.push('</table>');
}
arr.push('</div>');
arr.push('</td>');
}
}
}
}
appendCSS('div#snipmanager-panel{}\
div.HMenuParent{clear:both;font-size:8pt;width:100%;height:25px;border-bottom:1px solid #eee;}\
div.HMenuParent div{float:left;padding-top:4px;margin:3px 3px -3px 3px;text-align:center;width:94px;height:18px}\
div.HMenuParent div.selected{padding-top:3px;margin:3px 2px -3px 2px;background-color:#c3d6e1;border:1px solid black;border-bottom:0} /*the selected tab*/\
div.HMenuParent div.hover{padding-top:3px;margin:3px 2px -3px 2px;border:1px dashed black;border-bottom:0;background-color:#eee} /*hovering on a tab*/\
div.HStrip table tr td div{text-align:center}div.HStrip table tr td{vertical-align:middle}\
div.HStrip table tr td.HStripPC{vertical-align:middle}\
div.HStrip table tr td div div{height:18px;text-align:left;margin-bottom:1px;padding-left:5px;padding-right:8px;white-space:nowrap}\
div.HStrip table tr td div div img{margin-right:4px}\
div.HStrip table tr td div div.hover{text-decoration:underline;cursor:pointer;}/*hover on button*/\
div.HStrip {clear:both;border-top:0;margin-bottom:1px}\
div.HStrip table{background:#fafafa; margin:2px 0 2px 2px} /*just button area*/\
td.HStripS{width:2px}\
td.HStripP{padding:0 15px 0 5px;margin:0}\
td.HStripPC{padding:0 0 0 5px;margin:0}\
td.HStripLR{border-right:1px solid #c3d6e1;padding-left:5px;margin-left:8px}\
td.HStripL{ border-left:1px solid #c3d6e1;padding:0 5px 0 5px;margin:0}\
td.HStripR{border-right:1px solid #c3d6e1;padding:0 0 0 5px;margin:0}\
td.HStripB{font-size:0.8em; background:#c3d6e1;border-top:1px solid #c3d6e1;text-align:center;color:black}\
.HStripE td.HStripPC{vertical-align:middle; font-family:arial,helvetica;font-size:8pt; padding:0px 0px 0px 0px;margin:0px 0px 0px 0px}\
#snipmanager-form-panel{background:#fafafa;}');
hookEvent("load", createMenu);
}
if (window.parent == window) {
// append wrapper to head if run under Greasemonkey
if (typeof(GM_getValue) == 'function') {
var script = document.createElement('script');
script.id = 'SnippetManager';
script.type = 'text/javascript';
script.text = 'smHeadWrapper = ' + SnippetManagerWrapper.toString() + '; smHeadWrapper();';
document.getElementsByTagName('head')[0].appendChild(script);
}
// otherwise run installation directly
else {
SnippetManagerWrapper();
}
}
// </nowiki></pre>