2

I'm trying to do some image manipulation stuff depending on arbitrary data i've assocaied with my gallery.

  gallery.html('');
    $.each(data.photos, function(key, photo) {

        var item = "<li><a href='http://stage.domain.com/assets/img/user/"+photo.full+"'><img src='http://stage.domain.com/assets/img/user/"+photo.med+"'/></a></li>";

        gallery.append(item);
    });
    gallery.trigger('create');

    var options = {


        enableMouseWheel: false , 
        enableKeyboard: false ,
        captionAndToolbarAutoHideDelay:0,
        jQueryMobile:true

    }

    var swipe = $(".gallery a").photoSwipe(options);

    // onDisplayImage
    swipe.addEventHandler(PhotoSwipe.EventTypes.onDisplayImage, function(e){
        console.log('onDisplayImage{');
        console.log('onDisplayImage - e.action = ' + e.action);
        console.log('onDisplayImage - e.index = ' + e.index);
        console.log(swipe.getCurrentImage());
        console.log('onDisplayImage}');
    });

But the ondisplayimage event is never fired beacuse PhotoSwipe is not defined

 06-14 04:28:45.496: D/CordovaLog(31662): Uncaught ReferenceError: PhotoSwipe is not defined

The examples https://github.com/codecomputerlove/PhotoSwipe/blob/master/src/examples/07-custom-toolbar.html don't use the jquery implementation which is what I need. So basically how do I hook into the event handlers with jquery mobile.

Brian
  • 4,328
  • 13
  • 58
  • 103

1 Answers1

6

Change:

swipe.addEventHandler(PhotoSwipe.EventTypes.onDisplayImage, function(e){

To:

swipe.addEventHandler(window.Code.PhotoSwipe.EventTypes.onDisplayImage, function(e){

I was using jQuery to write content and calling the class directly like this resolved the issue.

Kijewski
  • 25,517
  • 12
  • 101
  • 143
Mike
  • 61
  • 2