Coder Social home page Coder Social logo

feimosi / baguettebox.js Goto Github PK

View Code? Open in Web Editor NEW
2.4K 92.0 433.0 15.41 MB

:zap: Simple and easy to use lightbox script written in pure JavaScript

Home Page: https://feimosi.github.io/baguetteBox.js/

License: MIT License

CSS 10.47% JavaScript 89.53%
javascript gallery lightbox lightbox-script vanilla-javascript pure-javascript responsive modal

baguettebox.js's People

Contributors

bartdelrue avatar binarious avatar chi-teck avatar davidhellmann avatar edkf avatar feimosi avatar gergo85 avatar h-lo avatar leibrug avatar leomelzer avatar lorenzck avatar louy avatar o-klp avatar rgalanakis avatar romanhotsiy avatar terrytilley avatar tobaco avatar xhmikosr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

baguettebox.js's Issues

Responsive images never fall back to default href

Responsive images never fall back to default href. Image with the biggest size specified by data-at attribute is used instead.

I think the problem is on lines 356-360:

// Find the first image bigger than or equal to the current width
var i = 0;
while(i < keys.length - 1 && keys[i] < width)
    i++;
result = srcs[keys[i]] || result;

While loop stop before checking the last key (i < keys.length - 1) thus there is always some result taken from srcs object. I suggest changing the condition to i < keys.length. Then i will overflow array size, undefined will be returned from srcs and result will be taken from fallback.

Global event listener on document can't be unbound

I use baguetteBox in app with front-end routing and need init baguetteBox on different routes. As I use front-end routing page doesn't reload between initialization so keydown event handler appears to be bound more than once.
Actually it even doesn't make sense to bind key events when overlay is hidden so my suggestion is bind keydown only when overlay is displayed and unbind after it's hidden.

Check if the 'a' contains an image link

More of a feature request than issue.

Wondering if there could be some sort of check for the 'a' element in the gallery to make sure it contains a link to an image. Then we could run baguetteBox on an element that contains both image links and standard links.

Add callback function

Hi, can you add callback options like afterShow and afterHide? I append <button> inside data-caption and but the button listener isn't triggered when the <button> is clicked because the button was appended on the fly. Adding afterShow callback might fix this issue.

Example:

<a href="image.jpg" data-caption="<button>Click to download</button>">
    <img src="thumbnail.jpg">
</a>
baguetteBox.run('.gallery', {
    afterShow: function () {
        // btn.addEventListener();
    }
});

Another solution to hide scroll bars

To hide scroll bars current solution is
document.body.style.overflow = 'hidden';
But in this case in some browsers (firefox & chrome) the page content rebuilding to refill all window width.

I've been hid scroll bars with this code:

/* for html tag */
document.documentElement.style.overflowY = 'hidden'; 
/* for body tag */
document.body.style.overflowY = 'scroll';

in context:

function showOverlay(chosenImageIndex) {
    /*if(options.noScrollbars)
        document.body.style.overflow = 'hidden';*/
    if(overlay.style.display === 'block') {
        return;
    }
    bind(document, 'keydown', keyDownHandler);
    currentIndex = chosenImageIndex;
    loadImage(currentIndex, function() {
        preloadNext(currentIndex);
        preloadPrev(currentIndex);
    });     

    updateOffset();
    overlay.style.display = 'block';
    if(options.fullScreen)
        enterFullScreen();
    // Fade in overlay
    setTimeout(function() {
        overlay.className = 'visible';
        if(options.afterShow)
            options.afterShow();
        /*kir*/document.documentElement.style.overflowY = 'hidden';
        /*kir*/document.body.style.overflowY = 'scroll';
    }, 50);
    if(options.onChange)
        options.onChange(currentIndex, imagesElements.length);
}

function hideOverlay() {
    /*if(options.noScrollbars)
        document.body.style.overflow = 'auto';*/
    if(overlay.style.display === 'none') {
        return;
    }

    unbind(document, 'keydown', keyDownHandler);
    // Fade out and hide the overlay
    overlay.className = '';
    setTimeout(function() {
        overlay.style.display = 'none';
        exitFullscreen();
        /*kir*/document.documentElement.style.overflowY = 'auto';
        /*kir*/document.body.style.overflowY = 'auto';
        if(options.afterHide)
            options.afterHide();
    }, 500);
}

Live demo on http://kirillaristov.com/en/my-routes/as-the-first-settlers/photos/fav (any clickable image)

This is my first experience in github, sorry if something is wrong.

(Marek, thank you for your project! This is very cool lightbox!)

Carousel option

Very interesting project. It could be useful to add a "carousel" option to cycle from the last image to the first (or from the first to the last image). Obviously the last or first image "bounce effect" should be disabled when the carousel option is active. Thank you

