Jump to content

User:Danski454/codeEditWindowSize.js

From Wikipedia, the free encyclopedia
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
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.
window.codeEditorHeight = window.codeEditorHeight || 700;
$(function(){
	var inited = false;
	var attempts = 0;
	function loop(){//we may have to wait for code editor to load
		if ($(".wikiEditor-ui-text div").first().is(".ui-resizable")) {
			if (!inited){
				$(".tool[rel='codeEditor'] a").first().click(loop);
				inited = true;
			}
			//do resize
			$(".wikiEditor-ui-text div").first().css("height", 
				window.codeEditorHeight.toString() + "px");
			//resizing the edit window causes part of the edit window to appear empty
			//calling the resize event fixes this.
			window.dispatchEvent(new Event("resize"));
			attempts = 0;//reset attempt tracker
		} else if (attempts < 100) {//try again later
			attempts++;
			window.setTimeout(loop, 50);
		}//after 100 attempts (min 5 seconds), give up
		else {
			attempts = 0;//reset attempt tracker
		}
	}
	
	if ((mw.config.get("wgAction") === "edit" || 
		mw.config.get("wgAction") === "submit") //are we in edit mode
		&& ["javascript", "css", "Scribunto"].indexOf(mw.config.get("wgPageContentModel")) !== -1) {//and on a code page?
		loop();
	}
});