Created
May 13, 2016 15:28
-
-
Save andflett/2518ff4d18d47cea67786d9a6707febb to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* 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