diff --git a/pinry/static/js/helpers.js b/pinry/static/js/helpers.js index 0989708..8668ff6 100644 --- a/pinry/static/js/helpers.js +++ b/pinry/static/js/helpers.js @@ -20,3 +20,9 @@ function cleanTags(tags) { } return tags } + + +function getPinData(pinId) { + var apiUrl = '/api/v1/pin/'+pinId+'/?format=json'; + return $.get(apiUrl); +} diff --git a/pinry/static/js/lightbox.js b/pinry/static/js/lightbox.js index 68e27e3..5a16787 100644 --- a/pinry/static/js/lightbox.js +++ b/pinry/static/js/lightbox.js @@ -30,13 +30,6 @@ $(window).load(function() { $(window).scrollTop($('body').data('scroll-level')); } } - - function getLightboxData(link) { - var data = link.data(); - data.tags = cleanTags(data.tags); - data.image = link.attr('href'); - return data; - } // End Helper Functions @@ -46,15 +39,15 @@ $(window).load(function() { $('body').append(renderTemplate('#lightbox-template', context)); var box = $('.lightbox-background'); box.css('height', $(document).height()); - $('.lightbox-image-wrapper').css('height', context.height); + $('.lightbox-image-wrapper').css('height', context.image.standard.height); box.fadeIn(200); $('.lightbox-image').load(function() { $(this).fadeIn(200); }); $('.lightbox-wrapper').css({ - 'width': context.width, + 'width': context.image.standard.width, 'margin-top': 70, - 'margin-left': -context.width/2 + 'margin-left': -context.image.standard.width/2 }); box.click(function() { @@ -74,8 +67,11 @@ $(window).load(function() { return links.each(function() { $(this).off('click'); $(this).click(function(e) { - createBox(getLightboxData($(this))); e.preventDefault(); + var promise = getPinData($(this).data('id')); + promise.success(function(pin) { + createBox(pin); + }); }); }); } diff --git a/pinry/static/js/pin-form.js b/pinry/static/js/pin-form.js index 61f41d5..aaea594 100644 --- a/pinry/static/js/pin-form.js +++ b/pinry/static/js/pin-form.js @@ -1,13 +1,6 @@ $(window).load(function() { var currentPin; - function cleanTags() { - var tags = $('#pin-form-tags').val() - tags = tags.split(',') - for (var tag in tags) tags[tag] = tags[tag].trim(); - return tags - } - function createPin() { var template = Handlebars.compile($('#pins-template').html()); var html = template({ @@ -22,7 +15,7 @@ $(window).load(function() { } }, description: $('#pin-form-description').val(), - tags: cleanTags() + tags: cleanTags($('#pin-form-tags').val()) }] }); currentPin = html; @@ -63,7 +56,7 @@ $(window).load(function() { } $('#pin-form-submit').click(function(e) { - var tags = cleanTags(); + var tags = cleanTags($('#pin-form-tags').val()); $.ajax({ type: "post", url: "/api/v1/pin/", diff --git a/pinry/templates/includes/lightbox.html b/pinry/templates/includes/lightbox.html index eca197d..a73d14a 100644 --- a/pinry/templates/includes/lightbox.html +++ b/pinry/templates/includes/lightbox.html @@ -3,7 +3,7 @@