MediaWiki:Gadget-block.js
// UWAGA! Z tego gadżetu korzystają także inne projekty
// Autor: [[User:Beau]], [[User:Msz2001]]
// Uwaga: Interakcje z komponentami Codex wymagają wysyłania zdarzeń (np. 'input') do odpowiednich
// elementów, aby zaktualizować model pod spodem. W przeciwnym razie zmiany są tylko wizualne.
window.blockGadget = {
version: 6,
init: function() {
if ( mw.config.get( "wgCanonicalSpecialPageName" ) != 'Blockip' && mw.config.get( "wgCanonicalSpecialPageName" ) != 'Block' ) {
return;
}
var disableUTEdit = document.querySelector( 'input[value=wpDisableUTEdit]' );
blockGadget.setInputValue( disableUTEdit, true );
var blockExpiryField = document.querySelector( '.mw-block-expiry-field' );
if ( blockExpiryField ) {
var customExpiryRadio = blockExpiryField.querySelector( 'input[name=expiryType][value=datetime]' );
var expContainer = document.createElement('div');
expContainer.style.padding = '3px';
expContainer.className = 'userSummaryButtons';
blockExpiryField.appendChild( expContainer );
for ( var caption in bk$times ) {
var newButton = document.createElement('a');
// atrybuty
// 'duration' jest w godzinach
newButton.dataset.duration = bk$times[caption];
newButton.onclick = function() {
// Tak, parsowanie dat w JS jest paskudne
var duration = parseFloat(this.dataset.duration);
duration *= 1000 * 3600;
var expiryTime = blockGadget.dateToString(new Date( Date.now() + duration ));
blockGadget.setInputValue( customExpiryRadio, true );
var setExpiryInterval = setInterval( function() {
// Ten element się dynamicznie dodaje
var wpBlockOther = document.querySelector( '[name=wpExpiry-other]' );
if ( !wpBlockOther ) return;
blockGadget.setInputValue( wpBlockOther, expiryTime );
clearInterval( setExpiryInterval );
}, 50 );
};
newButton.appendChild( document.createTextNode( caption ) );
// dodanie przycisku
expContainer.appendChild( newButton );
}
}
var wpBlockReasonList = document.querySelector( '[name=wpReason]' );
var wpBlockOtherReason = document.querySelector( '[name=wpReason-other]' );
if ( wpBlockReasonList ) {
var blockWrapper = wpBlockReasonList.parentNode.parentNode;
var summContainer = document.createElement('div');
summContainer.style.padding = '3px';
summContainer.className = 'userSummaryButtons';
blockWrapper.appendChild( summContainer );
for ( var i in bk$reasons ) {
var item = bk$reasons[i];
var newButton = document.createElement( 'a' );
// atrybuty
newButton.item = item;
newButton.title = item.reason;
newButton.onclick = function() {
blockGadget.setInputValue( wpBlockOtherReason, this.title );
if ( this.item.callback ) {
this.item.callback( item );
}
};
newButton.appendChild( document.createTextNode( item.caption ) );
// dodanie przycisku
summContainer.appendChild( newButton );
}
}
},
setInputValue: function( inputElem, value ) {
if ( !inputElem ) return;
// Wysłanie zdarzenia 'input' lub 'change' jest konieczne, inaczej wartość w polu
// będzie tylko wyświetlana, ale model pod spodem nie zostanie zaktualizowany.
if ( inputElem.type == 'checkbox' || inputElem.type == 'radio' ) {
inputElem.checked = value;
var changeEvent = new Event( 'change' );
inputElem.dispatchEvent( changeEvent );
} else {
inputElem.value = value;
var inputEvent = new InputEvent( 'input', {
inputType: 'insertText',
data: value,
} );
inputElem.dispatchEvent( inputEvent );
}
},
/**
* Converts a date to YYYY-MM-DDTHH:MM format, with local timezone.
*/
dateToString: function( date ) {
var year = date.getFullYear();
var month = date.getMonth() + 1;
if ( month < 10 ) {
month = '0' + month;
}
var day = date.getDate();
if ( day < 10 ) {
day = '0' + day;
}
var hour = date.getHours();
if ( hour < 10 ) {
hour = '0' + hour;
}
var minute = date.getMinutes();
if ( minute < 10 ) {
minute = '0' + minute;
}
return year + '-' + month + '-' + day + 'T' + hour + ':' + minute;
}
};
jQuery(document).ready(function() {
if ( document.querySelectorAll('[name=wpReason-other]').length > 0 ) {
blockGadget.init();
return;
}
// Codex form is lazily-loaded and has no hook, so we have to resort to this ugly hack
var observer = new MutationObserver(function(mutations) {
for ( var i = 0; i < mutations.length; i++ ) {
var mutation = mutations[i];
if ( mutation.type == 'childList' ) {
for ( var j = 0; j < mutation.addedNodes.length; j++ ) {
var node = mutation.addedNodes[j];
if ( node.nodeType != 1 || !node.querySelectorAll) {
continue;
}
var inputs = node.querySelectorAll('[name=wpReason-other]');
if ( inputs.length > 0 ) {
blockGadget.init();
observer.disconnect();
}
}
}
}
});
var contentWrapper = document.getElementById('mw-content-text');
if ( !contentWrapper ) {
return;
}
observer.observe(contentWrapper, {
subtree: true,
childList: true
});
});
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.