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

Use Trumbowyg with jQuery.noConflict() #1147

Closed
SamGoody opened this issue Jul 19, 2020 · 3 comments
Closed

Use Trumbowyg with jQuery.noConflict() #1147

SamGoody opened this issue Jul 19, 2020 · 3 comments
Labels
Milestone

Comments

@SamGoody
Copy link

Unable to use with JQuery in noConflict mode.

I rarely use jQuery. On new sites, I have my own $() method that replaces jQ, and on older sites I used Mootools. When I need jQuery for anything, it must be in noConflict() mode.

How can I do that with Trumbowyg?

Related:
I have lately come to using imports whenever possible.
I exported jQuery as a module, see here.
is there any way to do something like this:

<script type='module'>
    import { jQuery as $ } from "../modules/jq.module.js";
    import 'https://cdn.pika.dev/trumbowyg';
    $('.trumbo').trumbowyg();
</script>

Perhaps the method used to activate trumbowyg can be exported, and passed in the scope and the name of the variable?

Thanks!

@Alex-D
Copy link
Owner

Alex-D commented Jul 20, 2020

You can do something like that:

import jQuery from "../modules/jq.module.js";
import 'https://cdn.pika.dev/trumbowyg';

(function ($) {
  $('.trumbo').trumbowyg();
})(jQuery)

or use jQuery instead of the $ alias:

import jQuery from "../modules/jq.module.js";
import 'https://cdn.pika.dev/trumbowyg';

jQuery('.trumbo').trumbowyg();

Hope it helps :)

@SamGoody
Copy link
Author

Thank you very much!

Unfortunately, it does not work for me!

even just including trumbowyg without calling it, causes the error: Uncaught TypeError: can't access property "trumbowyg", jQuery is undefined

import jQuery from "../modules/jq.module.js";
import 'https://cdn.pika.dev/trumbowyg';

Again, I am using noConfilct(). Otherwise, $ would be global, and there would be no issue (except that the rest of my pages wont work)

@Alex-D
Copy link
Owner

Alex-D commented Jul 20, 2020

Trumbowyg does not use $ internally, it uses jQuery, so that's not related to noConflict() usage.

Seems like you need to declare jQuery on window manually to allow Trumbowyg to get access to it:

import jQuery from "../modules/jq.module.js";
window.jQuery = jQuery;
import 'https://cdn.pika.dev/trumbowyg';

jQuery('.trumbo').trumbowyg();

I will keep that in mind for the v3 (see #875)

@Alex-D Alex-D added this to the v3.0 milestone Jul 26, 2020
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