Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

MooEditable.CleanPaste does not work in Safari.

#29

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

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

State: new
Milestone: none
Assigned to: nobody

Activity

  1. Jordan
    Jordan

    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
                */
                //console.log(e.clipboardData.types);
                
                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?
                    false;
                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;
            },
    

    June 17th, 2011 @ 06:44 AM

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.