Skip to content

Instantly share code, notes, and snippets.

@chekalsky
Last active January 9, 2019 23:36
Show Gist options
  • Save chekalsky/7438084 to your computer and use it in GitHub Desktop.
Save chekalsky/7438084 to your computer and use it in GitHub Desktop.
Imperavi Redactor Plugin for Embedding Tweets Usage: mention "tweets" in "plugins" setting of you redactor.
/**
* Imperavi Redactor Plugin for Embedding Tweets
* for version >= 9.1
*
* @author Ilya Chekalskiy <[email protected]>
* @version 0.2.2
*/
if (typeof RedactorPlugins === 'undefined') var RedactorPlugins = {};
RedactorPlugins.tweets = {
init: function() {
var callback = $.proxy(function() {
$('.tweets-plugin #insert_button').click($.proxy(function(e){
e.preventDefault();
var tweet_url = $('#tweet_url').val();
var tweet_hide_media = ($('#tweet_show_media').prop('checked') == true) ? 0 : 1;
var tweet_hide_thread = ($('#tweet_show_thread').prop('checked') == true) ? 0 : 1;
$.get('https://api.twitter.com/1/statuses/oembed.json', { url: tweet_url, omit_script: 1,
related: 'tjournalru', maxwidth: 510, 'lang': 'ru', hide_media: tweet_hide_media,
hide_thread: tweet_hide_thread }, $.proxy(function(data) {
if (data.html) {
this.insertTweet(data.html);
} else {
alert('Ошибка!');
}
}, this), 'jsonp');
}, this));
this.selectionSave();
this.bufferSet();
$('#tweet_url').focus();
}, this);
this.buttonAdd('tweets', 'Вставить твит', function(e) {
this.modalInit('Вставить твит', '<div class="tweets-plugin"><section><p><label>Адрес твита:</label><input type="text" id="tweet_url" value="" placeholder="https://twitter.com/jack/status/398477578136461312" style="width: 100%" /></p><p><label><input type="checkbox" id="tweet_show_media" value="1" checked /> Показывать картинку</label></p><p><label><input type="checkbox" id="tweet_show_thread" value="1" /> Включить диалог целиком</label></p></section>'+
'<footer><a href="javascript:void(null);" class="redactor_modal_btn redactor_btn_modal_close">Отмена</a><input type="button" class="redactor_modal_btn" id="insert_button" value="Вставить"></footer></div>', 500, callback);
});
// toolbar button CSS
$('.redactor_toolbar li a.redactor_btn_tweets').css('background', "url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAZCAYAAADE6YVjAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAOBJREFUeNpi/P//PwOtARMDHcCoJSPUEhZcEiEhIQJr1qz5gE0cSCUAMYh+AFSzACrGgE09IZ/MB2pOwCK+H4j7gbgeqgbEPw/EAeQElwDUkPkwlwJpAyBlgKbOAar2AjmWLITSIN/cB1kGpONxqE0EBtUFkuMEzUBYPGAFQAs2kJu6CoH4AxGJ5wLZSRjq/YlEWDSR0nxyAJRM8fkClIQpsgRoAMiSRCDegCOYHMnOjNAk2w9N+wJYlIBcX4gr86EDRnyVFjRfIGcyUNAdABr+gJRihXG0Zhy1ZGhbAhBgADhGSuPgsW2jAAAAAElFTkSuQmCC') no-repeat");
},
insertTweet: function(html) {
this.selectionRestore();
this.insertHtmlAdvanced(html);
this.modalClose();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment