]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
[#380] API changes reverted
authorstevenaw <sweerdenburg@gmail.com>
Wed, 20 Apr 2011 21:18:49 +0000 (17:18 -0400)
committerstevenaw <sweerdenburg@gmail.com>
Wed, 20 Apr 2011 21:18:49 +0000 (17:18 -0400)
players/soundcloud/popcorn.soundcloud.html
players/soundcloud/popcorn.soundcloud.js
players/soundcloud/popcorn.soundcloud.unit.js

index 80d0ed300d9ff02da4ba057b7638e13424574e3c..b44ac085b92dff4aa5826833fb065790275f95c3 100644 (file)
           popcorn.mute();
         }, false);
         
-        popcorn = Popcorn( Popcorn.soundcloud({
-          target: "media_1",
+        popcorn = Popcorn( Popcorn.soundcloud( "media_1", "http://soundcloud.com/forss/flickermood", {
           width: "50%",
           /*
             This demo contains an api key used for retrieving comments from Soundcloud's API
             It is to be used for demonstration purposes only, and for only this demo
-         */
-          api_key: "PRaNFlda6Bhf5utPjUsptg",
-          src: "http://soundcloud.com/forss/flickermood",
-          commentdiv: "commentDisplay",
-          commentformat: (function() {
-            var count = 0;
-            
-            return function( comment ) {
-              return "<div>Comment # " + ( count++ ) + "<br />"
-                      + "<em>" + comment.user.name + "</em>: " + comment.text +"</div>";
-            }
-          })()
+          */
+          api: {
+            key: "PRaNFlda6Bhf5utPjUsptg",
+            commentdiv: "commentDisplay"/*,
+            commentformat: (function() {
+              var count = 0;
+              
+              return function( comment ) {
+                return "<div>Comment # " + ( count++ ) + "<br />"
+                        + "<em>" + comment.user.name + "</em>: " + comment.text +"</div>";
+              }
+            })()*/
+          }
         }) );
         
         popcorn.listen( "load", function() {
index 724895d3edb32ead9cc5f95f0d3e8abe12cde991..459a6f5f0a482815c4245b72634a1efd95d8bea7 100644 (file)
   *    <div id="player_1" style="width: 500px; height: 81px"></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
-  *          }));
+  *        var popcorn = Popcorn( Popcorn.soundcloud( "player_1", "http://soundcloud.com/forss/flickermood" ));
   *      }, false);
   *    </script>
   *
-  *  2. Width and height may also be configured directly with the player. This will override any CSS.
+  *  2. Width and height may also be configured directly with the player; this will override any CSS. This is useful for
+  *     when different sizes are desired. for multiple players within the same parent container.
   *
   *     <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
+  *       var popcorn = Popcorn( Popcorn.soundcloud( "player_1", "http://soundcloud.com/forss/flickermood", {
+  *         width: "500",                                     // Optional, will default to CSS values
+  *         height: "81"                                      // Optional, will default to CSS values
   *       }));
   *       }, false);
   *     </script>
   *
   * The player can be further configured to integrate with the SoundCloud API:
   *
-  * var popcorn = Popcorn( Popcorn.soundcloud( "player_1", {
-  *   target: "player_1",                               // Required, the location to place the player
-  *   src: "http://soundcloud.com/forss/flickermood",   // Required, the Soundcloud track to play
+  * var popcorn = Popcorn( Popcorn.soundcloud( "player_1", "http://soundcloud.com/forss/flickermood", {
   *   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
+  *   commentdiv: "divId_for_output",                   // Optional, the Div Id for outputting comments. Required if comments are desired
   *   commentformat: function( comment ) {}             // Optional, a function to format a comment. Returns HTML string
   * }));
   *
     });
   });
   
-  Popcorn.soundcloud = function( options ) {
-    return new Popcorn.soundcloud.init( options );
+  Popcorn.soundcloud = function( containerId, src, options ) {
+    return new Popcorn.soundcloud.init( containerId, src, options );
   };
   
   // A constructor, but we need to wrap it to allow for "static" functions
           bounds = container.getBoundingClientRect(),
           tmp,
           undef;
-          
-      if ( !options.src ) {
-        throw "An audio source must be supplied!";
-      }
       
       that.width = options.width || getStyle( container, "width" ) || "100%";
       that.height = options.height || getStyle( container, "height" ) || "81px";
     }
   
     // If container id is not supplied, assumed to be same as player id
