From ffea1676fdb8fae89a3517ce6e9e27d5d2e68366 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Tue, 26 Mar 2013 02:58:53 +0100 Subject: [PATCH] Fix unsafeWindow for the newer versions of Chrome. #968 --- lib/$.coffee | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/$.coffee b/lib/$.coffee index f238701f6..1da20735b 100644 --- a/lib/$.coffee +++ b/lib/$.coffee @@ -193,9 +193,15 @@ $.extend $, unsafeWindow else # Chrome do -> - p = d.createElement 'p' - p.setAttribute 'onclick', 'return window' - p.onclick() + uw = null + captureUW = (e) -> uw = e.detail + window.addEventListener 'unsafe', captureUW, false + s = d.createElement 'script' + s.textContent = 'window.dispatchEvent(new CustomEvent("unsafe", {detail: window}))' + (d.head or doc).appendChild s + s.parentNode.removeChild s + window.removeEventListener 'unsafe', captureUW, false + uw bytesToString: (size) -> unit = 0 # Bytes while size >= 1024