MediaWiki

Gadget-sandbox.js

From Dogcraft Wiki

m (-)
(testing middleclick)
 
(10 intermediate revisions by the same user not shown)
Line 4: Line 4:
mw.loader.using( ['oojs-ui-core', 'oojs-ui-widgets', 'oojs-ui-windows'] ).done( function () {
mw.loader.using( ['oojs-ui-core', 'oojs-ui-widgets', 'oojs-ui-windows'] ).done( function () {
function confirmDialoge() {
return (OO.ui.confirm( 'Are you sure?' ).done( function ( confirmed ) {
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 ) {
    if ( confirmed ) {
        console.log( 'User clicked "OK"!' );
        switch(event.data.clickType) {
        //window.location.href = e.target.href;
        case "click":
        return true;
        window.location.href = event.target.href;
    } else {
        break;
        console.log( 'User clicked "Cancel" or closed the dialog.' );
        case "middle":
        return false;
        window.open(event.target.href, "_blank");
    }
        break;
}));
        }
        }
       
    });
}
}
function inviteClicked(callback) {
if (callback) {
return true;
} else {
return false;
}
return -1;
}
$( 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 () {
/*$( '.page-User_Domino_Sandbox a[href="https://discord.gg/r5xDRcy"]' ).on('click', {clickType: "click"}, confirmDialog);*/
    console.log( 'User closed the dialog.' );
$( '.page-User_Domino_Sandbox a[href="https://discord.gg/r5xDRcy"]' ).on('mouseup', {clickType: "middle"}, false/*confirmDialog*/);
});*/
//$( '.page-User_Domino_Sandbox a[href="https://discord.gg/r5xDRcy"]' ).on('mousedown', false/*function( event ){
/*OO.ui.confirm( 'Are you sure?' ).done( function ( confirmed ) {
if (event.originalEvent.which != 2) return;
    if ( confirmed ) {
event.preventDefault();
        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', inviteClicked(confirmDialoge));
/*function (e) {
e.preventDefault();
console.log('1');
var result = confirmDialoge();
console.log('3');
return result;
});*/
});
});

Latest revision as of 00:31, 18 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"}, false/*confirmDialog*/);
				//$( '.page-User_Domino_Sandbox a[href="https://discord.gg/r5xDRcy"]' ).on('mousedown', false/*function( event ){
					if (event.originalEvent.which != 2) return;
					event.preventDefault();
				//}*///);
				
				
			});
		});
		
	}
	
});