]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
[#380] API signature updated. Test timeout increassed
authorstevenaw <sweerdenburg@gmail.com>
Wed, 20 Apr 2011 16:50:17 +0000 (12:50 -0400)
committerstevenaw <sweerdenburg@gmail.com>
Wed, 20 Apr 2011 16:50:17 +0000 (12:50 -0400)
players/soundcloud/popcorn.soundcloud.html
players/soundcloud/popcorn.soundcloud.js
players/soundcloud/popcorn.soundcloud.unit.js

index a575711b04db9c4b103fa9bc7f66ef1513e3b8e7..80d0ed300d9ff02da4ba057b7638e13424574e3c 100644 (file)
@@ -52,7 +52,8 @@
           popcorn.mute();
         }, false);
         
-        popcorn = Popcorn( Popcorn.soundcloud( "media_1", {
+        popcorn = Popcorn( Popcorn.soundcloud({
+          target: "media_1",
           width: "50%",
           /*
             This demo contains an api key used for retrieving comments from Soundcloud's API
index 23eaa25eedda69b32387db1d790039e9fdb16468..724895d3edb32ead9cc5f95f0d3e8abe12cde991 100644 (file)
@@ -5,43 +5,48 @@
   * This player adds enables Popcorn.js to handle Soundcloud audio. It does so by masking an embedded Soundcloud Flash object
   * as a video and implementing the HTML5 Media Element interface.
   *
-  * You can specify the video in four ways:
-  *  1. Use the embed code path supplied by Soundcloud as a div's data-src attribute, and pass the div id into a new Popcorn.soundcloud object
+  * You can configure the video source and dimensions in two ways:
+  *  1. Use the embed code path supplied by Soundcloud the id of the desired location into a new Popcorn.soundcloud object.
+  *     Width and height can be configured throughh CSS.
   *
-  *    <div id="player_1" data-width="500" data-height="281" data-src="http://soundcloud.com/forss/flickermood" ></div>
+  *    <div id="player_1" style="width: 500px; height: 81px"></div>
   *    <script type="text/javascript">
   *      document.addEventListener("DOMContentLoaded", function() {
-  *        var popcorn = Popcorn( Popcorn.soundcloud( "player_1" ) );
+  *        var popcorn = Popcorn( Popcorn.soundcloud({
+  *            target: "player_1",                               // Required
+  *            src: "http://soundcloud.com/forss/flickermood",   // Required
+  *          }));
   *      }, false);
   *    </script>
   *
-  *  2. Pass the div id and the embed code path supplied by Soundcloud into a new Popcorn.soundcloud object
+  *  2. Width and height may also be configured directly with the player. This will override any CSS.
   *
-  *    <div id="player_1" data-width="500" data-height="281" data-src="" ></div>
-  *    <script type="text/javascript">
-  *      document.addEventListener("DOMContentLoaded", function() {
-  *        var popcorn = Popcorn( Popcorn.soundcloud( "player_1", { src: "http://soundcloud.com/forss/flickermood" } ) );
-  *      }, false);
-  *    </script>
+  *     <div id="player_1"></div>
+  *     <script type="text/javascript">
+  *       document.addEventListener("DOMContentLoaded", function() {
+  *       var popcorn = Popcorn( Popcorn.soundcloud({
+  *         target: "player_1",                               // Required
+  *         src: "http://soundcloud.com/forss/flickermood",   // Required
+  *         width: "500",                                     // Optional
+  *         height: "81"                                      // Optional
+  *       }));
+  *       }, false);
+  *     </script>
   *
-  * The player can be further configured when it is created by adding other attrributes. A complete list (all optional):
+  * The player can be further configured to integrate with the SoundCloud API:
   *
   * var popcorn = Popcorn( Popcorn.soundcloud( "player_1", {
-  *   src: "http://soundcloud.com/forss/flickermood",     // The Soundcloud track to play
-  *   width: "100%",                                      // The width for the player. May also be as '##px'
-  *   height: "81px",                                     // The height for the player. May also be as '###%'
-  *   api_key: "abcdefsdfsdf",                            // Soundcloud API key, required for retrieving comments
-  *   commentdiv: "divId_for_output",                     // Div Id for outputting comments
-  *   commentformat: function( comment ) {}               // Function to format a comment. Returns HTML string
+  *   target: "player_1",                               // Required, the location to place the player
+  *   src: "http://soundcloud.com/forss/flickermood",   // Required, the Soundcloud track to play
+  *   width: "100%",                                    // Optional, the width for the player. May also be as '##px'
+  *                                                     //           Defaults to the maximum possible width
+  *   height: "81px",                                   // Optional, the height for the player. May also be as '###%'
+  *                                                     //           Defaults to 81px
+  *   api_key: "abcdefsdfsdf",                          // Optional, the Soundcloud API key, required for retrieving comments
+  *   commentdiv: "divId_for_output",                   // Optional, the Div Id for outputting comments
+  *   commentformat: function( comment ) {}             // Optional, a function to format a comment. Returns HTML string
   * }));
   *
-  * Height, width and track source may be specified in other ways. Height and width may be throughh CSS or inline on the container
-  * div's attributes (data-height, data-width). Track source may be specified on the container element as an attribute (data-src).
-  * See above example. Values may be overridden if height, width or souurce are specified in moree than one way.
-  * The hierarchy is:
-  *
-  *   constructor -> inline -> CSS
-  *
   * Comments are retrieved from Soundcloud when the player is registered with Popcorn by calling the registerWithPopcorn()
   * function. For this to work, the api_key and commentdiv attributes must be set. Comments are output by default similar to
   * how Soundcloud formats them in-player, but a custom formatting function may be supplied. It receives a comment object and
     });
   });
   
-  Popcorn.soundcloud = function( containerId, options ) {
-    return new Popcorn.soundcloud.init( containerId, options );
+  Popcorn.soundcloud = function( options ) {
+    return new Popcorn.soundcloud.init( options );
   };
   
   // A constructor, but we need to wrap it to allow for "static" functions
   Popcorn.soundcloud.init = (function() {
-    function pullFromContainer( that, options ) {      
-      var container = that._container,
+    function pullFromContainer( that ) {      
+      var options = that._options,
+          container = that._container,
           bounds = container.getBoundingClientRect(),
           tmp,
           undef;
       that.width = options.width || getStyle( container, "width" ) || "100%";
       that.height = options.height || getStyle( container, "height" ) || "81px";
       that.src = options.src;
-      that.autoplay = container.getAttribute( "data-autoplay" ) || undef;
+      that.autoplay = options.autoplay;
       
       if ( parseFloat( that.height, 10 ) !== 81 ) {
         that.height = "81px";
     }
   
     // If container id is not supplied, assumed to be same as player id
-    var ctor = function ( containerId, options ) {
-      if ( !containerId ) {
+    var ctor = function ( options ) {
+      if ( !options || !options.target ) {
         throw "Must supply an id!";
       } else if ( /file/.test( location.protocol ) ) {
         throw "Must run from a web server!";
       }
       
-      var container = this._container = document.getElementById( containerId );
+      var containerId = options.target,
+          container = this._container = document.getElementById( containerId );
       
       if ( !container ) {
         throw "Could not find that container in the DOM!";
       }
       
-      options = options || {};
-      
       options.commentformat = options.commentformat || formatComment
       
       this._mediaId = 0;
       this._comments = [];
       this._popcorn;
       
-      this._options.src = options.src || container.getAttribute( "data-src" );
-      
-      pullFromContainer( this, this._options );
+      pullFromContainer( this );
       
       this.duration = 0;
       this.volume = 1;
index 53b107c145a92a084cc8aa890b4ff20e257ae4ca..a60aaae68d4040b5ac2e9055bf02cf031ce8dfd9 100644 (file)
@@ -3,7 +3,8 @@ test( "API", function () {
 
   var expects = 0,
       count = 0,
-      player = Popcorn.soundcloud( "player_1", {
+      player = Popcorn.soundcloud({
+        target: "player_1",
         src: "http://soundcloud.com/forss/flickermood"
       }),
       members = {
@@ -101,10 +102,12 @@ test( "Default Attribute Functionality", function () {
   expect( expects );
   stop( 10000 );
   
-  playerDefault = Popcorn.soundcloud( "player_2", {
+  playerDefault = Popcorn.soundcloud({
+    target: "player_2",
     src: "http://soundcloud.com/forss/flickermood"
   });
-  playerOverride = Popcorn.soundcloud( "player_2", {
+  playerOverride = Popcorn.soundcloud({
+    target: "player_2",
     height: "100px",
     width: '90%',
     src: "http://soundcloud.com/forss/journeyman"
@@ -142,7 +145,10 @@ test( "Default Attribute Functionality", function () {
 test( "Player Volume Control", function () {
   var expects = 3,
       count = 0,
-      player = Popcorn.soundcloud( "player_1", { src: "http://soundcloud.com/forss/flickermood" } ),
+      player = Popcorn.soundcloud({
+        target: "player_1",
+        src: "http://soundcloud.com/forss/flickermood"
+      }),
       targetVolume,
       startVolume;
       
@@ -186,14 +192,21 @@ test( "Testing Comments", function() {
       cmtDate = new Date(),
       comment,
       players = {
-        player1: Popcorn.soundcloud( "player_1", { src: "http://soundcloud.com/forss/flickermood" } ),
-        player2: Popcorn.soundcloud( "player_2", {
+        player1: Popcorn.soundcloud({
+          target: "player_1",
+          src: "http://soundcloud.com/forss/flickermood"
+        }),
+        player2: Popcorn.soundcloud({
+          target: "player_2",
           src: "http://soundcloud.com/forss/flickermood",
           commentformat: function( comment ) {
             return comment.text
           }
         }),
-        player3: Popcorn.soundcloud( "player_1", { src: "http://soundcloud.com/forss/flickermood" } )
+        player3: Popcorn.soundcloud({
+          target: "player_1",
+          src: "http://soundcloud.com/forss/flickermood"
+        })
       }
       // Expecteed comment output
       commentOutput = {
@@ -254,7 +267,10 @@ test( "Testing Comments", function() {
 test( "Popcorn Integration", function () {
   var expects = 4,
       count = 0,
-      player = Popcorn.soundcloud( "player_1", { src: "http://soundcloud.com/forss/flickermood" } );
+      player = Popcorn.soundcloud({
+        target: "player_1",
+        src: "http://soundcloud.com/forss/flickermood"
+      });
       
   function plus() {
     if ( ++count === expects ) {
@@ -296,7 +312,10 @@ test( "Popcorn Integration", function () {
 test( "Events and Player Control", function () {
   var expects = 14,
       count = 0,
-      player = Popcorn.soundcloud( "player_1", { src: "http://soundcloud.com/forss/flickermood" } ),
+      player = Popcorn.soundcloud({ 
+        target: "player_1",
+        src: "http://soundcloud.com/forss/flickermood"
+      }),
       targetVolume;
       
   function plus() {
@@ -306,7 +325,7 @@ test( "Events and Player Control", function () {
   }
   
   expect(expects);
-  stop( 100000 );
+  stop( 150000 );
   
   player.addEventListener( "load", function() {
     ok( true, "Load was fired" );