MediaWiki
Gadget-editButton.js
From Dogcraft Wiki
m (Added Read support in edit mode) |
m (one less getElementById typeerror) |
||
| (2 intermediate revisions by the same user not shown) | |||
| Line 5: | Line 5: | ||
var wikiEdit = document.createElement("a"); | var wikiEdit = document.createElement("a"); | ||
wikiEdit.setAttribute("id", "wikiEdit"); | wikiEdit.setAttribute("id", "wikiEdit"); | ||
wikiEdit.setAttribute("class", "button"); | if (action === 'edit') { | ||
wikiEdit.setAttribute("class", "button editButton-view"); | |||
wikiEdit.setAttribute("href", "/wiki/index.php?title=" + mw.config.get('wgPageName')) | wikiEdit.setAttribute("href", "/wiki/index.php?title=" + mw.config.get('wgPageName')) | ||
else { | } else { | ||
if (namespace === 14 || namespace === 3004 || namespace == 2 || namespace == 0) | if (namespace === 14 || namespace === 3004 || namespace == 2 || namespace == 0) { | ||
wikiEdit.setAttribute("class", "button editButton-edit"); | |||
wikiEdit.setAttribute("href", "/wiki/index.php?title=" + mw.config.get('wgPageName') + "&veaction=edit") | wikiEdit.setAttribute("href", "/wiki/index.php?title=" + mw.config.get('wgPageName') + "&veaction=edit") | ||
else | } else { | ||
wikiEdit.setAttribute("class", "button editButton-editSource"); | |||
wikiEdit.setAttribute("href", "/wiki/index.php?title=" + mw.config.get('wgPageName') + "&action=edit") | wikiEdit.setAttribute("href", "/wiki/index.php?title=" + mw.config.get('wgPageName') + "&action=edit") | ||
} | |||
} | } | ||
| Line 41: | Line 43: | ||
wikiEditButton.appendChild(wikiEditButtonLabel); | wikiEditButton.appendChild(wikiEditButtonLabel); | ||
document.getElementById("wikiActions").before(wikiEdit); | var wikiActions = document.getElementById("wikiActions") | ||
if (wikiActions) wikiActions.before(wikiEdit); | |||
}) | }) | ||
Latest revision as of 21:52, 25 January 2025
$( function () {
var namespace = mw.config.get('wgNamespaceNumber');
var action = mw.config.get('wgAction');
var wikiEdit = document.createElement("a");
wikiEdit.setAttribute("id", "wikiEdit");
if (action === 'edit') {
wikiEdit.setAttribute("class", "button editButton-view");
wikiEdit.setAttribute("href", "/wiki/index.php?title=" + mw.config.get('wgPageName'))
} else {
if (namespace === 14 || namespace === 3004 || namespace == 2 || namespace == 0) {
wikiEdit.setAttribute("class", "button editButton-edit");
wikiEdit.setAttribute("href", "/wiki/index.php?title=" + mw.config.get('wgPageName') + "&veaction=edit")
} else {
wikiEdit.setAttribute("class", "button editButton-editSource");
wikiEdit.setAttribute("href", "/wiki/index.php?title=" + mw.config.get('wgPageName') + "&action=edit")
}
}
var wikiEditButton = document.createElement("button");
wikiEdit.appendChild(wikiEditButton);
var wikiEditButtonIcon = document.createElement("i");
if (action === "edit")
wikiEditButtonIcon.setAttribute("class", "fas fa-file");
else {
if (namespace === 14 || namespace === 3004 || namespace == 2 || namespace == 0)
wikiEditButtonIcon.setAttribute("class", "fas fa-pencil");
else
wikiEditButtonIcon.setAttribute("class", "fas fa-code");
}
wikiEditButton.appendChild(wikiEditButtonIcon);
var wikiEditButtonLabel = document.createElement("span");
if (action === "edit")
wikiEditButtonLabel.innerText = " Read";
else {
if (namespace === 14 || namespace === 3004 || namespace == 2 || namespace == 0)
wikiEditButtonLabel.innerText = " Edit";
else
wikiEditButtonLabel.innerText = " Edit source";
}
wikiEditButton.appendChild(wikiEditButtonLabel);
var wikiActions = document.getElementById("wikiActions")
if (wikiActions) wikiActions.before(wikiEdit);
})