/*
EditorSaveAndContinue Gadget - JS Initialisation, Setup, Events. Adds a Save continue button to the editor so the page is not reloaded everytime
See detailed documentation in Dev/mediawiki
deferrable:YES -- Because it's an augmentation and not needed as a dependency
*/

(function() {

	let editorSaveModal = $(''
		+ '<div class="mini-modal" id="saveAndContinueMiniModal">'
		+  '<iframe />'
		+ '</div>'
	);

	// Setup

	$('#editform .editButtons').prepend( $( '<span class="save-and-continue">Save continue</span>' ) );

	$('body').append(editorSaveModal);

	editorSaveModal.miniModal('init');

	// Event

	$('#editform .save-and-continue').on( 'click', function() {
		// if ace editor is activated (in js and css files) transfer latest editor text to mediawiki textarea
		if( $('.ace_editor').length ) {
			$('.ace_editor').attr('id','ace_editor');
			$('#wpTextbox1').val( ace.edit('ace_editor').getValue() );
		}

		$.ajax({
			url: $('#editform').attr('action'),
			type: $('#editform').attr('method').toUpperCase(),
			data: $('#editform').serialize(),
			success: function( response ) {
				editorSaveModal.miniModal('show');
				editorSaveModal.find('.content iframe').contents().find('body').html(response);
			},
		});
	});
})();

/*
[[Category:MultiWiki]]
*/