Last active
June 17, 2017 15:09
-
-
Save tablatronix/faea199d3abacf578d68495f1e02f82d to your computer and use it in GitHub Desktop.
getsimple ckeditor upload handler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// add to config.js editorconfig section. you can add ?path= query to this to use a subfolder | |
config.imageUploadUrl = "../admin/upload.php" | |
// add to config.js | |
CKEDITOR.on( 'instanceReady', function( ev ) { | |
// code for fileupload and response | |
ev.editor.on( 'fileUploadRequest', function( evt ) { | |
var fileLoader = evt.data.fileLoader, | |
formData = new FormData(), | |
xhr = fileLoader.xhr; | |
xhr.open( 'POST', fileLoader.uploadUrl, true ); | |
formData.append( 'file[]', fileLoader.file, fileLoader.fileName ); | |
fileLoader.xhr.send( formData ); | |
// Prevent default behavior. | |
evt.cancel(); | |
}, null, null, 4 ); // Listener with priority 4 will be executed before priority 5. | |
ev.editor.on( 'fileUploadResponse', function( evt ) { | |
// Prevent the default response handler. | |
evt.stop(); | |
// Get XHR and response. | |
var data = evt.data, | |
xhr = data.fileLoader.xhr, | |
response = xhr.responseText; | |
if ($(response).find('div.updated').html()) { | |
resphtml = $(response).find('div.updated').html(); | |
url = $("a",resphtml).attr("href"); | |
data.url = url; | |
$('div.bodycontent').before('<div class="updated"><p>' + resphtml + '</p></div>'); | |
return; | |
} | |
if ($(response).find('div.error').html()) { | |
resphtml = $(response).find('div.error').html(); | |
msg = resphtml; | |
data.message = msg; | |
$('div.bodycontent').before('<div class="error"><p>' + resphtml + '</p></div>'); | |
evt.cancel(); | |
return; | |
} | |
} ); | |
}); |
wo qu , the office docs shows that " editor.on( 'fileUploadRequest',) " ,I still think the editor is the CKEDITOR 。
it spend me almost 1 hours to debug .
I have to say that the English is so import to coding 。
not sure i understand
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://ckeditor.com/addon/uploadimage
uses
http://ckeditor.com/addon/uploadwidget
Upload Image requires the following dependancies
I suggest you use ckbuilder to add all these automatically, else you have to install them all, and add their entries to the extraplugins