Auto sliding of images on pop up window

Hi,

I'm using baguetteBox.js for image gallery. I want to auto scroll of images on pop up window.

A quick help on this would be appreciated.

thanks,
Sam Ambler

Conflict with Prototype

The plugin seems to fail when running with Prototype.js (my particular project uses Magento, which is dependent on prototype.js, otherwise I'd ditch prototype for sure).

link not ending with regex

If i have a link to an image that doesn't end with your regex for image matching the image will not be displayed

Question

Hi there,
I apologise if this is a dumb question, I am no coder...
How could I use the baguetteBox in such a way that a gallery would be triggered by a single image?...
I have tried adding the href code on the first image, and afterwards insert the code only for the following images, but this gets faulty results, sometimes it works, sometime it doesn't... :)
(I tried this solution, because it actually works with another script I used in the past)
Any hint would be greatly appreciated...
Thank you so much,
Ana
bagettebox-single-image

Click image > next

As subject, is this possible somehow ?

Maybe also nice to make it possible to change the arrow colors via options or css.

Doesn't work in AngularJS ng-repeat directive

The following works, copied from the build folder (of course changed the path on an image for local testing).

However when I call the same class 'baguetteBoxOne' on an anchor/image inside ng-repeat it doesn't work. Any work around? I'm a novice at JS so I don't know if I will be able to assist very much on the issue.

 <div class="baguetteBoxOne gallery">
                    <a href="img/1-1.jpg" data-caption="Golden Gate Bridge"><img src="img/thumbs/1-1.jpg"></a>
                    <a href="img/1-2.jpg" title="Midnight City"><img src="img/thumbs/1-2.jpg"></a>
                    <a href="../images/SouthernRebels Logo.jpg"><img src="../images/SouthernRebelsLogo75px.jpg"></a>
                    <a href="img/1-4.jpg"><img src="img/thumbs/1-4.jpg"></a>
                    <a href="img/1-5.jpg"><img src="img/thumbs/1-5.jpg"></a>
                    <a href="img/1-6.jpg"><img src="img/thumbs/1-6.jpg"></a>
                    <a href="img/1-7.jpg"><img src="img/thumbs/1-7.jpg"></a>
                    <a href="img/1-8.jpg"><img src="img/thumbs/1-8.jpg"></a>
                </div>

The next snippet is the code in the repeater:

  <tr ng-repeat="u in Users" ng-style="{'color': (u.Status == false ? 'red' : '')}">
                            <td class="baguetteBoxOne">
                                <!--<img ng-show="u.ImagePath == null || u.ImagePath == 'null'" src="../images/avatar.jpg" width="50" height="50" />-->
                                <a class="single-popup" href="{{u.ImagePath}}" title="{{u.Username}}'s Profile Pic">
                                    <img ng-src="{{u.ImagePath}}" width="50" height="50" />
                                </a>
                            </td>

Lightbox Thumbnail

Is there any method that i can use to add thumbnails inside the lightbox for better navigation? Thanks.

Add support for showing image(s) without predefined HTML structure

It looks like there's currently no way to show images programmatically.

I.e., the following is not possible, as far as I can tell.

baguetteBox.run('myimage.jpg');

or

baguetteBox.showImage({src:'myimage.jpg', caption: 'whatever'});

Having this ability would allow for easier integration with other scripts and custom markup.

I managed to bastardize a new "showImage" function for myself out of what's available, but such a simple addition could make this script a lot more useful to other people too, I think.

Add download image option

Hi.
I don't know if this is the right place to post this.

Would it be possible to add a download option to the gallery? where a user could click a download button and it would download a full resolution image defined for E.g. data-download="{{path to high resolution 4K PNG image}}"

I currently have some 4k resolution artwork that I don't want to load when you open the gallery but instead provide a download button linking to it.

Cheers,
Jack

P.S This plugin is great!

Bug in Chrome

Hello!

I'm using version 38.0.21.2125.24 beta-m (64-bit) Chrome and when I click close, continues to overlay. When you select something on the page it fades away, like rendering problem. It is Chrome? Had a recent update. I could not test in another version of Chrome, but testing on other browsers and all is right.

PS. Always used the beta version of Chrome. Had a recent update for 64-bit and other corrections.

image

What about navigation?

Any plan to add a navigation feature? I think that can be very useful.

It might look to something like this:
schermata 2014-09-01 alle 15 46 55

Thanks for the great lightbox!

Custom caption support?

I wonder if I am able to insert <a> inside the caption. Now I can achieve what I need by doing this

<a id="baguette" href="path-to-img" data-caption="Hi, I'm <a href='#'>clickable<a>">
    <img src="path-to-img">
</a>

I'm sure there is a better way to do that. What you thing about it?

Overlay flashes when moving mouse

OSX Mavericks, latest Chrome.

After opening up a picture in the lightbox, when you first move your mouse, the black overlay briefly turns off then back on. Here is a gif showing this:

baquettebox

Trigger display from another element

Hello @feimosi , congrats for this nice piece of code ! I meant it, simple, responsive and touch friendly 👍

I'm trying to trigger the display of the overlay + first image on click on another element (completely outside of the gallery element).

I have tried, with the help of jQuery

$('.item').first().trigger('click');

with no success. Do you have any tip or idea to do that ?

Thank you for your help.

No text wrap for long caption

Hi,
is it possible to force text wrapping of the captions?
When the text is too long or when the window is too small the caption simply goes out of view because it stays as a single line.
I have tried playing with the css file, in particular with the #baguetteBox-overlay .full-image figcaption {} but couldn't find a solution by myself...any help?
Thanks,

Stefano

animation - false

Please can switch images without effect (animation: false).
Сделайте пожалуйста возможность переключения изображений без эффекта (animation: false).

Thank you!
Благодарю.

AMD Support

This plugin is offered as an npm package but it doesn't support AMD or CommonJS. How comes? :)

bug

line 160
imagedEventHandlers[imageElement] = imageElementClickHandler;

when there has two or more img element is the same then can not unbind it because the imageElementClickHandler is not the same

can change it to
imagedEventHandlers[galleryID+'__'+imageIndex] = imageElementClickHandler;
?

No way to destroy

Unfortunately this makes the plugin useless for me, even though it is very nice. I needed to use it as a component in a single-page app.

Video Support

Any chance for video support? I know it wouldn't be easy but even the ability to use the default html video player in the lightbox would rock

Dynamically added images kill the script

Fantastic, minimal, very nicely designed script here!

Just running into one annoying bug.. it seems to be breaking when using on a page where the images within the '.gallery' div grow dynamically. I'm building a sort of drag + drop image displaying tool and the script works great for contents already in the gallery.. but the minute I add a new content and try to click on something I get this error in the log:

[Error] NotFoundError: DOM Exception 8: An attempt was made to reference a Node in a context where it does not exist.
removeChild (baguetteBox.min.js, line 7:3867)
onload (baguetteBox.min.js, line 7:3867)

I'm trying to do the baguetteBox.run() code on each time I load new contents.. (probably wrong) also tried first destroying it then re-running it to no avail. Also tested turning 'async' on, but no go. With another lightbox or lytebox, I recall being able to simply re-init the thing with new contents coming in– however your design is really elegant and jquery-free! Any tips? or something obvious I'm missing?

delegete / link selector

Hey, thank you for your nice work!

What about something similar to MagnificPopups delegate option?
It's used to tell which links are used to open the modal.
So you can have
baguetteBox.run('.gallery', {
delegate: '.modal'
});
so only links with "modal" class are considered within gallery (of course still checked if any image is present)
so you could have some image excluded, think this would be nice :)

