CKEDITOR.plugins.add( 'embedtweet', {
    requires: 'widget',
    icons: 'embedtweet',
    init: function( editor ) {
        function loadjQueryLibaries() {
        	try{
                if (typeof (twttr) != 'undefined') {
                    twttr.widgets.load();
                } else {
                	CKEDITOR.scriptLoader.load('//platform.twitter.com/widgets.js', function() {
                		twttr.widgets.load();
                	});
                }
        	}
        	catch(err){ throw err; }
        }
   	 	CKEDITOR.document.appendStyleSheet(this.path + "css/embedtweet.css");
        CKEDITOR.dialog.add( 'embedtweet', this.path + 'dialogs/embedtweet.js' );
        editor.widgets.add( 'embedtweet', {
            button: 'Embed tweets',
            template:
                '<div class="embedtweet"></div>',
            parts: {
    				tweetblock: 'div.embedtweet'
    		},
            requiredContent: 'div(embedtweet)',
            dialog: 'embedtweet',
            upcast: function( element ) {
                return element.name == 'div' && element.hasClass( 'embedtweet' );
            },
            allowedContent: '*',
            init: function() {
            	loadjQueryLibaries();
				this.setData('blockqoute', this.data.blockqoute);
            },
            data: function() {
            	if (this.data.blockqoute!=undefined)
            	{	this.parts.tweetblock.setHtml(this.data.blockqoute);  	}
            }
        } );
    }
} );