Hey everybody!
I am currently using jQueryUI by simply putting it entirely into Story JavaScript. In order to keep it more tidy, I tried to append jQueryUI from a CDN using TME´s suggestion in
this post.
Here is what I used:
(function ($) {
$(document.head)
.append('<script type="text/javascript" src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>');
})(jQuery);
These are the first lines of code in the StoryJavascript, everything else goes below. I get a fatal error (unexpected token). What am I doing wrong?
Comments
note: I had to use quote instead of code markup to stop an invalid semi-colon being added to the URL, this unfortunately removes indentation.
Well, we can work around that little problem. Change your code to something like the following: NOTE: I do suggest using an ID, as the example from the thread you linked does, so I added one. I also changed the URL to use the latest version of jQuery UI—if you actually need the older 1.11.4 version, simply change the URL back.
Can I bug you with another issue? I tried to append the jQuery UI touch punch the same way, so the beginning of my Story Javascript reads
Twine file doesn't show any errors when displayed on a desktop computer, but when opened on my mobile phone, I get an fatal error: Uncaught TypeError: Cannot read property 'mouse' of undefined.
Could that be a scope issue?
Assuming that there are no version conflicts, the most likely cause of your issue is probably that the Touch Punch add-on was being loaded before jQuery UI itself in the instance where you saw the error—due to asynchronicity issues. The solution is to synchronize its loading with jQuery UI's.
The following code should work in everything save older versions of IE: