Skip to content

Commit

Permalink
Added support to resize soundcloud embed module
Browse files Browse the repository at this point in the history
  • Loading branch information
Shobhit Sharma committed Nov 26, 2018
1 parent 1baf5d8 commit 4fc0b17
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 7 deletions.
5 changes: 3 additions & 2 deletions docs/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ function render() {
window.ga('send', 'event', '[done] ' + url, data.url, dimensions);
}
}).fail(function (err) {
document.getElementById('test-container').innerHTML = '<code>' + err.message + '</code>';
if (window.ga) {
window.ga('send', 'event', '[error] '+ url, err.message, dimensions);
window.ga('send', 'event', '[error] ' + url, err.message, dimensions);
}
});
}, 300);
}, 500);
}
}
15 changes: 11 additions & 4 deletions embedo.js
Original file line number Diff line number Diff line change
Expand Up @@ -1273,25 +1273,32 @@
* @method soundcloud
* SoundCloud Embed Player (api-web) prototype
*
* @see https://developers.soundcloud.com/docs/oembed
* @param {number} id
* @param {HTMLElement} element
* @param {string} url
* @param {object} options Optional parameters.
* @return callback
*/
Embedo.prototype.soundcloud = function(id, element, url, options, callback) {
var size = Embedo.utils.dimensions(element, options.width, options.height);
Embedo.prototype.soundcloud = function (id, element, url, options, callback) {
if (options.hasOwnProperty('width') && options.width) {
options.maxwidth = options.maxwidth || options.width || '100%';
}
if (options.hasOwnProperty('height') && options.height) {
options.maxheight = options.maxheight || options.height;
}
var size = Embedo.utils.dimensions(element, options.maxwidth, options.maxheight);
var embed_options = Embedo.utils.merge({
url: encodeURI(url),
format: 'js'
format: 'js' // Defaults JSONP
},
options,
Embedo.defaults.RESTRICTED
);
var embed_uri =
Embedo.defaults.SOURCES.soundcloud.oEmbed + '?' + Embedo.utils.querystring(embed_options);

Embedo.utils.fetch(embed_uri, function(error, content) {
Embedo.utils.fetch(embed_uri, function (error, content) {
if (error) {
Embedo.log('error', 'soundcloud', error);
return callback(error);
Expand Down
2 changes: 1 addition & 1 deletion embedo.min.js

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions test/embedo.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,21 @@ describe("Embedo", function() {
});
});

it("should embed a soundcloud track", function(done) {
embedo
.load(
document.getElementById("embedo-soundcloud"),
"https://soundcloud.com/uiceheidd/lucid-dreams-forget-me"
)
.done(function(data) {
expect(data).to.be.a("object");
done();
})
.fail(function(err) {
done(err);
});
});

it("should have requests stored after calling .load()", function(done) {
expect(embedo.requests).to.be.an("array");
done();
Expand Down
4 changes: 4 additions & 0 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ <h2>MEDIA Embed</h2>
<h2>JSFiddle Embed</h2>
<div id="embedo-jsfiddle"></div>
</div>
<div class="code-editor code-demo">
<h2>SoundCloud Embed</h2>
<div id="embedo-soundcloud"></div>
</div>
</section>
</div>
</main>
Expand Down
6 changes: 6 additions & 0 deletions test/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,12 @@ function run() {
'http://jsfiddle.net/skelly/FX44w/embedded/'
);

embedo
.load(
document.getElementById("embedo-soundcloud"),
"https://soundcloud.com/uiceheidd/lucid-dreams-forget-me"
);

// Loads google maps URL
// embedo.load(
// document.getElementById('embedo-googlemaps'),
Expand Down

0 comments on commit 4fc0b17

Please sign in to comment.