User:Ty221/Gadget-QuickEdit.js

/* */ /* * * * * * * * * * * * * * * * * * * MediaWiki QuickEdit 2 by ASM * Version: 2.4.2 @plwiki * * * * * * * * * * * * * * * * * * *           How to use * * Insert into your monobook.js: *  importScriptURI('http://de.wikipedia.org/w/index.php?title=Benutzer:ASM/quickedit.js&action=raw&ctype=text/javascript'); * * * Translate QuickEdit into your language: * de:Benutzer:ASM/quickedit-lang.js * * - - - Please DO NOT copy this script (in order to use it) - - - * -> if you have any suggestions, bugs etc. please contact me: de:Benutzer Diskussion:ASM * * This script uses the following external scripts: * • diff.js by Cacycle - en:User:Cacycle/diff.js * • SearchBox.js by Zocky - en:User:Zocky/SearchBox.js * * You can use these variables to customize QuickEdit: * * var qeEnabled         = true;     // Activate Script? * var qeEnableSection0  = true;     // Enable QuickEdit link for section 0 (introduction)? * var qeEnableAccessKeys = true;    // Activate access keys? * var qeSignature       = '--~'; // Signature (use '' to hide signature tab) * * * * * * * * * * * * * * * * * * */ /////////// Einstellungen /////////// if (typeof(qeEnabled) == 'undefined')         qeEnabled          = true; if (typeof(qeEnableSection0) == 'undefined')  qeEnableSection0   = true; if (typeof(qeEnableAccessKeys) == 'undefined') qeEnableAccessKeys = true; if (typeof(qeSignature) == 'undefined')       qeSignature        = '--~'; if (typeof(qeShowErrors) == 'undefined')      qeShowErrors       = false; //////// Ende Einstellungen //////// // version var qeVersion = '2.4-2608'; // qeVars.Mode constants var MODE_QUICKEDIT = 0; var MODE_PREVIEW  = 1; var MODE_DIFF     = 2; var MODE_PREF     = 3; // qeVars.AjaxRequestState constants var REQ_IDLE      = 0; var REQ_RECEIVE   = 1; var REQ_SUBMIT    = 2; // only initialize once // Knoten var qeNodes = new Object; qeNodes.Parent = false; qeNodes.Form   = false; qeNodes.Preview = false; qeNodes.Diff   = false; qeNodes.Tabbar = false; qeNodes.Toolbar = false; qeNodes.Pref   = false; // Variablen var qeVars = new Object; qeVars.Edit    = -1; qeVars.Mode    = MODE_QUICKEDIT; qeVars.Sections = new Object; qeVars.EditLink = false; qeVars.PreviewDisabled = false; qeVars.OriginalText = null; qeVars.FormAction  = false; qeVars.AjaxRequest     = false; qeVars.AjaxRequestState = REQ_IDLE; qeVars.OnDoubleClick   = null; qeVars.StickyMode      = false; qeVars.TextboxHeightPixel = 300; // default language if a translation is not available qeVars.DefLang = 0; qeVars.Lang = 0; // Hooks var qeHooks = new Object; qeHooks.qeInit = []; qeHooks.qeMakeForm = []; // Objects var qeObjects = new Object; qeObjects.ResizeBar = null; ////// Start Script ////// qeVars.IsInit   = false; qeVars.InitTimer = null; qeVars.InitTries = 0; //addOnloadHook(qeInitTimeout); WIP $(document).ready(qeInit); // init wrapper function qeInitTimeout {  if (!qeVars.InitTimer) qeVars.InitTimer = window.setInterval(qeInitTimeout, 500); var ex = true; if (!qeEnabled || qeVars.IsInit) ex = false;                                 // check init if (ex && !document.getElementById('ca-edit')) ex = false;              // check editable if (ex && document.location.search.indexOf('printable=yes') != -1) ex = false; // printable if (ex && qeVars.InitTries > 10) ex = false; if (!ex) { window.clearInterval(qeVars.InitTimer); return; } // abort if anything was false qeVars.InitTries++; if (typeof(qeLanguages) != 'undefined') // then we can init QuickEdit {     window.clearInterval(qeVars.InitTimer); qeInit; } } function qeInit {  if (!qeEnabled || qeVars.IsInit) return; qeVars.IsInit = true; // check if page is editable if (!document.getElementById('ca-edit')) return; // check if page is print page if (document.location.search.indexOf('printable=yes') != -1) return; // check if action is view or purge if (match = /[?&]action=([a-z]+)/.exec(window.location.href)) if (match[1] != 'view' && match[1] != 'purge') return; qeSetLang; if (!qeInitAjax) return; try { qeLoadExternalScripts; } catch (e) {} qeChangeSectionLinks; qeRunHook('qeInit'); } function qeAddHook(target, func) {  qeHooks[target].push(func); } function qeRunHook(target) {  if (qeHooks[target]) for (var i = 0; i < qeHooks[target].length; i++) qeHooks[target][i]; } function qeLoadExternalScripts {  // load Cacycle's diff script if not loaded if (typeof(WDiffString) != 'function') ImportScriptPlain(qeResource('diff')); // load search script ImportScriptPlain(qeResource('search')); // load stylesheet ImportCSS(qeResource('style')); } // wrapper functions for ImportScriptEx function ImportScriptPlain(script) { ImportScriptEx(script, false); } function ImportCSS(css) { ImportScriptEx(css, true); } // now using internal function function ImportScriptEx(script, css) {  mw.loader.load(script, css?'text/css':'text/javascript'); } /*function ImportScriptEx(script, css) {  var head = document.getElementsByTagName('head')[0]; var link = document.createElement(css?'link':'script'); link.setAttribute('charset',       'utf-8'); link.setAttribute('type',          css?'text/css':'text/javascript'); link.setAttribute(css?'href':'src', script); if (css) link.setAttribute('rel', 'stylesheet'); head.appendChild(link); }*/ function qeContentSub(text) {  var cs = document.getElementById('contentSub'); if (cs.innerHTML) cs.innerHTML += ' - ' + text; else cs.innerHTML = text; } function qeShowError(err) {  if (qeShowErrors) qeContentSub(qePhrase('quickedit') + ' ' + qePhrase('error') + ': ' + err); } function qeAlert(err) {  alert(qePhrase('quickedit') + ' ' + qePhrase('error') + ': ' + err); } function qeGetElementsByClassName(tagname, classname) {  var ret = new Array; var tags = document.getElementsByTagName(tagname); for (i = 0; i < tags.length; i++) if (tags[i].className == classname) ret.push(tags[i]); return ret; } function qeChangeSectionLinks {  qeVars.EditLink = document.getElementById('ca-edit').getElementsByTagName('a')[0].href + '&section='; // get all sections var sections = qeGetElementsByClassName('span', 'editsection'); var jumptonav = document.getElementById('jump-to-nav'); // Hauptabschnitt if (qeEnableSection0) {     var heading = qeGetElementsByClassName('h1', 'firstHeading')[0]; if (!heading || !jumptonav) qeShowError('Section 0 nicht gefunden.'); else {     // id verpassen if(!heading.id) heading.id = 'section-0'; // Knoten ins Array packen qeVars.Sections[0] = new Array; var nosections = (sections.length == 0); var node = jumptonav.nextSibling; while (node != null && node.className != 'editsection'            && node.className != 'printfooter' && (nosections|| !/^H[1-6]$/.test(node.nodeName))) {        if (node.nodeType == 1 && node.nodeName != 'SCRIPT') // avoid displaying in- scripts qeVars.Sections[0].push(node); node = node.nextSibling; }     // Link hinzufügen var newspan = document.createElement('span'); newspan.style.fontSize  = '8pt'; newspan.style.marginLeft = '10px'; newspan.dir             = 'ltr'; newspan.appendChild(document.createTextNode('[')); var newlink  = document.createElement('a'); newlink.href = 'javascript:qeEditSection(0)'; newlink.id   = 'sectionlink-0'; newlink.className = 'sectionlink'; newlink.appendChild(document.createTextNode(qePhrase('quickedit'))); newspan.appendChild(newlink); newspan.appendChild(document.createTextNode(']')); //   not appended to heading anymore //   heading.appendChild(newspan); var cs = document.getElementById('contentSub'); cs.style.display = 'block'; cs.appendChild(newspan); }  } // qeEnableSection0 // Abschnitte for (i = 0; i < sections.length; i++) {     // Section-Link suchen var link = sections[i].childNodes[1].href; var section = null, match = null; if (match = /section=((T-)?[0-9]+)/.exec(link)) var section = match[1]; else break; if (!section) continue; sections[i].style.fontSize = '8pt'; // QuickEdit-Link erstellen var newnode = document.createElement('a'); newnode.href = 'javascript:qeEditSection(\'' + section + '\')'; newnode.title = 'QuickEdit Section ' + section; newnode.id   = 'sectionlink-' + section; newnode.className = 'sectionlink'; newnode.appendChild(document.createTextNode(qePhrase('quickedit'))); var where = sections[i].childNodes[2]; sections[i].insertBefore(document.createTextNode('/'), where); sections[i].insertBefore(newnode, where); ////     // dem div eine ID verpassen sections[i].id = 'editsection-' + section; // zugehörige hX Überschrift suchen var hx = sections[i].parentNode; hx.id = 'section-' + section; ////     // alle zu dieser Section gehörigen Knoten suchen und ins Array packen qeVars.Sections[section] = new Array; var node = hx.nextSibling; while (node != null && node.className != 'editsection'            && node.className != 'printfooter' && !/^H[1-6]$/.test(node.nodeName)) {        if (node.nodeType == 1) qeVars.Sections[section].push(node); node = node.nextSibling; }  } } function qeEditSection(section) {  if (qeVars.AjaxRequestState) return; // load edit.js if not loaded for importTags (special chars) if (typeof(importTags) != 'function') {     ImportScriptPlain(wgServer + wgScriptPath + qeResource('edit.js')); }  // not necessarily int //section = parseInt(section); // es wird bereits ein Abschnitt bearbeitet // wenn es der aktuelle ist -> Bearbeiten abbrechen, sonst nichts tun if (qeVars.Edit != -1) {     if (qeVars.Edit == section) qeAbortEdit; return; }  qeVars.Edit = section; // save body.ondblclick if (document.getElementsByTagName('body')[0].getAttribute('ondblclick')) {     qeVars.OnDoubleClick = document.getElementsByTagName('body')[0].getAttribute('ondblclick'); document.getElementsByTagName('body')[0].setAttribute('ondblclick', null); }  // Inhalt des Abschnitts ausblenden var nodes = qeVars.Sections[section]; for (i = 0; i < nodes.length; i++) nodes[i].style.display = 'none'; ////  // andere Links ändern var links = qeGetElementsByClassName('a', 'sectionlink'); for (i = 0; i < links.length; i++) {     if (i == 0) links[i].parentNode.style.display = 'none'; if (links[i].id != 'sectionlink-' + qeVars.Edit) links[i].style.color = '#bfbfbf'; }  // Form anzeigen qeMakeForm; var hx = document.getElementById(section==0 ? 'firstHeading' : 'section-' + section); if(!hx) hx = document.getElementById('section-' + section); hx.parentNode.insertBefore(qeNodes.Parent, hx.nextSibling); qeNodes.Form.wpTextbox1.value = qePhrase('loading') + '...'; ////  // make sure the QuickEdit tab is activated and toolbar is hidden qeSwitch(0); qeSetToolbar(0); qeGetSection; } function qeAbortEdit {  if (qeVars.Edit == -1 || qeVars.AjaxRequestState) return; // Inhalt des Abschnitts wieder einblenden var nodes = qeVars.Sections[qeVars.Edit]; for (i = 0; i < nodes.length; i++) nodes[i].style.display = is_gecko?null:'block'; var links = qeGetElementsByClassName('a', 'sectionlink'); for (i = 0; i < links.length; i++) {     if (i == 0) links[i].parentNode.style.display = 'inline'; if (links[i].id != 'sectionlink-' + qeVars.Edit) links[i].style.color = null; }  qeNodes.Parent.parentNode.removeChild(qeNodes.Parent); qeNodes.Form.wpTextbox1.value = ''; qeVars.Edit = -1; // qeVars.AjaxRequest.abort; qeVars.AjaxRequestState = REQ_IDLE; qeVars.OriginalText = null; // restore body.ondblclick if (qeVars.OnDoubleClick) document.getElementsByTagName('body')[0].setAttribute('ondblclick', qeVars.OnDoubleClick); } function qeMakeForm {  if (qeNodes.Form) return; // create parent div qeNodes.Parent = document.createElement('div'); qeNodes.Parent.style.clear = 'both'; // create tabs [CSS] var ul = document.createElement('ul'); ul.className         = 'qeTabs'; qeNodes.Tabbar       = ul; var li1 = document.createElement('li'); var a = document.createElement('a'); a.href                = 'javascript:qeSwitch(0)'; a.appendChild(document.createTextNode(qePhrase('quickedit'))); li1.appendChild(a); // [CSS] li1.id                = 'qeTabEdit'; li1.title             = qePhrase('tQuickEdit'); li1.className         = 'qeTabs'; var li2 = li1.cloneNode(true); li2.id = 'qeTabPreview'; li2.title = qePhrase('tLivePrev'); li2.firstChild.href = 'javascript:qeSwitch(1)'; li2.firstChild.firstChild.nodeValue = qePhrase('liveprev'); // tab 2a - diff mode var li2a = li2.cloneNode(true); li2a.id               = 'qeTabDiff'; li2a.title            = qePhrase('tDiff'); li2a.firstChild.href  = 'javascript:qeSwitch(2)'; li2a.firstChild.firstChild.nodeValue = qePhrase('diff'); // tab 3 var li4 = li2.cloneNode(true); li4.id                = 'qeTabSubmit'; li4.className        += ' qeTabsSpace'; li4.title             = qePhrase('tSubmit'); li4.firstChild.href   = 'javascript:qeSubmit(0)'; li4.firstChild.firstChild.nodeValue = qePhrase('submit'); // tab 4 var li5 = li2.cloneNode(true); li5.id                = 'qeTabRealPreview'; li5.title             = qePhrase('tPreview'); li5.firstChild.href   = 'javascript:qeSubmit(1)'; li5.firstChild.firstChild.nodeValue = qePhrase('preview'); // tab 5 var li6 = li2.cloneNode(true); li6.id                = 'qeTabCancel'; li6.title             = qePhrase('tCancel'); li6.firstChild.href   = 'javascript:qeAbortEdit'; li6.firstChild.firstChild.nodeValue = qePhrase('cancel'); var li8 = li2.cloneNode(true); li8.id                = 'qeTabSig'; li8.title             = qePhrase('tSig'); li8.className        += ' qeTabsSpace'; li8.firstChild.href   = 'javascript:qeAddSignature'; li8.firstChild.firstChild.nodeValue = qePhrase('sig'); if (qeEnableAccessKeys) {     li1.firstChild.accessKey = 'e'; // quickedit li2.firstChild.accessKey = 'p'; // live prev li2a.firstChild.accessKey= 'v'; // diff li4.firstChild.accessKey = 's'; // submit li6.firstChild.accessKey = 'a'; // cancel li8.firstChild.accessKey = 'f'; // sig }  // [CSS] var li3 = document.createElement('li'); li3.className        = 'qeTabsVersion'; li3.title            = 'MediaWiki QuickEdit ' + qeVersion; var version = qePhrase('header') + ' ' + qeVersion.substr(0, qeVersion.indexOf('-')); li3.appendChild(document.createTextNode(version)); if (qeLanguages[qeVars.Lang-1][0] != wgUserLanguage) {     var a = document.createElement('a'); a.href            = '//de.wikipedia.org/wiki/Benutzer:ASM/quickedit-lang.js'; a.style.marginLeft = '3px'; a.style.color     = '#aaa'; a.appendChild(document.createTextNode('Add your translation!')); li3.appendChild(a); }  // options tab var li7 = li2.cloneNode(true); li7.id                = 'qeTabPref'; li7.title             = qePhrase('pref'); li7.className        += ' qeTabsSpace'; li7.firstChild.href   = 'javascript:qePreferences'; li7.firstChild.firstChild.nodeValue = qePhrase('pref'); ul.appendChild(li3); ul.appendChild(li1); ul.appendChild(li2); ul.appendChild(li2a); ul.appendChild(li4); ul.appendChild(li5); ul.appendChild(li6); if (qeSignature) ul.appendChild(li8); // sig tab // ul.appendChild(li7); new feature: wip. temporarily disabled qeNodes.Parent.appendChild(ul); // create frame div [CSS] var framediv = document.createElement('div'); framediv.id            = 'framediv'; qeNodes.Parent.appendChild(framediv); // create form qeNodes.Form = document.createElement('form'); qeNodes.Form.method = 'post'; qeNodes.Form.onsubmit = function { return qeCheckSubmit; } // create preview div [CSS] qeNodes.Preview = document.createElement('div'); qeNodes.Preview.id            = 'qePreview'; qeNodes.Preview.style.display = 'none'; qeNodes.Preview.style.height  = qeVars.TextboxHeightPixel + "px"; qeNodes.Preview.style.overflow = 'scroll'; qeNodes.Preview.style.backgroundColor = qeGetBGColor; // create diff div [CSS] qeNodes.Diff = document.createElement('div'); qeNodes.Diff.id            = 'qeDiff'; qeNodes.Diff.style.display = 'none'; qeNodes.Diff.style.height  = qeVars.TextboxHeightPixel + "px"; // preview message var div = document.createElement('div'); div.id                     = 'qeLoadPrevMsg'; div.appendChild(document.createTextNode(qePhrase('loadprev') + '...')); qeNodes.Preview.appendChild(div); framediv.appendChild(qeNodes.Diff); framediv.appendChild(qeNodes.Preview); framediv.appendChild(qeNodes.Form); ////  // add form div qeNodes.Form.appendChild(document.createElement('div')); var elements = new Array(    //         subject     type      name     new Array('input',    'hidden', 'wpSection'),     new Array('input',    'hidden', 'wpStarttime'),     new Array('input',    'hidden', 'wpEdittime'), //     new Array('input',    'hidden', 'wpSummary'), created later     new Array('textarea',           'wpTextbox1'),     new Array('input',    'hidden', 'wpEditToken'),     new Array('input',    'hidden', 'wpAutoSummary')   ); for (i = 0; i < elements.length; i++) {     var e = elements[i]; var newnode = document.createElement(e[0]); if (e[0] == 'input') {        newnode.type = e[1]; newnode.name = e[2]; }     else if (e[0] == 'textarea') {        newnode.id = e[1]; newnode.name = e[1]; newnode.appendChild(document.createTextNode('')); newnode.style.height = qeVars.TextboxHeightPixel + "px"; }     qeNodes.Form.firstChild.appendChild(newnode); }  if (qeEnableAccessKeys) qeNodes.Form.wpTextbox1.accessKey = ','; qeNodes.Form.wpTextbox1.tabIndex = 1; // the toolbar qeNodes.Toolbar = document.createElement('div'); qeNodes.Toolbar.id           = 'qeToolbar'; // close button [CSS] var img = document.createElement('img'); img.id                 = 'qeClose'; img.title              = qePhrase('close'); img.src                = qeResource('x'); img.setAttribute('onclick', 'qeSetToolbar(0)'); // search box var search = document.createElement('div'); search.id                = 'qeSearch'; qeCreateSearchBox(search); // special chars var chars = document.createElement('div'); chars.id = 'specialchars-container'; qeNodes.Toolbar.appendChild(img); qeNodes.Toolbar.appendChild(search); qeNodes.Toolbar.appendChild(chars); qeNodes.Form.appendChild(qeNodes.Toolbar); // create resize bar qeObjects.ResizeBar = new qeResizeBar; qeNodes.Form.appendChild(qeObjects.ResizeBar.Node); // create bottom bar newnode = document.createElement('div'); newnode.style.paddingTop= '5px'; newnode.style.borderTop = '1px dotted #aaa'; // mini toolbar (lower right corner) var span = document.createElement('span'); span.style.cssFloat    = 'right'; span.style.verticalAlign= 'middle'; span.style.marginTop   = '0.2em'; // search box icon [CSS] var img = document.createElement('img'); img.id                 = 'icon-search'; img.src                = qeResource('searchbox'); img.title              = qePhrase('searchbox'); img.setAttribute('onclick', 'qeSetToolbar(1)'); span.appendChild(img); // special chars icon var img = img.cloneNode(false); img.id                 = 'icon-specialchars'; img.src                = qeResource('chars'); img.title              = qePhrase('chars'); img.style.borderLeft   = '1px solid #ccc'; img.setAttribute('onclick', 'qeSetToolbar(2)'); span.appendChild(img); newnode.appendChild(span); // add fake submit button var c = document.createElement('input'); c.type              = 'submit'; c.name              = 'wpSave'; c.value             = ''; c.style.display     = 'none'; newnode.appendChild(c); // Speichern var c = document.createElement('a'); c.href        = 'javascript:qeSubmit(0)'; c.title       = qePhrase('tSubmit'); c.style.cursor = 'pointer'; c.appendChild(document.createTextNode(qePhrase('submit'))); newnode.appendChild(c); // Vorschau newnode.appendChild(document.createTextNode(' ')); c = document.createElement('a'); c.href            = 'javascript:qeSubmit(1)'; c.title           = qePhrase('tPreview'); c.style.marginLeft = '5px'; c.style.cursor    = 'pointer'; c.appendChild(document.createTextNode(qePhrase('preview'))); newnode.appendChild(c); // Zusammenfassung newnode.appendChild(document.createTextNode(' ')); c = document.createElement('input'); c.type            = 'text'; c.size            = '70'; c.id              = 'wpSummary'; c.name            = 'wpSummary'; c.maxLength       = '200'; c.tabIndex        = 2; //  if (c.addEventListener) c.addEventListener('change', qeSubmitByReturn, false); newnode.appendChild(c); // Kleine Änderung newnode.appendChild(document.createTextNode(' ')); var checkboxes = document.createElement('span'); checkboxes.style.whiteSpace = 'nowrap'; //  var c = document.createElement('input'); c.type = 'checkbox'; c.id   = 'wpMinoredit'; c.name = 'wpMinoredit'; c.value = '1'; c.style.marginLeft = '5px'; c.tabIndex = 3; c.title = qePhrase('tMinor'); if (qeEnableAccessKeys) c.accessKey = 'i'; checkboxes.appendChild(c); //  var c = document.createElement('label'); c.htmlFor = 'wpMinoredit'; c.className       = 'qeLabel'; c.title           = qePhrase('tMinor'); c.appendChild(document.createTextNode(qePhrase('k'))); checkboxes.appendChild(c); // Beobachten checkboxes.appendChild(document.createTextNode(' ')); //  var c = document.createElement('input'); c.type = 'checkbox'; c.id   = 'wpWatchthis'; c.name = 'wpWatchthis'; c.value = '1'; c.style.marginLeft = '5px'; c.tabIndex = 4; c.title = qePhrase('tWatch'); if (qeEnableAccessKeys) c.accessKey = 'w'; checkboxes.appendChild(c); //  var c = document.createElement('label'); c.htmlFor = 'wpWatchthis'; c.className       = 'qeLabel'; c.title           = qePhrase('tWatch'); c.appendChild(document.createTextNode(qePhrase('b'))); checkboxes.appendChild(c); //  qeRunHook('qeMakeForm'); //  newnode.appendChild(checkboxes); qeNodes.Form.appendChild(newnode); } function qeFillForm(formaction, wpStarttime, wpEdittime, wpSummary, wpTextbox1,                   wpEditToken, wpAutoSummary, wpWatchthis, wpMinoredit) {  if (!qeNodes.Form) return; // save form action since we need it for preview qeVars.FormAction = formaction; qeNodes.Form.wpSection.value  = qeVars.Edit; qeNodes.Form.wpStarttime.value = wpStarttime; qeNodes.Form.wpEdittime.value = wpEdittime; qeNodes.Form.wpSummary.value  = wpSummary; qeNodes.Form.wpTextbox1.value = wpTextbox1; qeNodes.Form.wpEditToken.value  = wpEditToken; qeNodes.Form.wpAutoSummary.value = wpAutoSummary; qeNodes.Form.wpWatchthis.checked = wpWatchthis; qeNodes.Form.wpMinoredit.checked = wpMinoredit; qeNodes.Form.action = formaction; // store the original text for diff qeVars.OriginalText = wpTextbox1; } function qeSetToolbar(type) {  var search = document.getElementById('qeSearch'), chars = document.getElementById('specialchars-container'), close = document.getElementById('qeClose'); search.style.display = (type == 1)?'block':'none'; chars.style.display = (type == 2)?'block':'none'; close.style.display = (type != 0)?'block':'none'; } // QuickEdit 2.3: Search function qeCreateSearchBox(node) {  sr$f = node; node.style.color   = '#888'; node.style.fontSize = '0.83em'; node.appendChild(document.createTextNode(qePhrase('srsearch') + ': ')); // search box var input = document.createElement('input'); input.id = 'srSearch'; input.type = 'text'; input.style.marginRight = '0.7em'; input.setAttribute('onkeypress', 'event.which == 13 && srNext'); node.appendChild(input); sr$s = input; node.appendChild(document.createTextNode(qePhrase('srreplace') + ': ')); // replace box input = input.cloneNode(false); input.id = 'srReplace'; node.appendChild(input); sr$r = input; // the find and replace-links var a = document.createElement('a'); a.href            = 'javascript:srBack'; a.style.color     = '#888'; a.appendChild(document.createTextNode('<')); node.appendChild(a); var links = 'srNext',            '0.4em', qePhrase('srfind') + ' >'],                ['srReplace;srBack', '1em',   '<'],                ['srReplace',          '0.4em', qePhrase('srreplace')],                ['srReplace;srNext',   '0.4em', '>'],                ['srReplaceall',       '1em',   qePhrase('srreplaceall'); for (var i = 0; i < links.length; i++) {     var a = a.cloneNode(false); a.href            = 'javascript:' + links[i][0]; a.style.marginLeft = links[i][1]; a.appendChild(document.createTextNode(links[i][2])); node.appendChild(a); }  // two checkboxes var input = document.createElement('input'); input.id              = 'srCase'; input.type            = 'checkbox'; input.style.marginLeft = '1em'; input.setAttribute('onclick', 'document.getElementById("srSearch").focus'); var label = document.createElement('label'); label.htmlFor         = 'srCase'; label.appendChild(document.createTextNode(qePhrase('srmatchcase'))); node.appendChild(input); node.appendChild(label); sr$mc = input; var input = input.cloneNode(false); var label = label.cloneNode(false); input.id              = 'srRegexp'; label.htmlFor         = 'srRegexp'; label.appendChild(document.createTextNode(qePhrase('srregexp'))); node.appendChild(input); node.appendChild(label); sr$re = input; // set up searchbox.js specific variables sr$t = qeNodes.Form.wpTextbox1; } // 2.4: Resize Bar function qeResizeBar {  var node       = qeResizeBar.CreateNode; this.Node     = node; this.dragging = false; this.reference = 0; this.height   = qeVars.TextboxHeightPixel; this.Node.onmousedown = this.MouseDown; } qeResizeBar.CreateNode = function {  var n = document.createElement('div'); n.id = 'qeResizeBar'; var span = n.appendChild(document.createElement('span')); span.innerHTML = '&#149; &#149; &#149; &#149; &#149;' return n; } qeResizeBar.prototype.MouseDown = function(e) {  qeObjects.ResizeBar.dragging = true; document.onmousemove = qeObjects.ResizeBar.MouseMove; document.onmouseup  = qeObjects.ResizeBar.MouseUp; document.ondrag       = function  { return !qeObjects.ResizeBar.dragging; } document.onselectstart = function { return !qeObjects.ResizeBar.dragging; } // get current object to resize switch (qeVars.Mode) {     case MODE_PREVIEW: var obj = qeNodes.Preview; break; case MODE_DIFF: var obj = qeNodes.Diff; break; default: var obj = qeNodes.Form.wpTextbox1; }  // get height of the object if (obj.style.height != "") var height = obj.style.height; else var height = qeGetStyle(obj, 'height') || qeVars.TextboxHeightPixel; qeObjects.ResizeBar.reference = e.clientY - height.replace(/[^0-9]/g, ""); return false; } qeResizeBar.prototype.MouseUp = function(e) {  qeObjects.ResizeBar.dragging  = false; document.onmousemove  = null; document.onmouseup    = null; document.ondrag       = null; document.onselectstart = null; qeNodes.Form.wpTextbox1.style.height = qeObjects.ResizeBar.height + "px"; qeNodes.Preview.style.height        = qeObjects.ResizeBar.height + "px"; qeNodes.Diff.style.height           = qeObjects.ResizeBar.height + "px"; } qeResizeBar.prototype.MouseMove = function(e) {  if (!qeObjects.ResizeBar.dragging) return false; qeObjects.ResizeBar.height = e.clientY - qeObjects.ResizeBar.reference; switch (qeVars.Mode) {     case MODE_PREVIEW: var obj = qeNodes.Preview; break; case MODE_DIFF: var obj = qeNodes.Diff; break; default: var obj = qeNodes.Form.wpTextbox1; }  obj.style.height = qeObjects.ResizeBar.height + "px"; return false; } // QuickEdit 2: Preview stuff function qeSwitch(type) {  if (qeVars.Edit == -1 || qeVars.AjaxRequestState || qeVars.Mode == MODE_PREF) return; if (type == 3 && typeof(WDiffString) != 'function') // diff mode {     qeNodes.Diff.appendChild(document.createTextNode('Error: Couldn\'t load diff.js')); return; }  switch (type) {     case 1:   var lid = document.getElementById('qeTabPreview'); break; case 2:  var lid = document.getElementById('qeTabDiff'); break; default: var lid = document.getElementById('qeTabEdit'); break; }  switch (qeVars.Mode) {     case MODE_PREVIEW: var lia = document.getElementById('qeTabPreview'); break; case MODE_DIFF:   var lia = document.getElementById('qeTabDiff'); break; default:          var lia = document.getElementById('qeTabEdit'); break; }  lia.className = lia.className.replace(/qeTabsSelected/, ''); lid.className += ' qeTabsSelected'; // now check if there is any change type = parseInt(type); if (type == qeVars.Mode) return; qeVars.Mode = type; if (qeVars.Mode != MODE_DIFF) qeNodes.Diff.innerHTML = ''; // switch to preview if (qeVars.Mode == MODE_PREVIEW) {     // set bg color according to the background of the current section qeNodes.Preview.style.backgroundColor = qeGetBGColorOf(document.getElementById('section-' + qeVars.Edit)) || qeGetBGColor; // remove all child nodes from previous previews, if any for (var i = 1; i < qeNodes.Preview.childNodes.length; i++) qeNodes.Preview.removeChild(qeNodes.Preview.childNodes[i]); // hide quickedit, hide diff qeNodes.Form.firstChild.style.display = 'none'; qeNodes.Diff.style.display = 'none'; // show preview qeNodes.Preview.style.display = 'block'; qeNodes.Preview.firstChild.style.display = 'block'; qeLoadPreview; }  else if (qeVars.Mode == MODE_QUICKEDIT) {     // hide diff, hide preview qeNodes.Diff.style.display = 'none'; qeNodes.Preview.style.display = 'none'; // show quickedit qeNodes.Form.firstChild.style.display = 'block'; }  else // MODE_DIFF {     // hide quickedit, hide preview qeNodes.Form.firstChild.style.display = 'none'; qeNodes.Preview.style.display = 'none'; // show diff qeNodes.Diff.style.display = 'block'; qeLoadDiff; } } function qeLoadDiff {	var currenttext = document.getElementById('wpTextbox1').value; qeNodes.Diff.innerHTML = WDiffShortenOutput(WDiffString(qeVars.OriginalText, currenttext)); var div = document.createElement('div'); div.style.textAlign  = 'right'; div.style.position   = 'relative'; div.style.bottom     = '10px'; var span = document.createElement('span'); span.style.fontSize = '83%'; span.style.color    = '#aaa'; span.style.marginRight = '10%'; span.appendChild(document.createTextNode('Using ')); var a = document.createElement('a'); a.href                = qeResource('diffscript'); a.style.textDecoration = 'underline'; a.style.color         = '#aaa'; a.appendChild(document.createTextNode('diff.js')); span.appendChild(a); span.appendChild(document.createTextNode(' by Cacycle')); div.appendChild(span); qeNodes.Diff.appendChild(div); } function qeLoadPreview {  if (qeVars.Edit == -1 || qeVars.AjaxRequestState || qeVars.Mode != MODE_PREVIEW || !qeVars.FormAction) return; var link = qeGetLink(qeVars.Edit); qeVars.AjaxRequestState = REQ_SUBMIT; qeVars.AjaxRequest.onreadystatechange = qeAjaxResponse; qeVars.AjaxRequest.open('POST', qeVars.FormAction, true); var send = qeMakeFormRequest; qeVars.AjaxRequest.overrideMimeType('text/xml'); qeVars.AjaxRequest.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); qeVars.AjaxRequest.setRequestHeader('Content-length', send.length); qeVars.AjaxRequest.setRequestHeader('Content', send.length); qeVars.AjaxRequest.send(send); } function qeMakeFormRequest {  if (!qeNodes.Form) return null; var str = ''; var inputs = qeNodes.Form.getElementsByTagName('input'); for (var i = 0; i < inputs.length; i++) if (inputs[i].value && inputs[i].value.length > 0) str += '&' + inputs[i].name + '=' + encodeURIComponent(inputs[i].value); str += '&wpPreview=Preview' + '&wpTextbox1=' + encodeURIComponent(document.getElementById('wpTextbox1').value); return str.substr(1); } function qeGetLink(section) {  if (section == 0) return qeVars.EditLink + '0'; var span = document.getElementById('editsection-' + section); if (!span) return false; var c = span.firstChild; while (c != null && c.nodeName != 'A') c = c.nextSibling; if (!c) return false; return c.href; } // Ajax stuff function qeInitAjax {  try {     if (window.XMLHttpRequest) {        qeVars.AjaxRequest = new XMLHttpRequest; if (qeVars.AjaxRequest.overrideMimeType) qeVars.AjaxRequest.overrideMimeType('text/xml'); }     else if (window.ActiveXObject) qeVars.AjaxRequest = new ActiveXObject('Microsoft.XMLHTTP'); else throw 'Kein AJAX-Objekt vorhanden'; }  catch (e) {     qeShowError(e); return false; }  if (!qeVars.AjaxRequest) {     qeShowError('AJAX-Objekt konnte nicht erstellt werden'); return false; }  return true; } function qeGetSection {  if (qeVars.Edit == -1 || !qeNodes.Form || !qeVars.AjaxRequest || qeVars.AjaxRequestState) return; var link = qeGetLink(qeVars.Edit); qeVars.AjaxRequestState = REQ_RECEIVE; qeVars.AjaxRequest.onreadystatechange = qeAjaxResponse; qeVars.AjaxRequest.open('GET', link, true); qeVars.AjaxRequest.send(null); } function qeAjaxResponse {  if (!qeVars.AjaxRequestState) {     alert('QuickEdit Fehler: qeAjaxResponse'); return; }  // receive if (qeVars.AjaxRequestState == REQ_RECEIVE && qeVars.Edit != -1) {     if (qeVars.AjaxRequest.readyState != 4 || qeVars.AjaxRequest.status != 200) return; qeVars.AjaxRequestState = REQ_IDLE; var xml = qeVars.AjaxRequest.responseXML; try // MediaWiki bug 6986 workaround {        // xmlGetById(xml, 'wpTextbox1').firstChild.nodeValue // w Firefoksie textarea ma wiele dzieci tekstowych... var wpTextbox1 = $.text(xmlGetById(xml, 'wpTextbox1')); }     catch (e) {        xml = qeFixXML(qeVars.AjaxRequest.responseText); if (!xml) {           qeShowError('XML parsing fehlgeschlagen.'); return; }        var wpTextbox1 = $.text(xmlGetById(xml, 'wpTextbox1')); }     var wpStarttime, wpEdittime, wpSummary, wpEditToken, wpAutoSummary, wpWatchthis, wpMinoredit; // FIXME to nie XML, tylko HTML var inputs = xml.getElementsByTagName('input'); for (i = 0; i < inputs.length; i++) {        if (inputs[i].getAttribute('name') == 'wpSection') wpSection = inputs[i].getAttribute('value'); else if (inputs[i].getAttribute('name') == 'wpStarttime') wpStarttime = inputs[i].getAttribute('value'); else if (inputs[i].getAttribute('name') == 'wpEdittime') wpEdittime = inputs[i].getAttribute('value'); else if (inputs[i].getAttribute('name') == 'wpSummary') wpSummary = inputs[i].getAttribute('value'); else if (inputs[i].getAttribute('name') == 'wpEditToken') wpEditToken = inputs[i].getAttribute('value'); else if (inputs[i].getAttribute('name') == 'wpAutoSummary') wpAutoSummary = inputs[i].getAttribute('value'); else if (inputs[i].getAttribute('name') == 'wpWatchthis') wpWatchthis = inputs[i].getAttribute('checked'); else if (inputs[i].getAttribute('name') == 'wpMinoredit') wpMinoredit = inputs[i].getAttribute('checked'); }     var formaction = xmlGetById(xml, 'editform').getAttribute('action'); var specialchars = document.getElementById('specialchars-container'); if (specialchars.childNodes.length == 0 && xmlGetById(xml, 'specialchars')) {        var node = xmlGetById(xml, 'specialchars').cloneNode(true); node.style.background = 'none'; node.style.border    = 'none'; node.style.fontSize  = '8pt'; for (var i = 0; i < node.childNodes.length; i++) if (node.childNodes[i].nodeName == 'A') {              node.removeChild(node.childNodes[i]); node.removeChild(node.childNodes[i+1]); break; }        specialchars.appendChild(node); addCharSubsetMenu; // wikipedia script }     // sollte nie passieren, wenn doch -> fatal error if (wpSection != qeVars.Edit) {        qeAlert(qePhrase('varmismatch')); qeVars.AjaxRequestState = REQ_IDLE; qeAbortEdit; return; }     qeFillForm(formaction, wpStarttime, wpEdittime, wpSummary, wpTextbox1,                 wpEditToken, wpAutoSummary, wpWatchthis, wpMinoredit); return; }  // preview (submit) if (qeVars.AjaxRequestState == REQ_SUBMIT && qeVars.Edit != -1) {     if (qeVars.AjaxRequest.readyState != 4 || qeVars.AjaxRequest.status != 200) return; qeVars.AjaxRequestState = REQ_IDLE; try {        var xml = qeVars.AjaxRequest.responseXML; var prev = xmlGetById(xml, 'wikiPreview').cloneNode(true); }     catch (e) {        // try to fix it, then try to parse again try {           xml = qeFixXML(qeVars.AjaxRequest.responseText); prev = xmlGetById(xml, 'wikiPreview').cloneNode(true); }        catch (e) {           qeVars.PreviewDisabled = true; qeNodes.Preview.firstChild.firstChild.nodeValue = qePhrase('noprev'); var tab = document.getElementById('qeTabPreview'); tab.firstChild.style.color = '#888'; return; }     }      qeNodes.Preview.firstChild.style.display = 'none'; while (prev.childNodes.length > 0 && prev.firstChild.getAttribute('class') != 'previewnote') prev.removeChild(prev.firstChild); prev.removeChild(prev.firstChild); qeNodes.Preview.appendChild(prev); qeNodes.Preview.innerHTML = qeNodes.Preview.innerHTML; // na "wklejonym" XML-u nie wyświetlają się style? return; } } function qeCheckSubmit {  return (qeVars.Edit != -1 && qeVars.AjaxRequest && qeNodes.Form && !qeVars.AjaxRequestState); } function qeSubmit(preview) {  if (!qeCheckSubmit) // redundant, but prevents accidential preview node return; if (preview == 1) {     var prev = document.createElement('input'); prev.name = 'wpPreview'; prev.value = 'Preview'; prev.type = 'hidden'; qeNodes.Form.appendChild(prev); }  qeNodes.Form.submit; } // parse string as XML if necessary function qeFixXML(text) {  // IE   try {     var parser = new ActiveXObject("Microsoft.XMLDOM"); parser.async = false; text = text.replace(/<!DOCTYPE.*?>/i, '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">'); parser.loadXML(text); return parser; }  // everything else catch (e) {     var parser = new DOMParser; var newdoc = parser.parseFromString(text, "text/xml"); return newdoc; } } // mamy teraz HTML5 zamiast XHTML-a i wszystko się sypie // brzydki hack, TODO: zaktualizować to wszystko function xmlGetById(doc, id) {  return $(doc).find('#'+id)[0]; } // Signature function qeAddSignature {  wpTextbox1 = document.getElementById('wpTextbox1'); // IE support if (document.selection) {     wpTextbox1.focus; sel = document.selection.createRange; sel.text = qeSignature; }  // MOZILLA/NETSCAPE support else if (wpTextbox1.selectionStart || wpTextbox1.selectionStart == '0') {     var startpos = wpTextbox1.selectionStart; var endpos  = wpTextbox1.selectionEnd; wpTextbox1.value = wpTextbox1.value.substring(0, startpos) + qeSignature + wpTextbox1.value.substring(endpos, wpTextbox1.value.length); wpTextbox1.focus; endpos += qeSignature.length; if (endpos > wpTextbox1.length) endpos = wpTextbox1.length; wpTextbox1.setSelectionRange(endpos, endpos); }  else {     wpTextbox1.value += qeSignature; wpTextbox1.focus; } } // Language stuff function qeGetBGColor {  var ret = qeGetStyle(document.getElementById('content'), 'background-color'); return ret?ret:'#fff'; } function qeGetBGColorOf(node) {  var col = qeGetStyle(node, 'background-color'); while (node && (!col || col == 'transparent')) {     node = node.parentNode; col = qeGetStyle(node, 'background-color'); }  return (node && col)?col:null; } function qeGetStyle(elem, style) {  if (document.defaultView) return document.defaultView.getComputedStyle(elem, null).getPropertyValue(style); return null; } function qeSetLang {  for (var i = 0; i < qeLanguages.length; i++) {     if (qeLanguages[i][0] == wgUserLanguage) qeVars.Lang = i + 1; if (qeLanguages[i][0] == 'en') qeVars.DefLang = i + 1; }  // if language was not found, use default language if (!qeVars.Lang) qeVars.Lang = qeVars.DefLang; qeSetPrefix; } function qePhrase(name) {  for (var i = 0; i < qePhrases.length; i++) if (qePhrases[i][0] == name) return qePhrases[i][qeVars.Lang]; return 'UNDEFINED PHRASE: ' + name; } function qeSetPrefix { // ausgeliehen vom Wikipedia-Script var pref = 'Alt'; if (is_safari || navigator.userAgent.toLowerCase.indexOf('mac') + 1      || navigator.userAgent.toLowerCase.indexOf('konqueror') + 1 ) pref = qePhrase('strg'); else if (is_opera)  pref = qePhrase('shift') + '-Esc'; else if (is_ff2_x11) pref = qePhrase('strg') + '-' + qePhrase('shift'); else if (is_ff2_win) pref = 'Alt-' + qePhrase('shift'); pref += '-'; // p: number of the entry in the current phrase which is to be copied (EN if available, DE otherwise) for (var i = 0; i < qePhrases.length; i++) {     // if the phrase is missing in the user language, use the english one if (qePhrases[i][qeVars.Lang] == '') qePhrases[i][qeVars.Lang] = qePhrases[i][qeVars.DefLang]; // check for KEY: if (qePhrases[i][0].charAt(0) == 't') qePhrases[i][qeVars.Lang] = qePhrases[i][qeVars.Lang].replace(/KEY:(.)/, pref + '$1'); } } function qeResource(name) {  var commonsurl = '//upload.wikimedia.org/wikipedia/commons/'; var wikiurl   = '//XX.wikipedia.org/w/index.php?title=TT&action=raw&ctype=text/TYPE'; for (var i = 0; i < qeResources.length; i++) if (qeResources[i][0] == name) {        var res = qeResources[i][1]; if (res.indexOf('c:') == 0) return commonsurl + res.substr(2); var type = 0; if (res.indexOf('js:') == 0) type = 1; else if (res.indexOf('css:') == 0) type = 2; if (type) {           wikiurl = wikiurl.replace(/XX/, res.substring(res.indexOf(':') + 1, res.indexOf(':', res.indexOf(':')+1))); wikiurl = wikiurl.replace(/TT/, res.substring(res.indexOf(':', res.indexOf(':')+1)+1)); wikiurl = wikiurl.replace(/TYPE/, (type == 1)?'javascript':'css'); return wikiurl; }        return qeResources[i][1]; }  return ''; } var qeResources = [ ['chars',    'c:0/0d/WikEd_case_sensitive.png'], ['searchbox', 'c:3/31/WikEd_preview.png'], ['x',        'c:6/61/Crystal_128_error.png'], ['language', 'js:de:Benutzer:ASM/quickedit-lang.js'], ['diff',     'js:en:User:Cacycle/diff.js'], ['style',    'css:de:Benutzer:ASM/quickedit.css'], ['diffscript','//en.wikipedia.org/wiki/User:Cacycle/diff.js'], ['search',   'js:de:Benutzer:ASM/quickedit-search.js'], ['edit.js',  '/skins-1.5/common/edit.js?203xx'] ]; // import languages from external script (Benutzer:ASM/quickedit-lang.js) // ImportScriptPlain(qeResource('language')); // array content: var name | var type | default value | user value // phrase name describing the option is is "'o' + var name" // the user value will be read by the script from a cookie // if there is no value set, the default value will be used var qeOptions = [ ['qeStickyMode', 'bool', 'false', null] ]; /* */ /* */ // from MediaWiki:Onlyifediting.js function addCharSubsetMenu { var specialchars = document.getElementById('specialchars'); if (specialchars) {  switch(wgContentLanguage){ case "ca": edittoolsOptions= /*català*/ ["matemàtiques","fonètica","diacrítiques","ciríl·lic","alt alemany antic", "anglés antic","àrab","berber","bosni/serbocroata","castellà","escandinau", "eslovac","esperanto","estonià","francés","gal·lés","grec","grec antic", "hawaià","hebreu","holandés","hongarés","indoeuropeu","irlandés", "islandés","italià","japonés (romanji)","jiddisch","letó","lituà","maltés", "navajo i apatxe", "pinyin","polonés","portugués","romanés","serbi", "turc i ll. turqueses", "txec","vietnamita"]; break; case "de": edittoolsOptions= /*Deutsch*/ ["Standard","WikiSyntax","IPA-Lautschrift","Lateinisch","AHD","Altenglisch", "Altgriechisch","Arabisch","DMG-Umschrift","Esperanto","Estnisch", "Französisch","Galicisch","Griechisch","Hawaiianisch","Isländisch", "Italienisch","Jiddisch","Katalanisch","Kroatisch","Kyrillisch", "Lettisch","Litauisch","Maltesisch","Pinyin","Polnisch","Portugiesisch", "Romanisch","Rumänisch","Serbisch","Skandinavisch","Slowakisch","Spanisch", "Tschechisch","Türkisch","Ungarisch","Vietnamesisch" ]; break; case "it": edittoolsOptions= /*Italiano*/ ["Latino esteso","Wiki","Greco antico","Greco moderno","Cirillico","Arabo", "Ebraico e yiddish","Armeno","Geroglifico","Vietnamita","IPA", "Matematica" ]; break; default : edittoolsOptions=["Your Edittools are not defined"]; }  var menu = ''; for(index in edittoolsOptions){ menu += ' ' + edittoolsOptions[index] + ' '; }  menu += ' '; specialchars.innerHTML = menu + specialchars.innerHTML; // Standard-CharSubset chooseCharSubset(0); } } // CharSubset-Auswahl function chooseCharSubset(s) {  var l = document.getElementById('specialchars').getElementsByTagName('p'); for (var i = 0; i < l.length ; i++) {        l[i].style.display    = (i == s) ? 'inline' : 'none'; l[i].style.visibility = (i == s) ? 'visible' : 'hidden'; // for the CSS-unsure it-wp ;)     } } /* */