]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
[#159] initial twitter plugin without unit tests
authorScottDowne <sdowne@learn.senecac.on.ca>
Mon, 20 Dec 2010 19:18:43 +0000 (14:18 -0500)
committerScottDowne <sdowne@learn.senecac.on.ca>
Mon, 20 Dec 2010 19:18:43 +0000 (14:18 -0500)
plugins/twitter/popcorn.twitter.html [new file with mode: 0644]
plugins/twitter/popcorn.twitter.js [new file with mode: 0644]

diff --git a/plugins/twitter/popcorn.twitter.html b/plugins/twitter/popcorn.twitter.html
new file mode 100644 (file)
index 0000000..3dd09ac
--- /dev/null
@@ -0,0 +1,55 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <title>Popcorn Twitter Plug-in Demo</title>
+  
+  <script src="../../popcorn.js"></script>
+  <script src="http://widgets.twimg.com/j/2/widget.js"></script>
+  <script src="popcorn.twitter.js"></script>
+  <script>
+    document.addEventListener('DOMContentLoaded', function () {
+      var p = Popcorn('#video')
+      .twitter({
+        start: 5, // seconds
+        end: 15, // seconds
+        title: 'Steve Song',
+        source: 'from:stevesong',
+        target: 'twitterdiv',
+      } )
+      .twitter({
+        start: 20, // seconds
+        end: 45, // seconds
+        title: 'Oil Spill',
+        source: '#oilspill',
+        target: 'twitterdiv'
+      } )
+      .play();
+    }, false);
+
+  </script>
+</head>
+<body>
+  <h1 id="qunit-header">Popcorn Twitter Plug-in Demo</h1>
+  <p>Twitter widget will appear at 5 seconds and disappear at 15 seconds.</p>
+  <p>More Twitter widget will appear at 20 seconds and disappear at 45 seconds.</p>
+  <div>
+    <video id='video' 
+      controls
+      width= '250px'
+      poster="../../test/poster.png"> 
+
+      <source id='mp4'
+        src="../../test/trailer.mp4"
+        type='video/mp4; codecs="avc1, mp4a"'> 
+
+      <source id='ogv'
+        src="../../test/trailer.ogv"
+        type='video/ogg; codecs="theora, vorbis"'> 
+
+      <p>Your user agent does not support the HTML5 Video element.</p> 
+
+    </video> 
+  </div>
+  <div id="twitterdiv"></div>
+</body>
+</html>
diff --git a/plugins/twitter/popcorn.twitter.js b/plugins/twitter/popcorn.twitter.js
new file mode 100644 (file)
index 0000000..9eb5c82
--- /dev/null
@@ -0,0 +1,107 @@
+// PLUGIN: FLICKR
+
+(function (Popcorn) {
+
+  /**
+   * Twitter popcorn plug-in 
+   * Appends a Twitter widget to an element on the page.
+   * Options parameter will need a start, end, target and source.
+   * Start is the time that you want this plug-in to execute
+   * End is the time that you want this plug-in to stop executing
+   * Source is the hash tag or twitter user to get tweets from
+   * Target is the id of the document element that the images are
+   *  appended to, this target element must exist on the DOM
+   * 
+   * @param {Object} options
+   * 
+   * Example:
+     var p = Popcorn('#video')
+        .twitter({
+          start:          5,                // seconds, mandatory
+          end:            15,               // seconds, mandatory
+          source:         'from:stevesong', // mandatory
+          title:          'title',          // optional
+          subject:        'subject',        // optional
+          height:         200,              // optional
+          width:          250,              // optional
+          target:         'twitterdiv'      // mandatory
+        } )
+   *
+   */
+  Popcorn.plugin( "twitter" , {
+
+      _setup: function( options ) {
+
+        // setup widget div that is unique per track
+        options.container = document.createElement( 'div' ); // create the div to store the widget
+        options.container.setAttribute('id', Popcorn.guid()); // use this id to connect it to the widget
+        options.container.style.display = "none"; // display none by default
+        document.getElementById( options.target ).appendChild( options.container ); // add the widget's div to the target div
+
+        // setup info for the widget
+        var source  = options.source || "",
+            title   = options.title || null,
+            subject   = options.subject || null,
+            width = options.width || 250,
+            height  = options.height || 200;
+
+        // create widget
+        var widget = new TWTR.Widget({
+          version: 2,
+          type: 'search',
+          id: options.container.getAttribute('id'),  // use this id to connect it to the div
+          search: source,
+          title: title,
+          subject: subject,
+          rpp: 30,
+          width: width,
+          height: height,
+          interval: 6000,
+
+          theme: {
+            shell: {
+              background: '#ffffff',
+              color: '#000000'
+            },
+            tweets: {
+              background: '#ffffff',
+              color: '#444444',
+              links: '#1985b5'
+            }
+          },
+
+          features: {
+            loop: true,
+            timestamp: true,
+            avatars: true,
+            hashtags: true,
+            toptweets: true,
+            live: true,
+            scrollbar: false,
+            behavior: 'default'
+          }
+        }).render().start();
+      },
+
+      /**
+       * @member Twitter 
+       * The start function will be executed when the currentTime 
+       * of the video  reaches the start time provided by the 
+       * options variable
+       */
+      start: function( event, options ) {
+        options.container.style.display = "inline";
+      },
+
+      /**
+       * @member Twitter 
+       * The end function will be executed when the currentTime 
+       * of the video  reaches the end time provided by the 
+       * options variable
+       */
+      end: function( event, options ) {
+        options.container.style.display = "none";
+      }
+    });
+
+})( Popcorn );