MediaWiki

Gadget-editButton.js

From Dogcraft Wiki

mNo edit summary
m (Added Read support in edit mode)
Line 1: Line 1:
$( function () {
$( function () {
var namespace = mw.config.get('wgNamespaceNumber');
var namespace = mw.config.get('wgNamespaceNumber');
var action = mw.config.get('wgAction');
var wikiEdit = document.createElement("a");
var wikiEdit = document.createElement("a");
Line 6: Line 7:
wikiEdit.setAttribute("class", "button");
wikiEdit.setAttribute("class", "button");
if (namespace === 14 || namespace === 3004 || namespace == 2 || namespace == 0)
if (action === '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'))
else
else {
wikiEdit.setAttribute("href", "/wiki/index.php?title=" + mw.config.get('wgPageName') + "&action=edit")
if (namespace === 14 || namespace === 3004 || namespace == 2 || namespace == 0)
wikiEdit.setAttribute("href", "/wiki/index.php?title=" + mw.config.get('wgPageName') + "&veaction=edit")
else
wikiEdit.setAttribute("href", "/wiki/index.php?title=" + mw.config.get('wgPageName') + "&action=edit")
}
var wikiEditButton = document.createElement("button");
var wikiEditButton = document.createElement("button");
Line 15: Line 20:
var wikiEditButtonIcon = document.createElement("i");
var wikiEditButtonIcon = document.createElement("i");
if (namespace === 14 || namespace === 3004 || namespace == 2 || namespace == 0)
if (action === "edit")
wikiEditButtonIcon.setAttribute("class", "fas fa-pencil");
wikiEditButtonIcon.setAttribute("class", "fas fa-file");
else  
else {
wikiEditButtonIcon.setAttribute("class", "fas fa-code");
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);
wikiEditButton.appendChild(wikiEditButtonIcon);
var wikiEditButtonLabel = document.createElement("span");
var wikiEditButtonLabel = document.createElement("span");
if (namespace === 14 || namespace === 3004 || namespace == 2 || namespace == 0)
if (action === "edit")
wikiEditButtonLabel.innerText = " Edit";
wikiEditButtonLabel.innerText = " Read";
else  
else {
wikiEditButtonLabel.innerText = " Edit source";
if (namespace === 14 || namespace === 3004 || namespace == 2 || namespace == 0)
wikiEditButtonLabel.innerText = " Edit";
else  
wikiEditButtonLabel.innerText = " Edit source";
}
wikiEditButton.appendChild(wikiEditButtonLabel);
wikiEditButton.appendChild(wikiEditButtonLabel);
document.getElementById("wikiActions").before(wikiEdit);
document.getElementById("wikiActions").before(wikiEdit);
})
})

Revision as of 00:59, 6 September 2024

$( function () {
	var namespace = mw.config.get('wgNamespaceNumber');
	var action = mw.config.get('wgAction');
	
	var wikiEdit = document.createElement("a");
	wikiEdit.setAttribute("id", "wikiEdit");
	wikiEdit.setAttribute("class", "button");
	
	if (action === 'edit')
		wikiEdit.setAttribute("href", "/wiki/index.php?title=" + mw.config.get('wgPageName'))
	else {
		if (namespace === 14 || namespace === 3004 || namespace == 2 || namespace == 0)
			wikiEdit.setAttribute("href", "/wiki/index.php?title=" + mw.config.get('wgPageName') + "&veaction=edit")
		else
			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);
	
	document.getElementById("wikiActions").before(wikiEdit);
})
This page was last modified on 6 September 2024, at 00:59. (2 months ago)
Background Takeshi by Edo