Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track the object element during init and remove it if the tech is dispos... #1340

Merged
merged 2 commits into from
Jul 28, 2014
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/js/media/flash.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we just set this.el_ = obj here? Then component would remove that instead of the placeholder.

I think the main reason for not doing that before was that we were using swfobj which uses an object or embed depending on the platform, but now we built a custom object that works across platforms. I'm trying to remember if there were any other reasons. Either way if it works on IE8 we should be good, and that should simplify this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like an improvement to me. I'll update the PR.

}
}
});

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);
};

Expand Down Expand Up @@ -404,13 +411,23 @@ 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);
};

// The SWF isn't alwasy ready when it says it is. Sometimes the API functions still need to be added to the object.
// 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) {

Expand Down
40 changes: 40 additions & 0 deletions test/unit/flash.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fyi, this test just saved me :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

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');
});