User:Ricordisamoa/SaveDelay.js

Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload.
/* <nowiki>
 * SaveDelay.js by [[User:Ricordisamoa]]
 * uses jQuery
 * delays page saving (dafault: 7 seconds)
*/
$(document).ready(function(){
	if(wgAction=="edit"&&document.editform){// in edit mode
		mw.loader.using("jquery.ui",function(){
			if(typeof(saveDelaySeconds)==="undefined") saveDelaySeconds=7;
			$(document.editform.wpSave)
			.click(function(event){
				event.preventDefault();// prevent the form to be sent
				var progress=
					$("<div>")
					.append(
						$("<div>")
						.addClass("progressbar-label")
						.text(saveDelaySeconds+" seconds remaining")
						.css({
							width:"100%",
							color:"green",
							textAlign:"center",
							float:"left",
							fontSize:"13px",
							fontWeight:"bold"
						})
					)
					.progressbar({
						max:saveDelaySeconds,
						value:0,
						complete:function(){
							dialog.dialog("close");
							document.editform.submit();
						}
					});
				$(progress).children("div.ui-progressbar-value").css("background","red");
				var dialog=$("<div>")
				.append(progress)
				.dialog({
					title:"Wait a moment...",
					buttons:{
						"Save NOW":function(){
							$(this).dialog("close");
							document.editform.submit();
						},
						"Cancel":function(){
							$(this).dialog("close");
						}
					},
					open:function(){
						$(this).children().blur();
					},
					close:function(){
						progress.progressbar("destroy");
					}
				});
				setInterval(function(){
					progress.progressbar("value",progress.progressbar("value")+1);
					$(progress).children(".progressbar-label").text((progress.progressbar("option","max")-progress.progressbar("value"))+" seconds remaining");
				},1000);
			});
		});
	}
});
/* </nowiki> */