-    var ctor = function ( options ) {
-      if ( !options || !options.target ) {
+    var ctor = function ( containerId, src, options ) {
+      if ( !containerId ) {
         throw "Must supply an id!";
+      } else if ( !src ) {
+        throw "Must supply a source!";
       } else if ( /file/.test( location.protocol ) ) {
         throw "Must run from a web server!";
       }
       
-      var containerId = options.target,
-          container = this._container = document.getElementById( containerId );
+      var container = this._container = document.getElementById( containerId );
       
       if ( !container ) {
         throw "Could not find that container in the DOM!";
       }
       
-      options.commentformat = options.commentformat || formatComment
+      options = options || {};
+      options.api = options.api || {};
+      options.target = containerId;
+      options.src = src;
+      options.api.commentformat = options.api.commentformat || formatComment;
       
       this._mediaId = 0;
       this._listeners = {};
-      this._playerId = Popcorn.guid( containerId );
-      this._containerId = containerId;
+      this._playerId = Popcorn.guid( options.target );
+      this._containerId = options.target;
       this._options = options;
       this._comments = [];
       this._popcorn;
       
       this._popcorn = popcorn;
       
-      if ( this._options && this._options.api_key && this._options.commentdiv ) {
+      var api = this._options.api;
+      
+      if ( api.key && api.commentdiv ) {
         var self = this;
         
         Popcorn.xhr({
-          url: "http://api.soundcloud.com/tracks/" + self._mediaId + "/comments.js?consumer_key=" + self._options.api_key,
+          url: "http://api.soundcloud.com/tracks/" + self._mediaId + "/comments.js?consumer_key=" + api.key,
           success: function( data ) {
             Popcorn.forEach( data.json, function ( obj ) {
               self.addComment({
               avatar: obj.user.avatar || ""
             },
             display: function() {
-              return ( displayFn || self._options.commentformat )( comment );
+              return ( displayFn || self._options.api.commentformat )( comment );
             }
           }
       
       
       this._popcorn.subtitle({
         start: comment.start,
-        target: this._options.commentdiv,
+        target: this._options.api.commentdiv,
         display: 'inline',
         language: 'en',
         text: comment.display()
index a60aaae68d4040b5ac2e9055bf02cf031ce8dfd9..129f95989df6c15d27068a922cc7334337bffc0e 100644 (file)
@@ -3,10 +3,7 @@ test( "API", function () {
 
   var expects = 0,
       count = 0,
-      player = Popcorn.soundcloud({
-        target: "player_1",
-        src: "http://soundcloud.com/forss/flickermood"
-      }),
+      player = Popcorn.soundcloud( "player_1", "http://soundcloud.com/forss/flickermood" ),
       members = {
         // HTMLMediaElement members
         'readyState' : 'number',
@@ -102,15 +99,10 @@ test( "Default Attribute Functionality", function () {
   expect( expects );
   stop( 10000 );
   
-  playerDefault = Popcorn.soundcloud({
-    target: "player_2",
-    src: "http://soundcloud.com/forss/flickermood"
-  });
-  playerOverride = Popcorn.soundcloud({
-    target: "player_2",
+  playerDefault = Popcorn.soundcloud( "player_2", "http://soundcloud.com/forss/flickermood" );
+  playerOverride = Popcorn.soundcloud( "player_2",  "http://soundcloud.com/forss/journeyman", {
     height: "100px",
-    width: '90%',
-    src: "http://soundcloud.com/forss/journeyman"
+    width: '90%'
   });
   
   playerDefault.addEventListener( "load", function() {
@@ -145,10 +137,7 @@ test( "Default Attribute Functionality", function () {
 test( "Player Volume Control", function () {
   var expects = 3,
       count = 0,
-      player = Popcorn.soundcloud({
-        target: "player_1",
-        src: "http://soundcloud.com/forss/flickermood"
-      }),
+      player = Popcorn.soundcloud( "player_1", "http://soundcloud.com/forss/flickermood" ),
       targetVolume,
       startVolume;
       
@@ -192,21 +181,13 @@ test( "Testing Comments", function() {
       cmtDate = new Date(),
       comment,
       players = {
-        player1: Popcorn.soundcloud({
-          target: "player_1",
-          src: "http://soundcloud.com/forss/flickermood"
-        }),
-        player2: Popcorn.soundcloud({
-          target: "player_2",
-          src: "http://soundcloud.com/forss/flickermood",
+        player1: Popcorn.soundcloud( "player_1", "http://soundcloud.com/forss/flickermood" ),
+        player2: Popcorn.soundcloud( "player_2", "http://soundcloud.com/forss/flickermood", {
           commentformat: function( comment ) {
             return comment.text
           }
         }),
-        player3: Popcorn.soundcloud({
-          target: "player_1",
-          src: "http://soundcloud.com/forss/flickermood"
-        })
+        player3: Popcorn.soundcloud( "player_1", "http://soundcloud.com/forss/flickermood" )
       }
       // Expecteed comment output
       commentOutput = {
@@ -267,10 +248,7 @@ test( "Testing Comments", function() {
 test( "Popcorn Integration", function () {
   var expects = 4,
       count = 0,
-      player = Popcorn.soundcloud({
-        target: "player_1",
-        src: "http://soundcloud.com/forss/flickermood"
-      });
+      player = Popcorn.soundcloud( "player_1", "http://soundcloud.com/forss/flickermood" );
       
   function plus() {
     if ( ++count === expects ) {
@@ -312,10 +290,7 @@ test( "Popcorn Integration", function () {
 test( "Events and Player Control", function () {
   var expects = 14,
       count = 0,
-      player = Popcorn.soundcloud({ 
-        target: "player_1",
-        src: "http://soundcloud.com/forss/flickermood"
-      }),
+      player = Popcorn.soundcloud( "player_1", "http://soundcloud.com/forss/flickermood" ),
       targetVolume;
       
   function plus() {