[ 32 posts ] Go to page 1, 2, 3, 4 Next

DaveStein

  • Joined: Mon Feb 07, 2011 8:42 am
  • Posts: 48
  • Offline
  • Profile

Clean Paste Help

Post Posted: Tue Mar 22, 2011 11:56 am
+0-
We were able to do this in YUI2. I had a plug-in I downloaded that attached to different events. For IE, it would attach to onbeforepaste for instance. It then inserted a fake node and focused to make sure the text ended up in that fake node.

I'm actually trying to get it to work again but can only successfully do it on FF for all markup. In Safari and IE, when the markup gets crazy, it only strips the first few images and whatnot.

I basically now run a line like this:

Code:
TE.yeditor.execCommand( 'insertandfocus', str );


The pasted text then goes into that container. I get the reference to it and then do a lot of regex replacing. Some is pasted from YUI2's function, some from the plug-in, and some additional stuff I added in.

Dav, do you have any idea why it would work flawlessly in FF but then cut out halfway for "harder" markup in the other browsers? I tried with text from Facebook and CNN. It appears to really hate if an input field is pasted in.

Dav Glass

  • Username: davglass
  • Joined: Thu Aug 28, 2008 9:28 am
  • Posts: 2088
  • Location: Marion, IL, US
  • Twitter: davglass
  • GitHub: davglass
  • Gists: davglass
  • IRC: davglass
  • Offline
  • Profile

Re: Clean Paste Help

Post Posted: Tue Mar 22, 2011 11:59 am
+0-
Without seeing it run, I can't give you a definite answer. But I would guess you have a race condition going on. The content getting pasted hasn't finished yet when it's being processed.

DaveStein

  • Joined: Mon Feb 07, 2011 8:42 am
  • Posts: 48
  • Offline
  • Profile

Re: Clean Paste Help

Post Posted: Tue Mar 22, 2011 12:43 pm
+0-
Okay this is interesting. If I paste the "simple" text in, Cleaner's HTML console.logs perfectly. When I paste two tweets in, it console logs as blank and I can see the full HTML in the editor. You can clearly see I've had quirky issues in past with what is in cleaner so I'm going to play with that some. Let me know if this jogs your memory some. I'll keep you posted on any solution I find so other users can take advantage too :)

Code:
CleanPaste.prototype.InsertContainer = function( e ) {

  // quirk
  var str       = ( ( $.browser.msie && parseInt($.browser.version) >= 8.0 ) ) ? "<span id='Cleaner'> </span>" : '<div id="Cleaner">_</div>';
  TE.yeditor.execCommand( 'insertandfocus', str );
  console.log('inserted');
   
};


Code:
CleanPaste.prototype.CleanPaste = function() {
console.log('html test: ', this.doc.getElementById("Cleaner").innerHTML );
};


Code:
CleanPaste.prototype.handleKeyDown = function(e) {

  // in my code this is actual logic
    if ( copy_pasted ) {
       
        console.log( 'insert container');
        this.InsertContainer( e );
        setTimeout(function() { console.log('clean paste' ); _this.CleanPaste(); }, 10);
    }
};

DaveStein

  • Joined: Mon Feb 07, 2011 8:42 am
  • Posts: 48
  • Offline
  • Profile

Re: Clean Paste Help

Post Posted: Tue Mar 22, 2011 12:43 pm
+0-
Increasing timeout to 150 didn't help btw

DaveStein

  • Joined: Mon Feb 07, 2011 8:42 am
  • Posts: 48
  • Offline
  • Profile

Re: Clean Paste Help

Post Posted: Tue Mar 22, 2011 1:18 pm
+0-
Oh boy. It looks like Firefox fixes invalid HTML on paste. If I paste the same thing everytime into Chrome, I get a small amount of markup. If I then do this bad string for cleaner:

<div id="Cleaner"><div>_</div>

It actually console logs the whole block.

DaveStein

  • Joined: Mon Feb 07, 2011 8:42 am
  • Posts: 48
  • Offline
  • Profile

Re: Clean Paste Help

Post Posted: Tue Mar 22, 2011 1:50 pm
+0-
Looks like I have to give up. My last post seems to be wrong. It really dependso n the markup but I can't pinpoint it. With another copy-paste sample I had it so everytime I hit ctrl+a ctrl+v it would alternate removing the markup or not removing it, even though clearly ctrl+a selects everything to overwite.

I'm at an insane loss

Dav Glass

  • Username: davglass
  • Joined: Thu Aug 28, 2008 9:28 am
  • Posts: 2088
  • Location: Marion, IL, US
  • Twitter: davglass
  • GitHub: davglass
  • Gists: davglass
  • IRC: davglass
  • Offline
  • Profile

Re: Clean Paste Help

Post Posted: Tue Mar 22, 2011 1:58 pm
+0-
Working with Copy Paste is a nightmare. Just working with Ctrl+A/C is not enough. What about Macs? What about right clicking? What about Edit > Copy menu interactions?

There are tons of things there. The other issue, is that some OSes clipboards are limited or special. They tend to change the content on the fly depending on where it's being pasted. For example. Copy some rich markup, then paste that into a textarea. The markup will go away and you will get plain text. But pasting that into something like Word, you will get rich markup.

The clipboard is intentionally hard to work with due to the massive security implications that it exposes. For example, what if you went to your banking site and copied your current bank info to your clipboard. Then visited my site and i read your clipboard. I now have access to that data. So they limited it and added a DOMPaste event (which Editor tries to fix a little). You should be able to listen to the "dom:paste" event on the Editor instance to be notified when a paste occurred.

When, and if, I decide to write a clipboard module for Editor, it will likely be a toolbar button that loads another iframe into a modal dialog. They paste into that, then I clean and inject the content where the cursor was positioned. That's about the most reliable way to deal with it.

DaveStein

  • Joined: Mon Feb 07, 2011 8:42 am
  • Posts: 48
  • Offline
  • Profile

Re: Clean Paste Help

Post Posted: Tue Mar 22, 2011 2:06 pm
+0-
I know ctrl+a is not the only way. I'm just using that as the simplest example. I'm currently catching it in a number of ways, but I'm gonna try out the dom:paste event and see if that will work properly.

It's just super frustrating since my node is clearly inserted before paste, and at least some of the pasted content is getting in there. I've tried removing setTimeout and increasing it with no luck. Going to keep my fingers crossed on the dom event you mentioned.

DaveStein

  • Joined: Mon Feb 07, 2011 8:42 am
  • Posts: 48
  • Offline
  • Profile
Tags:

Re: Clean Paste Help

Post Posted: Tue Mar 22, 2011 2:15 pm
+0-
dom:paste works in FF but not Chrome still. I tried dom:beforepaste for kicks, not knowing if you did that or not, and I'm guessing you didn't. You are so correct about nightmares

DaveStein

  • Joined: Mon Feb 07, 2011 8:42 am
  • Posts: 48
  • Offline
  • Profile

Re: Clean Paste Help

Post Posted: Wed Mar 23, 2011 6:28 am
+0-
What exactly goes on during insertandfocus? Are there any setTimeouts in there?
  [ 32 posts ] Go to page 1, 2, 3, 4 Next
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum