Log in

View Full Version : DD PHP Photo Album (using Slimbox2) on Mobile



mcos
05-05-2015, 07:23 PM
So we are using the following DD PHP Photo Album:

http://www.dynamicdrive.com/dynamicindex4/php-photoalbum.htm

with Slimbox2 using the following instructions:

http://www.dynamicdrive.com/forums/showthread.php?65828-PHP-Photo-Album-script-v2-11-Captions-Inside-Lightbox

Works fantastic, as it should, on desktop! But on mobile devices, it breaks all jquery/styling of the site and displays incorrectly.

To see the demo installed:

http://www.silverhorseracing.com/94-04-mustang-customers/

And on mobile site you can visit the same URL, it will recognize you are on mobile/tablet.

Is there a way to at least get the script to work correctly?

Beverleyh
05-05-2015, 07:33 PM
Nope - not loading for me on iPhone 5S (wifi)

I waiting around 10 seconds and all I see is the squirly loading thing in the middle of the screen.

Try reducing the weight of the page by optimising your images (if you haven't already) or reducing the number so that the page loads more quickly.

As an alternative script, you might be interested in this PHP generated responsive gallery with modal image viewer - version 5 in this blog post http://www.dynamicdrive.com/forums/entry.php?290-Paginated-Responsive-Modal-Gallery-(PHP-CSS3-JS)

mcos
05-05-2015, 07:45 PM
UPDATE:

Figured out some of the problem! My mobile site loads its own jquery-min.js file, and in the custom HTML I did for the photo album, I included another jquery-min.js, this caused an error.

Removed that and now the album shows correctly to me, but clicking images does not work yet [slimbox 2 isn't activating on click]

jscheuer1
05-05-2015, 08:30 PM
Slimbox 2 specifically excludes mobile devices because (as far as I can tell) at least some, if not all of its features do not work well on mobiles. Now, the code in the thread that you linked to removes this explicit exclusion, but makes no attempt at making Slimbox 2 work with touch events.

A tap (which is really a touchstart followed quickly by a touchend with the target elements being the same - no dragging off of the start element before the touchend occurs) is often interpreted the same as a click on mobiles, but not always.

There are lightbox type scripts that work with mobiles. It would perhaps be easiest to use one of these instead of Slimbox 2. Butif you want to stick with Slimbox 2 it might be able to be adapted. The first step though would be to see if it works on a non-mobile (a desktop or laptop). Just tried that and it works. So to see if we can get things started on mobile (more work will need to be done, but this is a test to see if it can happen at all) change in the ddphpalbum.js file:


phpimagealbum.prototype={

buildgallery:function(){
var thisalbum=this
var curimage=0
document.write('<div id="'+this.albumdivid+'">')
for (var rows=0; rows<this.dimensions[1]; rows++){
for (var cols=0; cols<this.dimensions[0]; cols++){
if (curimage<this.albumvar.images.length)
document.write('<div class="photodiv">' + phpimagealbum.routines.buildimage(this.albumvar, curimage, this.autodesc, this.showsourceorder) + '</div>')
curimage++
} //end cols loop
document.write('<br style="clear: left" />')
} //end rows loop
document.write('</div>')
var albumdiv=document.getElementById(this.albumdivid)
var alldivs=albumdiv.getElementsByTagName('div')
for (var i=0; i<alldivs.length; i++){
if (alldivs[i].className=="photodiv")
this.photodivs.push(alldivs[i])
}
phpimagealbum.routines.addEvent(albumdiv, function(e){
var e=window.event || e
var target=e.srcElement || e.target
if (target.tagName=="IMG" && target.getAttribute('data-index')){
thisalbum.onphotoclick(target, thisalbum.albumvar.images[parseInt(target.getAttribute('data-index'))][0], thisalbum.albumvar.images[parseInt(target.getAttribute('data-index'))][1])
}
}, "click")
},

to:


phpimagealbum.prototype={

buildgallery:function(){
var thisalbum=this
var curimage=0
document.write('<div id="'+this.albumdivid+'">')
for (var rows=0; rows<this.dimensions[1]; rows++){
for (var cols=0; cols<this.dimensions[0]; cols++){
if (curimage<this.albumvar.images.length)
document.write('<div class="photodiv">' + phpimagealbum.routines.buildimage(this.albumvar, curimage, this.autodesc, this.showsourceorder) + '</div>')
curimage++
} //end cols loop
document.write('<br style="clear: left" />')
} //end rows loop
document.write('</div>')
var albumdiv=document.getElementById(this.albumdivid)
var alldivs=albumdiv.getElementsByTagName('div')
for (var i=0; i<alldivs.length; i++){
if (alldivs[i].className=="photodiv")
this.photodivs.push(alldivs[i])
}
phpimagealbum.routines.addEvent(albumdiv, function(e){
var e=window.event || e
var target=e.srcElement || e.target
if (target.tagName=="IMG" && target.getAttribute('data-index')){
thisalbum.onphotoclick(target, thisalbum.albumvar.images[parseInt(target.getAttribute('data-index'))][0], thisalbum.albumvar.images[parseInt(target.getAttribute('data-index'))][1])
}
}, "click");
phpimagealbum.routines.addEvent(albumdiv, function(e){
var e=window.event || e
var target=e.srcElement || e.target
if (target.tagName=="IMG" && target.getAttribute('data-index')){
thisalbum.onphotoclick(target, thisalbum.albumvar.images[parseInt(target.getAttribute('data-index'))][0], thisalbum.albumvar.images[parseInt(target.getAttribute('data-index'))][1])
}
}, "touchstart");
},

mcos
05-05-2015, 08:36 PM
John,

I have implemented the suggested code and don't see any changes on my phone.

Can you verify if you see any changes or not? Mine might be cached (though I cleared cache and tried again).

jscheuer1
05-05-2015, 10:23 PM
Nope, I have no mobile to test on, hopefully Beverley or someone can check. I can verify that you made the change, and that the page/browser may need to be refreshed/have its cache cleared.

Beverleyh
05-06-2015, 09:01 AM
No joy here

jscheuer1
05-06-2015, 01:57 PM
I guess there's a reason then why Slimbox 2 excludes mobiles by default. But I also happen to know that refreshing the page and its resources is sometimes difficult on a mobile. Beverley, were you able to clear the cache and refresh the page before testing?

mcos
05-06-2015, 02:00 PM
I tried on multiple devices, no luck :(

Beverleyh
05-06-2015, 02:16 PM
Yes, cache cleared here John (I tried a few browsers and got zilch!)

jscheuer1
05-06-2015, 02:21 PM
OK, well adapting Slimbox 2 by itself to work on mobile could be quite a lot of work, and even if fairly simple, would be difficult without a device to test on. I have had some luck adapting much simpler code that I wrote, but even that took a lot of back and forth with someone who was testing it for me. I get frustrated because it's not always clear to me what is being seen, and the tester doesn't always follow instructions. So I'm choosing not to take this on at the moment.

My best recommendation would be to find a lightbox type script that works with mobile. Even then it might be tricky tying it in to the PHP Photo Album script.

mcos
05-06-2015, 02:38 PM
John,

Thank you for the help! I have decided on just disabling Slimbox2 on the mobile phone.

UPDATE:

Ignore the above, I seem to have got it to work!

mcos
05-06-2015, 02:51 PM
UPDATE:

Okay so, in the script provided here: http://www.dynamicdrive.com/forums/showthread.php?65828-PHP-Photo-Album-script-v2-11-Captions-Inside-Lightbox

the lines


if (!/android|iphone|ipod|series60|symbian|windows ce|blackberry/i.test(navigator.userAgent)) {
.....

}


Are used to detect if mobile devices are used (woops, didn't notice that).

I commented out the if statement (and its closing bracket) and it seems to be working! A little big for the screen, but nothing CSS cant fix.

Tested on android and iPhone, both working.

Beverleyh
05-06-2015, 02:58 PM
Yes it's visible and working here now.

jscheuer1
05-06-2015, 04:12 PM
Oh, right, I knew about that. But in the thread you referred to where I discussed using Slimbox 2 with PHP Photo Album, I thought I instructed that that part be removed. Maybe not.

Anyways, once it is working, you also have to contend with the possibility that the next/previous buttons might not appear. They're :hover pseudo class in css I believe and might not work with touch events. If not though, you could just have them be always visible.

mcos
05-06-2015, 04:15 PM
May have ran into another issue.

It seems to be working for some of the photos, and not for others. Pops up and disappears for some photos. Could this just be a cache issue? Or is it the order in which I'm loading my scripts?

EDIT: Noticed if I hold down, when I click, for a little longer than just a tap, it seems to work. Could this be something to do with the "touchstart" event we added to ddphpalbum.js?

EDIT 2: Went ahead and removed the following code from ddphpalbum.js and it seems to be working on my iPhone IOS8. I know you said that sometimes the click event on a mobile phone does not always work the way it should. Do you have any other suggestions?



phpimagealbum.routines.addEvent(albumdiv, function(e){
var e=window.event || e
var target=e.srcElement || e.target
if (target.tagName=="IMG" && target.getAttribute('data-index')){
thisalbum.onphotoclick(target, thisalbum.albumvar.images[parseInt(target.getAttribute('data-index'))][0], thisalbum.albumvar.images[parseInt(target.getAttribute('data-index'))][1])
}
}, "touchstart");

jscheuer1
05-06-2015, 05:17 PM
I wouldn't worry about it unless some mobile doesn't work.

If that happens, you can put back the code you just removed and make it conditional on the browser recognizing touchstart and have the click code conditional upon the browser not recognizing touchstart. If you need to do that later let me know.

mcos
05-07-2015, 03:37 PM
John,

We truly appreciate all the help you've given us!

We do have one more question though. We're messing with the CSS of slimbox popup, and are wondering how we can do the following:

On Desktop:
- Make the popup show up full sized (images are all sized at 600px width)
On Mobile:
- Have the popup fit 100% to screen width

Basically, on desktop it works great, as it should, but on mobile phones it shows popup&images full size (600px) thus pushing them off the screen of most phones.

The CSS is a little confusing to us when it comes to slimbox. I'm assuming maybe some of the CSS is populated using JS but can't figure it out.

jscheuer1
05-07-2015, 06:09 PM
Well media queries would be the way to go. I'm just starting to understand these, so anything I advise might need work. Beverley is more experienced with these. Hopefully she will have a look at what I put forth here and add any helpful comments.

The way I see it, for this sort of thing you first have to determine the various styles that will be good for various screen resolutions. It would be nice to be able to use a percentage width for this, but in the one emulator I'm using, that doesn't seem to work well.

Anyways, the div that shows the larger image has an id of lbImage and the way the script works is that the larger image becomes this div's background image.

I found that on an iphone 5 emulation that has a little more than 500px width available with in portrait view, that adding these styles worked well:


max-width: 500px;
background-size: contain;

As a media query in the stylesheet I think that would look like so:


@media screen and (min-width:540px) and (max-width:600px){
#lbImage{
max-width: 500px;
background-size: contain;
}
}

For other devices - screen widths really, you would do a similar thing. The min and max on the media line would change to fit the device/screen you are thinking of, while the max-width rule for the #lbImage selector would be set to fall within that range and to fit well. The one thing that would not change is the background-size: contain; rule (it forces the background image to fit inside the div). So for a screen that was - say 320 px wide, something like so could be added to the stylesheet:


@media screen and (min-width:300px) and (max-width:320px){
#lbImage{
max-width: 250px;
background-size: contain;
}
}

And you would need to make up media query blocks like these for all anticipated ranges of widths that might be encountered.

I think you can see why a percent max-width for lbimage would be so much easier. But in the emulator I tried that in, the lbimage was off kilter to begin and each time you hit next, it got smaller by the same percentage. If - and that's a big if, if that's just an artifact of the emulator, we could set max-width to something convenient like 90% and just let the browsers and the script work the rest out. One rule set of:


@media screen and (max-width:650px){
#lbImage{
max-width: 90%;
background-size: contain;
}
}

Would then do it. Try that first, you might get lucky. Otherwise, as I say, you will probably have to make up rules for all of the possibilities of screens less than 650px wide.

BTW, again in the emulator I used (Chrome's native device emulator) The iPhone 5 was fine with that page 'as is' if viewed using its landscape mode. Something to think about.

mcos
05-07-2015, 07:57 PM
John,

Thank you, the @media and fixed widths seem to be working. The percentage max-width however did not work. Does the same thing the chrome device emulator showed.

For now, we setup a couple different device sizes. Thanks again!

jscheuer1
05-07-2015, 08:04 PM
You're welcome. Good to know how accurate the emulator is, thanks for that.