Skip to content

Instantly share code, notes, and snippets.

@gudbergur
Created December 3, 2011 04:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gudbergur/1426081 to your computer and use it in GitHub Desktop.
Save gudbergur/1426081 to your computer and use it in GitHub Desktop.
Very bare Embed.ly plugin for TinyMCE
// Requirements: jQuery
// Installation: Add this to your tinyMCE.init, put in your button image and your Embed.ly key and you're good to go
// This is just a very simple embed.ly button cause Google turned up squat.
setup : function(ed) {
ed.addButton('myembedly', {
title : 'Embed.ly',
image : 'BUTTON IMAGE',
onclick : function() {
var url = prompt("Enter URL to embed");
if (url == null) return;
$.ajax({
url:"http://api.embed.ly/1/oembed?key=YOUR KEY&maxwidth=500&url="+encodeURIComponent(url),
dataType: 'jsonp',
success: (function(ed){
return function(data) {
if (data.html != undefined) {
ed.focus();
ed.selection.setContent(data.html);
} else {
alert('Couldn\'t find anything to embed')
}
}
})(ed)
});
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment