views:

50

answers:

1

So, I'm working on a WYSIWYG editor with an already setup Grammar, etc. I've been tasked to add copy and paste functionality for cross program. The code I have works in Google Chrome on Ubuntu, Firefox in Ubuntu and Windows, but not in Chrome on windows.

I've tracked down the problem to something basic. When the paste command is sent (through the Ctrl + V) event, I immediately change focus to a hidden, contenteditable, iframe, and trigger the event there. I then wait for it to bubble up and then handle parsing and pasting.

this.pasteOperation = function(event, controller) {
     this._cutpastearea.getEditable().focus().trigger(event);
     setTimeout(function() { controller.clipboardControl().handlePaste(); }, 1);
},

(Where getEditable gets the contenteditable section of the iframe)

Now, if I reveal the iframe, and disable the set timeout, I find that focus has been grabbed, but nothing has been pasted. If I proceed to manually paste it in, and then call the function, everything works.

So why does this not trigger the event?

Edit: Raised the issue at Chromium Issues as well. It seems to be an iframe only issue.

A: 

Found a work around. Instead of calling trigger, call this:

$.fn.forwardEvent = function(event) {
    this.each(function() {
        if (this.dispatchEvent) {
            if (event.originalEvent) {
                event = event.originalEvent
            }
            try {
                this.dispatchEvent(event);
            } catch(error) {
                $(this).trigger(event);
            }
        }
        else {
            $(this).trigger(event);
        }
    });
    return this;
};
Glen Nelson