-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
insertImage into Editor from File Browser #354
Comments
I have spent the last two days since this issue was opened trying to work out how to insert ANY content into the contenteditable div. Seeing as summernote is capable of doing it when uploading an image, or adding links and other stuff, then it already has a function for adding content where the caret position is, unfortunately I haven't been able to make heads or tails how to implement the usage of it. Surely, someone here has had the same issue with other types of content, and that the insertImage is able to do it when uploading images as I've found code for that, and it inserts the images at the caret position, someone must have a solution. This is one small thing I am asking, and I'm more than happy to share the rest of the code for implementing or for others to use with the editor. I'm also adding the ability to add any types of uploaded files for linking, like .zip, or documents, like .doc, or .pdf, as some of my client's require it. I've even created the php side to read the files into a json array to allow selecting the files via thumbnails for images, or filenames for files. So far I've been using a seperate jquery addon to determine the position of the caret within the .note-editable classed contenteditable div. And it works, but for one thing, it doesn't for some reason take into consideration of tags which are not visible, so no matter how many chars in tags are in the text, it positions the content that many chars away from the correct caret position to the left. |
After a little help from issue #293 with thanks to @maksymcierzniak, I've come up with the following, and is working fine, I'm adding it here in case anyone else wants to use it. I also have a similar browser for added content, like .pdf, .zip and so on, if requested I'll post the code here too. I hope this helps others.
and the PHP component: file($upload_dir.$file); if($type=='image/bmp'||$type=='image/x-windows-bmp'||$type=='image/jpeg'||$type=='image/pjpeg'||$type=='image/png'||$type=='image/gif'||$type=='image/tiff'||$type=='image/x-tiff'){ $docs[]=$file; } } } sort($docs); foreach($docs as $key=>$file){ $array[]=array( 'thumb'=>$path.$file, 'image'=>$upload_dir.$file, 'title'=>$file ); } echo stripslashes(json_encode($array)); |
Love your work on this. We are actually going to integrate this project (https://github.com/imgly/imgly-sdk-html5) for processing the images when selected before they are inserted in the editor. We'll be able to use this to cut down on a lot of issues with users trying to add images that are not properly suited for using online... like a full 21 megapixel image. |
Thanks, The imgly project looks interesting. |
I think is what you are looking for editor.insertImage(welEditable, url); |
I thought #1203 is helpful for this. |
I've been playing with adding a File Browser into the summernote "Insert Image" dialog box. So far I have been able to add tabs into the dialog, and add a json/php routine to grab the files from a folder, and display the images. I've also been able to add a click event which returns the file path in an alert box for now. But I have yet been able to make that image insert into the editor itself. I've double spaced where I think the issue is.
The code to read the files has been modified from Redactor, with small tweaks to get it working here.
I know this is something a lot of use have been wanting for some time, and I hope this goes at least in a small way to getting this implemented for the future.
The text was updated successfully, but these errors were encountered: