|
|
@@ -1,55 +1,83 @@ |
|
|
|
$(window).load(function() { |
|
|
|
var scrollLevel = 0; |
|
|
|
|
|
|
|
window.lightbox = function(pins) { |
|
|
|
var links = pins.find('.lightbox'); |
|
|
|
/** |
|
|
|
* Lightbox for Pinry |
|
|
|
* Descrip: A lightbox plugin for pinry so that I don't have to rely on some of |
|
|
|
* the massive code bases of other lightboxes, this one uses data |
|
|
|
* fields to acquire the info we need and dynamically loads comments. |
|
|
|
* It also has a nice parallax view mode where the top scrolls and the |
|
|
|
* background stays stationary. |
|
|
|
* Authors: Pinry Contributors |
|
|
|
* Updated: Feb 26th, 2013 |
|
|
|
* Require: jQuery, Pinry JavaScript Helpers |
|
|
|
*/ |
|
|
|
|
|
|
|
function createBox(boxData) { |
|
|
|
var template = Handlebars.compile($('#lightbox-template').html()); |
|
|
|
var html = template(boxData); |
|
|
|
$('body').append(html); |
|
|
|
|
|
|
|
scrollLevel = $(window).scrollTop(); |
|
|
|
$(window).load(function() { |
|
|
|
// Start Helper Functions |
|
|
|
function freezeScroll(freeze) { |
|
|
|
freeze = typeof freeze !== 'undefined' ? freeze : true; |
|
|
|
if (freeze) { |
|
|
|
$('body').data('scroll-level', $(window).scrollTop()); |
|
|
|
$('#pins').css({ |
|
|
|
'margin-top': String(-scrollLevel)+'px', |
|
|
|
'position': 'fixed' |
|
|
|
'position': 'fixed', |
|
|
|
'margin-top': -$('body').data('scroll-level') |
|
|
|
}); |
|
|
|
|
|
|
|
$('.lightbox-wrapper img').load(function() { |
|
|
|
$('.lightbox-background').css('height', String($(document).height())+'px'); |
|
|
|
$('.lightbox-wrapper').css({ |
|
|
|
'width': boxData.width, |
|
|
|
'margin-top': String(100)+'px', |
|
|
|
'margin-left': '-'+String(boxData.width/2)+'px' |
|
|
|
}); |
|
|
|
$(window).scrollTop(0); |
|
|
|
} else { |
|
|
|
$('#pins').css({ |
|
|
|
'position': 'static', |
|
|
|
'margin-top': 0 |
|
|
|
}); |
|
|
|
|
|
|
|
return $('.lightbox-background'); |
|
|
|
$(window).scrollTop($('body').data('scroll-level')); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
for (var i=0; i < links.length; i++) { |
|
|
|
link = links.eq(i); |
|
|
|
link.off('click'); |
|
|
|
link.click(function(e) { |
|
|
|
var box = createBox({ |
|
|
|
image: $(this).attr('href'), |
|
|
|
gravatar: $(this).data('gravatar'), |
|
|
|
username: $(this).data('username'), |
|
|
|
description: $(this).data('description'), |
|
|
|
tags: $(this).data('tags').split(','), |
|
|
|
width: $(this).data('width'), |
|
|
|
height: $(this).data('height') |
|
|
|
}); |
|
|
|
box.click(function() { |
|
|
|
box.remove() |
|
|
|
$('#pins').css({ |
|
|
|
'position': 'static', |
|
|
|
'margin-top': 0 |
|
|
|
}); |
|
|
|
$(window).scrollTop(scrollLevel); |
|
|
|
}); |
|
|
|
function getLightboxData(link) { |
|
|
|
var data = link.data(); |
|
|
|
data.tags = cleanTags(data.tags); |
|
|
|
data.image = link.attr('href'); |
|
|
|
return data; |
|
|
|
} |
|
|
|
// End Helper Functions |
|
|
|
|
|
|
|
|
|
|
|
// Start View Functions |
|
|
|
function createBox(context) { |
|
|
|
freezeScroll(); |
|
|
|
$('body').append(renderTemplate('#lightbox-template', context)); |
|
|
|
var box = $('.lightbox-background'); |
|
|
|
box.css('height', $(document).height()); |
|
|
|
$('.lightbox-image-wrapper').css('height', context.height); |
|
|
|
box.fadeIn(200); |
|
|
|
$('.lightbox-image').load(function() { |
|
|
|
$(this).fadeIn(200); |
|
|
|
}); |
|
|
|
$('.lightbox-wrapper').css({ |
|
|
|
'width': context.width, |
|
|
|
'margin-top': 100, |
|
|
|
'margin-left': -context.width/2 |
|
|
|
}); |
|
|
|
|
|
|
|
box.click(function() { |
|
|
|
$(this).fadeOut(200); |
|
|
|
setTimeout(function() { |
|
|
|
box.remove(); |
|
|
|
}, 200); |
|
|
|
freezeScroll(false); |
|
|
|
}); |
|
|
|
} |
|
|
|
// End View Functions |
|
|
|
|
|
|
|
|
|
|
|
// Start Global Init Function |
|
|
|
window.lightbox = function() { |
|
|
|
var links = $('body').find('.lightbox'); |
|
|
|
return links.each(function() { |
|
|
|
$(this).off('click'); |
|
|
|
$(this).click(function(e) { |
|
|
|
createBox(getLightboxData($(this))); |
|
|
|
e.preventDefault(); |
|
|
|
}); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
// End Global Init Function |
|
|
|
}); |