]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
[#480] _cleanup function for map plugin + tests
authorScottDowne <sdowne@learn.senecac.on.ca>
Fri, 15 Apr 2011 17:05:36 +0000 (13:05 -0400)
committerScottDowne <sdowne@learn.senecac.on.ca>
Fri, 15 Apr 2011 17:05:36 +0000 (13:05 -0400)
plugins/googlemap/popcorn.googlemap.js
plugins/googlemap/popcorn.googlemap.unit.js
popcorn.js
test/popcorn.unit.js

index 46d4d98929308d2390e9741a1a541cbee8a208aa..2f85d66e9f7b8fe7a19fb121a5c0ccb57f2d0482 100644 (file)
@@ -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 );
       }
     };
   },
index bb2bab3e823ad5fc2499d037fd2c2865df41e944..39c0cdf2ee14f835a8049e3aa2eccddf66df315a 100644 (file)
@@ -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();
   });
 
index 0372d8f56d16e0a58948a4e23db5b8f5361b9a7b..c6137052c02daa94cc5af14859ea41dd8f645656 100644 (file)
         //  Capture the position of the track being removed.
         if ( o._id === trackId ) {
           indexWasAt = i;
+          o._natives._cleanup && o._natives._cleanup.call( obj, o );
         }
       }
     });
index 066a37e98b522052917597128619885b76ea4bd6..252a2c90fd8acdba47366cfb067c634b4c7a4830 100644 (file)
@@ -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();
 
 });