sampotts / plyr

A simple HTML5, YouTube and Vimeo player
https://plyr.io
MIT License
26.63k stars 2.93k forks source link

RequireJS and Plyr #879

Closed jonnitto closed 6 years ago

jonnitto commented 6 years ago

If I use RequireJS and Plyr, I didn't receive the Plyr instance:

Example: (Lock at the console output)

https://s.codepen.io/jonnitto/debug/zWeGjz/LQkExPzbXpYA

<script src='https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.5/require.js'></script>
<script >
require(["https://cdn.plyr.io/3.1.0/plyr.js"], function () {
  console.log('3.1.0', arguments);
});

require(["https://cdn.plyr.io/2.0.18/plyr.js"], function () {
  console.log('2.0.18', arguments);
});
</script>
friday commented 6 years ago

That's because that way doesn't work with named modules I think.

<script src='https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.5/require.js'></script>
<script src="https://cdn.plyr.io/3.1.0/plyr.js"></script>
<script>
require(["Plyr"], function () {
  console.log('3.1.0', arguments);
});
</script>
sampotts commented 6 years ago

I'm not massively familiar with require but sounds like you have your solution? If so, can you please close this one.

jonnitto commented 6 years ago

I still have to figure it out. I‘ve to support our old UI in the Neos Plugin. I think the post @friday made will help, but I can‘t use the code 1:1. I‘ll close this issue as soon as I have a solution.

friday commented 6 years ago

I'm also not that well acquainted with requirejs. I tried searching for "requirejs external named modules" for example, but with no luck. This strikes me as a pretty basic use case, but still nothing. If requirejs still has a decent number of users out there, you could probably find help on stackoverflow and similar places.

This should work too:

require(["https://cdn.plyr.io/3.1.0/plyr.js"], function () {
  require(["Plyr"], function () {
    console.log('3.1.0', arguments);
  });
});

Feels like a hack rather than a solution though.

jonnitto commented 6 years ago

I found the same solution. Released Plyr 3 for Neos.io: https://github.com/jonnitto/Jonnitto.Plyr and https://github.com/jonnitto/Jonnitto.TextWithPlyr