Picture of Henrik Aabom
Re: Draggable with GSAP not working
by Henrik Aabom - Wednesday, 24 May 2017, 3:29 PM
 

Hi Dan

Yeah, I tried that, but with no luck...

 

However, I think I found the reason to my error. It's not that the scripts aren't loaded, but they are loaded in the wrong order.

I tried using the adapt-contrib-match component instead of mcq, because it already has a "library" folder to put the scripts into. In the js file I've turned this:

define([
'core/js/adapt',
'core/js/views/questionView',
'libraries/select2'
],function(Adapt, QuestionView) {

into this:

define([
'core/js/adapt',
'core/js/views/questionView',
'libraries/select2',
'libraries/TweenMax.min',
'libraries/Draggable.min'
],function(Adapt, QuestionView) {

which did the trick!

Just for testing, I tried switching my two scripts around inside the define function, and then I got the error again. It makes sense as Draggable is dependent on TweenMax.

My question now is: Can I always be certain that scripts will be loaded in the same order as their position inside the define([..])?

If not, is there a way to make sure that TweenMax is always loaded before Draggable?

Thank you

Picture of Henrik Aabom
Re: Draggable with GSAP not working
by Henrik Aabom - Friday, 2 June 2017, 12:47 PM
 

So it turns out, that you cannot be sure that scripts will be loaded in the order they are placed inside define([...]).

I have:

define([
'core/js/adapt',
'core/js/views/questionView',
'libraries/select2',
'libraries/TweenMax.min',
'libraries/Draggable.min'
],function(Adapt, QuestionView) {

and it seems that it starts loading TweenMax.min.js before Draggable.min.js, but sometimes it seems as if TweenMax isn't done loading before Draggable. Because one out of 3 times when I refresh the page I get the following errors in the browser console:

- GET http://localhost:9001/TweenLite.js 
- Uncaught Error: Script error for "TweenLite" http://requirejs.org/docs/errors.html#scripterror
- GET http://localhost:9001/CSSPlugin.js
- Uncaught Error: Script error for "CSSPlugin" http://requirejs.org/docs/errors.html#scripterror


Which to me looks like the TweenMax isn't done loading when Draggable needs it...?

Is there any other way to load in my two scripts in a way that I can be completely sure that one of them is loading before the other?

Any help here would be hot! :D

Thanks

Henrik

Picture of Oliver Foster
Re: Draggable with GSAP not working
by Oliver Foster - Friday, 2 June 2017, 7:14 PM
 

Hej Henrik,

Require normally works by having each library independently declare its own dependencies, as such, it becomes a little harder to declare dependencies after the libraries have been published.

You've a few options.

1. You can use Modernizr.load as is used in the core/src/scriptLoader.js

2. You can nest a require statement inside your define (require example)

3. You can try using require.config({ shim: { lib1: { deps: [ 'lib2' ] } } }); 

4. You can edit the library and add the correct dependency to its define statement
    

I hope that helps.

 

Ollie