User:Neriah/tasks.js

$( function {	var page = 'User:' + mw.config.get('wgUserName') + '/tasks';	function showPage(e) {		e.preventDefault;		mw.loader.using( ['mediawiki.api'] ).then( function { new mw.Api({ ajax: { cache: false } }).get( { action: 'parse', page: page, smaxage: 0,					disableeditsection: true } ).done( function( data ) {				if ( data && data.parse && data.parse.text && data.parse.text['*'] )					showContent( page, data.parse.text['*'] );			} ); // parse returned } ); // using api returned	} // showpage.sho	function showRaw {		$.ajax( { url: mw.util.wikiScript, data: { action: 'raw', title: page }, dataType: 'text' } ).done( function( data ) { showContent( page, data, true ); } );	}	function showContent( title, content, raw ) {		mw.loader.using( [ 'jquery.ui', 'mediawiki.api' ] ).then( function { var dialog, api = new mw.Api({ ajax: { cache: false } }), inside = raw ? $( ' ' )						.attr( { raws: 25, resize: true } ) .val( content ) .css( { 'width': $('body').width * (window.my_93_width || 0.8),							'height' : $('body').height * (window.my_93_height || 0.8), overflow: 'auto' } ) : $( ' ' )						.css( { 'max-width': $('body').width * 0.9, 'max-height' : $('body').height * 0.8,							overflow: 'auto' } ) .append( content ), buttons = [ {text: 'Save and close', click: doSaveClose} ], buttons1 = [ {text: 'edit', click: doEdit} ]; function doSaveClose { api.postWithEditToken( { action: 'edit', title: title, text: inside.val, smaxage: 0,					summary: dialog.find('input').val || "Change tasks." } ).done(function(d) {						if (d && d.edit && d.edit.result == 'Success') mw.notify('The page has been successfully updated!');					}); dialog.dialog( 'close' ); }			function doEdit { showRaw; dialog.dialog( 'close' ); }			dialog = $( ' ' ) .dialog( { 					title: title,					width: 'auto', 					height: 'auto',					position: [$('body').width * 0.05, $('body').height * 0.05],					buttons: raw ? buttons : buttons1				} ) .append( inside ); if (raw) {dialog.append('  '); } } ); // using dialog returned

}	$( mw.util.addPortletLink( 'p-personal', '#', 'tasks', 'pt-remainder', , , '#pt-mytalk') ) .click( showPage ); } );