Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add download link #323

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lightbox",
"version": "2.7.1",
"version": "2.7.2",
"homepage": "http://lokeshdhakar.com/projects/lightbox2/",
"authors": [
"Lokesh Dhakar <[email protected]>"
Expand Down
18 changes: 18 additions & 0 deletions css/lightbox.css
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,21 @@ body:after {
filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=100);
opacity: 1;
}

.lb-download{
border-radius: 5px;
display: block;
height: 40px;
width: 40px;
background: url(../img/arrow-down.png) 50% 50% no-repeat;
background-color: rgba(0,0,0,.5);
transition: .2s;
opacity: .3;
position: absolute;
bottom: 15px;
right: 15px;
z-index: 11;
}
.lb-download:hover{
opacity: 1;
}
Binary file added img/arrow-down.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 19 additions & 13 deletions js/lightbox.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Lightbox v2.7.1
* Lightbox v2.7.2
* by Lokesh Dhakar - http://lokeshdhakar.com/projects/lightbox2/
*
* @license http://creativecommons.org/licenses/by/2.5/
Expand All @@ -21,7 +21,7 @@
this.alwaysShowNavOnTouchDevices = false;
this.wrapAround = false;
}

// Change to localize to non-english language
LightboxOptions.prototype.albumLabel = function(curImageNum, albumSize) {
return "Image " + curImageNum + " of " + albumSize;
Expand Down Expand Up @@ -58,8 +58,8 @@
// Attach event handlers to the new DOM elements. click click click
Lightbox.prototype.build = function() {
var self = this;
$("<div id='lightboxOverlay' class='lightboxOverlay'></div><div id='lightbox' class='lightbox'><div class='lb-outerContainer'><div class='lb-container'><img class='lb-image' src='' /><div class='lb-nav'><a class='lb-prev' href='' ></a><a class='lb-next' href='' ></a></div><div class='lb-loader'><a class='lb-cancel'></a></div></div></div><div class='lb-dataContainer'><div class='lb-data'><div class='lb-details'><span class='lb-caption'></span><span class='lb-number'></span></div><div class='lb-closeContainer'><a class='lb-close'></a></div></div></div></div>").appendTo($('body'));
$("<div id='lightboxOverlay' class='lightboxOverlay'></div><div id='lightbox' class='lightbox'><div class='lb-outerContainer'><div class='lb-container'><img class='lb-image' src='' /><div class='lb-nav'><a class='lb-prev' href='' ></a><a class='lb-next' href='' ></a></div><div class='lb-loader'><a class='lb-cancel'></a></div><a class='lb-download' href='' target='_blank'></a></div></div><div class='lb-dataContainer'><div class='lb-data'><div class='lb-details'><span class='lb-caption'></span><span class='lb-number'></span></div><div class='lb-closeContainer'><a class='lb-close'></a></div></div></div></div>").appendTo($('body'));

// Cache jQuery objects
this.$lightbox = $('#lightbox');
this.$overlay = $('#lightboxOverlay');
Expand All @@ -71,7 +71,7 @@
this.containerRightPadding = parseInt(this.$container.css('padding-right'), 10);
this.containerBottomPadding = parseInt(this.$container.css('padding-bottom'), 10);
this.containerLeftPadding = parseInt(this.$container.css('padding-left'), 10);

// Attach event handlers to the newly minted DOM elements
this.$overlay.hide().on('click', function() {
self.end();
Expand Down Expand Up @@ -114,6 +114,10 @@
self.end();
return false;
});

this.$lightbox.find('.lb-download').on('click', function (e) {
window.open(e.target.href);
});
};

// Show overlay and lightbox. If the image is part of a set, add siblings to album array.
Expand Down Expand Up @@ -166,7 +170,7 @@
}
}
}

// Position Lightbox
var top = $window.scrollTop() + this.options.positionFromTop;
var left = $window.scrollLeft();
Expand All @@ -184,6 +188,7 @@

this.disableKeyboardNav();
var $image = this.$lightbox.find('.lb-image');
var $downloadLink = this.$lightbox.find('.lb-download');

this.$overlay.fadeIn(this.options.fadeDuration);

Expand All @@ -197,12 +202,13 @@
preloader.onload = function() {
var $preloader, imageHeight, imageWidth, maxImageHeight, maxImageWidth, windowHeight, windowWidth;
$image.attr('src', self.album[imageNumber].link);
$downloadLink.attr('href', self.album[imageNumber].link);

$preloader = $(preloader);

$image.width(preloader.width);
$image.height(preloader.height);

if (self.options.fitImagesInViewport) {
// Fit image inside the viewport.
// Take into account the border around the image and an additional 10px gutter on each side.
Expand Down Expand Up @@ -244,12 +250,12 @@
// Animate the size of the lightbox to fit the image we are showing
Lightbox.prototype.sizeContainer = function(imageWidth, imageHeight) {
var self = this;

var oldWidth = this.$outerContainer.outerWidth();
var oldHeight = this.$outerContainer.outerHeight();
var newWidth = imageWidth + this.containerLeftPadding + this.containerRightPadding;
var newHeight = imageHeight + this.containerTopPadding + this.containerBottomPadding;

function postResize() {
self.$lightbox.find('.lb-dataContainer').width(newWidth);
self.$lightbox.find('.lb-prevLink').height(newHeight);
Expand All @@ -273,7 +279,7 @@
Lightbox.prototype.showImage = function() {
this.$lightbox.find('.lb-loader').hide();
this.$lightbox.find('.lb-image').fadeIn('slow');

this.updateNav();
this.updateDetails();
this.preloadNeighboringImages();
Expand Down Expand Up @@ -330,15 +336,15 @@
location.href = $(this).attr('href');
});
}

if (this.album.length > 1 && this.options.showImageNumberLabel) {
this.$lightbox.find('.lb-number').text(this.options.albumLabel(this.currentImageIndex + 1, this.album.length)).fadeIn('fast');
} else {
this.$lightbox.find('.lb-number').hide();
}

this.$outerContainer.removeClass('animating');

this.$lightbox.find('.lb-dataContainer').fadeIn(this.options.resizeDuration, function() {
return self.sizeOverlay();
});
Expand Down
Loading