1
0
mirror of https://github.com/videojs/video.js.git synced 2024-12-27 02:43:45 +02:00

Track the object element during init and remove it if the tech is disposed before onReady. For #1339.

If dispose() was called before the SWF triggered onReady(), the placeholder div would be cleaned up but the actual object element would be left behind to mess things up in the future. Keep track of the object element during initialization and make sure it is removed if flash is unloaded early.
This commit is contained in:
David LaPalomento 2014-07-09 16:08:47 -04:00
parent 392cbda095
commit da19fa3ead
2 changed files with 58 additions and 1 deletions

View File

@ -244,12 +244,19 @@ vjs.Flash = vjs.MediaTechController.extend({
// If not using iFrame mode, embed as normal object
} else {
vjs.Flash.embed(options['swf'], placeHolder, flashVars, params, attributes);
this.obj = vjs.Flash.embed(options['swf'], placeHolder, flashVars, params, attributes);
}
}
});
vjs.Flash.prototype.dispose = function(){
// the tech is being disposed before onReady has been triggered
// removing the object from the DOM prevents that from firing
// and overwriting the state of the replacement tech
if (this.obj) {
this.obj.parentNode.removeChild(this.obj);
this.obj = null;
}
vjs.MediaTechController.prototype.dispose.call(this);
};
@ -404,6 +411,11 @@ vjs.Flash['onReady'] = function(currSwf){
// Update reference to playback technology element
tech.el_ = el;
// Remove the initialization reference to the tech element
if (tech.obj) {
tech.obj = null;
}
vjs.Flash.checkReady(tech);
};
@ -411,6 +423,11 @@ vjs.Flash['onReady'] = function(currSwf){
// If it's not ready, we set a timeout to check again shortly.
vjs.Flash.checkReady = function(tech){
// Stop worrying if the tech has been disposed
if (!tech.el()) {
return;
}
// Check if API property exists
if (tech.el().vjs_getProperty) {

View File

@ -96,3 +96,43 @@ test('currentTime is the seek target during seeking', function() {
seeking = true;
strictEqual(7, tech.currentTime(), 'during seeks the target time is returned');
});
test('dispose removes the object element even before ready fires', function() {
var noop = function() {},
parentEl = document.createElement('div'),
tech = new vjs.Flash({
id: noop,
on: noop,
options_: {}
}, {
'parentEl': parentEl
});
tech.dispose();
strictEqual(tech.el(), null, 'tech el is null');
strictEqual(parentEl.children.length, 0, 'parent el is empty');
});
test('dispose removes the object element after ready fires', function() {
var noop = function() {},
parentEl = document.createElement('div'),
player = {
id: noop,
on: noop,
options_: {}
},
tech = new vjs.Flash(player, {
'parentEl': parentEl
});
player.tech = tech;
document.getElementById('qunit-fixture').appendChild(parentEl);
tech.obj['player'] = player;
vjs.Flash['onReady'](parentEl.children[0].id);
strictEqual(tech.obj, null, 'nulled initialization reference');
tech.dispose();
strictEqual(tech.el(), null, 'tech el is null');
strictEqual(parentEl.children.length, 0, 'parent el is empty');
});