pupunzi / jquery.mb.YTPlayer

use a custom yutube player for a video as background on jQuery framework
https://pupunzi.com/mb.components/mb.YTPlayer/demo/demo.html
1.3k stars 431 forks source link

Can't Use data-property and YTPlayer(options) for Self Containment #358

Closed JoelDKraft closed 6 years ago

JoelDKraft commented 6 years ago

Specifically, this situation does not work correctly.

<div id="ytplayer" data-property="{videoURL:'http://youtu.be/BsekcY04xvQ'></div> jQuery("#ytplayer").YTPlaylist({containment:'self'});

In this scenario where data-property exists, but the containment is listed in the options, the player will never be displayed.

Here is why! When data-property is set, this is line executed, but since the self reference is not yet defined at all, containment gets set to an empty jQuery result. YTPlayer.property.containment = YTPlayer.property.containment == "self" ? $YTPlayer : jQuery(YTPlayer.property.containment);

Then when this occurs, the value specified in options is now replaced by incorrect empty jQuery value in YTPlayer.property. jQuery.extend(YTPlayer.opt,jQuery.mbYTPlayer.defaults, options, YTPlayer.property);

The workaround is to put containment in data-property, which isn't a big deal.

I did a little testing to try for a workaround. Seems like that first line could actually be removed, and the final determination should be before or after this: YTPlayer.isPlayer = YTPlayer.opt.containment == "self" || ($YTPlayer.is (YTPlayer.opt.containment));

Joel