editor.js/plugins/twitter/twitter.js
khaydarov bc8fb1aed9 cover restoring and fetch function fixed (#101)
* cover restoring fixed

* upd

* fetch fixed in safari

* updated

* plugins

* plugins ready

* code improved

* fixed bug with backspace

* improved architecture
2016-12-25 17:41:57 +03:00

91 lines
2.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* Twitter plugin
* @version 1.0.0
*/
var twitterTool = {
/**
* Prepare twitter scripts
*/
prepare : function() {
var script = "//platform.twitter.com/widgets.js";
/**
* Load script
*/
codex.core.importScript(script, 'twitterAPI');
},
make : function(data) {
if (!data.id)
return;
twitterTool.content.twitter(data.id);
},
save : function(blockContent) {
var data;
data = {
media:true,
conversation:false,
user:{
profile_image_url:"http:\/\/pbs.twimg.com\/profile_images\/1817165982\/nikita-likhachev-512_normal.jpg",
profile_image_url_https:"https:\/\/pbs.twimg.com\/profile_images\/1817165982\/nikita-likhachev-512_normal.jpg",
screen_name:"Niketas",
name:"Никита Лихачёв"
},
id: blockContent.dataset.tweetId,
text:"ВНИМАНИЕ ЧИТАТЬ ВСЕМ НЕ ДАЙ БОГ ПРОПУСТИТЕ НУ ИЛИ ХОТЯ БЫ КЛИКНИ И ПОДОЖДИ 15 СЕКУНД https:\/\/t.co\/iWyOHf4xr2",
created_at:"Tue Jun 28 14:09:12 +0000 2016",
status_url:"https:\/\/twitter.com\/Niketas\/status\/747793978511101953",
caption:"Caption"
};
return data;
},
render : function(data) {
return twitterTool.make(data);
}
};
twitterTool.content = {
/**
* Twitter render method appends content after block
* @param tweetId
*/
twitter : function(tweetId) {
var tweet = twitterTool.content.twitterBlock();
codex.content.switchBlock(codex.content.currentNode, tweet, 'twitter');
var blockContent = codex.content.currentNode.childNodes[0];
blockContent.classList.add('twitter__loader');
window.twttr.widgets.createTweet(tweetId, blockContent);
setTimeout(function() {
blockContent.classList.remove('twitter__loader');
}, 500);
/** Remove empty DIV */
blockContent.childNodes[0].remove();
},
twitterBlock : function() {
var block = codex.draw.node('DIV', '', {});
return block;
}
};