#29 new

MooEditable.CleanPaste does not work in Safari.

Reported by Jonathan | February 18th, 2011 @ 07:20 AM

Using the new CleanPaste class does not work in Safari.

The browser show an error in the console (I have narrowed it down to this.selection.getRange() returning null) and no pasted text is shown. Additionally, the editable area loses focus.

Using Safari 5.0.3 on a Macbook Pro running Snow Leopard (10.6.6) (verified on different machines and MooEditable configurations as well).

Comments and changes to this ticket

  • Jordan

    Jordan June 17th, 2011 @ 06:44 AM

    Hi Jonathan

    Not sure if you found a solution by now, but I was having the same problem with the CleanPaste class. It worked ok in Firefox and Chrome, and interestingly it was ok copying from Firefox to Safari – that seemed to work.

    So after a bit of digging around in the Webkit documentation, I found how to examine the different types of data that were stored in the clipboard. It seems that text/html is only available in Firefox and Chrome, which explains why it works in those, and whilst there is a whole myriad of data types available to the paste event in Safari, the only one I had much success with was text/plain. It isn't idea, but it does work.

    This is my updated function for cleanPaste. (note I also renamed txtPastet to txtPasted as it looked like a typo and was driving me mad!).

    I hope someone finds this useful. I got it working in Safari 5 (plain text pasting), Chrome 12 and Firefox 4. I haven't tested in IE but I didn't make any changes to that part of the code so I am hoping it will still work when I come to test it there.

    cleanPaste: function(e){
                /*  You can use this command to investigate the available content types on the clipboard (but only in Webkit browsers)
                    However, it can be used to investigate content copied from Firefox, or other applications, so you can see what 
                    format their data is copied in
                var txtPasted = e.clipboardData && e.clipboardData.getData('text/html') ?
                        e.clipboardData.getData('text/html') : // HTML (for Chrome)
                    e.clipboardData && e.clipboardData.getData('text/plain') ? 
                        e.clipboardData.getData('text/plain') : // Plain text (for Safari)
                    window.clipboardData && window.clipboardData.getData ?
                        window.clipboardData.getData('Text') : // For Internet Explorer?
                if(!!txtPasted) { // IE and Safari
                    if(window.clipboardData) this.selection.insertContent(this.cleanHtml(txtPasted, 1)); // IE
                    else this.selection.insertContent(this.cleanHtml(txtPasted)); // Safari
                    new Event(e).stop();
                else { // Firefox and other browsers with no access to the clipboard
                    console.log('no clipboard data');
                    this.selection.insertContent('<span id="INSERTION_MARKER">&nbsp;</span>');
                    this.txtMarked = this.doc.body.get('html');
                    this.doc.body.set('html', '');
                    this.replaceMarkerWithPastedText.delay(5, this);
                return this;

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

A simple web-based WYSIWYG editor, written in Mootools.

People watching this ticket