User:Gryllida/js/addInstantSaveToNewArticle.js

/* Author : Svetlana Tkachenko svetlana@members.fsf.org This file is a part of addInstantSaveToCodeEditor. Licence: GPLv3+ Release date: 2018-03-13 Description: adds an instant save button to spans with gryllida-instant-save class

mw.loader.using(['mediawiki.api', 'oojs-ui'], function {	if('.gryllida-instant-save'){		// for spans		var saveThePageForSpan = function{			// Update button text			$('.gryllida-instant-save').text('Saving...');			// Get text area contents			var textbox = $('#wpTextbox1');			var context = textbox && textbox.data('wikiEditor-context');			var currentText = context.$textarea.textSelection( 'getContents' );			// Save the page via AJAX edit api			var api = new mw.Api;			api.postWithToken("edit", { action: 'edit', title: mw.config.get ('wgPageName'), text: currentText, summary: $('#wpSummary').val + ' (assisted)' }).done(function (data){ // Success; Update button text $('.gryllida-instant-save').text('Saved'); $('.gryllida-create-article-nav').css('visibility', 'visible'); textbox.on('input propertychange paste', function{					$('.gryllida-instant-save').text('Save');					$('.gryllida-create-article-nav').css('visibility', 'hidden');				}); });		};	$('.gryllida-instant-save').click(function{saveThePageForSpan;});	$('.gryllida-instant-save').css('visibility', 'visible');	} });

//	text: $('#wpTextbox1').text