Skip to content

Instantly share code, notes, and snippets.

@dsadaka
Created November 1, 2011 01:44
Show Gist options
  • Save dsadaka/1329616 to your computer and use it in GitHub Desktop.
Save dsadaka/1329616 to your computer and use it in GitHub Desktop.
JS with getJSON to build select tag of albums
// Modal Behaviors:
$('.share-facebook-wall').fancybox($.extend({}, modal_lightbox, {
onComplete : function() {
var $target_div = $('#copy-to-album');
$target_div.find('a').click(function() {
$(this).text('Loading Albums...').addClass('button-disabled').prev().remove();
$.getJSON("/partner_album_list.json", {site : "Facebook"},
function(data) {
var html = '<select name="' + 'target_album' + '" id="' + 'target_album' + '">';
html += '<option value="">(Select Existing or Create New)</option>';
html += '<option value="0">(Create a New Album)</option>';
$.each(data.resource, function(i,item) {
html += '<option value="' + item.resource_id + '">' + item.title + '</option>';
});
html += '</select>';
$html = $(html);
$html.change(function() {
if ($(this).val() == '0') {
$(this).after('<input type="text" id="new_album_title" name="new_album_title" placeholder="Enter Album Title">');
} else {
$(this).next().remove();
}
});
$target_div.empty().append($html).prev().text('Copy to Album');
})
.error(function(xhr, ajaxOptions, thrownError) {
$target_div.find('a').text('Try Again').removeClass('button-disabled').before('<span>Could not connect. ' + xhr.status + ' ' + thrownError + '</span>');
});
});
$('#share-facebook-wall-submit').click(function() {
if ($(this).closest('form').valid()) {
$(this).attr('disabled', 'disabled').val('Posting...');
$(this).closest('form').submit();
}
});
}
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment