Created
November 23, 2013 01:48
-
-
Save matula/7609762 to your computer and use it in GitHub Desktop.
Custom Sir Trevor JS block for embedding Soundcloud
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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