Skip to content
This repository has been archived by the owner on Feb 23, 2023. It is now read-only.

button helper / printing with v3 beta? #858

Closed
morrow95 opened this issue Apr 25, 2014 · 8 comments
Closed

button helper / printing with v3 beta? #858

morrow95 opened this issue Apr 25, 2014 · 8 comments

Comments

@morrow95
Copy link

I came across the v3 beta while searching about adding a print feature... does this have a print option included or not? I read this would be included in version 3. Does the 2.1 button helper work with this beta? I did not see it included in the beta zip.

@morrow95 morrow95 changed the title button helper with v3 beta? button helper / printing with v3 beta? Apr 25, 2014
@fancyapps
Copy link
Owner

fancyapps commented Feb 27, 2017

With v3, you could easily create your own buttons - http://fancyapps.com/fancybox/3/docs/#faq

@morrow95
Copy link
Author

Is that link supposed to actually go somewhere?

@fancyapps
Copy link
Owner

Oh, sorry, I accidentally copied link from my local computer - http://fancyapps.com/fancybox/3/docs/#faq

@morrow95
Copy link
Author

morrow95 commented Mar 1, 2017

Purchased a license the other day for v3 - very nice I must add! I am trying to implement the custom download button example you show in the faqs and it doesn't seem to be working correctly. I am wondering if this has something to do with the structure of the link on my site :

<a data-fancybox="ss-gallery" title="some title" data-caption="some caption" href="/showimage.php?show=capture22415.jpg"><img src="/showimage.php?show=capture22415.jpg" width="150"></a>

That is an example from my page. I have a thumbnail of the image linked to the full size of the image. Without going into a ton of detail I am using showimage.php to show (and link to) images because they are dynamically pulled from a database and I do not want to show the true file location of the image. When I try to use the download button example what ends up happening is it just links to the image by itself when clicked rather than asking to download it - with none of the fancybox buttons, close, etc shown, but the overlay is still behind it. The only way to 'exit' out of this is to use the back button which goes back to the original page.

Outside of the download button Fancybox works perfect with this example in every other way. If possible I would like to add this download button option to my users though.

Any ideas?

Is this because of the showimage.php method I am using as a link or something else? Any ideas how to get around this?

@fancyapps
Copy link
Owner

If you wish, you can force file download -

  1. Using PHP - update your "showimage.php" file to send necessary headers. Maybe this will help - http://stackoverflow.com/questions/25364389/how-to-download-image-file-by-force-download

  2. Adding HTML5 "download" attribute to the link, but it is not supported on Safari/Old IE - http://caniuse.com/#feat=download

    I have updated demo with this attribute, works fine on Chrome/FF/Edge.

  3. Use some JS ugly hack, not recommended.

@morrow95
Copy link
Author

morrow95 commented Mar 8, 2017

Looks like I will have to do some custom work with this one when I have some time. I like idea #1, but will need to create another php script to specifically handle this case as that file is used for other things. I supposed in the custom button code I could figure out a way to pass the correct information to the other page then somehow.... I'll have to look at how the custom button coding works again.

@fancyapps
Copy link
Owner

If I understand you correctly, you could just create links like "/showimage.php?show=capture22415.jpg&download=1" or simply "/showimage.php?download=capture22415.jpg". Then inside that php file just check the passed parameters to choose what headers to output.

@morrow95
Copy link
Author

morrow95 commented Mar 8, 2017

Yep, something like that. I would need to figure out how to write the custom button script though to do what I wanted.

I don't have time right now, but it looks like you are just using api and callbacks for the one in your demo. I would just need to modify this to do what I needed it to (pull the correct link off the page and what not). I guess I could add in a 'data-download='downloadlink here'' or something on my pages then pull out that link in the script below with some modifications. I'll have to play around with it when I have time.

$( '[data-fancybox]' ).fancybox({
	onInit : function( instance ) {
		instance.$refs.downloadButton = $('<a class="fancybox-button fancybox-download"></a>')
			.appendTo( instance.$refs.buttons );
	},
	beforeMove: function( instance, current ) {
		instance.$refs.downloadButton.attr('href', current.src);
	}
});

or better yet just append the &download=1 to the current links then I could use the same file and just modify the php to throw headers on download=true.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants