Jump to content

User:DannyS712 test/RemindMe.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by DannyS712 test (talk | contribs) at 23:09, 17 April 2020 (link). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// <nowiki>
$( function () {

RemindMe = {
	config: {
		name: 'RemindMe',
		version: 'dev'
	},
	init: function () {
		console.log( 'In the script' );
		
		mw.util.addCSS(`
			#RemindMe-window {
				position: fixed;
				z-index: 1;
				left: 0;
				top: 0;
				width: 100%;
				height: 100%;
				overflow: hidden;
				background-color: rgba(0,0,0,0.4);
			}
			#RemindMe-dialog {
				background-color: #d6d6d6;
				margin: 10% auto;
				padding: 2px 20px;
				border: 1px solid #888;
				width: 80%;
				max-width: 60em;
				font-size: 90%;
			}
		`);
		
		var $window = $('<div>');
		$window.attr( 'id', 'RemindMe-window' );
		
		var $dialog = $('<div>');
		$dialog.attr( 'id', 'RemindMe-dialog' );
		
		$window.append( $dialog );
		
		var today = ( new Date() ).toISOString().split('T')[0];
		var dateInput = new mw.widgets.DateInputWidget( {
			name: 'date',
			mustBeAfter: today,
			precision: 'day',
			required: true
		} );
		
		var mwConfig = mw.config.get( [ 'wgTitle', 'wgCanonicalNamespace' ] );
		var currentPage = mwConfig.wgCanonicalNamespace + ':' + mwConfig.wgTitle;
		
		$dialog.append(
			$('<div>')
				.attr( 'id', 'RemindMe-title' )
				.append(
					$('<b>')
						.text( 'Schedule a reminder using RemindMe' )
					),
			$('<hr>'),
			$('<div>')
				.attr( 'id', 'RemindMe-schedule' )
				.append(
					$('<label>')
						.text( 'Remind me on...')
				)
				.append( dateInput.$element ),
			$('<hr>'),
			$('<div>')
				.attr( 'id', 'RemindMe-message' )
				.append(
					$('<label>')
						.text( 'Reminder content' ),
					$('<textarea>')
						.attr( 'id', 'RemindMe-message-content' )
						.attr( 'rows', 18 )
						.attr( 'cols', 15 )
						.text( '[[' + currentPage + ']]: ' )
				),
			$('<hr>'),
			$('<button>')
				.attr( 'id', 'RemindMe-submit' )
				.text( 'Schedule' )
		);
		
		$( 'body' ).prepend( $window );
	}
};

$.when(
	mw.loader.using( 'mediawiki.util' ),
	$.ready
).then( function () {
	mw.util.addPortletLink ( 'p-cactions', '', 'RemindMe', 'ca-RemindMe', 'Schedule a reminder');
	$('#ca-RemindMe').on('click', function( e ) {
		e.preventDefault();
		mw.loader.using( 'mediawiki.widgets.DateInputWidget' ).then( RemindMe.init );
	} );
} );

} );