Skip to content

Instantly share code, notes, and snippets.

@andflett
Created May 13, 2016 15:28
Show Gist options
  • Save andflett/2518ff4d18d47cea67786d9a6707febb to your computer and use it in GitHub Desktop.
Save andflett/2518ff4d18d47cea67786d9a6707febb to your computer and use it in GitHub Desktop.
/**
* Mixcloud oEmbed discovery
*/
SirTrevor.Blocks.Mixcloud = (function(){
return SirTrevor.Block.extend({
type: 'Mixcloud',
title: function() { return 'Mixcloud' },
pastable: true,
icon_name: 'video',
loadData: function(data){
this.editor.innerHTML = data.html
},
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 (url.indexOf('mixcloud') != -1) {
// Get the oembed code
this.handleOembed(url);
}
},
handleOembed: function(url){
var $this = this;
parser = document.createElement('a');
parser.href = url;
console.log(parser.pathname);
$.get('https://api.mixcloud.com/'+parser.pathname+'/embed-json/?color=25292b', 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