-
Notifications
You must be signed in to change notification settings - Fork 163
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
Download picture from gallery #183
Conversation
Could we make this an option in admin panel? |
80fd11f
to
5dd808c
Compare
You'll take care of it? Or should I look at it tomorrow? |
I'm on it. However, I was just thinking that it wouldn't make sense to allow QR but no download and vice versa. I would combine it: if DL is enabled, both will be shown QR and DL button. OK with that? |
5dd808c
to
7e91e11
Compare
I have now implemented it as separate option. Still, I don't think this makes sense, but it can be easily changed once there is an agreement. Or left as is... ;-) |
I'd make it an own option independent of QR, gives people all possibilities to fit personal needs. |
Just tested, working fine :) thanks a lot!!! |
Only one thing we could change is to hide the button if we're accessing the page from our Pi (hide on access from IP of the Pi, localhost and 127.0.0.1). |
maybe you could cherry-pick and push this one here too andi34@366ea66 |
7e91e11
to
eaacc51
Compare
eaacc51
to
63f4b59
Compare
@andi34 I added a check for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution, but I think there are still some details to fix. See my comments and drop your two cents.
resources/js/photoinit.js
Outdated
$('.pswp__button--download').on('click touchstart', function (e) { | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
location = 'api/download.php?image=' + img; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
window.location
would be better than location
(because it makes clear that location
is no local variable), but the html5 download attribute would be even better. If you create a new a
element at this position with the corresponding attributes a emulated click event on that element should work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I get you right, you suggest to replace <button class="pswp__button pswp__button--download" ...
in pwswp.template.php
(i.e. the current approach that applies to all the other buttons there) with an <a href="<js-injected-url>" download="" ...
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I meant something like this (untested):
const linkElement = $('<a>');
linkElement.attr({
href: 'URL_TO_IMAGE',
download: 'FILENAME',
});
linkElement.click();
This should ensure that the browser shows the download prompt instead of open the image.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also check if download attribute is supported by the browser?
function doesAnchorSupportDownload() {
return "download" in document.createElement("a")
}
Currently I am checking it this way
if (doesAnchorSupportDownload()) {
location = 'api/download.php?image=' + img;
} else {
alert('Unsupported on your Browser');
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I’m afraid I don’t get it. „On click“ the element gets manipulated and then .click() gets called? What’s the benefit?
I guess I will leave this PR open and leave it up to you (or s.o. else with web developer skills) to properly implement this feature. 😌
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was smart. Even better than my solution. I made only a couple of minor changes, otherwise a great pr. Thanks a lot. @andi34 there is no need to check for support. If the browser doesn't know the attribute it get's ignored. |
@sualko but wouldn't it be better to tell the people instead silent not working? |
@sualko Thanks, but that was a bit too quick now, I guess... You merged just the first but not the latest commit. I suggest to squash these on my branch and then merge the PR? |
Ah ok i see.. Okay but there might be one minor issue left with the button. I haven't looked into it yet as I first wanted to wait if this gets accepted at all. IIRC the button was not correctly aligned with the others - I will have to have a look... |
@rawbertp haven't checked yet, but he also added the line hight here: |
Alright, looks good (also on the iPad). :) |
Yes, he did 😂
That's no problem. The browser will still show the picture. |
Allow download of pictures from gallery.
Should fix #7 .