user892670
user892670

Reputation: 197

prettyPhoto changepicturecallback data

Anyone know how to retrieve the current image data (alt, src) via the changepicturecallback function with Jquery prettyPhoto?

I want to pass these two variables to an ajax script and can't seem to get my hands on the info to pass. Tried this to no avail.

    var image = jQuery(".pp_pic_holder").find("#pp_full_res img").attr("src");      

There must be a way to easily access this data at run time. Any suggestions or point in the right direction?

When I was working with Gallerific I was able to get this info using

var image_src = this.data[nextIndex].slideUrl;

EDIT => Just had to narrow my search down for the target

        var image = jQuery('#fullResImage').attr('src');

Works just fine now.

Upvotes: 1

Views: 2323

Answers (1)

Kyle Macey
Kyle Macey

Reputation: 8154

Technically, your attempt is right, but try to broaden your scope a bit, and do some testing...

myCallbackTest = function() {
  alert('the callback worked! thats a good start!');

  var $activeimage = $("#fullResImage");

  var source = $activeimage.attr('src'), altText = $activeimage.attr('alt');

  if(!$activeimage.length) {
    alert('The image selector failed');
  } else if (!source) {
    alert('The image selector worked, but I found no source');
  } else if (!altText) {
    alert('Found The image and its source, but it doesnt seem to have any alt text');
  } else {
    alert('i got it! alt: ' + altText + ' src: ' + source);
  } 
}

Then give it a go...

$(function() {
  $('a[rel^=prettyPhoto]').prettyPhoto({
    theme: 'facebook',
    slideshow:5000, 
    autoplay_slideshow:true,
    changepicturecallback: myCallbackTest
  });
});

Upvotes: 3

Related Questions