Skip to content

Instantly share code, notes, and snippets.

@matula
Created November 23, 2013 01:48
Show Gist options
  • Save matula/7609762 to your computer and use it in GitHub Desktop.
Save matula/7609762 to your computer and use it in GitHub Desktop.
Custom Sir Trevor JS block for embedding Soundcloud
/**
* Block for a Soundcloud link
*/
SirTrevor.Blocks.Soundcloud = (function(){
return SirTrevor.Block.extend({
type: 'Soundcloud',
title: 'Soundcloud',
pastable: true,
loadData: function(data){
this.$editor.html(data.html).show();
},
onContentPasted: function(event){
// Content pasted. Delegate to the drop parse method
var input = $(event.target),
val = input.val();
// Pass this to the same handler as onDrop
this.handleDropPaste(val);
},
handleDropPaste: function(url){
if(_.isURI(url))
{
if (url.indexOf('soundcloud') != -1) {
// Get the oembed code
this.handleOembed(url);
}
}
},
handleOembed: function(url){
var $this = this;
$.post('http://soundcloud.com/oembed', { url: url, color: '1fbdbc', format: 'json' }, function(post_data) {
var data = {};
data.html = post_data.html;
data.url = url;
$this.setAndLoadData(data);
}, 'json');
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment