Skip to content
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

Drag and drop image files (Feature) #4

Open
m-artin opened this issue Jan 27, 2017 · 1 comment
Open

Drag and drop image files (Feature) #4

m-artin opened this issue Jan 27, 2017 · 1 comment

Comments

@m-artin
Copy link

m-artin commented Jan 27, 2017

I made a small prototype in order to make the editor field accept Kirby typical file drag and drop events. It's far from being perfect, cause I'm stronger with design and Frontend stuff.

The concept is to drop the typical kirby image tag (image:myimage.jpg) to the editor and convert the string to a html image tag. Also the filepath to the content folder needs to be inserted.
After a click on Save page in the panel, the image is visible in the editor. (It may still need a second save to recognize the image by the editor or a double click on the image.)

ckeditor.php

// Set up wrapping element
        …
        // save the content url or directory path for javascript as an data-attribute
        $wrapper->data('path', $this->page()->diruri()); 

create new ckeditorfield.js file (in a similar way like this is done in VisualMarkdownEditor)

…
// the main part after creating the field function and setting the wrapper
self.$wrapper.droppable({
            hoverClass: 'ckeditorfield-wrapper-over',
            accept: self.draggable,
            drop: function (event, element) {
		var dropdata = element.draggable.data('text');
		var contentpath = self.$wrapper.attr('data-path');
		var HTMLImg = "<img src='/content/" + contentpath + "/";
		var drophtml = dropdata.replace( '(image: ' , HTMLImg ).replace(")" , "'>");
		var html = $.parseHTML( drophtml );
                $('div.cke_textarea_inline').append(html);
            }
        });
…
@jciaurrant
Copy link

Hi, I've tried to implement this in my CKeditor but it didn't run. I don't understand what code I have to implement before and after the "droppable event" in ckeditorfield.js. I've tried to get the visualmarkdownfield.js of VisualMarkdownEditor and change the content according to ckeditor.

What should I put? Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants