Difference between revisions of "MediaWiki:Common.js"

From The Powder Toy
Jump to: navigation, search
(Save blocks JS)
 
(Correct saveblock function)
Line 5: Line 5:
 
function LoadBlocks(){
 
function LoadBlocks(){
 
$(".ForumSaveBlock").each(function(Index, Element){
 
$(".ForumSaveBlock").each(function(Index, Element){
Element = $(this);
+
SaveBlock(Element);
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);
 
});
 
 
});
 
});
 
}
 
}

Revision as of 22:48, 10 October 2012

/* 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){
		SaveBlock(Element);
	});
}