How can I access the caller in the popup definition?

Using Magnific Popup I would like to access the data attributes of the caller / link so that I can POST it to the popup. Code:

$('.editRecord').magnificPopup({
    type: 'ajax',
    preloader: false,
    ajax: {
        settings: {
            method: "POST",
            data: {
                recordID: $(this).data("recordid"),
                field1: $(this).data("field1"),
                // similar with the rest of the fields
            }
        }
    }
});

      

This doesn't work because it $(this)

seems to actually reference the document object.

I found this question and tried all the suggestions in the answers, but none of them work as it is not in the callback but in the settings. Have tried:

recordID: $.magnificPopup.instance.st.el.data("recordid")

      

and

recordID: $.magnificPopup.instance.currItem.el[0].data("recordid")

      

But I'm getting error messages that $.magnificPopup.instance.currItem

and $.magnificPopup.instance.st

are undefined. $.magnificPopup.instance

is defined, but I don't see any attribute that contains the current element.

How can I access the caller from the MagnificPopup definition?

+3


source to share


1 answer


You can use event updateStatus

and change settings when status loading

, it fires right before the ajax call.

$('.editRecord').on('mfpUpdateStatus', function(e, statusObj) {
    if(statusObj.status === 'loading') {
        var instance = $.magnificPopup.instance,
            currEl = instance.currItem.el;

        // modify settings object
        instance.st.ajax.settings.data = {
            something: currEl.data('something') 
        };

    }
});

      



The above can also be added as callback http://dimsemenov.com/plugins/magnific-popup/documentation.html#api

0


source







All Articles