Skip to content

Instantly share code, notes, and snippets.

@rsiddle
Created May 20, 2014 21:08
Show Gist options
  • Save rsiddle/4f2095b055821bae1ee2 to your computer and use it in GitHub Desktop.
Save rsiddle/4f2095b055821bae1ee2 to your computer and use it in GitHub Desktop.
A simple TinyMCE 4 plugin to add Click to Tweet HTML to your site.
<script type="text/javascript">
// Notes: Change @yourname to become your Twitter name.
tinymce.PluginManager.add('tweet', function(editor, url) {
// Adds a menu item to the tools menu
editor.addMenuItem('tweet', {
text: 'Tweet This',
context: 'insert',
onclick: function() {
editor.windowManager.open({
title: 'Tweet This',
body: [
{type: 'textbox', name: 'message', label: 'Message'}
],
onsubmit: function(e) {
// Insert content when the window form is submitted
editor.insertContent('<blockquote> ' + e.data.message + ' @yourname <footer><a href="https://twitter.com/intent/tweet?text=' + encodeURI(e.data.message) + '%20@yourname" target="_blank" rel="nofollow">Tweet This</a></footer></blockquote>');
}
});
}
});
});
tinymce.init({
selector: 'textarea',
plugins: 'tweet'
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment