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

@ -1,4 +1,6 @@
jquery.soundcloud
=================
jQuery plugin to inject the SoundCloud player
jQuery plugin to inject the SoundCloud player.
Check `example.html` for more information.

View file

@ -12,6 +12,21 @@
</script>
</head>
<body>
<div class="soundcloud" data-url="https://soundcloud.com/joshtronic/baby-got-back/s-IGDdX" data-auto_play="true"></div>
<h1>jQuery SoundCloud Plugin</h1>
<h2>Maximum Config</h2>
<div
class="soundcloud"
data-url="https://soundcloud.com/joshtronic/baby-got-back"
data-auto_play="true"
data-color="336699"
data-iframe="false"
data-maxheight="81px"
data-max-width="500px"
data-show_comments="true"
></div>
<h2>Minimal Config</h2>
<div class="soundcloud" data-url="https://soundcloud.com/joshtronic/baby-got-back"></div>
</body>
</html>

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);