User:Gryllida/js/editBoxResize.js

From Wikinews, the free news source you can write!
Jump to navigation Jump to search

Note: After saving, you may have to bypass your browser's cache to see the changes. Mozilla / Firefox / Safari: hold down Shift while clicking Reload, or press Ctrl-Shift-R (Cmd-Shift-R on Apple Mac); IE: hold Ctrl while clicking Refresh, or press Ctrl-F5; Konqueror: simply click the Reload button, or press F5; Opera users may need to completely clear their cache in Tools→Preferences. — More skins

var editform = document.querySelector('#editform');
if ( editform ) {
mw.loader.using(['mediawiki.api'], function () {
	// hide bulky (C) notice
	$('#editpage-copywarn').hide();
	// scroll to the beginning of the edit box
	var yForm = editform.getBoundingClientRect().y;
	var yBody = document.body.getBoundingClientRect().y;
	window.scrollTo(0, yForm - yBody);
	// resize the edit box for the 'save changes' button to fit screen
	var dy = document.querySelector('#wpSave').getBoundingClientRect().y - $(window).height() + document.querySelector('#wpSave').offsetHeight + 32;
	var dRows = $('#wpTextbox1').attr('rows') * dy / document.querySelector('#wpTextbox1').offsetHeight;
	$('#wpTextbox1').attr('rows', $('#wpTextbox1').attr('rows') - dRows);
});
}