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

preventing image paste on editor #132

Open
lovesh opened this issue Dec 31, 2014 · 4 comments
Open

preventing image paste on editor #132

lovesh opened this issue Dec 31, 2014 · 4 comments

Comments

@lovesh
Copy link

lovesh commented Dec 31, 2014

I want to disallow image pasting inside the editor(because i am using base64 of images in some other way). So here is my editor

var ed = new wysihtml5.Editor(....

Now i listened to all 3 events paste, paste:composer and paste:textarea. On these 3 events i check if
the item is a file using event.clipboardData.items[event.clipboardData.items.length-1].kind == 'file' and if true i tried all of these.

event.stopPropagation()
event.preventDefault();
return false;

Ideally return false should be enough for preventing the action and stopping the propagation but anyway. But still the image is pasted. What else do i need to do to prevent the image from being pasted?

@pulges
Copy link
Contributor

pulges commented Mar 16, 2015

You can define special rules for clearing pasted content before pasting it
https://github.com/Voog/wysihtml/blob/master/parser_rules/advanced_and_extended.js#L668

You will have to pass these special paste rules on editor init to make it work
https://github.com/Voog/wysihtml/blob/master/examples/advanced_div.html#L466

Rule without condition is executed as default
If you want even more special cases you can add rules with RegExp condition (if true the set is used instead)

In your case this should work

(function() {
    var commonRules = wysihtml5.lang.object(wysihtml5ParserRules).clone(true);
    commonRules.tags.img = false;

    window.wysihtml5ParserPasteRulesets = [{
        set: commonRules
    }];
})();

@mschering
Copy link

I can't get image pasting working at all. I'm using firefox on a mac. Is there something I can change to make it work?

@lovesh
Copy link
Author

lovesh commented Mar 31, 2015

@mschering Are you copying images from a word processor or some other desktop program. wysihtml does not work with copying images from word(or it did not used to work). I had to make some changes to make it accept copied images from word.

@mschering
Copy link

I found out that that the editor prevents the default paste event. I made a small change to make it work. I created a new issue for it here:
#163

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

3 participants