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

AMD Loading with require.js #348

Closed
danhorner opened this issue Apr 19, 2015 · 7 comments
Closed

AMD Loading with require.js #348

danhorner opened this issue Apr 19, 2015 · 7 comments

Comments

@danhorner
Copy link

I haven't been able to load the keyboard plugin via AMD. I'm a little new at this but have encountered a couple of issues:

  • There are two define() blocks in jquery.keyboard.js. One for the keyboard and one for the caret plugin. Keyboard has an undeclared dependency on the caret plugin but is first in the source order.
  • Keyboard invokes caret plugin on domReady:
    $( function(){
        $keyboard.checkCaretSupport();
    });
  • But when loading via AMD, the DOM is ready before keyboard.js loads, so the call is not properly deferred. Changing the order of the two plugins in the source fixes the immediate problem, but the two define()'d modules confuse require.js

Trying to figure out how to postpone dom ready and/or declare the dependency. Thoughts?

@danhorner
Copy link
Author

Update: I inlined the jQuery.caret plugin inside the Keyboard module and everthing works great. This is probably correct for AMD and doesn't break the examples. Change here:
danhorner/Keyboard@a39f4ea

@Mottie Mottie closed this as completed in 372226d Apr 19, 2015
@Mottie
Copy link
Owner

Mottie commented Apr 19, 2015

Thanks @danhorner!

Hopefully this last update fixes this issue.

@Mottie Mottie reopened this Apr 19, 2015
@Mottie
Copy link
Owner

Mottie commented Apr 19, 2015

Opps, I didn't address the DOM ready event. I'll take a look at it.

@danhorner
Copy link
Author

Thank you! Works great. The DOM ready event is incidental. The intent was obviously "Wait until the caret plugin is available", which thanks to the inlining, it now is.

@danhorner
Copy link
Author

Sorry. My mistake: domReady is too soon if Keyboard is injected later with eg. with setTimeout.

@danhorner danhorner reopened this Apr 19, 2015
@Mottie Mottie closed this as completed in 5f2c408 Apr 19, 2015
@Mottie
Copy link
Owner

Mottie commented Apr 19, 2015

Ok, it should work properly now ;)

@danhorner
Copy link
Author

Brilliant. Thanks.

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

No branches or pull requests

2 participants