„Benutzer:Ireas/irset.js“ – Versionsunterschied
Erscheinungsbild
Inhalt gelöscht Inhalt hinzugefügt
Ireas (Diskussion | Beiträge) K Begründung in die Zusammenfassung |
Ireas (Diskussion | Beiträge) fix #3 |
||
Zeile 79: | Zeile 79: | ||
body.appendChild(ul); |
body.appendChild(ul); |
||
var |
var addedSomething = false; |
||
for (var i in IRSet.sidebarElements) { |
for (var i in IRSet.sidebarElements) { |
||
Zeile 85: | Zeile 85: | ||
var li = document.createElement("li"); |
var li = document.createElement("li"); |
||
⚫ | |||
var addedItem = false; |
|||
for (var j in item) { |
for (var j in item) { |
||
Zeile 97: | Zeile 98: | ||
a.style.cursor = "default"; |
a.style.cursor = "default"; |
||
li.appendChild(a); |
li.appendChild(a); |
||
addedItem = true; |
|||
addedSomething = true; |
|||
} |
} |
||
} catch (e) { |
} catch (e) { |
||
} |
|||
if (addedItem) { |
|||
⚫ | |||
} |
} |
||
} |
} |
||
Zeile 109: | Zeile 115: | ||
error("There seems to be no navigation ..."); |
error("There seems to be no navigation ..."); |
||
} |
} |
||
if ( |
if (addedSomething) { |
||
navi.parentNode.insertBefore(div, navi); |
navi.parentNode.insertBefore(div, navi); |
||
} |
} |
Version vom 15. März 2010, 07:52 Uhr
/* irset.js */
// <nowiki>
var IRSet = {
/* the items of our sidebar */
sidebarElements: new Array(
// first column
new Array(
// addSLA (SLA+)
new Array(
function() {
return !IRSet.isSpecial();
},
new Array( "SLA+",
function() { IRSet.addSLA(); }
)
)
)
),
/* is this page a special page? */
isSpecial: function() {
return (wgCanonicalNamespace == "Special");
},
/* are we in edit mode? */
isEdit: function() {
return (wgAction == "edit");
},
/* are we in submit mode? */
isSubmit: function() {
return (wgAction == "submit");
},
/* open this page in edit mode */
openEdit: function(app) {
var url = wgServer + wgScript + "?title=" + encodeURIComponent(wgPageName) + "&action=edit&" + app;
window.location = url;
},
/* parse the URL and return the GET param */
getURLParam: function(key) {
var nkey = key.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + nkey + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.href);
if (results == null) {
return "";
} else {
return results[1];
}
},
/* create the sidebar and fill it */
init: function() {
IRSet.createSidebar();
if (IRSet.getURLParam("irsla").trim() == "1" && IRSet.getURLParam("irreason").trim() != "") {
IRSet.doSLA(unescape(IRSet.getURLParam("irreason").trim()));
}
},
/* create the sidebar */
createSidebar: function() {
var div = document.createElement("div");
div.id = "p-irset";
div.className = "portal";
var heading = document.createElement("h5");
heading.innerHTML = "Tools";
div.appendChild(heading);
var body = document.createElement("div");
body.className = "body";
div.appendChild(body);
var ul = document.createElement("ul");
body.appendChild(ul);
var addedSomething = false;
for (var i in IRSet.sidebarElements) {
var item = IRSet.sidebarElements[i];
var li = document.createElement("li");
var addedItem = false;
for (var j in item) {
var link = item[j];
try {
if (link[0]()) {
var a = document.createElement("a");
a.textContent = link[1][0];
a.onclick = link[1][1];
a.style.cursor = "default";
li.appendChild(a);
addedItem = true;
addedSomething = true;
}
} catch (e) {
}
if (addedItem) {
ul.appendChild(li);
}
}
}
var navi = document.getElementById('p-navigation');
if (!navi) {
error("There seems to be no navigation ...");
}
if (addedSomething) {
navi.parentNode.insertBefore(div, navi);
}
},
/* add a SLA to the current page */
addSLA: function() {
var defreason = "Kein Artikel";
var reason = prompt("SLA-Grund:", defreason);
if (reason.trim() != "") {
if (IRSet.isEdit() || IRSet.isSubmit()) {
IRSet.doSLA(reason);
} else {
IRSet.openEdit("irsla=1&irreason=" + escape(reason));
}
}
},
/* really add SLA */
doSLA: function(reason) {
if (!document.getElementById("wpTextbox1").value.match(/{{(Löschen|SLA)\|.+?}}/) && document.getElementById("wpTextbox1").value != "") {
IRSet.insertAtBegin("{{Löschen|''" + reason.trim() + " ~~~~''}}\n\n", "SLA: " + reason.trim(), true);
}
},
/* insert the given string at the beginning of the page */
insertAtBegin: function(code, summary, save) {
if (IRSet.isEdit() || IRSet.isSubmit()) {
var textbox = document.getElementById("wpTextbox1");
var value = textbox.value;
var newvalue = code + value;
textbox.value = newvalue;
document.getElementById("wpSummary").value = summary;
if (save) {
document.getElementById("wpSave").click();
}
}
}
}
addOnloadHook(IRSet.init);
//</nowiki>