function dlLink(title, currentArray, currentIndex, currentOpts)
{
var img = new Image();
img.src = 'Gallery/Wallpapers/' + title;
html = img.width + ' x ' + img.height + '<br />'
+ '<a class = "nav" href = "Gallery/Wallpapers/' + title + '" target = "_blank">Download</a><br />http://';
// set up default options
var defaults = {
login: '*************',
apiKey: '*******************************',
longUrl: 'http%3A%2F%2Fschnell.dreamhosters.com%2Fwallpapers.php%3Fwp=' + title
};
// Build the URL to query
var daurl = "http://api.bit.ly/v3/shorten?"
+ "&login=" + defaults.login
+ "&apiKey=" + defaults.apiKey
+ "&longUrl=" + defaults.longUrl
+ "&format=json&callback=?";
// Utilize the bit.ly API
$.getJSON(daurl, function(results) {
$('#fancybox-title').append(results.data["url"].substr(7));
});
if(img.complete)
return html;
}
Ok, the point of this function is that it's a callback to a Fancybox that puts HTML content into it's 'title' section. In this section I put the image's resolution, a download link and a bit.ly link for coming back to the image at this website - http://schnell.dreamhosters.com/wallpapers.php?page=12 Originally I was having XMLHTTPRequest problems with the bit.ly URL, but I seem to have resolved those.
The problem now, though, is that I need the variable 'html' to have all the html content that's going into the fancybox before the return statement comes up. While it may look like everything happens before the return statement, jQuery is doing the $.getJSON() function asynchronosly and so it's not garaunteed that 'html' will have stuff in it before dlLink ends. I need a way to make it so that the order of things happens as its shown in the code, so that the $.getJSON request and the subsequent callback function will always finish what they're doing before going onto the return statement.
Edit - I figured out what to do and the code above correctly does as I wanted. See my answer below.