0

I am using a jQuery photo wall plugin. I want to have a pull down menu that lets users switch the gallery.

Can anyone help me with the code for this?

This is what I have so far

http://codepen.io/anon/pen/bFsHv/

I don't know how to get the revised variable into AJAX call.

2 Answers 2

2

The condensed example below should work - provided the photo wall plugin supports reloading with a different URL.

$(document).ready(function(){
    // TODO: Init photo wall plugin

    // Moved photo loading AJAX call into a function that can be re-used whenever the photos need to be reloaded...
    var loadPhotos = function(photoUrl) {
        console.log(photoUrl);
        // TODO: Photo loading code goes here
        // $.ajax({url: photoUrl + ...
    }

    // Got rid of the currentURL variable... instead just call loadPhotos with the new URL whenever it needs to change
    $('#gallery-switcher').on('change', function(){
        var value = $('#gallery-switcher option:selected').val();

        if (value == 'home') {
            loadPhotos('https://picasaweb.google.com/data/feed/api/user/106385870100722729161/albumid/5985138864602491185');
        } else {
            loadPhotos('https://picasaweb.google.com/data/feed/api/user/106385870100722729161/albumid/5985463574421076049');
        }
    });

    // Initial load
    loadPhotos('https://picasaweb.google.com/data/feed/api/user/106385870100722729161/albumid/5985138864602491185');
});

I had the full version on CodePen but it was failing to save the comments for some reason...

Sign up to request clarification or add additional context in comments.

5 Comments

wow! thank you so much. I'll have a go with that. I knew that I wasn't refreshing the AJAX call but I didn't know how to do.
You forgot a starting call to your loadPhotos function. Now it won't show on document load.
Thanks for pointing that out Thomas - knew I was forgetting something... Just edited it in.
Yeah, it should work - just insert the bits I omitted from your original code at the TODOs.
Matt, you are a legend sir!!!!!!!! only went and worked like a charm. Thank you so very much. Really appreciate your help my friend.
0

You are changing the value, but not refreshing your photowall contents. The Photowall will only run once, which is after the document has finished loading.

I'm not familiar with photowall, but I guess you'd need to redo your ajax call in the onchange event where you're changing your url right now. You'll probably need to reload your plugin in the onchange every time your user selects a different option.

I can't really help you with that as I'm not a photowall user, but here are the steps I would take:

  1. Make the photowall init a function so you don't have duplicate code
  2. Run the function in the document ready function
  3. Not sure if needed, but empty the control currently loaded with photowall before the next point.
  4. Call the function at the end of your onchange

Hope this helps you a bit.

1 Comment

Thanks Thomas for your help, Matt's code above with your help worked great.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.