SwingJS apps don't work on sites using Prototype - need to use JQuery's noConflict mode
foreveremain opened this issue · comments
Prototype.js remains widely used, but Including prototype.js either before or after SwingJS will break SwingJS. e.g.
<script src="swingjs/swingjs2.js"/>
<script type='text/javascript' src="https://ajax.googleapis.com/ajax/libs/prototype/1.7.3.0/prototype.js"/>
For JalviewJS we see the following in the console:
J2SApplet exec JalviewJS start applet null
TypeError: params.put$TK$TV is not a function
TypeError: params.put$TK$TV is not a function
at Object.J2S._setAppletParams (http://0.0.0.0:3000/static/jalview-js/swingjs/swingjs2.js:12955:13)
at Array.proto.__startAppletJS (http://0.0.0.0:3000/static/jalview-js/swingjs/swingjs2.js:13167:10)
at __nextExecution (http://0.0.0.0:3000/static/jalview-js/swingjs/swingjs2.js:12834:7)
at Function.LoadClazz._Loader.loadPackageClasspath (http://0.0.0.0:3000/static/jalview-js/swingjs/swingjs2.js:15957:15)
at Array.__loadClazz (http://0.0.0.0:3000/static/jalview-js/swingjs/swingjs2.js:12860:18)
It looks like swingjs2 should at some point call jquery.noConflict() to stash its custom $ in a field local to J2S.
Shouldn't be too much of an issue. I've been aware of this sort of issue for a long time; just waiting for a good use case. $ is (I guess only partially) taken care of by SwingJS using J2S.$ instead, with a wrapper for that. Probably just found the place where this is missing.
Oops - I interpolated between testing and reporting. tldr; prototype 1.7 causes swingjs2 to fail at the first hurdle. 1.7.3 looks promising, until a 'cannot read from undefined' is raised deep in SwingJS code stops the fun. All the following was with J2S._version = 3.2.4.07
One example uses a local version of prototype-1.7, but I see the same with https://ajax.googleapis.com/ajax/libs/prototype/1.7.0/prototype.js :
<script src="swingjs/swingjs2.js"></script>
<script src="prototype-1.7.js"></script>
<script>
if (!self.SwingJS)alert('swingjs2.js was not found. It needs to be in swingjs folder in the same directory as ' + document.location.href)
That fails with this error:
J2SApplet exec JalviewJS start applet null
TypeError: params.put$TK$TV is not a function
TypeError: params.put$TK$TV is not a function
...
Prototype 1.7.3 gives a different error. With ?j2snocore you can see the full stack trace:
TypeError: Cannot read property '_isDragger' of undefined
at Object.J2S.setDraggable (http://localhost:8000/swingjs/swingjs2.js:13460:11)
at clazz.eval [as setDraggableEvents$] (swingjs/j2s/swingjs/plaf/JSFrameUI.js:116:10)
at clazz.eval [as bindWindowEvents$] (swingjs/j2s/swingjs/plaf/JSWindowUI.js:130:6)
at clazz.eval [as updateDOMNode$] (swingjs/j2s/swingjs/plaf/JSFrameUI.js:75:7)
at clazz.eval [as getDOMNode$] (swingjs/j2s/swingjs/plaf/JSComponentUI.js:553:41)
at clazz.eval [as propertyChangedCUI$java_beans_PropertyChangeEvent$S] (swingjs/j2s/swingjs/plaf/JSComponentUI.js:480:24)
at clazz.eval (swingjs/j2s/swingjs/plaf/JSComponentUI.js:454:7)
at clazz.eval (swingjs/j2s/swingjs/plaf/JSFrameUI.js:228:72)
The specific reference you have there, to params.put$TK$TV, indicates you are using an old version of swingjs2.js (from j2sClazz.js) the correct call is params.put$O$O. This was fixed Jan 2020.