]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
testing instances
authorunknown <Venom@.(none)>
Tue, 1 Feb 2011 22:52:07 +0000 (17:52 -0500)
committerunknown <Venom@.(none)>
Tue, 1 Feb 2011 22:52:07 +0000 (17:52 -0500)
popcorn.js
test/instanceTester.html [new file with mode: 0644]

index 48123cf92be926390025be1b840fb1553bf28445..2e80729f16837618464f21f5c419fcf190a2a030 100644 (file)
     //  Return new Popcorn object
     return new Popcorn.p.init( entity );
   };
+  
+  Popcorn.instances = [];
+  Popcorn.instanceIds = {};
+  Popcorn.removeInstance = function(id) {
+    Popcorn.instances.splice(Popcorn.instanceIds[id], 1);
+    delete Popcorn.instanceIds[id];
+  };
+
+  Popcorn.addInstance = function(popcornInstance) {
+    if (popcornInstance.video.id === "undefined" || !popcornInstance.video.id.length) {
+      popcornInstance.video.id = "__popcorn" + Popcorn.instances.length;
+    }
+    Popcorn.instanceIds[popcornInstance.video.id] = Popcorn.instances.length;
+    Popcorn.instances.push(popcornInstance);
+  };
 
+  Popcorn.getInstanceById = function(name) {
+    return Popcorn.instances[Popcorn.instanceIds[name]];
+  };
+  
+  
   //  Declare a shortcut (Popcorn.p) to and a definition of 
   //  the new prototype for our Popcorn constructor 
   Popcorn.p = Popcorn.prototype = {
       
       
       this.video = elem ? elem : null;
-      
+      Popcorn.addInstance(this);
       this.data = {
         history: [],
         events: {},
diff --git a/test/instanceTester.html b/test/instanceTester.html
new file mode 100644 (file)
index 0000000..39ff91b
--- /dev/null
@@ -0,0 +1,53 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <title>Popcorn API</title>
+  <link rel="stylesheet" href="qunit/qunit.css" type="text/css" media="screen">
+  <script src="../popcorn.js"></script>
+  <script>
+  
+  Popcorn(function (e) {
+    var p = Popcorn("#video");
+  });
+
+  Popcorn(function () {
+    var p = Popcorn("#video2");
+    p.play();
+    Popcorn.getInstanceById("video").play();
+  });  
+  </script>
+  
+</head>
+<body>
+  <video id='video'style="display:" 
+    controls 
+    poster="http://media.w3.org/2010/05/sintel/poster.png"> 
+
+    <source id='mp4'
+      src="http://media.w3.org/2010/05/sintel/trailer.mp4"
+      type='video/mp4; codecs="avc1, mp4a"'> 
+
+    <source id='ogv'
+      src="http://media.w3.org/2010/05/sintel/trailer.ogv"
+      type='video/ogg; codecs="theora, vorbis"'> 
+
+    <p>Your user agent does not support the HTML5 Video element.</p> 
+
+  </video>   
+  <video id='video2'style="display:" 
+    controls 
+    poster="http://media.w3.org/2010/05/sintel/poster.png"> 
+
+    <source id='mp4'
+      src="http://media.w3.org/2010/05/sintel/trailer.mp4"
+      type='video/mp4; codecs="avc1, mp4a"'> 
+
+    <source id='ogv'
+      src="http://media.w3.org/2010/05/sintel/trailer.ogv"
+      type='video/ogg; codecs="theora, vorbis"'> 
+
+    <p>Your user agent does not support the HTML5 Video element.</p> 
+
+  </video>   
+</body>
+</html>