mirror of
https://github.com/videojs/video.js.git
synced 2025-07-15 01:34:23 +02:00
Close GH-614: added dispose event. fixes #613.
This commit is contained in:
committed by
Steve Heffernan
parent
9d424c61f4
commit
a449cb043a
@ -45,6 +45,8 @@ vjs.Component = vjs.CoreObject.extend({
|
|||||||
* Dispose of the component and all child components.
|
* Dispose of the component and all child components.
|
||||||
*/
|
*/
|
||||||
vjs.Component.prototype.dispose = function(){
|
vjs.Component.prototype.dispose = function(){
|
||||||
|
this.trigger('dispose');
|
||||||
|
|
||||||
// Dispose all children.
|
// Dispose all children.
|
||||||
if (this.children_) {
|
if (this.children_) {
|
||||||
for (var i = this.children_.length - 1; i >= 0; i--) {
|
for (var i = this.children_.length - 1; i >= 0; i--) {
|
||||||
|
@ -86,7 +86,9 @@ vjs.Player = vjs.Component.extend({
|
|||||||
vjs.Player.prototype.options_ = vjs.options;
|
vjs.Player.prototype.options_ = vjs.options;
|
||||||
|
|
||||||
vjs.Player.prototype.dispose = function(){
|
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
|
// Kill reference to this player
|
||||||
vjs.players[this.id_] = null;
|
vjs.players[this.id_] = null;
|
||||||
|
@ -82,8 +82,12 @@ test('should dispose of component and children', function(){
|
|||||||
var data = vjs.getData(comp.el());
|
var data = vjs.getData(comp.el());
|
||||||
var id = comp.el()[vjs.expando];
|
var id = comp.el()[vjs.expando];
|
||||||
|
|
||||||
|
var hasDisposed = false;
|
||||||
|
comp.on('dispose', function(){ hasDisposed = true; });
|
||||||
|
|
||||||
comp.dispose();
|
comp.dispose();
|
||||||
|
|
||||||
|
ok(hasDisposed, 'component fired dispose event');
|
||||||
ok(!comp.children(), 'component children were deleted');
|
ok(!comp.children(), 'component children were deleted');
|
||||||
ok(!comp.el(), 'component element was deleted');
|
ok(!comp.el(), 'component element was deleted');
|
||||||
ok(!child.children(), 'child children were deleted');
|
ok(!child.children(), 'child children were deleted');
|
||||||
|
Reference in New Issue
Block a user