Got players working.
This commit is contained in:
parent
cfdb083a81
commit
fea34835e1
3 changed files with 65 additions and 40 deletions
|
@ -1,4 +1,6 @@
|
||||||
jquery.soundcloud
|
jquery.soundcloud
|
||||||
=================
|
=================
|
||||||
|
|
||||||
jQuery plugin to inject the SoundCloud player
|
jQuery plugin to inject the SoundCloud player.
|
||||||
|
|
||||||
|
Check `example.html` for more information.
|
||||||
|
|
17
example.html
17
example.html
|
@ -12,6 +12,21 @@
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<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>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -4,50 +4,53 @@
|
||||||
{
|
{
|
||||||
// Default settings
|
// Default settings
|
||||||
var defaults = {
|
var defaults = {
|
||||||
client_id: false,
|
|
||||||
url: false,
|
|
||||||
callback: false,
|
|
||||||
maxwidth: '100%',
|
|
||||||
maxheight: false,
|
|
||||||
color: false,
|
|
||||||
auto_play: false,
|
auto_play: false,
|
||||||
|
//callback: false,
|
||||||
|
client_id: false,
|
||||||
|
color: false,
|
||||||
|
iframe: true,
|
||||||
|
maxheight: false,
|
||||||
|
maxwidth: false,
|
||||||
show_comments: true,
|
show_comments: true,
|
||||||
iframe: false
|
url: false
|
||||||
};
|
};
|
||||||
|
|
||||||
// Overrides the defaults with passed in options
|
// 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://';
|
var protocol = document.location.protocol == 'https:' ? 'https://' : 'http://';
|
||||||
|
|
||||||
if (typeof SC === 'undefined')
|
if (typeof SC === 'undefined')
|
||||||
{
|
{
|
||||||
// Adds the SoundCloud SDK
|
$.getScript(
|
||||||
var script = document.createElement('script');
|
protocol + 'connect.soundcloud.com/sdk.js',
|
||||||
script.src = protocol + 'connect.soundcloud.com/sdk.js';
|
function()
|
||||||
$('body').append(script);
|
{
|
||||||
}
|
elements.each(function(index, element)
|
||||||
|
|
||||||
return this.each(function()
|
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Overrides the options with the data attributes
|
// Overrides the options with the data attributes
|
||||||
options = $.extend(options, $(this).data());
|
parameters = $.extend({}, options, $(this).data());
|
||||||
|
|
||||||
// Checks that we have a client ID
|
// Checks that we have a client ID
|
||||||
if (!options.client_id)
|
if (!parameters.client_id)
|
||||||
{
|
{
|
||||||
throw 'Missing client ID.';
|
throw 'Missing client ID.';
|
||||||
}
|
}
|
||||||
|
|
||||||
// SC.initialize({ client_id: options.client_id });
|
SC.initialize({ client_id: parameters.client_id });
|
||||||
// var track_url = protocol + options.url;
|
|
||||||
// SC.oEmbed(track_url, { auto_play: true, maxheight: 166 }, function(oEmbed)
|
// Request the embed HTML
|
||||||
// {
|
SC.oEmbed(
|
||||||
// //'$(".soundcloud").eq(' + index + ').replaceWith(oEmbed.html.replace("https:", "http:"));',
|
parameters.url,
|
||||||
// console.log(oEmbed);
|
parameters,
|
||||||
// });
|
function(oEmbed)
|
||||||
|
{
|
||||||
|
$(element).replaceWith(oEmbed.html.replace("https://", protocol));
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
catch (error)
|
catch (error)
|
||||||
{
|
{
|
||||||
|
@ -55,4 +58,9 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
})(jQuery);
|
})(jQuery);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue