opal / opal-jquery

jQuery for Opal
https://github.com/opal/opal-jquery#readme
MIT License
186 stars 63 forks source link

Not working when transpiled using Opal 0.8.1 #83

Closed essenciary closed 7 years ago

essenciary commented 8 years ago

Hi!

I'm hammering at porting Opal Playground from it's current implementation with Middleman over to Rails. https://github.com/fkchang/opal-playground

If you don't know it, what this does is that it sets up an iframe in which it injects opal generated JS. By "sets up" I mean loads a manifest JS file with the necessary dependencies, served via sprockets. The manifest file contains:

require 'opal'
require 'jquery'
require 'opal-jquery'

opal-jquery works very well in the Middleman version, using

opal (0.7.2)
opal-jquery (0.4.1)

However, opal-jquery fails to work with the Rails version, using

opal (0.8.1)
opal-jquery (0.4.1)

In Chrome's console I get:

Uncaught NameError: uninitialized constant Object::Document
(anonymous function) @ result_boot.js:3607
def.$const_missing @ result_boot.js:1924
Opal.get @ result_boot.js:75
(anonymous function) @ (index):9
(anonymous function) @ (index):12

My workaround was to save the opal-jquery.js file from Middleman (via sprockets) as a static file and include it, instead of using the Rails sprockets served version. Ending up with:

require 'opal'
require 'jquery'
#require 'opal-jquery'
require 'vendor/opal_jquery_072'

Since opal-jquery is at the same gem version, I suspect that something breaks when it's outputted (via sprockets) using opal 0.8.1

elia commented 7 years ago

Sorry for the great delay!

Support for opal versions prior to 0.9 is being dropped, let me know if you have any difficulties with more recent versions.