NEW_CKEDITOR.plugins.add("cloudservices",{requires:"filetools,ajax",onLoad:function(){function e(e,r,n,s){o.call(this,e,r,n),this.customToken=s}var o=NEW_CKEDITOR.fileTools.fileLoader;e.prototype=NEW_CKEDITOR.tools.extend({},o.prototype),e.prototype.upload=function(e,r){(e=e||this.editor.config.cloudServices_uploadUrl)?o.prototype.upload.call(this,e,r):NEW_CKEDITOR.error("cloudservices-no-upload-url")},NEW_CKEDITOR.plugins.cloudservices.cloudServicesLoader=e},beforeInit:function(e){var o=e.config.cloudServices_tokenUrl,r={token:null,REFRESH_INTERVAL:e.CLOUD_SERVICES_TOKEN_INTERVAL||36e5,refreshToken:function(){NEW_CKEDITOR.ajax.load(o,(function(e){e&&(r.token=e)}))},init:function(){this.refreshToken();var o=window.setInterval(this.refreshToken,this.REFRESH_INTERVAL);e.once("destroy",(function(){window.clearInterval(o)}))}};o?r.init():NEW_CKEDITOR.error("cloudservices-no-token-url"),e.on("fileUploadRequest",(function(e){var o=e.data.fileLoader,n=e.data.requestData,s=o.customToken||r.token;o instanceof NEW_CKEDITOR.plugins.cloudservices.cloudServicesLoader&&(n.file=n.upload,delete n.upload,s?e.data.fileLoader.xhr.setRequestHeader("Authorization",s):(NEW_CKEDITOR.error("cloudservices-no-token"),e.cancel()))}),null,null,6),e.on("fileUploadResponse",(function(e){var o,r=e.data.fileLoader,n=r.xhr;if(r instanceof NEW_CKEDITOR.plugins.cloudservices.cloudServicesLoader){e.stop();try{o=JSON.parse(n.responseText),e.data.response=o}catch(e){NEW_CKEDITOR.warn("filetools-response-error",{responseText:n.responseText})}}}))}}),NEW_CKEDITOR.plugins.cloudservices={cloudServicesLoader:null};