Changes between Initial Version and Version 1 of Ticket #12952

Feb 19, 2015, 11:41:20 AM (6 years ago)
Artur Delura


  • Ticket #12952 – Description

    initial v1  
    11Working on ticket:12612 we found out that we need to allow user to add flag `withCredentials` and some extra headers to XHR object in filetools plugins. Use case for this is to allow cross domain requests.
     3Following [ this] example I tried to customize a bit my request object. I end up with:
     6CKEDITOR.replace( 'editor', function() {
     7  CKEDITOR.fileTools.fileLoader.prototype.sendRequest = function() {
     8          var formData = new FormData(),
     9                        xhr = this.xhr;
     11                formData.append( 'upload', this.file, this.fileName );
     12                xhr.withCredentials = true; // Extra lines
     13                xhr.setRequestHeader( 'X-PINGOTHER', 'pingpong' ); // Extra lines
     14       'POST', this.uploadUrl, true );
     15                xhr.send( formData );
     16        };
     17} );
     20Shortcomings of this solution are:
     21* We overwrite global function `sendRequest` which influence all editor instances while option`imageUploadUrl` is unique for all editor isntances.
     22* We have to wait for plugin to be loaded and editor instance as well to overwrite this method. If user have got a few editors he have to impelement special mechanism to overwrite this function when first editor instance is loaded. Or maybe there is a global event which fire when plugin is loaded?
     24We got at least two sulutions for this:
     25* We can add extra config option like:
     27xhrData =  {
     28    withCredentials: true,
     29    headers: {
     30        'X-HEADER-NAME': "X-HEADER VALUE"
     31    }
     35And function send request will take into consideration {{{xhrData}}} config options and set flag and headers. This is simples solution but don't allow user whole freedom.
     37* Second option is to fire events like `prerequest` which will have an xhr object as a property and user would make whatever he wants with this.
© 2003 – 2021 CKSource – Frederico Knabben. All rights reserved. | Terms of use | Privacy policy