dimsemenov / PhotoSwipe

JavaScript image gallery for mobile and desktop, modular, framework independent
http://photoswipe.com
MIT License
24.23k stars 3.31k forks source link

call download using custom button #1318

Open pixellet14 opened 7 years ago

pixellet14 commented 7 years ago

is it possible to call download using a custom button / link ??

rinogo commented 4 years ago

I wanted to add a "Download" button to the top level so our users don't have to "drill down" into the "Share" menu.

This seems to work for me (not extensively tested):

Add a new button near the other buttons you already have. Note that we're surrounding it in an <a> tag:

<a target="_blank" download>
    <button class="pswp__button pswp__button--download" title="Download"></button>
</a>

Then, add two lines to the ui.update() function:

ui.update = function() {
    // Don't update UI if it's hidden
    if(_controlsVisible && pswp.currItem) {

        ui.updateIndexIndicator();

        //Add two new lines below:
        //Find our top-level "Download" button and set its `href` attribute appropriately.
        document.querySelectorAll(".pswp__button--download")[0].parentElement.setAttribute("href", _options.getImageURLForShare());
//(function continues)...

Of course, you'll want to style the new Download button according to your desires.

rinogo commented 4 years ago

For correct functioning on Android, you may also need to add something like this to _uiElements:

{
    name: 'button--download',
    option: 'downloadEl',
    onInit: function(el) {
    },
    onTap: function() {
    }
},

...and then "enabling" it in options:

downloadEl: true
pixellet14 commented 4 years ago

Hey,

Thanks for replying mate...it's never too late... uh...if you must have noticed that question was posted in the year 2017 and it's almost 3 yrs now...but your solution is different than what we found out at the time it was needed so I am definitely gonna try it! Cheers

rinogo commented 4 years ago

I definitely noticed! Figured it might help someone else. What’s a good way to contact you outside of GH? I’ll send you a link to our live app in case you want to check out the source!

pixellet14 commented 4 years ago

sure! ...ritesh@adhocteam.com