Widget:ContactsPageWidget: различия между версиями
Перейти к навигации
Перейти к поиску
(Новая страница: «<noinclude>__NOTOC__ This widget created to hold some JavaScript code for Contacts Button custom behaiour </noinclude> <includeonly> <style> .wk2bUnAuthPopup { display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 300px; padding: 20px; background-color: white; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); border-radius: 8px; border: 1px solid rgb(167, 215, 249); text-align:...») |
Нет описания правки |
||
| (не показано 7 промежуточных версий этого же участника) | |||
| Строка 48: | Строка 48: | ||
function wk2bFuncTurnButtonIntoLink(buttonId) { | function wk2bFuncTurnButtonIntoLink(buttonId) { | ||
const targetButton = document.getElementById(buttonId); | |||
if (targetButton != undefined) { | |||
const linkToGo = targetButton.childNodes[1].childNodes[0].href.replace("source", "returnto"); | |||
const buttonText = targetButton.childNodes[1].childNodes[0].textContent; | |||
targetButton.childNodes[1].removeChild(targetButton.childNodes[1].childNodes[0]) | |||
targetButton.innerHTML = '<p>' + buttonText + '</p>'; | |||
targetButton.onclick = function() { | |||
window. Location = linkToGo; | |||
} | |||
} | |||
} | } | ||
| Строка 73: | Строка 73: | ||
wk2bFuncTurnButtonIntoLink(buttonLoginId); | wk2bFuncTurnButtonIntoLink(buttonLoginId); | ||
const targetDiv = document.getElementById(targetDivId); | const buttons = document.getElementsByClassName(targetDivId); | ||
if (buttons.length > 0) { | |||
for (let index in buttons) { | |||
const targetDiv = buttons[index]; | |||
console.log(mw.user); | |||
window.wk2bRedirectAddress = targetDiv.childNodes[1].childNodes[0].href; | |||
const redirectButtonText = targetDiv.childNodes[1].childNodes[0].textContent; | |||
targetDiv.childNodes[1].removeChild(targetDiv.childNodes[1].childNodes[0]) | |||
targetDiv.innerHTML = '<p>' + redirectButtonText + '</p>'; | |||
if (mw.user.tokens.values.csrfToken === | |||
mw.user.tokens.values.patrolToken && | |||
mw.user.tokens.values.patrolToken == | |||
mw.user.tokens.values.watchToken) { | |||
/* User is not authenticated */ | |||
targetDiv.onclick = wk2bFuncShowUnauthPopUp; | |||
document.getElementById("wk2bUnAuthPopup-close-btn").onclick = wk2bFuncHideUnauthPopUp; | |||
console.log("User is NOT authenticated") | |||
} else { | |||
targetDiv.onclick = wk2bFuncRedirectToContactsPage; | |||
console.log("User IS authenticated") | |||
} | |||
} | |||
} else { | |||
const targetDiv = document.getElementById(targetDivId); | |||
if (targetDivId != undefined) { | |||
console.log(mw.user); | |||
window.wk2bRedirectAddress = targetDiv.childNodes[1].childNodes[0].href; | |||
const redirectButtonText = targetDiv.childNodes[1].childNodes[0].textContent; | |||
targetDiv.childNodes[1].removeChild(targetDiv.childNodes[1].childNodes[0]) | |||
targetDiv.innerHTML = '<p>' + redirectButtonText + '</p>'; | |||
if (mw.user.tokens.values.csrfToken === | |||
mw.user.tokens.values.patrolToken && | |||
mw.user.tokens.values.patrolToken == | |||
mw.user.tokens.values.watchToken) { | |||
/* User is not authenticated */ | |||
targetDiv.onclick = wk2bFuncShowUnauthPopUp; | |||
document.getElementById("wk2bUnAuthPopup-close-btn").onclick = wk2bFuncHideUnauthPopUp; | |||
console.log("User is NOT authenticated") | |||
} else { | |||
targetDiv.onclick = wk2bFuncRedirectToContactsPage; | |||
console.log("User IS authenticated") | |||
} | |||
} else { | } else { | ||
console.log("Target div for contacts was not found") | |||
console.log(" | |||
} | } | ||
} | } | ||
}, | }, | ||
Текущая версия от 02:36, 8 августа 2025
This widget created to hold some JavaScript code for Contacts Button custom behaiour