/* * Youtube Embed Plugin * * @author Jonnas Fonini * @version 1.0.7 */ ( function() { CKEDITOR.plugins.add( 'youtube', { lang: [ 'en', 'pt', 'ja', 'hu', 'it', 'fr', 'tr', 'ru', 'de' ], init: function( editor ) { editor.addCommand( 'youtube', new CKEDITOR.dialogCommand( 'youtube', { allowedContent: 'iframe[!width,!height,!src,!frameborder,!allowfullscreen]; object param[*]' })); 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 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', onKeyUp : function ( api ) { if ( this.getValue().length > 0 ) { this.getDialog().getContentElement( 'youtubePlugin', 'txtUrl' ).disable(); } else { this.getDialog().getContentElement( 'youtubePlugin', 'txtUrl' ).enable(); } }, 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, onKeyUp : function ( api ) { if ( this.getValue().length > 0 ) { this.getDialog().getContentElement( 'youtubePlugin', 'txtEmbed' ).disable(); } else { this.getDialog().getContentElement( 'youtubePlugin', 'txtEmbed' ).enable(); } }, validate : function () { if ( this.isEnabled() ) { if ( !this.getValue() ) { alert( editor.lang.youtube.noCode ); return false; } else{ video = ytVidId(this.getValue()); if ( this.getValue().length === 0 || video === 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; } } } ] }, { type : 'hbox', widths : [ '55%', '45%' ], children : [ { id : 'chkRelated', type : 'checkbox', 'default' : editor.config.youtube_related != null ? editor.config.youtube_related : true, label : editor.lang.youtube.chkRelated }, { id : 'chkOlderCode', type : 'checkbox', 'default' : editor.config.youtube_older != null ? editor.config.youtube_older : false, label : editor.lang.youtube.chkOlderCode } ] }, { type : 'hbox', widths : [ '55%', '45%' ], children : [ { id : 'chkPrivacy', type : 'checkbox', label : editor.lang.youtube.chkPrivacy, 'default' : editor.config.youtube_privacy != null ? editor.config.youtube_privacy : false }, { id : 'txtStartAt', type : 'text', label : editor.lang.youtube.txtStartAt, validate : function () { if ( this.getValue() ) { var str = this.getValue(); if ( !/^(?:(?:([01]?\d|2[0-3]):)?([0-5]?\d):)?([0-5]?\d)$/i.test( str ) ) { alert( editor.lang.youtube.invalidTime ); return false; } } } } ] } ] } ], onOk: function() { var content = ''; 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 ( this.getContentElement( 'youtubePlugin', 'chkPrivacy' ).getValue() === true ) { url += 'www.youtube-nocookie.com/'; } else { url += 'www.youtube.com/'; } url += 'embed/' + video; if ( this.getContentElement( 'youtubePlugin', 'chkRelated' ).getValue() === false ) { params.push('rel=0'); } startSecs = this.getValueOf( 'youtubePlugin', 'txtStartAt' ); if ( startSecs ){ var seconds = hmsToSeconds( startSecs ); params.push('start=' + seconds); } if ( this.getContentElement( 'youtubePlugin', 'chkOlderCode' ).getValue() === true ) { url = url.replace('embed/', 'v/'); url = url.replace(/&/g, '&'); if ( params.length == 0 ) { url += '?'; } url += 'hl=pt_BR&version=3'; content = ''; content += ''; content += ''; content += ''; content += ' 0 ) { url = url + '?' + params.join( '&' ); } content = '