fishme / kirby_ckeditor

Visual Editor for Kirby2
GNU General Public License v2.0
10 stars 1 forks source link

Drag and drop image files (Feature) #4

Open m-artin opened 7 years ago

m-artin commented 7 years ago

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 commented 6 years ago

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 :)