<?xml version="1.0" encoding="utf-8"?>
<configuration version="1" date="2018-02-23 18:23:39" synergyVersion="3.15">
    <objects version="1" date="2018-02-23 18:23:39" synergyVersion="3.15">
        <customComponent code="include_js_ckeditor"
            name="CKEditor 4 CDN" use_in_forms="false">
            <javascript>jQuery('head').append('&lt;script src="https://cdn.ckeditor.com/4.8.0/full-all/ckeditor.js"&gt;&lt;/script&gt;');
            </javascript>
            <html></html>
        </customComponent>
        <customComponent code="ckeditor4_extcomponent"
            name="CKEditor4 Component" use_in_forms="true">
            <javascript>var ckeditor;

var textView = jQuery('&lt;div&gt;');

if(editable) {
    
    function generateUUID () { // Public Domain/MIT
        var d = new Date().getTime();
        if (typeof performance !== 'undefined' &amp;&amp; typeof performance.now === 'function'){
            d += performance.now(); //use high-precision timer if available
        }
        return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
            var r = (d + Math.random() * 16) % 16 | 0;
            d = Math.floor(d / 16);
            return (c === 'x' ? r : (r &amp; 0x3 | 0x8)).toString(16);
        });
    }
    
    var guid = generateUUID();

    view.container.append('&lt;textarea name="ckeditor'+guid+'"&gt;&lt;/textarea&gt;');
    
    ckeditor = CKEDITOR.replace('ckeditor'+guid+'',{
			// Define the toolbar groups as it is a more accessible solution.
			toolbarGroups: [
        		{ name: 'styles', groups: [ 'styles' ] },
        		{ name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ] },
        		{ name: 'paragraph', groups: [ 'align', 'list', 'indent', 'blocks', 'bidi', 'paragraph' ] },
        		{ name: 'colors', groups: [ 'colors' ] },
        		{ name: 'insert', groups: [ 'insert' ] },
        		{ name: 'links', groups: [ 'links' ] },
        		{ name: 'document', groups: [ 'mode', 'document', 'doctools' ] },
        		{ name: 'clipboard', groups: [ 'clipboard', 'undo' ] },
        		{ name: 'editing', groups: [ 'find', 'selection', 'spellchecker', 'editing' ] },
        		{ name: 'forms', groups: [ 'forms' ] },
        		{ name: 'tools', groups: [ 'tools' ] },
        		{ name: 'others', groups: [ 'others' ] },
        		{ name: 'about', groups: [ 'about' ] }
        	],

			// Remove the redundant buttons from toolbar groups defined above.
			removeButtons: 'Cut,Undo,Redo,Copy,Paste,Format,Styles,Source,Save,NewPage,Preview,Templates,Subscript,Superscript,Blockquote,CreateDiv,BidiLtr,BidiRtl,Language,Flash,HorizontalRule,Smiley,SpecialChar,PageBreak,Iframe,PasteText,PasteFromWord,Find,Replace,SelectAll,Scayt,Form,Maximize,About,ShowBlocks,Checkbox,Radio,TextField,Textarea,Select,Button,ImageButton,HiddenField',
			extraPlugins: 'tableresize',

			filebrowserWindowWidth: '640',
            filebrowserWindowHeight: '480',
            allowedContent: true,
            extraAllowedContent: 'table(*)',

		    bodyClass: 'document-editor',
		    format_tags: 'p;h1;h2;h3;pre',
			
			stylesSet: [
				{ name: 'Narrow image', type: 'widget', widget: 'image', attributes: { 'class': 'image-narrow' } },
				{ name: 'Wide image', type: 'widget', widget: 'image', attributes: { 'class': 'image-wide' } },
				{ name: 'Marker', element: 'span', attributes: { 'class': 'marker' } },
			{ name: 'Cited Work', element: 'cite' },
			{ name: 'Inline Quotation', element: 'q' },
			/* Inline Styles */
			{ name: 'Marker', element: 'span', attributes: { 'class': 'marker' } },
			{ name: 'Cited Work', element: 'cite' },
			{ name: 'Inline Quotation', element: 'q' },
			/* Object Styles */
			{
				name: 'Special Container',
				element: 'div',
				styles: {
					padding: '5px 10px',
					background: '#eee',
					border: '1px solid #ccc'
				}
			},
			{
				name: 'Compact table',
				element: 'table',
				attributes: {
					cellpadding: '5',
					cellspacing: '0',
					border: '1',
					bordercolor: '#ccc'
				},
				styles: {
					'border-collapse': 'collapse'
				}
			},
			{ name: 'Borderless Table', element: 'table', styles: { 'border-style': 'hidden', 'background-color': '#E6E6FA' } },
			{ name: 'Square Bulleted List', element: 'ul', styles: { 'list-style-type': 'square' } }
			]
			,
			contentsCss: [ CKEDITOR.basePath + 'contents.css', 'https://sdk.ckeditor.com/samples/assets/css/widgetstyles.css', window.location.host + '/Synergy/css/my_style_ckeditor.css'],
			
			image2_alignClasses: [ 'image-align-left', 'image-align-center', 'image-align-right' ],
			image2_disableResizer: true,
			
			height: 470,
			uiColor: '#E5E5E5',
			language: AS.OPTIONS.locale
		});

    ckeditor.setData(model.getValue());
    
    ckeditor.on('change', function() {
        model.setValue(ckeditor.getData());
    });
    

    ckeditor.on('paste', function( evt ) {
        var file, i, el, loader;
        if (evt.data.dataValue === '') {
        for ( i = 0; i &lt; evt.data.dataTransfer.getFilesCount(); i++ ) {
                file = evt.data.dataTransfer.getFile( i );
                if (CKEDITOR.fileTools.isTypeSupported( file, /image\/(jpeg|png|gif|bmp)/)) {
                   
                    var f = evt.data.dataTransfer.getFile(i);					
            		var reader = new FileReader();
            		reader.onload = function(evt) {
            			var element = ckeditor.document.createElement('img', {
            				attributes: {
            					src: evt.srcElement.result
            				}
            			});
            
            			ckeditor.insertElement(element);
            		};
            		
            		reader.readAsDataURL(f);
                }
            }
        } else {
            debugger;
            var tableSource = evt.data.dataValue;
            if (tableSource.indexOf('&lt;table ') !== -1) {
                tableSource = tableSource.replace('border="0"', '');
                tableSource = tableSource.replace('class=" cke_show_border"', '');
                tableSource = tableSource.replace('&lt;table ', '&lt;table bordercolor="#d0d0d0" border="1px" style="border-collapse: collapse;"');
                tableSource = tableSource.replace(new RegExp('border:none;', 'g'), '');
                evt.data.dataValue = tableSource;
            }
        }
    });
    
    CKEDITOR.on('dialogDefinition', function(ev) {
		var dialogName = ev.data.name;
		var dialogDefinition = ev.data.definition;

        if(dialogName == 'image') {
          dialogDefinition.onLoad = function () {
            var dialog = CKEDITOR.dialog.getCurrent(); 
            dialog.hidePage('Link' ); 
            dialog.hidePage('advanced' ); 
          };
        }
	});
} else {
    view.container.append(textView);
    textView.html(model.getValue());
}

model.textValue = "";

model.updateTextView = function () {
    if(!model.getValue()) {
        model.textValue = "";
        model.trigger(AS.FORMS.EVENT_TYPE.dataLoad, [model]);
        return;
    }
};

model.getTextValue = function(){
    return model.textValue;
};

model.setAsfData = function(asfData){
    model.setValue(asfData.value);
};

model.getAsfData = function(blockNumber){
    return AS.FORMS.ASFDataUtils.getBaseAsfData(model.asfProperty, blockNumber, model.value, null);
};

view.updateValueFromModel = function(){
    textView.html(model.getValue());
};




            </javascript>
            <html></html>
        </customComponent>
        <externalModuleComponent code="include_js_ckeditor"
            name="Подключение CKEditor 4" path="main" action_type="ADD" comp_code="include_js_ckeditor"/>
    </objects>
    <dependencies>
        <dependency dependingObjectType="1073741836"
            dependingObjectCode="include_js_ckeditor"
            ownerObjectType="268435456" ownerObjectCode="include_js_ckeditor"/>
    </dependencies>
</configuration>
