Started building out the plugin
This commit is contained in:
parent
397184c7ad
commit
cfdb083a81
2 changed files with 75 additions and 0 deletions
17
example.html
Normal file
17
example.html
Normal file
|
@ -0,0 +1,17 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>jQuery SoundCloud Plugin</title>
|
||||
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
|
||||
<script src="./jquery.soundcloud.js" charset="utf-8"></script>
|
||||
<script>
|
||||
$(function()
|
||||
{
|
||||
$('.soundcloud').soundcloud({ client_id: 'b0d6766e74d8b02f74459447c186b12e' });
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="soundcloud" data-url="https://soundcloud.com/joshtronic/baby-got-back/s-IGDdX" data-auto_play="true"></div>
|
||||
</body>
|
||||
</html>
|
58
jquery.soundcloud.js
Normal file
58
jquery.soundcloud.js
Normal file
|
@ -0,0 +1,58 @@
|
|||
(function($)
|
||||
{
|
||||
$.fn.soundcloud = function(options)
|
||||
{
|
||||
// Default settings
|
||||
var defaults = {
|
||||
client_id: false,
|
||||
url: false,
|
||||
callback: false,
|
||||
maxwidth: '100%',
|
||||
maxheight: false,
|
||||
color: false,
|
||||
auto_play: false,
|
||||
show_comments: true,
|
||||
iframe: false
|
||||
};
|
||||
|
||||
// Overrides the defaults with passed in options
|
||||
options = $.extend(defaults, options);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
})(jQuery);
|
Loading…
Add table
Add a link
Reference in a new issue