Have a working custom lightbox plugin now

This commit is contained in:
Isaac Bythewood
2013-02-23 04:42:22 +00:00
parent 5a74253bf8
commit 2264d96528
6 changed files with 61 additions and 3 deletions

View File

@@ -0,0 +1,12 @@
.lightbox-background {
background: rgba(0, 0, 0, 0.7);
top: 0;
left: 0;
right: 0;
position: absolute;
}
.lightbox-wrapper {
position: absolute;
left: 50%;
}

View File

@@ -0,0 +1,38 @@
$(window).load(function() {
window.lightbox = function(pins) {
var links = pins.find('.lightbox');
function createBox(imageUrl) {
var template = Handlebars.compile($('#lightbox-template').html());
var html = template({image: imageUrl});
$('body').append(html);
$('.lightbox-wrapper img').load(function() {
$('.lightbox-background').css('height', String($(document).height())+'px');
$(this).css({
'max-width': String($(window).width()-200)+'px',
'max-height': String($(window).height()-200)+'px',
'margin-top': String($(window).scrollTop()+100)+'px'
});
var width = $(this).width();
$('.lightbox-wrapper').css({
'margin-left': '-'+String(width/2)+'px'
});
});
return $('.lightbox-background');
}
for (var i=0; i < links.length; i++) {
link = links.eq(i);
link.off('click');
link.click(function(e) {
var box = createBox($(this).attr('href'));
box.click(function() {
box.remove()
});
e.preventDefault();
});
}
}
});

View File

@@ -45,6 +45,7 @@ $(window).load(function() {
colHeights[sCol] += block.height()+(blockMargin); colHeights[sCol] += block.height()+(blockMargin);
} }
lightbox(blocks);
$('.spinner').css('display', 'none'); $('.spinner').css('display', 'none');
blockContainer.css('height', colHeights.sort().slice(-1)[0]); blockContainer.css('height', colHeights.sort().slice(-1)[0]);
} }
@@ -63,7 +64,6 @@ $(window).load(function() {
// Set which items are editable by the current user // Set which items are editable by the current user
for (var i=0; i < pins.objects.length; i++) for (var i=0; i < pins.objects.length; i++)
pins.objects[i].editable = (pins.objects[i].submitter.username == currentUser); pins.objects[i].editable = (pins.objects[i].submitter.username == currentUser);
console.log(pins.objects);
// Use the fetched pins as our context for our pins template // Use the fetched pins as our context for our pins template
var template = Handlebars.compile($('#pins-template').html()); var template = Handlebars.compile($('#pins-template').html());

View File

@@ -9,9 +9,9 @@
<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Monoton"> <link rel="stylesheet" href="//fonts.googleapis.com/css?family=Monoton">
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.0/css/bootstrap.min.css"> <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.0/css/bootstrap.min.css">
{% compress css %} {% compress css %}
<link rel="stylesheet" href="{{ STATIC_URL }}css/pinry.css">
<link rel="stylesheet" href="{{ STATIC_URL }}css/messages.css"> <link rel="stylesheet" href="{{ STATIC_URL }}css/messages.css">
<link rel="stylesheet" href="{{ STATIC_URL }}css/lightbox.css"> <link rel="stylesheet" href="{{ STATIC_URL }}css/lightbox.css">
<link rel="stylesheet" href="{{ STATIC_URL }}css/pinry.css">
{% endcompress %} {% endcompress %}
</head> </head>
<body> <body>
@@ -58,9 +58,9 @@
<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.0/js/bootstrap.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.0/js/bootstrap.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.0.0-rc.3/handlebars.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.0.0-rc.3/handlebars.min.js"></script>
{% compress js %} {% compress js %}
<script src="{{ STATIC_URL }}js/pinry.js"></script>
<script src="{{ STATIC_URL }}js/messages.js"></script> <script src="{{ STATIC_URL }}js/messages.js"></script>
<script src="{{ STATIC_URL }}js/lightbox.js"></script> <script src="{{ STATIC_URL }}js/lightbox.js"></script>
<script src="{{ STATIC_URL }}js/pinry.js"></script>
{% endcompress %} {% endcompress %}
</body> </body>
</html> </html>

View File

@@ -15,6 +15,14 @@
{% block templates %} {% block templates %}
{% verbatim %} {% verbatim %}
<script id="lightbox-template" type="text/x-handlebars-template">
<div class="lightbox-background">
<div class="lightbox-wrapper">
<img src="{{image}}" />
</div>
</div>
</script>
<script id="pins-template" type="text/x-handlebars-template"> <script id="pins-template" type="text/x-handlebars-template">
{{#each pins}} {{#each pins}}
<div class="pin"> <div class="pin">