jQuery(document).ready(function ($) {
//$("#a2widget").html('
Loading AlternativeTo Widget

');
$("#a2widget").css("display", "none");
if ($('#a2options').length != 0) {
var a2options = $("#a2options").val().split(",");
var a2app = a2options[1];
var a2count = a2options[0];
var a2category = a2options[2];
var a2theme = a2options[3];
var is_preview = a2options[4];
var ref = "?ref=plugin";
if (is_preview == 1) { ref = ""; };
$.ajax({ type: "GET",
dataType: "json",
url: "http://api.alternativeto.net/" + a2category + "/" + a2app + "/?count=" + a2count + "&jsoncallback=?",
success: function (data) {
var sHtml = "";
if (a2theme == "default") {
sHtml = "";
sHtml += "
The best alternatives to " + data.Name + " from AlternativeTo
";
sHtml += "
";
$.each(data.Items, function (i, item) {
sHtml += '' + item.Votes + 'likes
' + a2_cutString(item.Name) + ' ' + a2_getLicenseString(item.License) + ' | ' + a2_getPlatformString(item.Platforms, true) + ' ';
});
sHtml += "
";
} else if (a2theme == "small") {
sHtml = "";
sHtml += "
The best alternatives to " + data.Name + " from AlternativeTo
";
sHtml += "
";
$.each(data.Items, function (i, item) {
sHtml += '- ' + a2_cutString(item.Name) + ' ' + item.Votes + ' likes | ' + a2_getLicenseString(item.License) + ' | ' + a2_getPlatformString(item.Platforms, true) + '
';
});
sHtml += "
";
} else if (a2theme == "minimal") {
sHtml = data.Name + " alternatives: ";
$.each(data.Items, function (i, item) {
sHtml += '' + item.Name + ', ';
});
sHtml = sHtml.slice(0, -2);
}
$("#a2widget").html(sHtml);
$("#a2widget").css("display", "block");
return;
}
});
}
});
function a2_getPlatformString(platform, shortVersion) {
if (shortVersion)
return platform.join(", ").replace("Windows", "Win");
else
return platform.join(", ");
}
function a2_getLicenseString(license) {
return license.replace('Free with limited functionality', 'Free (Limited)');
}
function a2_cutString(itemName) {
var name;
if (itemName.length > 24) {
name = itemName.substring(0, 24) + "...";
} else {
name = itemName;
}
return name;
}