MediaWiki

Gadget-sandbox.js

From Dogcraft Wiki

(middleclick didnt prevent default with mouseup for some reason)
(preventing middle click mousedown default too)
Line 6: Line 6:
function confirmDialog( event ) {
function confirmDialog( event ) {
event.preventDefault();
if (event.data.clickType == "middle")
if (event.data.clickType == "middle")
if (event.originalEvent.which != 2) return;
if (event.originalEvent.which != 2) return;
event.preventDefault();
     
     
OO.ui.confirm( 'Are you sure?' ).done( function ( confirmed ) {
OO.ui.confirm( 'Are you sure?' ).done( function ( confirmed ) {
Line 27: Line 27:
$( function () {
$( function () {
var button = new OO.ui.ButtonWidget( {
/*var button = new OO.ui.ButtonWidget( {
label: 'Click me!',
label: 'Click me!',
classes: [ 'confirm-sandbox' ]
classes: [ 'confirm-sandbox' ]
});
});
//button.on( 'click', function () {
$( '#mw-content-text' ).append( button.$element );*/
//alert( 'You clicked the button!' );
/*OO.ui.alert( 'Something happened!' ).done( function () {
    console.log( 'User closed the dialog.' );
});*/
/*OO.ui.confirm( 'Are you sure?' ).done( function ( confirmed ) {
    if ( confirmed ) {
        console.log( 'User clicked "OK"!' );
    } else {
        console.log( 'User clicked "Cancel" or closed the dialog.' );
    }
});
});*/
$( '#mw-content-text' ).append( button.$element );
$( '.page-User_Domino_Sandbox a[href="https://discord.gg/r5xDRcy"]' ).on('click', {clickType: "click"}, confirmDialog);
$( '.page-User_Domino_Sandbox a[href="https://discord.gg/r5xDRcy"]' ).on('click', {clickType: "click"}, confirmDialog);
$( '.page-User_Domino_Sandbox a[href="https://discord.gg/r5xDRcy"]' ).on('mouseup', {clickType: "middle"}, confirmDialog);
$( '.page-User_Domino_Sandbox a[href="https://discord.gg/r5xDRcy"]' ).on('mouseup', {clickType: "middle"}, confirmDialog);
$( '.page-User_Domino_Sandbox a[href="https://discord.gg/r5xDRcy"]' ).on('mousedown', function( event ){
if (event.originalEvent.which != 2) return;
event.preventDefault();
});
});
});

Revision as of 22:49, 2 December 2021

$(document).ready(function() {
	
	if (mw.config.get('wgPageName') === 'User:Domino/Sandbox') {
		
		mw.loader.using( ['oojs-ui-core', 'oojs-ui-widgets', 'oojs-ui-windows'] ).done( function () {
			
			function confirmDialog( event ) {
						if (event.data.clickType == "middle")
							if (event.originalEvent.which != 2) return;
							
						event.preventDefault();
					    
						OO.ui.confirm( 'Are you sure?' ).done( function ( confirmed ) {
	    					if ( confirmed ) {
	        					switch(event.data.clickType) {
	        						case "click":
	        							window.location.href = event.target.href;
	        							break;
        							case "middle":
        								window.open(event.target.href, "_blank");
        								break;
	        					}
	        				}
	        					
	    				});
					}
			
			$( function () {
				/*var button = new OO.ui.ButtonWidget( {
					label: 'Click me!',
					classes: [ 'confirm-sandbox' ]
				});
				$( '#mw-content-text' ).append( button.$element );*/
				
				$( '.page-User_Domino_Sandbox a[href="https://discord.gg/r5xDRcy"]' ).on('click', {clickType: "click"}, confirmDialog);
				$( '.page-User_Domino_Sandbox a[href="https://discord.gg/r5xDRcy"]' ).on('mouseup', {clickType: "middle"}, confirmDialog);
				$( '.page-User_Domino_Sandbox a[href="https://discord.gg/r5xDRcy"]' ).on('mousedown', function( event ){
					if (event.originalEvent.which != 2) return;
					event.preventDefault();
				});
				
				
			});
		});
		
	}
	
});
This page was last modified on 2 December 2021, at 22:49. (2 years ago)
Background SRN Opening by Montenator