I ran into an something that did not expect today when removing part of a function that previously was loaded in my asset pipeline but needed to be extracted to a partial for some A/B testing.
I'm using the bigVideo.js library to load a full-screen video on the page. BigVideo.js started loading the wrong dimensions today when I extracted the code to the partial. The partial loads below the rest of my javascript assets.
I previously had the code incapsulated in a anonymous function inside my normal asset pipeline.
original code (working)
$(function () {
(function () {
var bgVid = new $.BigVideo({useFlashForFirefox: false})
bgVid.show('http://videourl.com', { ambient : true });
}();
});
Next, I tried to set this equal variable so I could call it in the partial. Video started loading without using correct dimensions.
$(function () {
var initVid = function () {
var bgVid = new $.BigVideo({useFlashForFirefox: false})
bgVid.show('http://videourl.com', { ambient : true });
};
in partial:
$(function () {
initVid();
});
It looked like something was going on with the dom dimensions not fully loading, so I tried switching the function to something like this:
in partial:
$(window).load(function () {
var bgVid = new $.BigVideo({useFlashForFirefox: false});
bgVid.show('http://videourl.com', { ambient : true });
});
Still no luck.
Finally, I resorted to using window.onload
window.onload = function () {
var bgVid = new $.BigVideo({useFlashForFirefox: false})
bgVid.show('http://videourl.com', { ambient : true });
};
It works?! So why is $(window).load failing here while window.onload seems to be working fine?