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 all commits
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
10 changes: 6 additions & 4 deletions src/js/media/flash.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ 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.el_ = vjs.Flash.embed(options['swf'], placeHolder, flashVars, params, attributes);
}
}
});
Expand Down Expand Up @@ -401,16 +401,18 @@ vjs.Flash['onReady'] = function(currSwf){
// Reference player on tech element
el['player'] = player;

// Update reference to playback technology element
tech.el_ = el;

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
16 changes: 16 additions & 0 deletions test/unit/flash.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,19 @@ 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');
});