/* * Youtube Embed Plugin * * @author Jonnas Fonini * @version 2.0.0 */ (function () { CKEDITOR.plugins.add('youtube', { lang: ['en', 'pt', 'ja', 'hu', 'it', 'fr', 'tr', 'ru', 'de', 'ar', 'nl', 'pl', 'vi', 'zh', 'el'], init: function (editor) { editor.addCommand('youtube', new CKEDITOR.dialogCommand('youtube', { allowedContent: 'iframe[!width,!height,!src,!frameborder,!allowfullscreen]; object param[*]; div[*]' })); editor.ui.addButton('Youtube', { label: editor.lang.youtube.button, toolbar: 'insert', command: 'youtube', icon: this.path + 'images/icon.png' }); CKEDITOR.dialog.add('youtube', function (instance) { var host, video; return { title: editor.lang.youtube.title, minWidth: 500, minHeight: 200, contents: [{ id: 'youtubePlugin', expand: true, elements: [{ id: 'txtEmbed', type: 'textarea', label: editor.lang.youtube.txtEmbed, autofocus: 'autofocus', onChange: function (api) { handleEmbedChange(this, api); }, onKeyUp: function (api) { handleEmbedChange(this, api); }, validate: function () { if (this.isEnabled()) { if (!this.getValue()) { alert(editor.lang.youtube.noCode); return false; } else if (this.getValue().length === 0 || this.getValue().indexOf('//') === -1) { alert(editor.lang.youtube.invalidEmbed); return false; } } } }, { type: 'html', html: editor.lang.youtube.or + '
' }, { type: 'hbox', widths: ['70%', '15%', '15%'], children: [ { id: 'txtUrl', type: 'text', label: editor.lang.youtube.txtUrl, onChange: function (api) { handleLinkChange(this, api); }, onKeyUp: function (api) { handleLinkChange(this, api); }, validate: function () { if (this.isEnabled()) { if (!this.getValue()) { alert(editor.lang.youtube.noCode); return false; } else { var parsedUrl = ytVidId(this.getValue()); video = parsedUrl.video; host = parsedUrl.host; if(host === 'vimeo.com') { video = checkVimeoVideo(video, this.getValue()); } if (this.getValue().length === 0 || parsedUrl === false) { alert(editor.lang.youtube.invalidUrl); return false; } } } } }, { type: 'text', id: 'txtWidth', width: '60px', label: editor.lang.youtube.txtWidth, 'default': editor.config.youtube_width != null ? editor.config.youtube_width : '640', validate: function () { if (this.getValue()) { var width = parseInt(this.getValue()) || 0; if (width === 0) { alert(editor.lang.youtube.invalidWidth); return false; } } else { alert(editor.lang.youtube.noWidth); return false; } } }, { type: 'text', id: 'txtHeight', width: '60px', label: editor.lang.youtube.txtHeight, 'default': editor.config.youtube_height != null ? editor.config.youtube_height : '360', validate: function () { if (this.getValue()) { var height = parseInt(this.getValue()) || 0; if (height === 0) { alert(editor.lang.youtube.invalidHeight); return false; } } else { alert(editor.lang.youtube.noHeight); return false; } } } ] }, ] } ], onOk: function () { var content = ''; var responsiveStyle = ''; if (this.getContentElement('youtubePlugin', 'txtEmbed').isEnabled()) { content = '

' + this.getValueOf('youtubePlugin', 'txtEmbed') + '

'; } else { var url = '//', params = [], startSecs; var width = this.getValueOf('youtubePlugin', 'txtWidth'); var height = this.getValueOf('youtubePlugin', 'txtHeight'); if (host == 'vimeo.com') { url += 'player.vimeo.com/video/' + video } else { url += 'www.youtube.com/embed/' + video; } //content += '
'; content += '