MediaWiki:Common.js

From The Powder Toy
Revision as of 22:45, 10 October 2012 by Simon (talk | contribs) (Save blocks JS)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
/* Any JavaScript here will be loaded for all users on every page load. */
$(document).bind("ready", function(){
	LoadBlocks();
});
function LoadBlocks(){
	$(".ForumSaveBlock").each(function(Index, Element){
		Element = $(this);
		SaveID = $(Element).children("b").html();
		$.getJSON('/Browse/View.json?ID='+SaveID, function(data){
			SaveElement = $("<div class=\"fSaveGame\"></div>");
				ThumbElement = $("<div class=\"fSaveGameThumb\"></div>").appendTo(SaveElement);
					ScoreElement = $("<div class=\"fSaveRating\">"+data.Score+"</div>").appendTo(ThumbElement);
					//ImgElement = $("<img src=\"/Utilities/Utility.GetScreenshot.php?ID="+data.ID+"&Size=small\"/>").appendTo(ThumbElement);
					ImgElement = $("<a href=\"/Browse/View.html?ID="+data.ID+"\"><img src=\"http://static.powdertoy.co.uk/"+data.ID+"_small.png\"/></a>").appendTo(ThumbElement);
				SaveInfoElement = $("<div class=\"fSaveDetails\"></div>").appendTo(SaveElement);
					TitleElement = $("<span class=\"fTitle\" title=\""+data.Name+"\"><a href=\"/Browse/View.html?ID="+data.ID+"\">"+data.ShortName+"</a></span>").appendTo(SaveInfoElement);
					AuthorElement = $("<span class=\"fAuthor\">"+data.Username+"</span>").appendTo(SaveInfoElement);
					CommentsElement = $("<span class=\"fComments\">"+data.Comments+" comments</span>").appendTo(SaveInfoElement);
					ClearElement = $("<div class=\"Clear\"></div>").appendTo(SaveInfoElement);
					FormElement = $("<form class=\"SaveDownloadDo\" method=\"POST\" action=\"/Browse/View.html?ID="+data.ID+"\"></form>").appendTo(SaveInfoElement);
						DownloadElement = $("<input type=\"submit\" id=\"fDB"+data.ID+"\" value=\"Download\"/>").appendTo(FormElement);
						HiddenIDElement = $("<input type=\"hidden\" name=\"DoDownload\" value=\""+data.ID+"\"/>").appendTo(FormElement);
					FormElement.submit(function(){
						Link = $(this).attr("action").replace(/\.html/, ".json");
						$.post(Link, $(this).serialize(), function(data){
							//PopupUtility(data.HTML);
							if(data.Status=="1"){
								CDownloadElement = $("#fDB"+data.SaveID);
								CDownloadElement.val("Queued");
								CDownloadElement.attr("disabled", "disabled");
							} else {
								PopupUtility(data.HTML);
							}
						}, "json");
						return false;
					});
			$(Element).replaceWith(SaveElement);
		});
	});
}