Sugarcube 2.11
Twine 1.4
jQuery Mobile 1.4.5
jquery 1.12.4
I am using the function in this thread (
https://twinery.org/forum/discussion/5574/include-external-javascript-scripts-sugarcube) to load external js and css files. I know this script works and that the file paths are correct because 10 different jQuery mobile widgets work just fine.
However, the jQuery Mobile popup widget has an apparently unique problem. When I visit the passage containing the popup, the widget works as expected. If I move away from that passage and then come back, the popup no longer works. By "return," I mean that I have tried <<back>>, <<return>>, and a direct link to return to the passage, and the popup widget fails every time. The only thing that works to "reactivate" the popup is CTRL-R (in Firefox) to reload the page. I also know that the code I am using for the popup widget is correct because I have created a stand-alone HTML file with the same external files and the same widget code and the popup works as expected. Clearly, I'm missing something.
What can I do to make the jQuery Mobile popup widget work reliably upon repeat visits to a passage?
Comments
2. Show some code. We can't help you solve your issue unless we know what you're actually doing. A description is insufficient in most cases and all but absolutely so when dealing with libraries.
As for your point #1... I am aware that jQuery v3 is included in SugarCube, and, therefore, was surprised to find that if I don't append jQuery-1.12.4.min.js, then, when I access a passage containing a jQuery Mobile widget (a) the following error is generated: "Error: TypeError: a.event.props is undefined." and (b) the popup widget does not work even on first access to the passage. In the latter case, what I see, using the code directly below this paragraph, is exactly what you would expect to see were all the data- attributes removed. Importantly, though, the tabs widget continues to work perfectly if I omit jQuery-1.12.4.min.js. The problem appears to be unique to the popup widget.
Here is the code in the passage containing the tooltip:
This is the code for the jQuery Mobile tabs widget, which works just fine:
As a final note, the situation is not improved if I remove everything else from the script tagged passage except for the loadExternals macro. Also, if I don't include the loadExternals macro in EACH passage containing a mobile widget, the widget in that passage won't work.
That would be because jQuery Mobile, which is part of the jQuery Foundation no less, cannot seem to maintain compatibility with jQuery itself on anything remotely resembling even a glacially slow timescale. That is an extremely sad state of affairs.
That said, at least use the latest in the jQuery v2.1 series (v2.1.4) which is compatible with jQuery Mobile v1.4.5. This is important as jQuery v1.x is not guaranteed to be compatible with SugarCube v2.
That's because you're attempting to treat a web application like it was a web page, which it is not. To make your tabs work properly, you need to use either one of the post-action task objects or the PassageDone special passage. I'd suggest the postdisplay task object, since you're already using JavaScript. (code example below)
JavaScript Example
The following has been tested with the markup shown below and should be all you need—aside from the libraries; no <<loadExternals>> macro, no <<script>> invocations on passages with tabs. It includes both the code to load the libraries and a postdisplay task to enable tabs. (Twine 1: goes in your script-tagged passage; Twine 2: goes in Story JavaScript)
CSS Example
Beyond the JavaScript, I'd suggest using something like the following style, if you're not already. It will remove the external link symbol from the popup and tab links. (Twine 1: goes in your stylesheet-tagged passage; Twine 2: goes in Story Stylesheet)
Tested Markup Examples NOTE: Your sample of the tabs markup was missing the final closing </div>. I'm unsure if that was simply a copy/paste snafu or it's missing in your working markup as well, but you might want to look into that.
The tabs widget works. The popup widget does not... IF I access the popup passage from the Start passage. If I "test play" the popup passage directly, then the popup widget works.
Yes. It's exactly what I though it was. You need to call its API method post-display, like is being done with the tabs API, to initialize new popups on the page.
Replace the scripting I previously gave with something like the following:
Except, I ran into a problem when I applied the fix to my project...
I am having an embarrassing problem with relative paths in the jQuery function. The widgets work with these paths:
...but not with these paths:
...the difference being that, for the function that works, I'm accessing files via a mixture of http and local files at ../js-css/. Since the ../js-css/*.css files are being accessed in the first version of the function, above, I know the relative paths in the second version (that doesn't work) are correct. If I move the js-css folder so that it is a sub-directory of my project, rather than one folder <i>up</i>, and change the relative paths in the function accordingly, the widgets work. So, I know it isn't a problem with the local .js files <i>per se</i>. None of this makes any sense to me, which is why I'm embarrassed: the solution probably involves something ridiculously simple.
Based on those paths your directory and file structure would have to look something like the following: Where the parent directory of the compiled HTML file is a sibling of the js-css directory.