Browse Source

Further improve lightbox by getting rid of all the data tags and use ajax call for pin

tags/v1.0.0
Isaac Bythewood 11 years ago
parent
commit
96af25f5fb
5 changed files with 20 additions and 32 deletions
  1. +6
    -0
      pinry/static/js/helpers.js
  2. +7
    -11
      pinry/static/js/lightbox.js
  3. +2
    -9
      pinry/static/js/pin-form.js
  4. +3
    -3
      pinry/templates/includes/lightbox.html
  5. +2
    -9
      pinry/templates/includes/pins.html

+ 6
- 0
pinry/static/js/helpers.js View File

@@ -20,3 +20,9 @@ function cleanTags(tags) {
} }
return tags return tags
} }


function getPinData(pinId) {
var apiUrl = '/api/v1/pin/'+pinId+'/?format=json';
return $.get(apiUrl);
}

+ 7
- 11
pinry/static/js/lightbox.js View File

@@ -30,13 +30,6 @@ $(window).load(function() {
$(window).scrollTop($('body').data('scroll-level')); $(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 // End Helper Functions




@@ -46,15 +39,15 @@ $(window).load(function() {
$('body').append(renderTemplate('#lightbox-template', context)); $('body').append(renderTemplate('#lightbox-template', context));
var box = $('.lightbox-background'); var box = $('.lightbox-background');
box.css('height', $(document).height()); box.css('height', $(document).height());
$('.lightbox-image-wrapper').css('height', context.height);
$('.lightbox-image-wrapper').css('height', context.image.standard.height);
box.fadeIn(200); box.fadeIn(200);
$('.lightbox-image').load(function() { $('.lightbox-image').load(function() {
$(this).fadeIn(200); $(this).fadeIn(200);
}); });
$('.lightbox-wrapper').css({ $('.lightbox-wrapper').css({
'width': context.width,
'width': context.image.standard.width,
'margin-top': 70, 'margin-top': 70,
'margin-left': -context.width/2
'margin-left': -context.image.standard.width/2
}); });


box.click(function() { box.click(function() {
@@ -74,8 +67,11 @@ $(window).load(function() {
return links.each(function() { return links.each(function() {
$(this).off('click'); $(this).off('click');
$(this).click(function(e) { $(this).click(function(e) {
createBox(getLightboxData($(this)));
e.preventDefault(); e.preventDefault();
var promise = getPinData($(this).data('id'));
promise.success(function(pin) {
createBox(pin);
});
}); });
}); });
} }


+ 2
- 9
pinry/static/js/pin-form.js View File

@@ -1,13 +1,6 @@
$(window).load(function() { $(window).load(function() {
var currentPin; 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() { function createPin() {
var template = Handlebars.compile($('#pins-template').html()); var template = Handlebars.compile($('#pins-template').html());
var html = template({ var html = template({
@@ -22,7 +15,7 @@ $(window).load(function() {
} }
}, },
description: $('#pin-form-description').val(), description: $('#pin-form-description').val(),
tags: cleanTags()
tags: cleanTags($('#pin-form-tags').val())
}] }]
}); });
currentPin = html; currentPin = html;
@@ -63,7 +56,7 @@ $(window).load(function() {
} }


$('#pin-form-submit').click(function(e) { $('#pin-form-submit').click(function(e) {
var tags = cleanTags();
var tags = cleanTags($('#pin-form-tags').val());
$.ajax({ $.ajax({
type: "post", type: "post",
url: "/api/v1/pin/", url: "/api/v1/pin/",


+ 3
- 3
pinry/templates/includes/lightbox.html View File

@@ -3,7 +3,7 @@
<div class="lightbox-background"> <div class="lightbox-background">
<div class="lightbox-wrapper"> <div class="lightbox-wrapper">
<div class="lightbox-image-wrapper"> <div class="lightbox-image-wrapper">
<img class="lightbox-image" src="{{image}}" />
<img class="lightbox-image" src="{{image.standard.image}}" />
</div> </div>
<div class="lightbox-data clearfix"> <div class="lightbox-data clearfix">
{{#if description}} {{#if description}}
@@ -12,10 +12,10 @@
</div> </div>
{{/if}} {{/if}}
<div class="avatar pull-left"> <div class="avatar pull-left">
<img src="http://gravatar.com/avatar/{{gravatar}}.jpg">
<img src="http://gravatar.com/avatar/{{submitter.gravatar}}.jpg">
</div> </div>
<div class="text pull-left"> <div class="text pull-left">
<span class="dim">pinned by</span> {{username}}
<span class="dim">pinned by</span> {{submitter.username}}
{{#if tags}} {{#if tags}}
<br /><span class="dim">in</span> <br /><span class="dim">in</span>
{{#each tags}} {{#each tags}}


+ 2
- 9
pinry/templates/includes/pins.html View File

@@ -9,14 +9,7 @@
</div> </div>
</div> </div>
{{/if}} {{/if}}
<a href="{{image.standard.image}}"
class="lightbox"
data-username="{{submitter.username}}"
data-tags="{{tags}}"
data-gravatar="{{submitter.gravatar}}"
data-description="{{description}}"
data-width="{{image.standard.width}}"
data-height="{{image.standard.height}}">
<a href="{{image.standard.image}}" class="lightbox" data-id="{{id}}">
<img src="{{image.thumbnail.image}}" /> <img src="{{image.thumbnail.image}}" />
</a> </a>
{{#if description}} {{#if description}}
@@ -24,7 +17,7 @@
{{/if}} {{/if}}
<div class="pin-footer clearfix"> <div class="pin-footer clearfix">
<div class="avatar pull-left"> <div class="avatar pull-left">
<img src="http://gravatar.com/avatar/{{submitter.gravatar}}.jpg">
<img src="http://gravatar.com/avatar/{{submitter.gravatar}}">
</div> </div>
<div class="text pull-right"> <div class="text pull-right">
<span class="dim">pinned by</span> {{submitter.username}} <span class="dim">pinned by</span> {{submitter.username}}


Loading…
Cancel
Save