/**
 * Created by YaoJi on 2017/6/23.
 * Ckeditor Picture upload plugin.
 * @author: CoverCMS Web steam.
 * @file: coverimage/plugin.js
 */
CKEDITOR.plugins.add('coverimage', {
    icons: 'coverimage',
    init: function (editor) {
        CKEDITOR.dialog.addIframe('coverimage', '图片上传', mediaEntry+'?cl=editorImageUpload(response.f_url);&f_num_limit=10&ac={extensions:\'gif,jpg,jpeg,bmp,png\',mimeTypes:\'image/*\'}', 700, 480, function () {}, {
            onOk: function (element) {
                var imagesLength = uploadedImages.length;
                if (imagesLength > 0) {
                    var inserted = [];
                    for (var i = 0; i < imagesLength; i++) {
                        inserted.push('<p><img src="'+uploadedImages[i]+'" /></p>');
                    }
                    var insertedString = inserted.join('');
                    editor.insertHtml(insertedString);
                    uploadedImages = [];
                }
            },
            onCancel: function () {
                uploadedImages = [];
            }
        });

        editor.addCommand('insertimage', {
            exec: function (editor) {
                editor.openDialog('coverimage')
            }
        });

        editor.ui.addButton('coverimage', {
            label: '插入图片',
            command: 'insertimage',
            toolbar: 'insert'
        });
    }
});