MediaWiki:Common.js: Difference between revisions
No edit summary |
No edit summary |
||
| Line 90: | Line 90: | ||
$('#t-log').after(chkusr); | $('#t-log').after(chkusr); | ||
} | } | ||
/** | |||
* Add support to mw-collapsible for autocollapse, innercollapse and outercollapse | |||
* | |||
* Maintainers: TheDJ | |||
*/ | |||
function mwCollapsibleSetup( $collapsibleContent ) { | |||
var $element, | |||
$toggle, | |||
autoCollapseThreshold = 2; | |||
$.each( $collapsibleContent, function ( index, element ) { | |||
$element = $( element ); | |||
if ( $element.hasClass( 'collapsible' ) ) { | |||
$element.find( 'tr:first > th:first' ).prepend( $element.find( 'tr:first > * > .mw-collapsible-toggle' ) ); | |||
} | |||
if ( $collapsibleContent.length >= autoCollapseThreshold && $element.hasClass( 'autocollapse' ) ) { | |||
$element.data( 'mw-collapsible' ).collapse(); | |||
} else if ( $element.hasClass( 'innercollapse' ) ) { | |||
if ( $element.parents( '.outercollapse' ).length > 0 ) { | |||
$element.data( 'mw-collapsible' ).collapse(); | |||
} | |||
} | |||
// because of colored backgrounds, style the link in the text color | |||
// to ensure accessible contrast | |||
$toggle = $element.find( '.mw-collapsible-toggle' ); | |||
if ( $toggle.length ) { | |||
// Make the toggle inherit text color (Updated for T333357 2023-04-29) | |||
if ( $toggle.parent()[ 0 ].style.color ) { | |||
$toggle.css( 'color', 'inherit' ); | |||
$toggle.find( '.mw-collapsible-text' ).css( 'color', 'inherit' ); | |||
} | |||
} | |||
} ); | |||
} | |||
mw.hook( 'wikipage.collapsibleContent' ).add( mwCollapsibleSetup ); | |||
}); | }); | ||
Revision as of 19:29, 26 December 2024
/* Any JavaScript here will be loaded for all users on every page load. */
mw.loader.using(['mediawiki.api']).then(function () {
function addToDMZ() {
var api = new mw.Api();
api.postWithToken('csrf', {
action: 'edit',
title: 'DMZ:Users',
appendtext: '\n* ' + mw.config.get('wgUserName'), // Append the current user's name
summary: 'User self-added to DMZ'
}).done(function (response) {
if (response.edit && response.edit.result === 'Success') {
alert('You have been added to the DMZ.');
// Notify administrators
api.postWithToken('csrf', {
action: 'edit',
title: 'User_talk:Admin',
appendtext: '\n* ' + mw.config.get('wgUserName') + ' added themselves to the DMZ.',
summary: 'Notifying admins of DMZ addition'
});
} else {
alert('Error: Unable to add to DMZ.');
}
}).fail(function () {
alert('Error contacting the API.');
});
}
$(document).on('click', '.addToDMZLink', function (e) {
e.preventDefault();
addToDMZ();
});
$( document ).ready(function() {
var audioElem = $('#file.fullImageLink a[href$=".mp3"], #file.fullImageLink a[href$=".wav"], #file.fullImageLink a[href$=".aac"], #file.fullImageLink a[href$=".flac"]');
var displayAudio = $('<audio controls />');
displayAudio.attr('src', audioElem.attr('href'));
displayAudio.attr('onclick', 'return false;');
audioElem.html(displayAudio);
var videoElem = $('#file.fullImageLink a[href$=".mp4"], #file.fullImageLink a[href$=".ogg"], #file.fullImageLink a[href$=".webm"], #file.fullImageLink a[href$=".wmv"]');
var displayVideo = $('<video controls />');
displayVideo.attr('src', videoElem.attr('href'));
displayVideo.attr('onclick', 'return false;');
videoElem.html(displayVideo);
});
if ( mw.config.get( 'wgIsArticle' ) && !mw.config.get( 'wgPageName' ).startsWith('File:') ) {
$('a[title^="File:"][title$=".mp3"], a[title^="File:"][title$=".wav"], a[title^="File:"][title$=".aac"], a[title^="File:"][title$=".flac"]').each(function (index, item) {
var mediaControl = $('<audio controls />');
mediaControl.attr('class', 'mw-file-element');
mediaControl.attr('onclick', 'return false;');
mediaControl.attr('src', '/wiki/index.php/Special:Filepath/' + item.textContent.split('File:')[1]);
$(item).html(mediaControl);
});
$('a[title^="File:"][title$=".mp4"], a[title^="File:"][title$=".ogg"], a[title^="File:"][title$=".webm"], a[title^="File:"][title$=".wmv"]').each(function (index, item) {
var mediaControl = $('<video controls />');
mediaControl.attr('class', 'mw-file-element');
mediaControl.attr('onclick', 'return false;');
mediaControl.attr('src', '/wiki/index.php/Special:Filepath/' + item.textContent.split('File:')[1]);
$(item).html(mediaControl);
});
$('span[typeof="mw:File"] .mw-file-description[href$=".webm"]').each(function (index, item) {
var mediaControl = $('<video controls />');
mediaControl.attr('class', 'mw-file-element');
mediaControl.attr('onclick', 'return false;');
mediaControl.attr('src', '/wiki/index.php/Special:Filepath/' + $(item).attr('href').split('/wiki/index.php/File:')[1]);
$(item).html(mediaControl);
});
$('.player-mini[data-file]').each(function (index, item) {
var mediaControl = $('<audio/>');
mediaControl.attr('class', 'mw-file-element');
mediaControl.attr('src', '/wiki/index.php/Special:Filepath/' + $(item).attr('data-file'));
$(item).find('span').after(mediaControl);
});
$('.player-mini').click(function(){
$(this).find('audio').trigger( $(this).find('audio').prop('paused') ? 'play' : 'pause');
});
}
if ( mw.config.get( 'wgUserGroups' ).includes('checkuser') ) {
var chkusr = $('<li />');
chkusr.attr('id', 't-checkuser');
chkusr.attr('class', 'mw-list-item');
chkusr.html('<a href="/wiki/index.php/Special:CheckUser/' + mw.config.get('wgPageName').split(':')[1] + '"><span>Check user</span></a>');
$('#t-log').after(chkusr);
}
/**
* Add support to mw-collapsible for autocollapse, innercollapse and outercollapse
*
* Maintainers: TheDJ
*/
function mwCollapsibleSetup( $collapsibleContent ) {
var $element,
$toggle,
autoCollapseThreshold = 2;
$.each( $collapsibleContent, function ( index, element ) {
$element = $( element );
if ( $element.hasClass( 'collapsible' ) ) {
$element.find( 'tr:first > th:first' ).prepend( $element.find( 'tr:first > * > .mw-collapsible-toggle' ) );
}
if ( $collapsibleContent.length >= autoCollapseThreshold && $element.hasClass( 'autocollapse' ) ) {
$element.data( 'mw-collapsible' ).collapse();
} else if ( $element.hasClass( 'innercollapse' ) ) {
if ( $element.parents( '.outercollapse' ).length > 0 ) {
$element.data( 'mw-collapsible' ).collapse();
}
}
// because of colored backgrounds, style the link in the text color
// to ensure accessible contrast
$toggle = $element.find( '.mw-collapsible-toggle' );
if ( $toggle.length ) {
// Make the toggle inherit text color (Updated for T333357 2023-04-29)
if ( $toggle.parent()[ 0 ].style.color ) {
$toggle.css( 'color', 'inherit' );
$toggle.find( '.mw-collapsible-text' ).css( 'color', 'inherit' );
}
}
} );
}
mw.hook( 'wikipage.collapsibleContent' ).add( mwCollapsibleSetup );
});