From 3232db440403ee8d1dce620901f2b9aac15a1656 Mon Sep 17 00:00:00 2001 From: Andrew Shaffer Date: Fri, 29 May 2015 17:33:16 -0700 Subject: [PATCH] use setTimeout rather than MutationObserver --- index.ts | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/index.ts b/index.ts index 0fb8f3e..d8f5e27 100644 --- a/index.ts +++ b/index.ts @@ -23,7 +23,7 @@ function domPaste(e: Event, callback: (data: HTMLElement) => void) { var backward: boolean = isBackward(selection); var range: Range = currentRange(selection); var activeElement = doc.activeElement; - + // create temporary content editable contaner var container: HTMLElement = doc.createElement('div'); container.contentEditable = 'true'; @@ -36,8 +36,7 @@ function domPaste(e: Event, callback: (data: HTMLElement) => void) { doc.body.appendChild(container); - // observer for dom mutations in container - var observer = new MutationObserver(function() { + setTimeout(function() { // remove br element, if it's still there (Firefox fix) if (br.parentNode) { br.parentNode.removeChild(br); @@ -49,10 +48,6 @@ function domPaste(e: Event, callback: (data: HTMLElement) => void) { setRange(selection, range, backward); } - // avoid having handler fire again if changes - // are made within the callback - observer.disconnect(); - try { callback(container); } finally { @@ -61,13 +56,6 @@ function domPaste(e: Event, callback: (data: HTMLElement) => void) { } }); - observer.observe(container, { - childList: true, - attributes: true, - characterData: true, - subtree: true - }); - // move focus and selection to temporary container container.focus(); var selector: Range = doc.createRange();