$('.fm-container').richFilemanager({
    baseUrl: base_url+'themes/filemanager/plugins',
    callbacks: {
        beforeCreateImageUrl: function (resourceObject, url) {
            var split = url.split('/');
            if(split[4] !== 'filemanager')
            {
                split[3] = 'assets/img';
                url = split.join('/');
            }
            return url += 'modified=ImageUrl';
        },
        beforeCreatePreviewUrl: function (resourceObject, url) {
            return url += '&modified=previewUrl';
        },
        beforeSelectItem: function (resourceObject, url) {
            return resourceObject.attributes.path;
            var split = url.split('/');
            if(split[4] !== 'filemanager')
            {
                split[3] = 'assets/img';
                url = split.join('/');
            }
            
            //url = url.replace("mode=readfile", "mode=getinfo");
            
            return url += '&modified=selectItem';
        },
        afterSelectItem: function (resourceObject, url) {
            
            console.log(resourceObject.attributes)
            
            return resourceObject;
            
            // example on how to set url into target input and close bootstrap modal window
            // assumes that filemanager is opened via iframe, which is at the same domain as parent
            // https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy
            
            $('.cke_dialog_image_url').find('input').val(resourceObject.attributes.path);
            
            $('#target-input', parent.document).val(resourceObject.attributes.path);
            $('#modal', parent.document).find('.close').click();
            
        }
    }
    // configuration options not included in .json configuration file, see:
    // https://github.com/servocoder/RichFilemanager/wiki/Configuration-options#client-side-configuration
});

/*$('#js-window-button').on('click', function() {
                var opener = window.open("./../index.html", 'targetWindow',
                    'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=800, height=800');
                function handlePostMessage(e) {
                    var data = e.originalEvent.data;
                    console.log('js-data', data);
                    if (data.source === 'richfilemanager') {
						$('#js-window-input').val(data.preview_url);
                        opener.close();
                    }
                    // remove an event handler
                    $(window).off('message', handlePostMessage);
                }
                $(window).on('message', handlePostMessage);
            });*/


/*$('body').on('show.bs.modal','#fm-bs-modal', function() 
{
    
});*/

 /*$('.fm-container').richFilemanager();*/