Content deleted Content added
fix template preview (WP update their code?) |
Amorymeltzer (talk | contribs) m Remove legacy globals per phab:T72470 (via WP:JWB) |
||
(14 intermediate revisions by 3 users not shown) | |||
Line 1:
// <pre><nowiki>
// ==UserScript==
// @name
// @
// @
// @description SnipManager is a script for Wikipedia which adds a toolbar to the top of the edit box for holding complex signatures, templates, or other pieces of text. It is compatible with wikEd (and TW/HW).
// @homepage http://en.wikipedia.org/wiki/User:Odie5533/SnipManager
// @screenshot http://upload.wikimedia.org/wikipedia/commons/2/29/SnipManager.png
// @namespace http://en.wikipedia.org/*
// @include http://*.wikipedia.org/*
// @include https://*.wikipedia.org/*
// @include https://secure.wikimedia.org/*
// @updateURL http://en.wikipedia.org/w/index.php?action=raw&ctype=text/javascript&title=User:Odie5533/SnipManager.user.js
// @grant none
// ==/UserScript==
//
Line 11 ⟶ 19:
//
// Credit also to wikiEd for coding examples
//
// Changelog:
// 2014-06-13 - Updated some of the citation templates
// 2014-05-23 - Fix insertions not working with wikEd (insertTags); added Cite press release
// 2012-11-09 - Cleanup code; fix bug in insertTags when using wikiEd
// 2012-11-07 - Updated {{cite web}}
if (typeof(SnippetManagerWrapper) == 'undefined') { window.SnippetManagerWrapper = {}; }
window.SnippetManagerWrapper = function() {
Line 18 ⟶ 33:
if (typeof(smConfig['smTextWidth']) == 'undefined') { window.smConfig['smTextWidth'] = '220px'; }
if (typeof(smConfig['smSingleForm']) == 'undefined') { window.smConfig['smSingleForm'] = true; }
if (typeof(smConfig['
if (typeof(smConfig['smForms']) == 'undefined') {
window.smConfig['smForms'] = {
'doicite' : [ { 'httpeval':[ 'http://tools.wikimedia.de/~verisimilus/Bot/DOI_bot/doibot.php?edit=false&slow=1&page=%s', "escape(mw.config.get('wgPageName')).replace('&', '%26');" ] } ],
'cleanup' : [ { 'inserttext':'{{Cleanup}}' } ],
'copyedit' : [ { 'inserttext':'{{Copyedit}}' } ],
Line 55:
'fact' : [ { 'inserttext':'{{Fact|{{subst:DATE}}}}' } ],
'weasel-inline' : [ { 'inserttext':'{{Weasel-inline|{{subst:DATE}}}}' } ],
'Primarysources' : [ { 'inserttext':'{{
'Notability' : [ { 'inserttext':'{{Notability|{{subst:DATE}}}}' } ],
'One source' : [ { 'inserttext':'{{One source|{{subst:DATE}}}}' } ],
'showrefs' : [ { 'evaluate':'easyCiteMain();citeNamedRef();' } ],
'referrs' : [ { 'evaluate':'easyCiteMain();dispErrors();' } ],
Line 64 ⟶ 66:
{'title':'Additional text', 'code':'4' }
],
'Cite web' : [ { 'prepend':'<ref>{{Cite web', 'append':'}}</ref>', 'description':'This template is used to cite online sources in Wikipedia articles. {{<a href="/wiki/Template:Cite_news" title="Template:Cite news">Cite news</a>}} can also be used when citing a news source; for general information about citations in Wikipedia articles, see <a href="/wiki/Wikipedia:
{'title':'<strong>Title:</strong>', 'code':'title', 'help':'
{'title':'
{'title':'First name:', 'code':'first', 'help':'
{'title':'Last name:', 'code':'last', 'help':'
{'title':'Publication date:', 'code':'date', 'help':'Full date of source being referenced in the
{'title':'
{'title':'
{'title':'
{'title':'Original year', 'code':'origyear', 'help':'Original publication year; displays after the date or year. For clarity, please supply specifics; example: |origyear=First published 1859 or |origyear=Composed 1904.'},
{'title':'
{'title':'
{'title':'Others:', 'code':'others', 'help':'To record other contributors to the work, such as "Illustrated by John Smith" or "Translated by John Smith."'},
{'title':'Format:', 'code':'format', 'help':'e.g. PDF. HTML is implied'},
{'title':'Type:', 'code':'type', 'help':'Provides additional information about the media type of the source; format in sentence case. Displays in parentheses following the title. Examples: Thesis, Booklet, CD liner, Press release.'},
{'title':'Location:', 'code':'___location', 'help':'Geographical place of publication; generally not wikilinked; omit when the name of the work includes the ___location; examples: The Boston Globe, The Times of India. Displays preceding publisher.'},
{'title':'
{'title':'At:', 'code':'at', 'help':'For sources where a page number is inappropriate or insufficient. Overridden by |page= or |pages=. Examples: page (p.) or pages (pp.); section (sec.), column (col.), paragraph (para.); track; hours, minutes and seconds; act, scene, canto, book, part, folio, stanza, back cover, liner notes, indicia, colophon, dust jacket, verse.'},
{'title':'Language:', 'code':'language', 'help':'The language the source is written in, if not English. Displays in parentheses with "in" before the language name. Use the full language name; do not use icons or templates.'},
{'title':'DOI:', 'code':'doi', 'help':'A digital object identifier for the document, such as 10.1038/news070508-7'},
{'title':'Archive url:', 'code':'archiveurl', 'help':'The URL of an archived copy of
{'title':'Archive date:', 'code':'archivedate', 'help':'Date when the item was archived;
{'title':'Quote:', 'code':'quote', 'help':'Relevant quote from online item.'},
],
'citenews' : [ { 'prepend':'<ref>{{cite news', 'append':'}}</ref>' },
Line 94 ⟶ 99:
{'title':'Last name:', 'code':'last', 'help':'Last name of the author'},
{'title':'Publication date:', 'code':'date', 'help':'Date of publication. Use the same format as the main text of the article.'},
{'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':'Author link:', 'code':'authorlink', 'help':'works either with author or with last & first to link to the appropriate Wikipedia article. Does not work with URLs.'},
{'title':'Author:', 'code':'author', 'help':'Author'},
{'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':'Location:', 'code':'___location', 'help':'Place of the publication, e.g. Toronto for The Globe and Mail. For student newspapers, include the name of the school.'},
{'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 The McClatchy Company.'},
Line 106 ⟶ 110:
{'title':'Pages:', 'code':'pages', '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':'Publication year:', 'code':'year', 'help':'year of publication'},
{'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. If English (the default) do not use this parameter.'},
Line 117 ⟶ 120:
{'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':'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':'Other Contribs:', 'code':'others', 'help':'To record other contributors to the work, such as "illustrated by Smith" or "trans. Smith".'},
Line 130 ⟶ 132:
{'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 a there is a value for "year" or "date".'},
{'title':'Publication year:', 'code':'year', 'help':'Year of publication edition being referenced, and month: Name of the month of publication. If you also have the day, use date instead. Must not be wikilinked.'},
{'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.'},
Line 156 ⟶ 157:
{'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':'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':'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.'},
Line 186 ⟶ 184:
],
'Cite video' : [ { 'prepend':'<ref>{{Cite video', 'append':'}}</ref>' },
{'title':'Title:', 'code':'title', 'help':'Title of the production. This is the only required field.'},
{'title':'Date:', 'code':'date', 'help':'Date of source being referenced. Can be full date (day, month, and year) or partial date (month and year, season and year, year). Use same format as other publication dates in the citations.'},
{'title':'Last:', 'code':'last', 'help':'Surname of author. Do not wikilink—use authorlink instead. Where the surname is usually written first—as in Chinese—or for corporate authors, simply use last to include the same format as the source.'},
{'title':'First:', 'code':'first', 'help':'Given or first names of author, including title(s); for example: Firstname Middlename or Firstname M. or Dr. Firstname M., Sr. Do not wikilink—use authorlink instead. Aliases: first1. Requires last; first name will not display if last is empty.'},
{'title':'Url:', 'code':'url', 'help':'Provides a link to either the production\'s website or to its entry at IMDb. May wikilink to an article rather than provide a URL.'},
{'title':'Format:', 'code':'format', 'help':'File format of the URL link if containing digital media. For example, "mov" or "avi".'},
Line 197 ⟶ 194:
{'title':'Location:', 'code':'___location', 'help':'Physical ___location of the publisher, formatted as either "City, State" or "City, Country". For example, "New York, NY" or "London, England".'},
{'title':'Access date:', 'code':'accessdate', 'defeval':'smGetTime()', 'help':'Full date when url was accessed, in ISO 8601 YYYY-MM-DD format, eg. 2005-01-31 (January 01, 2005). Required when url field is used to link a url. (Must not be wikilinked.) '},
{'title':'Time:', 'code':'time', 'help':'Roughly what time, if accessible, a scene occurs with-in a production. Useful for citing specific scenes, quotations or data.'},
{'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 {{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.)'},
Line 204 ⟶ 199:
{'title':'OCLC:', 'code':'oclc', 'help':'Online Computer Library Center ID number, such as 3185581.'},
{'title':'Quote:', 'code':'quote', 'help':'information source quotation of pertinent data like is the likely reason for citing the media in the first place!'},
],
'Cite press release' : [ {'prepend':'<ref>{{Cite press release', 'append':'}}</ref>' },
{'title':'First', 'code':'first', 'help':'Given or first names of author, including title(s); for example: Firstname Middlename or Firstname M. or Dr. Firstname M., Sr. Do not wikilink—use authorlink instead. Aliases: first1. Requires last; first name will not display if last is empty.'},
{'title':'Last', 'code':'last', 'help':'Surname of author. Do not wikilink—use authorlink instead. Where the surname is usually written first—as in Chinese—or for corporate authors, simply use last to include the same format as the source.'},
{'title':'Title', 'code':'title', 'help':'Title of source. Can be wikilinked to an existing Wikipedia article or url may be used to add an external link, but not both. Displays in quotes.'},
{'title':'URL', 'code':'url', 'help':'URL of an online ___location where the text of the publication can be found. Cannot be used if title is wikilinked. If applicable, the link may point to the specific page(s) referenced. Remove spurious tracking parameters from URLs, e.g. #ixzz2rBr3aO94 or ?utm_source=google&utm_medium=...&utm_term=...&utm_campaign=.... Do not link to any commercial booksellers, such as Amazon.com. See: WP:PAGELINKS.'},
{'title':'Date', 'code':'date', 'help':'Date of source being referenced. Can be full date (day, month, and year) or partial date (month and year, season and year, year). Use same format as other publication dates in the citations. Required when year is used to disambiguate {{sfn}} links to multiple-work citations by the same author in the same year. Do not wikilink. Displays after the authors and is enclosed in parentheses. If there is no author, then displays after publisher.'},
{'title':'Place (___location)', 'code':'place', 'help':'Geographical place of publication; generally not wikilinked; omit when the name of the work includes the ___location; examples: The Boston Globe, The Times of India. Displays after the title; if work is defined, then ___location is enclosed in parentheses. Alias: ___location'},
{'title':'Publisher', 'code':'publisher', 'help':'Name of publisher; may be wikilinked if relevant. The publisher is the company that publishes the work being cited. Do not use the publisher parameter for the name of a work (e.g., a book, encyclopedia, newspaper, magazine, journal, website). Not normally used for periodicals. Corporate designations such as "Ltd", "Inc" or "GmbH" are not usually included. Omit where the publisher\'s name is substantially the same as the name of the work (for example, The New York Times Co. publishes The New York Times newspaper, so there is no reason to name the publisher). Displays after title; if work is defined, then publisher is enclosed in parentheses.'},
{'title':'Agency', 'code':'agency', 'help':'The news agency (wire service) that provided the content; examples: Associated Press, Reuters, Agence France-Presse. May be wikilinked if relevant.'},
{'title':'Format', 'code':'format', 'help':'Format of the work referred to by url; for example: PDF, DOC, or XLS; displayed in parentheses after title. HTML is implied and should not be specified. Does not change the external link icon. Note: External link icons do not include alt text; thus, they do not add format information for the visually impaired.'},
{'title':'Trans. title', 'code':'trans_title', 'help':'English translation of the title if the source cited is in a foreign language. Displays in square brackets after title; if url is defined, then trans_title is included in the link. Use of the language parameter is recommended.'},
{'title':'Language', 'code':'language', 'help':'The language the source is written in, if not English. Displays in parentheses with "in" before the language name. Use the full language name or ISO 639-1 code; use of ISO 639-1 also adds appropriate language categorization; do not use icons or templates.'},
{'title':'Page', 'code':'page', 'help':'The number of a single page in the source that supports the content. Use either |page= or |pages=, but not both. Displays preceded by p. unless |nopp=y.'},
{'title':'Pages', 'code':'pages', 'help':'A range of pages in the source that supports the content. Use either |page= or |pages=, but not both. Separate using an en dash (–); separate non-sequential pages with a comma (,); do not use to indicate the total number of pages in the source. Displays preceded by pp. unless |nopp=y. Hyphens are automatically converted to en dashes; if hyphens are appropriate, for example: pp. 3-1–3-15, use |at=.'},
{'title':'Dead URL?', 'code':'deadurl', 'help':'When the URL is still live, but pre-emptively archived, then set |deadurl=no. This changes the display order with the title retaining the original link and the archive linked at the end.'},
{'title':'Archive url', 'code':'archiveurl', 'help':'The URL of an archived copy of a web page, if or in case the url becomes unavailable. Typically used to refer to services like WebCite (see: Wikipedia:Using WebCite) and Internet Archive (see: Wikipedia:Using the Wayback Machine); requires archivedate and url.'},
{'title':'Archive date', 'code':'archivedate', 'help':'Date when the original URL was archived; preceded by default text "archived from the original on". Use the same format as other access and archive dates in the citations. This does not necessarily have to be the same format that was used for citing publication dates. Do not wikilink.'},
{'title':'Access date', 'code':'accessdate', 'defeval':'smGetTime()', 'help':'Full date when original URL was accessed; use the same format as other access and archive dates in the citations; requires url. Do not wikilink. Not required for web pages or linked documents that do not change; mainly for use of web pages that change frequently or have no publication date. Can be hidden or styled by registered editors.'},
{'title':'Via', 'code':'via', 'help':'e.g. [[HighBeam Research]]'},
{'title':'Subscription', 'code':'subscription', 'help':'For online sources that require a subscription, set |subscription=yes; supersedes registration if both are set.'},
{'title':'Quote', 'code':'quote', 'help':'Relevant text quoted from the source. Displays enclosed in quotes. When supplied, the citation terminator (a period by default) is suppressed, so the quote needs to include terminating punctuation.'},
{'title':'First1', 'code':'first1', 'help':'for multiple authors, use last1, first1 through lastn, firstn where n is any consecutive number for an unlimited number of authors (each firstn requires a corresponding lastn). By default, if nine authors are defined, then only eight will show and "et al." will show in place of the last author.'},
{'title':'Last1', 'code':'last1', 'help':''},
{'title':'First2', 'code':'first2', 'help':''},
{'title':'Last2', 'code':'last2', 'help':''},
],
'Infobox Military Conflict' : [ { 'prepend':'{{Infobox Military Conflict', 'append':'}}', 'description':'' },
Line 357 ⟶ 378:
};
}
if (smConfig['smCustomForms'] != 'undefined') {
for (key in smConfig['smCustomForms']) {
Line 365 ⟶ 387:
window.smRibbon = new Ribbon('smRibbon',{
"Rows":"2",
"defaultItemImage":"
"MainClass":"HStrip",
"GroupClass":"HStripB",
Line 411 ⟶ 433:
[
{
"Image":"
"Items":["Web","Book","News","Journal","Video","Press release", "DOI Bot"],
"ItemCodes":["Cite web","citebook","citenews","citejournal","Cite video","Cite press release", "doicite"]
}
]
Line 423 ⟶ 445:
"Tabs": [
{
"Items":["No refs","More refs","No notes","More notes","Cite check","Prim sources","Notability","One source"],
"ItemCodes":["unreferenced","Refimprove","No footnotes","More footnotes","citecheck","Primarysources","Notability","One source"]
}
]
Line 435 ⟶ 457:
[
{
"Image":"
"Items":["Cleanup","Copy Edit"],
"ItemCodes":["cleanup","copyedit"]
Line 479 ⟶ 501:
// 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);
}*/
// Gets the current time in the format Sep 7, 2014
window.smGetTime = (function() {
var m = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
return function() {
var t = new Date();
return m[t.getUTCMonth()] + " " + t.getUTCDate() + ", " + t.getUTCFullYear();
}
})();
window.smVisibleMenu = 0;
// Creates
function createMenu() {
// support wikiEd if it is installed
var toolbar = document.getElementById('toolbar');
if (!toolbar) {
}
if (toolbar) {
// All output is added to the sm_panel div
var sm_panel = document.createElement('div');
sm_panel.id = 'snipmanager-panel';
//toolbar.insertBefore(sm_panel, toolbar.childNodes[0]); // alt. insertion
toolbar.appendChild(sm_panel); // added to the bottom of toolbar
// the actual ribbon bar is constructed
var ribbonStrip = document.createElement('div');
ribbonStrip.className = 'HStrip';
var ribbonMenu = document.createElement('div');
ribbonMenu.className = 'HMenu';
//a place to display forms to the user
window.smFormPanel = document.createElement('div');
smFormPanel.id = 'snipmanager-form-panel';
smFormPanel.style.clear = 'both';
// All these items are added to sm_panel
sm_panel.appendChild(ribbonMenu);
sm_panel.appendChild(smFormPanel);
window.smRibbon.configuration.Menu[0].Default='true';
window.smRibbon.Initialize(ribbonStrip,ribbonMenu);
window.smRibbon.state = 'load';
window.smRibbon.
}
}
Line 526 ⟶ 565:
while (formFieldSet.className != 'smForm')
formFieldSet = formFieldSet.parentNode;
}
function smCompileTemplate(formFieldSet) {
if (inp.className == "%ref") {
insertText[0] = insertText[0].replace(/<ref>/, '<ref name="' +
inp.value + '">');
continue;
}
insertText.push('|' + inp.className + '=' + inp.value);
}
}
return insertText.join('');
}
// Called whenever SnipManager needs to insert text into the edit area
function smInsertTags(insert_text) {
insertTags(insert_text, '', '');
}
// Adds the template to the edit box using smInsertTags
// Called from the Add Template button on the form
window.smAddTemplate = function(sender) {
var formFieldSet = sender;
Line 558 ⟶ 603:
formFieldSet = formFieldSet.parentNode;
smInsertTags(insert_text);
}
Line 582 ⟶ 628:
if (templateCode.indexOf('</ref>') != -1)
templateCode = templateCode.replace(/<\/?ref.*?>/g, '');
smWikiPreview(templateCode, function(content) {
previewDiv.innerHTML = content; }); }
Line 594 ⟶ 641:
}
// Called by the Ribbon when a Ribbon button is clicked.
// code refers to a form or function
//
window.smExecuteCode = function(code, name) {
if (!form || !form['length'] || form['length'] < 1) {
return;
}
if (form[0]['inserttext']) {
} else if (form[0]['inserteval']) {
var text = sprintf(form[0]['inserteval'][0], form[0]['inserteval']);
smInsertTags(text, '', '');
} else if (form[0]['httplink']) {
window.open(form[0]['httplink']);
// httpeval is used to open websites with dynamically generated urls
} else if (form[0]['httpeval']) {
var url = sprintf(form[0]['httpeval'][0], form[0]['httpeval']);
window.open(url);
} else if (form[0]['evaluate']) {
eval(form[0]['evaluate']);
Line 630 ⟶ 678:
// Creates a fieldset and adds it to the form panel
var form = smConfig['smForms'][formName];
fieldSet.formName = formName;
smFormPanel.appendChild(fieldSet);
Line 639 ⟶ 687:
fieldSet.className = 'smForm'; //class is used to find the fieldset by
// crawling up from a button node
legend.innerHTML = '<a href="
if (typeof(form[0]['description']) != 'undefined') {
var formDesc = document.createElement('div');
Line 646 ⟶ 694:
fieldSet.appendChild(formDesc);
}
// Creates the table for all the text fields
var table = document.createElement('table');
fieldSet.appendChild(table);
// loop creates the table cells going from left to right maxcols
// and then top to bottom
}
var textField;
} else {
continue;
}
// Allows for default values or functions to be passed and their
// return value becomes the default value for the form field
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
}
// buttons are added to the bottom of the fieldset as a table
Line 689 ⟶ 745:
var buttonRow = document.createElement('tr');
buttonTable.appendChild(buttonRow);
var previewTemplateButton = addOption("smPreviewTemplate(this)", "Preview Template");
buttonRow.appendChild(document.createElement('td').appendChild(previewTemplateButton));
var previewPanel = document.createElement('div');
previewPanel.className = 'formPreview';
Line 708 ⟶ 764:
// Called when showing a form
function smGetFormFields(form) {
}
}
Line 730 ⟶ 786:
// 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;
}
//
// give it the markup and a function(content)
// and it will call the function with the returned preview's HTML content
Line 744 ⟶ 800:
// from within the page's JS scope
window.smWikiPreview = function(wiki_markup, func) {
var form = document.editform;
var addr =
"&action=submit&wpPreview=true&live=true";
var qwxmlhttp
qwxmlhttp.
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);
}
Line 789 ⟶ 851:
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];
Line 1,217 ⟶ 1,279:
}
mw.util.addCSS('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:sans-serif;font-size:8pt; padding:0px 0px 0px 0px;margin:0px 0px 0px 0px}\
#snipmanager-form-panel{background:#fafafa;}');
//
// wrapper for addEventListener (http://ejohn.org/projects/flexible-javascript-events/)
//
var AddEventListener = function(domElement, eventType, eventHandler, useCapture) {
if (domElement == null) {
return;
}
if (typeof(domElement.addEventListener) == 'function') {
domElement.addEventListener(eventType, eventHandler, useCapture);
}
else {
domElement['wikEd' + eventType + eventHandler] = eventHandler;
domElement[eventType + eventHandler] = function() {
var eventRootElement = document;
if (document.addEventListener == null) {
eventRootElement = window;
}
domElement['wikEd' + eventType + eventHandler](eventRootElement.event);
};
domElement.attachEvent('on' + eventType, domElement[eventType + eventHandler] );
}
return;
};
AddEventListener(window, 'load', createMenu, false);
}
SnippetManagerWrapper.startup = function() {
if (document.title == '')
return;
SnippetManagerWrapper();
}
SnippetManagerWrapper.startup();
// </nowiki></pre>
|