Created
May 13, 2016 15:28
-
-
Save andflett/d22cc5e7ffa2d77d84ead3a0dd9bde3d 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
/** | |
* Soundcloud oEmbed discovery | |
*/ | |
SirTrevor.Blocks.Soundcloud = (function(){ | |
return SirTrevor.Block.extend({ | |
type: 'Soundcloud', | |
title: function() { return 'Soundcloud' }, | |
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('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