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

Disable fileDragging #876

Closed
cblavier opened this issue Nov 12, 2015 · 4 comments
Closed

Disable fileDragging #876

cblavier opened this issue Nov 12, 2015 · 4 comments

Comments

@cblavier
Copy link

I'm using mediumEditor with a custom drag'n drop behavior but it seems that MediumEditor is catching all dragover / drop events.

I tried to disable this behavior with imageDragging: false and fileDragging: false but it's not working.

At the moment, the only solution I found out was to comment out this line
extension = new MediumEditor.extensions.fileDragging(opts);

Thanks for your help

@gpbmike
Copy link

gpbmike commented Nov 16, 2015

The following appears to do what you want by returning the desired response (false) from the shouldUseFileDraggingExtension method (

function shouldUseFileDraggingExtension() {
// Since the file-dragging extension replaces the image-dragging extension,
// we need to check if the user passed an overrided image-dragging extension.
// If they have, to avoid breaking users, we won't use file-dragging extension.
return !this.options.extensions['imageDragging'];
}
)

    new MediumEditor(editorNode, {
      extensions: {
        'imageDragging': new YourCustomExtension(),
      },
    });

@anilmaurya
Copy link
Contributor

Are you using custom imageDragging extension ? If yes than @gpbmike solution will work for you.

You should also checkout following cases:

   4 Cases for imageDragging + fileDragging extensons:

     1. ImageDragging ON + No Custom Image Dragging Extension:
        * Use fileDragging extension (default options)
     2. ImageDragging OFF + No Custom Image Dragging Extension:
        * Use fileDragging extension w/ images turned off
     3. ImageDragging ON + Custom Image Dragging Extension:
        * Don't use fileDragging (could interfere with custom image dragging extension)
     4. ImageDragging OFF + Custom Image Dragging:
        * Don't use fileDragging (could interfere with custom image dragging extension)

source:

// 4 Cases for imageDragging + fileDragging extensons:
//
// 1. ImageDragging ON + No Custom Image Dragging Extension:
// * Use fileDragging extension (default options)
// 2. ImageDragging OFF + No Custom Image Dragging Extension:
// * Use fileDragging extension w/ images turned off
// 3. ImageDragging ON + Custom Image Dragging Extension:
// * Don't use fileDragging (could interfere with custom image dragging extension)
// 4. ImageDragging OFF + Custom Image Dragging:
// * Don't use fileDragging (could interfere with custom image dragging extension)

@nmielnik
Copy link
Member

Apologies for this being very confusing, but so is this concept of allowing custom file dragging extensions in a good way, while not breaking people who are depending on the deprecated image-dragging extension!

If I can remember correctly after re-reading the code, we still support a custom option for enabling/disabling drag & drop of images (the deprecated imageDragging option). The new file-dragging extension allows you to override the default behavior (only allowing images to be drag & dropped in) and allow anything, nothing, or specific file types to be drag & dropped into medium-editor.

So, if you wanted to do some custom drag & drop behavior, I would recommend doing what @gpbmike suggested, and passing your own custom extension to handle this. You can build off of the existing file-dragging extension by extending it before you pass it in, and overriding some of these parts which are what handling preventing drag & drop.

var YourFileDraggingExtension = MediumEditor.extensions.fileDragging.extend({
   // override the things you want to change
});

new MediumEditor(editorNode, {
    extensions: {
        'imageDragging': new YourCustomExtension(),
    }
});

@cblavier
Copy link
Author

Thanks for your help!
Fixed my problem by providing an empty imageDragging extension

new MediumEditor(editorNode, {
    extensions: {
        'imageDragging': {}
    }
});

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

No branches or pull requests

4 participants