From: stevenaw Date: Wed, 20 Apr 2011 21:18:49 +0000 (-0400) Subject: [#380] API changes reverted X-Git-Tag: v0.5~1^2~2 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=57ce81711131fd88b1d945f92624f894afe9fd25;p=popcorn-js.git [#380] API changes reverted --- diff --git a/players/soundcloud/popcorn.soundcloud.html b/players/soundcloud/popcorn.soundcloud.html index 80d0ed3..b44ac08 100644 --- a/players/soundcloud/popcorn.soundcloud.html +++ b/players/soundcloud/popcorn.soundcloud.html @@ -52,24 +52,24 @@ 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 "
Comment # " + ( count++ ) + "
" - + "" + comment.user.name + ": " + comment.text +"
"; - } - })() + */ + api: { + key: "PRaNFlda6Bhf5utPjUsptg", + commentdiv: "commentDisplay"/*, + commentformat: (function() { + var count = 0; + + return function( comment ) { + return "
Comment # " + ( count++ ) + "
" + + "" + comment.user.name + ": " + comment.text +"
"; + } + })()*/ + } }) ); popcorn.listen( "load", function() { diff --git a/players/soundcloud/popcorn.soundcloud.js b/players/soundcloud/popcorn.soundcloud.js index 724895d..459a6f5 100644 --- a/players/soundcloud/popcorn.soundcloud.js +++ b/players/soundcloud/popcorn.soundcloud.js @@ -12,38 +12,32 @@ *
* * - * 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. * *
* * * 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 * })); * @@ -327,8 +321,8 @@ }); }); - 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 @@ -339,10 +333,6 @@ 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"; @@ -375,26 +365,31 @@ } // 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; @@ -635,11 +630,13 @@ 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({ @@ -672,7 +669,7 @@ avatar: obj.user.avatar || "" }, display: function() { - return ( displayFn || self._options.commentformat )( comment ); + return ( displayFn || self._options.api.commentformat )( comment ); } } @@ -684,7 +681,7 @@ this._popcorn.subtitle({ start: comment.start, - target: this._options.commentdiv, + target: this._options.api.commentdiv, display: 'inline', language: 'en', text: comment.display() diff --git a/players/soundcloud/popcorn.soundcloud.unit.js b/players/soundcloud/popcorn.soundcloud.unit.js index a60aaae..129f959 100644 --- a/players/soundcloud/popcorn.soundcloud.unit.js +++ b/players/soundcloud/popcorn.soundcloud.unit.js @@ -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() {