Got players working.

This commit is contained in:
Joshua Sherman 2014-02-25 19:58:38 -05:00
parent cfdb083a81
commit fea34835e1
3 changed files with 65 additions and 40 deletions

View file

@ -4,55 +4,63 @@
{
// Default settings
var defaults = {
client_id: false,
url: false,
callback: false,
maxwidth: '100%',
maxheight: false,
color: false,
auto_play: false,
//callback: false,
client_id: false,
color: false,
iframe: true,
maxheight: false,
maxwidth: false,
show_comments: true,
iframe: false
url: false
};
// Overrides the defaults with passed in options
options = $.extend(defaults, options);
options = $.extend({}, defaults, options);
var elements = this;
var protocol = document.location.protocol == 'https:' ? 'https://' : 'http://';
if (typeof SC === 'undefined')
{
// Adds the SoundCloud SDK
var script = document.createElement('script');
script.src = protocol + 'connect.soundcloud.com/sdk.js';
$('body').append(script);
$.getScript(
protocol + 'connect.soundcloud.com/sdk.js',
function()
{
elements.each(function(index, element)
{
try
{
// Overrides the options with the data attributes
parameters = $.extend({}, options, $(this).data());
// Checks that we have a client ID
if (!parameters.client_id)
{
throw 'Missing client ID.';
}
SC.initialize({ client_id: parameters.client_id });
// Request the embed HTML
SC.oEmbed(
parameters.url,
parameters,
function(oEmbed)
{
$(element).replaceWith(oEmbed.html.replace("https://", protocol));
}
);
}
catch (error)
{
console.log('[jQuery.SoundCloud] [error] ' + error);
}
});
}
);
}
return this.each(function()
{
try
{
// Overrides the options with the data attributes
options = $.extend(options, $(this).data());
// Checks that we have a client ID
if (!options.client_id)
{
throw 'Missing client ID.';
}
// SC.initialize({ client_id: options.client_id });
// var track_url = protocol + options.url;
// SC.oEmbed(track_url, { auto_play: true, maxheight: 166 }, function(oEmbed)
// {
// //'$(".soundcloud").eq(' + index + ').replaceWith(oEmbed.html.replace("https:", "http:"));',
// console.log(oEmbed);
// });
}
catch (error)
{
console.log('[jQuery.SoundCloud] [error] ' + error);
}
});
return this;
}
})(jQuery);