Created
September 8, 2010 12:45
-
-
Save koenbok/570080 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
AppCast Dowloader (c) 2010 Sofa BV (Koen Bok) | |
Description: | |
Returns the url for the latest version in an AppCast url. | |
Requirements: | |
jQuery > 1.4 | |
Example: | |
$("#button").click(function() { | |
downloadLatest("http://files.madebysofa.com/public/Enstore/ETUUpdates/appcast.xml"); | |
}); | |
*/ | |
function downloadLatest(appcastURL) { | |
var highestVersion = 0; | |
var downloadURL = ''; | |
function handleError() { | |
alert("Could not retreive download link for: " + appcastURL); | |
} | |
$.ajax({ | |
type: "GET", | |
url: appcastURL, | |
dataType: "xml", | |
error: handleError, | |
success: function(xml) { | |
$(xml).find("enclosure").each(function() { | |
var node = $(this); | |
var version = parseInt(node.attr("sparkle:version")); | |
var url = node.attr("url"); | |
if (version > highestVersion) { | |
highestVersion = version; | |
downloadURL = url; | |
} | |
}); | |
// At this point we should have a download url | |
if (downloadURL.indexOf("http") == -1) { | |
handleError() | |
} else { | |
window.location = downloadURL; | |
} | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment