Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dont work correctly with es6 modules when jquery is external depency #138

Closed
alex-eganov opened this issue Feb 11, 2020 · 3 comments
Closed
Labels

Comments

@alex-eganov
Copy link

alex-eganov commented Feb 11, 2020

Hi!

I'm using es6 modules in development, babel for transpiling and browserify for depency managment and built script bundle for the browser. jQuery is external script from our CDN and dont included in this bundle.

<script src="//i.sakh.com/js/jquery/jquery-3.4.1.min.js"></script>
<!-- in this moment jQuery is defined and available via window.jQuery -->
<script defer src="/assets/dist/js/office.js?v=1581461330"></script>

JS:

import jBox from "jbox";

const modal = new jBox('Tooltip', {
        attach: '#js-city-block',
        trigger: 'click',
        closeOnClick: 'body',
        content: $('#city-list'),
        animation: 'slide:top'
    });

When modal is open, content that it displayed looks like JSON, becouse in the src jQuery instance dont be determined correctly?!

if (content instanceof jQuery) {
    this.content.html('');
    content.attr('data-jbox-content-appended', 1).appendTo(this.content).css({display: 'block'});
} else {
    this.content.html(JSON.stringify(content));
}

jbox 1.0.7
jquery 3.4.1

How resolve this problem? Thank u!

@StephanWagner
Copy link
Owner

I just read through this article again: https://stackoverflow.com/questions/1853223/check-if-object-is-a-jquery-object

I think thats where I got the idea from to use content instanceof jQuery.

Maybe this approach might be better:

if (content && (content instanceof jQuery || content.constructor.prototype.jquery))

Can you test if that would work in your case?

@alex-eganov
Copy link
Author

Yes, it worked!

    // Set the new content
    switch (jQuery.type(content)) {
      case 'string':
        this.content.html(content);
        break;
      case 'object':
        if (content && (content instanceof jQuery || content.constructor.prototype.jquery)) {
          this.content.html('');
          content.attr('data-jbox-content-appended', 1).appendTo(this.content).css({display: 'block'});
        } else {
          this.content.html(JSON.stringify(content));
        }
        break;
     }

StephanWagner added a commit that referenced this issue Feb 24, 2020
@StephanWagner
Copy link
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants