Last active
December 19, 2015 19:59
-
-
Save whitmer/6010232 to your computer and use it in GitHub Desktop.
Modified version of canvabadges embed code that should work, even if pasted into another script file.
This file contains hidden or 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
// --- Canvas Profile Badges --- | |
$(function() { | |
var protocol_and_host = "https://canvabadges.herokuapp.com"; | |
var $scripts = $("script"); | |
var match = location.href.match(/\/users\/(\d+)$/); | |
if(match && protocol_and_host) { | |
var user_id = match[1]; | |
var domain = location.host; | |
var url = protocol_and_host + "/api/v1/badges/public/" + user_id + "/" + encodeURIComponent(domain) + ".json"; | |
$.ajax({ | |
type: 'GET', | |
dataType: 'jsonp', | |
url: url, | |
success: function(data) { | |
if(data.objects && data.objects.length > 0) { | |
var $box = $("<div/>"); | |
$box.append("<h2 class='border border-b'>Badges</h2>"); | |
for(idx in data.objects) { | |
var badge = data.objects[idx]; | |
var $badge = $("<div/>", {style: 'float: left;'}); | |
var link = protocol_and_host + "/badges/criteria/" + badge.config_id + "/" + badge.config_nonce + "?user=" + badge.nonce; | |
var $a = $("<a/>", {href: link}); | |
$a.append($("<img/>", {src: badge.image_url, style: 'width: 72px; height: 72px; padding-right: 10px;'})); | |
$badge.append($a); | |
$box.append($badge); | |
} | |
$box.append($("<div/>", {style: 'clear: left'})); | |
$("#edit_profile_form").after($box); | |
} | |
}, | |
error: function() { | |
console.log("badges failed to load"); | |
}, | |
timeout: 5000 | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment