MediaWiki:Gadget-dialogue-options.js: Difference between revisions

MediaWiki interface page
Content added Content deleted
(added cookies)
mNo edit summary
 
(9 intermediate revisions by the same user not shown)
Line 1: Line 1:
( function ( $, mw ) {
mw.loader.using( ['oojs-ui-core', 'oojs-ui-widgets'] ).done( function() {
'use strict';
function makeLangToggle() {
function makeLangToggle() {
var toggle = new OO.ui.ButtonSelectWidget( {
var toggle = new OO.ui.ButtonSelectWidget( {
items: [
items: [
new OO.ui.ButtonOptionWidget({ data: 'en', label: 'English' }),
new OO.ui.ButtonOptionWidget( { data: 'en', label: 'English' } ),
new OO.ui.ButtonOptionWidget({ data: 'jp', label: 'Japanese' }),
new OO.ui.ButtonOptionWidget( { data: 'jp', label: 'Japanese' } ),
new OO.ui.ButtonOptionWidget({ data: 'both', label: 'Both' })
new OO.ui.ButtonOptionWidget( { data: 'both', label: 'Both' } )
],
],
align: 'left'
align: 'left'
Line 36: Line 37:
var cookie_val = $.cookie( 'dialogue_lang' );
var cookie_val = $.cookie( 'dialogue_lang' );
if ( cookie_val !== 'en' && cookie_val !== 'jp' && cookie_val !== 'both' ) {
if ( cookie_val !== 'en' && cookie_val !== 'jp' && cookie_val !== 'both' ) {
toggle.selectItemByData('en');
toggle.selectItemByData( 'both' );
} else {
} else {
toggle.selectItemByData(cookie_val);
toggle.selectItemByData( cookie_val );
}
}
Line 47: Line 48:
var toggle = new OO.ui.ButtonSelectWidget( {
var toggle = new OO.ui.ButtonSelectWidget( {
items: [
items: [
new OO.ui.ButtonOptionWidget({ data: 'cozy', label: 'Cozy' }),
new OO.ui.ButtonOptionWidget( { data: 'modern', label: 'Modern' } ),
new OO.ui.ButtonOptionWidget({ data: 'compact', label: 'Compact' }),
new OO.ui.ButtonOptionWidget( { data: 'traditional', label: 'Traditional' } ),
],
],
align: 'left'
align: 'left'
} );
} );
function changeClass( value, $elem ) {
if ( value === 'cozy' ) {
$elem.removeClass( 'compact' );
$elem.addClass( 'cozy' );
} else if ( value === 'compact' ) {
$elem.removeClass( 'cozy' );
$elem.addClass( 'compact' );
}
}
function layoutToggle( item, selected ) {
function layoutToggle( item, selected ) {
$.cookie( 'dialogue_layout', item.getData(), { expires: 365, path: '/' } );
$.cookie( 'dialogue_layout', item.getData(), { expires: 365, path: '/' } );
$( '.dialogue' ).each( function() {
$( '.dialogue, .dialogue-scene, .dialogue-sfx, .dialogue-image' ).each ( function() {
changeClass( item.getData(), $( this ) );
if ( item.getData() === 'modern' ) {
$( this ).removeClass( 'traditional' );
} );
$( '.dialogue-scene' ).each( function() {
$( this ).addClass( 'modern' );
changeClass( item.getData(), $( this ) );
} else if ( item.getData() === 'traditional' ) {
$( this ).removeClass( 'modern' );
$( this ).addClass( 'traditional' );
}
} );
} );
}
}
toggle.on( 'choose', layoutToggle );
toggle.on( 'choose', layoutToggle );
Line 79: Line 72:
var cookie_val = $.cookie( 'dialogue_layout' );
var cookie_val = $.cookie( 'dialogue_layout' );
if ( cookie_val !== 'cozy' && cookie_val !== 'compact' ) {
if ( cookie_val !== 'modern' && cookie_val !== 'traditional' ) {
toggle.selectItemByData('cozy');
toggle.selectItemByData( 'modern' );
} else {
} else {
toggle.selectItemByData(cookie_val);
toggle.selectItemByData( cookie_val );
}
}
Line 90: Line 83:
function makeColorToggle() {
function makeColorToggle() {
var toggle = new OO.ui.CheckboxInputWidget( {
var toggle = new OO.ui.CheckboxInputWidget( {
value: 'colorized',
value: 'colorized'
selected: false
} );
} );
function colorToggle( selected ) {
toggle.on( 'change', function( selected ) {
$.cookie( 'dialogue_colorized', selected, { expires: 365, path: '/' } );
$.cookie( 'dialogue_colorized', selected, { expires: 365, path: '/' } );
Line 107: Line 99:
}
}
} );
} );
}
} );
toggle.on( 'change', colorToggle );
var cookie_val = $.cookie( 'dialogue_colorized' );
var cookie_val = $.cookie( 'dialogue_colorized' );
if ( cookie_val !== null ) {
if ( cookie_val !== null ) {
toggle.setSelected( cookie_val );
toggle.setSelected( cookie_val === 'true' );
}
}
Line 123: Line 113:
$( this ).css( 'cursor' , 'pointer' );
$( this ).css( 'cursor' , 'pointer' );
$( this ).attr( 'title', 'Mark' );
$( this ).attr( 'title', 'Mark' );
$( this ).click( function () {
$( this ).on( 'click tap touchstart', function () {
if ( $( this ).hasClass( 'marked' ) ) {
if ( $( this ).hasClass( 'marked' ) ) {
$( this ).removeClass( 'marked' );
$( this ).removeClass( 'marked' );
Line 146: Line 136:
fieldset.addItems( [
fieldset.addItems( [
new OO.ui.FieldLayout( langToggle, { label: 'Display language', align: 'inline' } ),
new OO.ui.FieldLayout( langToggle, { label: 'Display language', align: 'inline' } ),
new OO.ui.FieldLayout( layoutToggle, { label: 'Display layout' , align: 'inline' } ),
new OO.ui.FieldLayout( layoutToggle, { label: 'Display layout', align: 'inline' } ),
new OO.ui.FieldLayout( colorToggle, { label: 'Show character colors', align: 'inline' } ),
new OO.ui.FieldLayout( colorToggle, { label: 'Show character colors', align: 'inline' } ),
] );
] );
Line 154: Line 144:
initMarking();
initMarking();
} );
} );
});
} )( jQuery, mediaWiki );

Latest revision as of 05:57, 22 December 2021

( function ( $, mw ) {
	'use strict';
	
	function makeLangToggle() {
		var toggle = new OO.ui.ButtonSelectWidget( {
			items: [
				new OO.ui.ButtonOptionWidget( { data: 'en', label: 'English' } ),
				new OO.ui.ButtonOptionWidget( { data: 'jp', label: 'Japanese' } ),
				new OO.ui.ButtonOptionWidget( { data: 'both', label: 'Both' } )
			],
			align: 'left'
		} );
		
		function langToggle( item, selected ) {
			$.cookie( 'dialogue_lang', item.getData(), { expires: 365, path: '/' } );
			
			$( '.dialogue' ).each( function() {
				var $dt_en = $( this ).find( '.dt-en' );
				var $dt_jp = $( this ).find( '.dt-jp' );
				
				if ( item.getData() === 'en' ) {
					$dt_jp.hide();
					$dt_en.show();
				} else if ( item.getData() === 'jp' ) {
					$dt_en.hide();
					$dt_jp.show();
				} else if ( item.getData() === 'both' ) {
					$dt_en.show();
					$dt_jp.show();
				}
			} );
		} 
		
		toggle.on( 'choose', langToggle );
		toggle.on( 'select', langToggle );
		
		var cookie_val = $.cookie( 'dialogue_lang' );
		if ( cookie_val !== 'en' && cookie_val !== 'jp' && cookie_val !== 'both' ) {
			toggle.selectItemByData( 'both' );
		} else {
			toggle.selectItemByData( cookie_val );
		}
		
		return toggle;
	}
	
	function makeLayoutToggle() {
		var toggle = new OO.ui.ButtonSelectWidget( {
			items: [
				new OO.ui.ButtonOptionWidget( { data: 'modern', label: 'Modern' } ),
				new OO.ui.ButtonOptionWidget( { data: 'traditional', label: 'Traditional' } ),
			],
			align: 'left'
		} );
		
		function layoutToggle( item, selected ) {
			$.cookie( 'dialogue_layout', item.getData(), { expires: 365, path: '/' } );
			
			$( '.dialogue, .dialogue-scene, .dialogue-sfx, .dialogue-image' ).each ( function() {
				if ( item.getData() === 'modern' ) {
					$( this ).removeClass( 'traditional' );
					$( this ).addClass( 'modern' );
				} else if ( item.getData() === 'traditional' ) {
					$( this ).removeClass( 'modern' );
					$( this ).addClass( 'traditional' );
				}
			} );
		}
		
		toggle.on( 'choose', layoutToggle );
		toggle.on( 'select', layoutToggle );
		
		var cookie_val = $.cookie( 'dialogue_layout' );
		if ( cookie_val !== 'modern' && cookie_val !== 'traditional' ) {
			toggle.selectItemByData( 'modern' );
		} else {
			toggle.selectItemByData( cookie_val );
		}
		
		return toggle;
	}
	
	function makeColorToggle() {
		var toggle = new OO.ui.CheckboxInputWidget( {
			value: 'colorized'
		} );
		
		toggle.on( 'change', function( selected ) {
			$.cookie( 'dialogue_colorized', selected, { expires: 365, path: '/' } );
			
			$( '.dialogue-text' ).each( function() {
				if ( selected ) {
					var color = $( this ).attr('data-character-color');
					$( this ).css( 'border-left-color', color );
					$( this ).css( 'border-left-width', 'thick' );
				} else {
					$( this ).css( 'border-left-color', '' );
					$( this ).css( 'border-left-width', '' );
				}
			} );
		} );
		
		var cookie_val = $.cookie( 'dialogue_colorized' );
		if ( cookie_val !== null ) {
			toggle.setSelected( cookie_val  === 'true' );
		}
		
		return toggle;
	}
	
	function initMarking() {
		$( '.dialogue-text' ).each( function() {
			$( this ).css( 'cursor' , 'pointer' );
			$( this ).attr( 'title', 'Mark' );
			$( this ).on( 'click tap touchstart', function () {
				if ( $( this ).hasClass( 'marked' ) ) {
					$( this ).removeClass( 'marked' );
					$( this ).attr( 'title', 'Mark' );
				} else {
					$( this ).addClass( 'marked' );
					$( this ).attr( 'title', 'Unmark' );
				}
			} );
		} );
	}
	
	$( function() {
		var langToggle = makeLangToggle();
		var layoutToggle = makeLayoutToggle();
		var colorToggle = makeColorToggle();
		
		var fieldset = new OO.ui.FieldsetLayout( {
			label: 'Dialogue display options'
		} );
		
		fieldset.addItems( [
			new OO.ui.FieldLayout( langToggle, { label: 'Display language', align: 'inline' } ),
			new OO.ui.FieldLayout( layoutToggle, { label: 'Display layout', align: 'inline' } ),
			new OO.ui.FieldLayout( colorToggle, { label: 'Show character colors', align: 'inline' } ),
		] );
		
		$( '.dialogue-options' ).append( fieldset.$element );
		
		initMarking();
	} );
	
} )( jQuery, mediaWiki );
Cookies help us deliver our services. By using our services, you agree to our use of cookies.