]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
initial webpage plugin work [#160]
authorAnna Sobiepanek <annaopensource@gmail.com>
Sat, 4 Dec 2010 23:54:01 +0000 (18:54 -0500)
committerAnna Sobiepanek <annaopensource@gmail.com>
Sat, 4 Dec 2010 23:54:01 +0000 (18:54 -0500)
demos/webpage.html [new file with mode: 0644]
demos/webpage.js [new file with mode: 0644]
plugins/popcorn.webpage.js [new file with mode: 0644]

diff --git a/demos/webpage.html b/demos/webpage.html
new file mode 100644 (file)
index 0000000..9516857
--- /dev/null
@@ -0,0 +1,44 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <title>Popcorn API Draft DEMO</title>
+  
+  <script src="../popcorn.js"></script>
+  <script src="webpage.js"></script>
+</head>
+<body>
+  <h1 id="qunit-header">Popcorn API Draft</h1>
+  
+  <style>
+    /* test positioning  */
+    
+    video {
+      position: fixed;
+      left: 100px;
+      top: 100px;
+    }
+  
+  </style>
+  
+  <div>
+    <video id='video' 
+      controls preload='none' 
+      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> 
+  </div>
+  <div id="webpagediv">
+  
+  </div>
+</body>
+</html>
diff --git a/demos/webpage.js b/demos/webpage.js
new file mode 100644 (file)
index 0000000..6093aad
--- /dev/null
@@ -0,0 +1,72 @@
+(function (Popcorn) {
+  /**
+   * Webpages popcorn plug-in 
+   * Creates an iframe showing a website specified by the user
+   * Options parameter will need a start, duration or out, and src.
+   * Start is the time that you want this plug-in to execute
+   * Out is the time that you want this plug-in to stop executing [not currently implemented]
+   * Duration can be used instead of out to state how long you want the plug-in to execute for
+   * Target is the id of the document element that the iframe needs to be attached to
+   * @param {Object} options
+   * @param {Object} object element to be added to the list
+   */
+  Popcorn.plugin( "webpages" , function ( options ) {
+    
+    var iframe = document.createElement('iframe'),
+        page = [], 
+        context = this.video;
+    
+    // set the style of the iframe
+    iframe.setAttribute('width', "100%");
+    iframe.setAttribute('height', "100%");
+    
+    
+    
+    // get the options that the user included
+    if ( typeof options === "object" && "join" in options ) {
+      page = options;
+    } else {
+      page.push(options);
+    }
+    
+    this.listen("timeupdate", function (event) {
+      // loop threw all of the webpages 
+      Popcorn.forEach(page, function ( thispage ) {
+               
+        var temp  = document.getElementById( thispage.target );
+        iframe.setAttribute('id', thispage.id);
+        var exists  = document.getElementById( thispage.id );
+        
+        if ( this.currentTime() >= thispage.start && !exists &&  this.currentTime() <= thispage.end) {
+          //div.innerHTML = div.innerHTML + thispage.html;
+          // set the source of the webpage that this plugin should display
+          iframe.setAttribute('src', thispage.src);
+          temp.appendChild(iframe);
+        }
+
+        if ( this.currentTime() >= thispage.end  && exists) {         
+          temp.removeChild(iframe);
+        }
+      }, this);
+    });
+  });
+
+})(Popcorn);
+
+
+document.addEventListener('DOMContentLoaded', function () {
+ // var video = document.getElementById("video");
+  var p = Popcorn('#video');
+  
+  p.play();  
+  
+ 
+  p.webpages({
+    id: "webpages-a", 
+    start: 2, // seconds
+    end: 5, // seconds
+    src: 'http://www.webmademovies.org',
+    target: 'webpagediv'
+  });
+
+}, false);
diff --git a/plugins/popcorn.webpage.js b/plugins/popcorn.webpage.js
new file mode 100644 (file)
index 0000000..b582552
--- /dev/null
@@ -0,0 +1,54 @@
+(function (Popcorn) {
+  /**
+   * Webpages popcorn plug-in 
+   * Creates an iframe showing a website specified by the user
+   * Options parameter will need a start, duration or out, and src.
+   * Start is the time that you want this plug-in to execute
+   * Out is the time that you want this plug-in to stop executing [not currently implemented]
+   * Duration can be used instead of out to state how long you want the plug-in to execute for
+   * Target is the id of the document element that the iframe needs to be attached to
+   * @param {Object} options
+   * @param {Object} object element to be added to the list
+   */
+  Popcorn.plugin( "webpages" , function ( options ) {
+    
+    var iframe = document.createElement('iframe'),
+        page = [], 
+        context = this.video;
+    
+    // set the style of the iframe
+    iframe.setAttribute('width', "100%");
+    iframe.setAttribute('height', "100%");
+    
+    
+    
+    // get the options that the user included
+    if ( typeof options === "object" && "join" in options ) {
+      page = options;
+    } else {
+      page.push(options);
+    }
+    
+    this.listen("timeupdate", function (event) {
+      // loop threw all of the webpages 
+      Popcorn.forEach(page, function ( thispage ) {
+               
+        var temp  = document.getElementById( thispage.target );
+        iframe.setAttribute('id', thispage.id);
+        var exists  = document.getElementById( thispage.id );
+        
+        if ( this.currentTime() >= thispage.start && !exists &&  this.currentTime() <= thispage.end) {
+          //div.innerHTML = div.innerHTML + thispage.html;
+          // set the source of the webpage that this plugin should display
+          iframe.setAttribute('src', thispage.src);
+          temp.appendChild(iframe);
+        }
+
+        if ( this.currentTime() >= thispage.end  && exists) {         
+          temp.removeChild(iframe);
+        }
+      }, this);
+    });
+  });
+
+})(Popcorn);
\ No newline at end of file