diff --git a/example.html b/example.html new file mode 100644 index 0000000..3334698 --- /dev/null +++ b/example.html @@ -0,0 +1,17 @@ + + + + jQuery SoundCloud Plugin + + + + + +
+ + diff --git a/jquery.soundcloud.js b/jquery.soundcloud.js new file mode 100644 index 0000000..fc49328 --- /dev/null +++ b/jquery.soundcloud.js @@ -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);