1
0
mirror of https://github.com/videojs/video.js.git synced 2025-01-04 06:48:49 +02:00

Close GH-614: added dispose event. fixes #613.

This commit is contained in:
Jeremy West 2013-07-18 14:39:14 -07:00 committed by Steve Heffernan
parent 9d424c61f4
commit a449cb043a
3 changed files with 9 additions and 1 deletions

View File

@ -45,6 +45,8 @@ vjs.Component = vjs.CoreObject.extend({
* Dispose of the component and all child components.
*/
vjs.Component.prototype.dispose = function(){
this.trigger('dispose');
// Dispose all children.
if (this.children_) {
for (var i = this.children_.length - 1; i >= 0; i--) {

View File

@ -86,7 +86,9 @@ vjs.Player = vjs.Component.extend({
vjs.Player.prototype.options_ = vjs.options;
vjs.Player.prototype.dispose = function(){
// this.isReady_ = false;
this.trigger('dispose');
// prevent dispose from being called twice
this.off('dispose');
// Kill reference to this player
vjs.players[this.id_] = null;

View File

@ -82,8 +82,12 @@ test('should dispose of component and children', function(){
var data = vjs.getData(comp.el());
var id = comp.el()[vjs.expando];
var hasDisposed = false;
comp.on('dispose', function(){ hasDisposed = true; });
comp.dispose();
ok(hasDisposed, 'component fired dispose event');
ok(!comp.children(), 'component children were deleted');
ok(!comp.el(), 'component element was deleted');
ok(!child.children(), 'child children were deleted');