]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
[#181] Setup for future support for plugin event definitions
authorrwldrn <waldron.rick@gmail.com>
Sun, 5 Dec 2010 17:15:29 +0000 (12:15 -0500)
committerrwldrn <waldron.rick@gmail.com>
Sun, 5 Dec 2010 17:15:29 +0000 (12:15 -0500)
popcorn.js
test/popcorn.unit.js
test/popcorn.unit.setup.js

index e523ee8999b0ce47b0fe8d6862b383dd90612781..13d697a3f5ffa234f45aea76367bf519488d1738 100644 (file)
       }, 
       listen: function ( type, fn ) {
         
-        var self = this, hasEvents = true;
+        var self = this, hasEvents = true, ns = '';
         
         if ( !this.data.events[type] ) {
           this.data.events[type] = {};
       
       setup = definition;
       
-      
+      if ( !( "timeupdate" in setup ) ) {
+        setup.timeupdate = Popcorn.nop;
+      }         
+
       definition  = function ( options ) {
         
         var self = this;
           options.end = this.duration();
         }
 
-        if ( !( "timeupdate" in options ) ) {
-          options.timeupdate = Popcorn.nop;
-        }        
-        
         //  If a _setup was declared, then call it before 
         //  the events commence
         
         }
         
         //  Plugin timeline handler 
-        this.video.addEventListener( "timeupdate", function( event ) {
+        this.listen( "timeupdate", function( event ) {
           
           
           if ( ~~self.currentTime() === options.start || 
             setup.end.call(self, event, options);
           }
           
-        }, false);
-        
-
-        //  Future support plugin definitions for all of the native events
-        Popcorn.forEach( options, function ( key ) {
-          
-          console.log(key);
         });
         
 
-              
-      
+        //  Future support for plugin event definitions 
+        //  for all of the native events
+        Popcorn.forEach( setup, function ( callback, type ) {
+          
+          if ( reserved.indexOf(type) === -1 ) {
+            
+            this.listen( type, callback );
+          }
+          
+        }, this);
         
         return this;
       };
index d13c5acf367add8cbd4c8360b1f1bb02121b1278..9162feb6b240c790e0b5b905128b038ae2e6250a 100644 (file)
@@ -140,14 +140,10 @@ test("Popcorn Events Simulated", function () {
   QUnit.reset();
   
   var p = Popcorn("#video"),
-      completed = [], 
-      eventtest = "loadstart progress suspend emptied stalled play pause " + 
-                  "loadedmetadata loadeddata waiting playing canplay canplaythrough " + 
-                  "seeking seeked timeupdate ended ratechange durationchange volumechange", 
-      events = eventtest.split(/\s+/g);                              
+      completed = [];
 
   
-  var expects = events.length, 
+  var expects = Setup.events.length, 
       count = 0;
 
   expect(expects);
@@ -159,7 +155,7 @@ test("Popcorn Events Simulated", function () {
   stop();  
   
   
-  events.forEach(function ( name ) {
+  Setup.events.forEach(function ( name ) {
     p.listen( name, function (event) {
       
       if ( completed.indexOf(name) === -1 ) {
@@ -173,7 +169,7 @@ test("Popcorn Events Simulated", function () {
     });  
   });
 
-  events.forEach(function ( name ) {
+  Setup.events.forEach(function ( name ) {
     p.trigger( name );  
   });
   
@@ -186,11 +182,7 @@ test("Popcorn Events Real", function () {
   QUnit.reset();
 
   var p = Popcorn("#video"),
-      completed = [], 
-      eventtest = "loadstart progress suspend emptied stalled play pause " + 
-                        "loadedmetadata loadeddata waiting playing canplay canplaythrough " + 
-                        "seeking seeked timeupdate ended ratechange durationchange volumechange", 
-      events = eventtest.split(/\s+/g);                              
+      completed = [];                              
   
   
   var expects = 11, 
@@ -205,7 +197,7 @@ test("Popcorn Events Real", function () {
   stop();  
   
   
-  events.forEach(function ( name ) {
+  Setup.events.forEach(function ( name ) {
     p.listen( name, function (event) {
       
       if ( completed.indexOf(name) === -1 ) {
@@ -308,7 +300,7 @@ test("Popcorn Plugin", function () {
     },
     end: function () {
     
-      start();
+      //start();
     
     }, 
     timeupdate: function () {
@@ -328,5 +320,132 @@ test("Popcorn Plugin", function () {
     end: 2
   });  
   
+
+  Popcorn.plugin("breaker", {
+    
+    start: function () {
+      ok(true, "plugin:breaker started");
+    },
+    end: function () {
+      ok(true, "plugin:ended started");
+      start();
+    } 
+  });
+
+  
+  
+  popped.currentTime(0);
+  
+  popped.breaker({
+    start: 1, 
+    end: 2
+  });    
+});
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+test("Popcorn Plugin Extended Events", function () {
+  
+  //QUnit.reset();
+  
+  // needs expectation
+
+  var popped = Popcorn("#video"), 
+      expects = 11, 
+      count = 0;
+
+  //expect(expects);
+  // not in full use
+  function plus(){ 
+    if ( ++count == expects ) start(); 
+  }
+  
+  stop();  
+  
+  
+  Popcorn.plugin("extendedEvents", (function () {
+  
+
+    var pluginObj = {
+
+      start: function() {
+
+      },
+      end: function() {
+
+      }
+    };
+    
+    $.each( Setup.events, function ( k, type ) {
+      
+      pluginObj[type]  = function (event, opts) {
+        ok( true, type + " fired!" );
+        
+        plus();
+      };
+    
+    });
+    
+    return pluginObj;
+    
+  })());
+  
   
-});
\ No newline at end of file
+  
+  
+  popped.extendedEvents({
+    
+    start: 20,
+    end: 21
+    
+  });
+  
+  
+  popped.currentTime(19).play();
+  
+  
+});
+
+/*
+module("Popcorn Video Object")
+test("wait()", function () {
+  
+  //QUnit.reset();
+  
+  // needs expectation
+
+  var popped = Popcorn("#video"), 
+      startat = +new Date();
+
+
+  
+  
+  popped.play().wait(2).exec(function () {
+    
+    console.log( +new Date() - startat );
+    
+    ok(true)
+    
+  }).pause();
+  
+  
+});
+*/
\ No newline at end of file
index 5999b04e4df3e25e7975db54419d91b3c5dfc968..999adaa99a6b813a44f53d7bc744a1c79e14c9b9 100644 (file)
   };
   
   
+  
+  Setup.eventset  = "loadstart progress suspend emptied stalled play pause " + 
+                          "loadedmetadata loadeddata waiting playing canplay canplaythrough " + 
+                          "seeking seeked timeupdate ended ratechange durationchange volumechange";
+  
+  Setup.events = Setup.eventset.split(/\s+/g);                              
+
+  
+  
   global.Setup = Setup;
 
 })(window);