2013-02-23 04:42:22 +00:00
|
|
|
$(window).load(function() {
|
2013-02-26 06:46:55 +00:00
|
|
|
var scrollLevel = 0;
|
|
|
|
|
|
2013-02-23 04:42:22 +00:00
|
|
|
window.lightbox = function(pins) {
|
|
|
|
|
var links = pins.find('.lightbox');
|
|
|
|
|
|
2013-02-23 06:28:02 +00:00
|
|
|
function createBox(boxData) {
|
2013-02-23 04:42:22 +00:00
|
|
|
var template = Handlebars.compile($('#lightbox-template').html());
|
2013-02-23 06:28:02 +00:00
|
|
|
var html = template(boxData);
|
2013-02-23 04:42:22 +00:00
|
|
|
$('body').append(html);
|
|
|
|
|
|
2013-02-26 06:46:55 +00:00
|
|
|
scrollLevel = $(window).scrollTop();
|
|
|
|
|
$('#pins').css({
|
|
|
|
|
'margin-top': String(-scrollLevel)+'px',
|
|
|
|
|
'position': 'fixed'
|
|
|
|
|
});
|
|
|
|
|
|
2013-02-23 04:42:22 +00:00
|
|
|
$('.lightbox-wrapper img').load(function() {
|
|
|
|
|
$('.lightbox-background').css('height', String($(document).height())+'px');
|
|
|
|
|
$('.lightbox-wrapper').css({
|
2013-02-26 06:46:55 +00:00
|
|
|
'width': boxData.width,
|
|
|
|
|
'margin-top': String(100)+'px',
|
|
|
|
|
'margin-left': '-'+String(boxData.width/2)+'px'
|
2013-02-23 04:42:22 +00:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return $('.lightbox-background');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (var i=0; i < links.length; i++) {
|
|
|
|
|
link = links.eq(i);
|
|
|
|
|
link.off('click');
|
|
|
|
|
link.click(function(e) {
|
2013-02-23 06:28:02 +00:00
|
|
|
var box = createBox({
|
|
|
|
|
image: $(this).attr('href'),
|
|
|
|
|
gravatar: $(this).data('gravatar'),
|
|
|
|
|
username: $(this).data('username'),
|
2013-02-26 06:46:55 +00:00
|
|
|
description: $(this).data('description'),
|
|
|
|
|
tags: $(this).data('tags').split(','),
|
|
|
|
|
width: $(this).data('width'),
|
|
|
|
|
height: $(this).data('height')
|
2013-02-23 06:28:02 +00:00
|
|
|
});
|
2013-02-23 04:42:22 +00:00
|
|
|
box.click(function() {
|
|
|
|
|
box.remove()
|
2013-02-26 06:46:55 +00:00
|
|
|
$('#pins').css({
|
|
|
|
|
'position': 'static',
|
|
|
|
|
'margin-top': 0
|
|
|
|
|
});
|
|
|
|
|
$(window).scrollTop(scrollLevel);
|
2013-02-23 04:42:22 +00:00
|
|
|
});
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|