From: ScottDowne Date: Fri, 15 Apr 2011 17:05:36 +0000 (-0400) Subject: [#480] _cleanup function for map plugin + tests X-Git-Tag: v0.5~18^2~1^2~1 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=a17ffa91508bc89c38d7a19511742184dfc09c79;p=popcorn-js.git [#480] _cleanup function for map plugin + tests --- diff --git a/plugins/googlemap/popcorn.googlemap.js b/plugins/googlemap/popcorn.googlemap.js index 46d4d98..2f85d66 100644 --- a/plugins/googlemap/popcorn.googlemap.js +++ b/plugins/googlemap/popcorn.googlemap.js @@ -187,6 +187,10 @@ var googleCallback; if (map) { map.getDiv().style.display = "none"; } + }, + _cleanup: function( options ) { + // the map must be manually removed + document.getElementById( options.target ).removeChild( newdiv ); } }; }, diff --git a/plugins/googlemap/popcorn.googlemap.unit.js b/plugins/googlemap/popcorn.googlemap.unit.js index bb2bab3..39c0cdf 100644 --- a/plugins/googlemap/popcorn.googlemap.unit.js +++ b/plugins/googlemap/popcorn.googlemap.unit.js @@ -1,7 +1,7 @@ test("Popcorn Google Map Plugin", function () { var popped = Popcorn("#video"), - expects = 10, + expects = 11, count = 0; expect(expects); @@ -31,7 +31,7 @@ test("Popcorn Google Map Plugin", function () { lat: 43.665429, lng: -79.403323, zoom: 10 - } ) + }) .googlemap({ start: 0, // seconds end: 5, // seconds @@ -39,9 +39,20 @@ test("Popcorn Google Map Plugin", function () { target: 'map2', location:'boston', zoom: 15 - } ) + }) .volume(0); + popped.googlemap({ + start: 0, // seconds + end: 10, // seconds + type: 'SATELLITE', + target: 'map2', + location:'toronto', + zoom: 15 + }); + +var setupId = popped.getLastTrackEventId(); + popped.exec( 4, function() { ok(google.maps, "Google maps is available"); plus(); @@ -62,7 +73,13 @@ test("Popcorn Google Map Plugin", function () { popped.exec( 6, function() { ok (document.getElementById('actualmap2').style.display === "none" && - document.getElementById('actualmap1').style.display === "none", "Both maps are no lnger visible" ); + document.getElementById('actualmap1').style.display === "none", "Both maps are no longer visible" ); + plus(); + popped.pause(); + + popped.removeTrackEvent( setupId ); + + ok( !document.getElementById('actualmap3'), "removed map was properly destroyed" ); plus(); }); diff --git a/popcorn.js b/popcorn.js index 0372d8f..c613705 100644 --- a/popcorn.js +++ b/popcorn.js @@ -674,6 +674,7 @@ // Capture the position of the track being removed. if ( o._id === trackId ) { indexWasAt = i; + o._natives._cleanup && o._natives._cleanup.call( obj, o ); } } }); diff --git a/test/popcorn.unit.js b/test/popcorn.unit.js index 066a37e..252a2c9 100644 --- a/test/popcorn.unit.js +++ b/test/popcorn.unit.js @@ -1358,7 +1358,7 @@ test("Remove Plugin", function () { p2 = Popcorn("#video"), rlen = Popcorn.registry.length, count = 0, - expects = 19, + expects = 21, interval; function plus() { @@ -1450,6 +1450,29 @@ test("Remove Plugin", function () { clearInterval( interval ); } }, 1); + + Popcorn.plugin( "cleanup", { + + _setup: function( options ) { + + options.exist = true; + }, + _cleanup: function( options ) { + + ok( true, "cleanup function is called during removal" ); + plus(); + + ok( options.exist, "options object exists at time of cleanup" ); + plus(); + } + }); + + p2.cleanup({ + start: 2, + end: 3 + }); + p2.removeTrackEvent( p2.getLastTrackEventId() ); + p2.currentTime( 2 ).play(); });