Buttons don't show up on Windows 10

So this is weird :/ In my main OS, Windows 10 64-bit, the buttons don't show up in auto mode.

On my Windows 7 VM they show up. Something must be different in the touch detection.

npm is still on 1.3.2

Can you update to the newest version?
Maybe combine the gulp bump-patch task with npm publish to keep it always sync.

Custom image filter

Hello @feimosi they nice lib)

I was interested then trying use with image placeholder services, where gallery builded unexpectedly.
So after debug i find image filter that works by regex rule /.+\.(gif|jpe?g|png|webp)/i

May be add custom filter?

baguetteBox.run('.gallery', {
  filter: new RegExp('.+\.(gif|jpe?g|png|webp)', 'i')
});

and to skip filtering

baguetteBox.run('.gallery', {
  filter: null
});

Enable zooming of images on mobile devices

when the image is opened in the popup screen, zooming is disabled or almost unusable. since the mobile width is short so if u could add zooming enhancement, it would be a great experience for user to zoom in the opened image.
thanks

exclude figcaption from dismiss area

Clicking on the figcaption dismiss the lightbox. I don't know if that is an intended behavior, but this prevent user to select or highlight texts from the caption.

Added 4 new features

Hello!

I have 4 new features to your code:

-- titleTag - copy title tag from thumbnail to main image; this one is good for copyright notice, but to have fullscreen photos

-- removeButtonsAfter - remove navigation and close buttons after some idle time and show them on mousemove; this one is very good when using keyborad navigation

-- noScrollbars - remove scrollbars from body element while displaying image in overlay

-- fullScreen - display overlay in full screen

All features are disabled by default and can be set using options object while calling run().

Modified file is available here: http://malizwrk.net/baguetteBox-v1.4.2/baguetteBox-H.Lo.js
Live demo is available here: http://malizwrk.net/gallery/

Tried to write code in your style.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.