editor.js/plugins/video/video.js

86 lines
1.5 KiB
JavaScript
Raw Normal View History

/**
2017-01-11 12:00:50 +01:00
* Video plugin by gohabereg
* @version 1.0.0
*/
2017-01-11 12:00:50 +01:00
var videoTool = {
make : function(data, isInternal) {
2017-01-11 12:00:50 +01:00
if (!data.video_url)
return;
var properties = {
width: '560',
height: '315',
2017-01-11 12:00:50 +01:00
src: data.video_url,
frameborder: '0',
allowfullscreen: true
};
2017-01-11 12:00:50 +01:00
var frame = codex.draw.node('IFRAME', 'video', properties);
if (isInternal) {
2017-01-11 12:00:50 +01:00
frame.src = videoTool.content.makeEmbedUrl(data.video_url);
setTimeout(function() {
/** Render block */
2017-01-11 12:00:50 +01:00
videoTool.content.render(frame);
}, 200);
}
return frame;
},
/**
* Saving JSON output.
* Upload data via ajax
*/
save : function(blockContent) {
var data;
if (!blockContent)
return;
data = {
2017-01-11 12:00:50 +01:00
video_url: blockContent.src
};
return data;
},
/**
* Render data
*/
render : function(data) {
2017-01-11 12:00:50 +01:00
return videoTool.make(data);
}
};
2017-01-11 12:00:50 +01:00
videoTool.content = {
render: function (content) {
2017-01-11 12:00:50 +01:00
codex.content.switchBlock(codex.content.currentNode, content, 'video');
var blockContent = codex.content.currentNode.childNodes[0];
2017-01-11 12:00:50 +01:00
blockContent.classList.add('video__loader');
setTimeout(function(){
2017-01-11 12:00:50 +01:00
blockContent.classList.remove('video__loader');
}, 1000);
},
makeEmbedUrl: function (url) {
return url.replace(/watch\?v=/, 'embed/');
}
};