jsor/lity

lity.iframe is not a function (when running via npm/Laravel mix)

adam-jones-net opened this issue · 0 comments

I think this is likely something very simple and it's just a syntax / setup type issue that I am unaware of having moved a working lity install under the Laravel Mix/WebPack system, which has caused it to stop working.

I'm using the following in my app.js of a laravel project to include lity:

window.lity = require('lity');

I then setup lity handlers follows just below this in the main js file:

$(document).ready(function() {
    lity.handlers('', function(target, instance) {
        // for specific page urls I add a class to the lity container
        if ( target.indexOf('/page1')>-1 || target.indexOf('/page-name2')>-1 ) {
            instance.element().find('.lity-container').addClass("lity-resize450");
        }
        return lity.iframe(target, instance);
    });
});

However I get errors once it's compiled such as:

app.js?20200217:62 Uncaught TypeError: lity.iframe is not a function
    at app.js?20200217:62
    at Function.<anonymous> (app.js?20200217:13561)
    at Function.each (app.js?20200217:2612)
    at factory (app.js?20200217:13548)
    at new Lity (app.js?20200217:13661)
    at lity (app.js?20200217:13724)
    at HTMLSpanElement.<anonymous> (app.js?20200217:461)
    at HTMLDocument.dispatch (jquery.min.js:2)
    at HTMLDocument.v.handle (jquery.min.js:2)

Anyone can please advise ? This worked when I was running lity without using Laravel Mix and had a manually assembled js file in my project.

I assume it's something to do with where/how I reference the lity object I've defined and that now needs altering since moving to Mix?