2013-02-27 04:34:44 +00:00
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
|
|
*/
|
2013-02-23 04:42:22 +00:00
|
|
|
|
|
|
|
|
|
2013-02-27 04:34:44 +00:00
|
|
|
$(window).load(function() {
|
|
|
|
|
// Start Helper Functions
|
|
|
|
|
function freezeScroll(freeze) {
|
|
|
|
|
freeze = typeof freeze !== 'undefined' ? freeze : true;
|
|
|
|
|
if (freeze) {
|
|
|
|
|
$('body').data('scroll-level', $(window).scrollTop());
|
2013-02-26 06:46:55 +00:00
|
|
|
$('#pins').css({
|
2013-02-27 04:34:44 +00:00
|
|
|
'position': 'fixed',
|
|
|
|
|
'margin-top': -$('body').data('scroll-level')
|
2013-02-26 06:46:55 +00:00
|
|
|
});
|
2013-02-27 04:34:44 +00:00
|
|
|
$(window).scrollTop(0);
|
|
|
|
|
} else {
|
|
|
|
|
$('#pins').css({
|
|
|
|
|
'position': 'static',
|
|
|
|
|
'margin-top': 0
|
2013-02-23 04:42:22 +00:00
|
|
|
});
|
2013-02-27 04:34:44 +00:00
|
|
|
$(window).scrollTop($('body').data('scroll-level'));
|
2013-02-23 04:42:22 +00:00
|
|
|
}
|
2013-02-27 04:34:44 +00:00
|
|
|
}
|
2013-02-23 04:42:22 +00:00
|
|
|
|
2013-02-27 04:34:44 +00:00
|
|
|
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,
|
2013-02-27 04:37:42 +00:00
|
|
|
'margin-top': 70,
|
2013-02-27 04:34:44 +00:00
|
|
|
'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)));
|
2013-02-23 04:42:22 +00:00
|
|
|
e.preventDefault();
|
|
|
|
|
});
|
2013-02-27 04:34:44 +00:00
|
|
|
});
|
2013-02-23 04:42:22 +00:00
|
|
|
}
|
2013-02-27 04:34:44 +00:00
|
|
|
// End Global Init Function
|
2013-02-23 04:42:22 +00:00
|
|
|
});
|