Lankide:Theklan/quickedit.js
Wikipedia(e)tik
Oharra: Gorde ondoren zure nabigatzailearen katxea ekidin beharko duzu aldaketak ikusteko. Mozilla / Firefox / Safari: Shift tekla sakatu birkargatzeko momentuan, edo Ctrl-Shift-R sakatu (Cmd-Shift-R Apple Mac baten); IE: Ctrl tekla sakatu birkargatzeko momentuan, edo Ctrl-F5 sakatu; Konqueror:: Birkargatzeko klik egin, edo F5 sakatu, besterik ez; Opera erabiltzaileek Tresnak-Hobespenak atalera jo eta katxea garbitzeko aukera hautatu.
//<pre><nowiki> //Fuente: http://de.wikipedia.org/wiki/Benutzer:ASM/quickedit.js //Personalizada por Axxgreazz, para el [[w:es:User:Axxgreazz/Monobook-Suite]] //http://es.wikipedia.org/wiki/Usuario:Axxgreazz/Monobook-Suite /* * * * * * * * * * * * * * * * * * * MediaWiki QuickEdit by ASM * * Version: 17. August 2006-1 * * * * * * * * * * * * * * * * * * * * Opcionalmente cambiar las sgte variables: * * var qeEnabled = true; // Activate Script? * var qeEnableSection0 = true; // Enable QuickEdit link for section 0 (introduction)? * var qeShowErrors = true; // Show errors (should be left false) * var qeEnableAccessKeys = true; // Activate access keys? * var qeTextboxHeight = 15; // Height of the textbox * * Acces keys are the same as usual (except 'a' for abort edit) * * * * * * * * * * * * * * * * * * */ /////////// Einstellungen /////////// // -> Standardeinstellungen zuweisen try { var dummy = qeEnabled; } catch (e) { qeEnabled = true; } try { var dummy = qeShowErrors; } catch (e) { qeShowErrors = false; } try { var dummy = qeEnableSection0; } catch (e) { qeEnableSection0 = true; } try { var dummy = qeTextboxHeight; } catch (e) { qeTextboxHeight = 15; } try { var dummy = qeEnableAccessKeys; } catch (e) { qeEnableAccessKeys = true; } //////// Ende Einstellungen //////// // 2D-Array mit allen Sections und den jeweiligen Unterknoten var qeSections = new Array(); // Aktuell bearbeitete Section var qeEdit = -1; // Link zum Bearbeiten der Abschnitte var qeEditLink = false; // Form-Knoten var qeForm = false; // XmlHttpRequest var qeRequest = false; // 0 = idle 1 = receive 2 = submit var qeRequestState = 0; ////// Start Script ////// addOnloadHook(qeInit); function qeInit() { if (navigator.appName.indexOf("Microsoft")!=-1) return; if (!qeEnabled) return; // check if page is editable if (!document.getElementById('ca-edit')) return; //chequear si se trata de un diff if(document.location.href.indexOf('&diff=') != -1 ) return; // check if there is no other action than view var pos = document.location.href.indexOf('action='); if (pos != -1 && document.location.href.substr(pos+7, 4) != 'view') return; //qeSetLang(); no es necesario if (!qeInitAjax()) return; qeChangeSectionLinks(); } function qeContentSub(text) { var cs = document.getElementById('contentSub'); if (cs.innerHTML) cs.innerHTML += ' - ' + text; else cs.innerHTML = text; } function qeShowError(err) { if (qeShowErrors) qeContentSub(msStringU('quickedit') + ' ' + msStringU('error') + ': ' + err); } function qeAlert(err) { alert(msStringU('quickedit') + ' ' + msStringU('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() { qeEditLink = document.getElementById('ca-edit').firstChild.href + '§ion='; // Alle Abschnitte var sections = qeGetElementsByClassName('div', 'editsection'); var jumptonav = document.getElementById('jump-to-nav'); qeNewLinks = false; if (sections.length == 0) if (typeof oldEditsectionLinks == 'undefined' || !oldEditsectionLinks) { qeNewLinks = true; var node = jumptonav.nextSibling; while(node != null && node.className != 'printfooter') { if (/^H[1-6]$/.test(node.nodeName) && node.getElementsByTagName('span').length != 0) sections.push(node.getElementsByTagName('span')[0]); node = node.nextSibling; } } // Hauptabschnitt if (qeEnableSection0) { var heading = qeGetElementsByClassName('h1', 'firstHeading')[0]; if (!heading || !jumptonav) qeShowError('Section 0 nicht gefunden.'); else { // id verpassen heading.id = 'section-0'; // Knoten ins Array packen qeSections[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.nodeName.charAt(0) != '#') qeSections[0].push(node); node = node.nextSibling; } // Link hinzufügen var newspan = document.createElement('span'); newspan.style.fontSize = '8pt'; newspan.style.marginLeft = '10px'; 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(msStringU('edizio azkarra'))); newspan.appendChild(newlink); newspan.appendChild(document.createTextNode(']')); heading.appendChild(newspan); } } // qeEnableSection0 // Abschnitte for (i = 0; i < sections.length; i++) { // Section-Link suchen var link = sections[i].childNodes[1].href; var pos = link.search(/section=/); var section = link.substring(pos+8); // Sicherstellen dass nur gütlige Section-Nummern dort sind // (im Normalfall überflüssig, aber wer weiß) var j; for (j = 0; j < 2; j++) if (isNaN(section.charAt(j))) break; if (j == 0) continue; section = section.substring(0, j); //// sections[i].style.fontSize = '8pt'; // x-small sieht bei mir "doof" aus // 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(msStringU('edizio azkarra'))); 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 if (qeNewLinks) var hx = sections[i].parentNode; else { var hx = sections[i].nextSibling; while (hx != null && !/^H[1-6]$/.test(hx.nodeName)) hx = hx.nextSibling; } // auch ne ID verpassen hx.id = 'section-' + section; //// // alle zu dieser Section gehörigen Knoten suchen und ins Array packen qeSections[section] = new Array(); var node = hx.nextSibling; while (node != null && node.className != 'editsection' && node.className != 'printfooter' && !/^H[1-6]$/.test(node.nodeName)) { // nur echte knoten bitte if (node.nodeName.charAt(0) != '#') qeSections[section].push(node); node = node.nextSibling; } //// } } function qeEditSection(section) { section = parseInt(section); // könnte etwas suboptimal sein, reicht aber vorerst if (qeRequestState || !qeEditLink) return; // es wird bereits ein Abschnitt bearbeitet // wenn es der aktuelle ist -> Bearbeiten abbrechen, sonst nichts tun if (qeEdit != -1) { if (qeEdit == section) qeAbortEdit(section); return; } qeEdit = section; // Inhalt des Abschnitts ausblenden var nodes = qeSections[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 (links[i].id != 'sectionlink-' + qeEdit) links[i].style.color = '#bfbfbf'; } // Form anzeigen qeMakeForm(); var hx = document.getElementById('section-' + section); hx.parentNode.insertBefore(qeForm, hx.nextSibling); qeForm.childNodes[4].value = msStringU('irakurtzen') + '...'; //// qeGetSection(); } function qeAbortEdit() { if (qeEdit == -1) return; // Inhalt des Abschnitts wieder einblenden var nodes = qeSections[qeEdit]; 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 (links[i].id != 'sectionlink-' + qeEdit) links[i].style.color = null; } qeForm.parentNode.removeChild(qeForm); qeForm.childNodes[4].value = ''; qeEdit = -1; qeRequest.abort(); } function qeMakeForm() { if (qeForm) return; if (qeSections.length == 1) qeTextboxHeight += 10; // higher textbox for the main section only qeForm = document.createElement('form'); qeForm.method = 'post'; qeForm.onsubmit = qeSubmitByReturn; 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'), new Array('textarea', 'wpTextbox1'), new Array('input', 'hidden', 'wpEditToken'), new Array('input', 'hidden', 'wpAutoSummary') //, new Array('input', 'hidden', 'wpWatchthis') ); 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.rows = qeTextboxHeight; } qeForm.appendChild(newnode); } if (qeEnableAccessKeys) qeForm.childNodes[4].accessKey = ','; qeForm.childNodes[4].tabIndex = 1; newnode = document.createElement('div'); newnode.style.marginTop = '5px'; // Speichern newnode.appendChild(document.createElement('a')); newnode.firstChild.href = 'javascript:qeSubmit(0)'; newnode.firstChild.style.cursor = 'pointer'; newnode.firstChild.appendChild(document.createTextNode(msStringU('aldatu'))); if (qeEnableAccessKeys) newnode.firstChild.accessKey = 's'; // Vorschau newnode.appendChild(document.createTextNode(' ')); newnode.appendChild(document.createElement('a')); newnode.childNodes[2].href = 'javascript:qeSubmit(1)'; newnode.childNodes[2].style.marginLeft = '5px'; newnode.childNodes[2].style.cursor = 'pointer'; newnode.childNodes[2].appendChild(document.createTextNode(msStringU('aurrez ikusi'))); if (qeEnableAccessKeys) newnode.childNodes[2].accessKey = 'p'; // Abbrechen newnode.appendChild(document.createTextNode(' ')); newnode.appendChild(document.createElement('a')); newnode.childNodes[4].href = 'javascript:qeAbortEdit()'; newnode.childNodes[4].style.marginLeft = '5px'; newnode.childNodes[4].style.cursor = 'pointer'; newnode.childNodes[4].appendChild(document.createTextNode(msStringU('ezeztatu'))); if (qeEnableAccessKeys) newnode.childNodes[4].accessKey = 'a'; // Zusammenfassung newnode.appendChild(document.createTextNode(' ')); newnode.appendChild(document.createElement('input')); newnode.childNodes[6].type = 'text'; newnode.childNodes[6].size = '70'; newnode.childNodes[6].id = 'qeSummary'; newnode.childNodes[6].maxLength = '200'; newnode.childNodes[6].style.marginLeft = '5px'; newnode.childNodes[6].tabIndex = 2; // Kleine Änderung newnode.appendChild(document.createTextNode(' ')); var checkboxes = document.createElement('span'); checkboxes.style.whiteSpace = 'nowrap'; checkboxes.appendChild(document.createElement('input')); checkboxes.childNodes[0].type = 'checkbox'; checkboxes.childNodes[0].id = 'wpMinoredit'; checkboxes.childNodes[0].name = 'wpMinoredit'; checkboxes.childNodes[0].value = '1'; checkboxes.childNodes[0].style.marginLeft = '5px'; checkboxes.childNodes[0].tabIndex = 3; if (qeEnableAccessKeys) checkboxes.childNodes[0].accessKey = 'i'; checkboxes.appendChild(document.createElement('label')); checkboxes.childNodes[1].htmlFor = 'wpMinoredit'; checkboxes.childNodes[1].style.fontWeight = 'bold'; checkboxes.childNodes[1].appendChild(document.createTextNode(msStringU('k'))); // Beobachten checkboxes.appendChild(document.createTextNode(' ')); checkboxes.appendChild(document.createElement('input')); checkboxes.childNodes[3].type = 'checkbox'; checkboxes.childNodes[3].id = 'wpWatchthis'; checkboxes.childNodes[3].name = 'wpWatchthis'; checkboxes.childNodes[3].value = '1'; checkboxes.childNodes[3].style.marginLeft = '5px'; checkboxes.childNodes[3].tabIndex = 4; if (qeEnableAccessKeys) checkboxes.childNodes[3].accessKey = 'w'; checkboxes.appendChild(document.createElement('label')); checkboxes.childNodes[4].htmlFor = 'wpWatchthis'; checkboxes.childNodes[4].style.fontWeight = 'bold'; checkboxes.childNodes[4].appendChild(document.createTextNode(msStringU('b'))); newnode.appendChild(checkboxes); qeForm.appendChild(newnode); } function qeFillForm(formaction, wpStarttime, wpEdittime, wpSummary, wpTextbox1, wpEditToken, wpAutoSummary, wpWatchthis) { if (!qeForm) return; qeForm.childNodes[0].value = qeEdit; qeForm.childNodes[1].value = wpStarttime; qeForm.childNodes[2].value = wpEdittime; qeForm.childNodes[3].value = wpSummary; qeForm.childNodes[4].value = wpTextbox1; qeForm.childNodes[5].value = wpEditToken; qeForm.childNodes[6].value = wpAutoSummary; // qeForm.childNodes[7].name = wpWatchthis?'wpWatchthis':'dummy'; document.getElementById('wpWatchthis').checked = wpWatchthis; qeForm.action = formaction; document.getElementById('qeSummary').value = wpSummary; } // Ajax stuff function qeInitAjax() { try { if (window.XMLHttpRequest) { qeRequest = new XMLHttpRequest(); qeRequest.overrideMimeType('text/xml'); // netscape.security.PrivilegeManager.enablePrivilege('UniversalBrowserRead'); } else if (window.ActiveXObject) qeRequest = new ActiveXObject('Microsoft.XMLHTTP'); else throw 'Kein AJAX-Objekt vorhanden'; } catch (e) { qeShowError(e); return false; } if (!qeRequest) { qeShowError('AJAX-Objekt konnte nicht erstellt werden'); return false; } return true; } function qeGetSection() { if (qeEdit == -1 || !qeForm || !qeRequest || !qeEditLink || qeRequestState) return; var link = qeEditLink + qeEdit; qeRequestState = 1; qeRequest.onreadystatechange = qeAjaxResponse; qeRequest.open('GET', link, true); qeRequest.send(null); } function qeAjaxResponse() { if (!qeRequestState) { alert('QuickEdit Fehler: qeAjaxResponse'); return; } // receive if (qeRequestState == 1 && qeEdit != -1) { if (qeRequest.readyState != 4 || qeRequest.status != 200) return; qeRequestState = 0; var xml = qeRequest.responseXML; try // MediaWiki bug 6986 workaround { var wpTextbox1 = xml.getElementById('wpTextbox1').value; } catch (e) { xml = qeFixXML(qeRequest.responseText); if (!xml) { qeShowError('XML parsing fehlgeschlagen.'); return; } var wpTextbox1 = xml.getElementById('wpTextbox1').value; } var inputs = xml.getElementsByTagName('input'); for (i = 0; i < inputs.length; i++) { if (inputs[i].name == 'wpSection') wpSection = inputs[i].value; else if (inputs[i].name == 'wpStarttime') wpStarttime = inputs[i].value; else if (inputs[i].name == 'wpEdittime') wpEdittime = inputs[i].value; else if (inputs[i].name == 'wpSummary') wpSummary = inputs[i].value; else if (inputs[i].name == 'wpEditToken') wpEditToken = inputs[i].value; else if (inputs[i].name == 'wpAutoSummary') wpAutoSummary = inputs[i].value; else if (inputs[i].name == 'wpWatchthis') wpWatchthis = inputs[i].checked; } var formaction = xml.getElementById('editform').action; // sollte nie passieren, wenn doch -> fatal error if (wpSection != qeEdit) { qeAlert(msStringU('varmismatch')); qeRequestState = 0; qeAbortEdit(); return; } qeFillForm(formaction, wpStarttime, wpEdittime, wpSummary, wpTextbox1, wpEditToken, wpAutoSummary, wpWatchthis); } } function qeSubmitByReturn() { qeSubmit(0); return false; } function qeSubmit(preview) { if (qeEdit == -1 || !qeRequest || !qeForm || qeRequestState) return; qeForm.childNodes[3].value = document.getElementById('qeSummary').value; if (preview == 1) { var prev = document.createElement('input'); prev.name = 'wpPreview'; prev.value = 'Preview'; prev.type = 'hidden'; qeForm.appendChild(prev); } qeForm.submit(); } // MediaWiki bug 6986 workaround function qeFixXML(text) { var pos = text.indexOf('<h1 class="firstHeading">'); var pos2 = text.indexOf('</h1>'); if (pos == -1 || pos2 == -1) return null; text = text.substring(0, pos) + text.substring(pos2+5); var parser = new DOMParser(); var newdoc = parser.parseFromString(text, "text/xml"); return newdoc; } //</nowiki></pre>