From 703f922ed803e20682678cebb19039039f47f0bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20=C3=96berg?= Date: Mon, 7 Dec 2015 17:39:08 +0100 Subject: [PATCH 1/3] Fixed drag release outside of iframe when the iframe is on the same domain. --- src/mousetracker.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/mousetracker.js b/src/mousetracker.js index 0a66cfee..425b22e7 100644 --- a/src/mousetracker.js +++ b/src/mousetracker.js @@ -1367,6 +1367,14 @@ eventParams = getCaptureEventParams( tracker, $.MouseTracker.havePointerEvents ? 'pointerevent' : pointerType ); // We emulate mouse capture by hanging listeners on the document object. // (Note we listen on the capture phase so the captured handlers will get called first) + if (isInIframe() && canAccessEvents(window.top)) { + $.addEvent( + window.top, + eventParams.upName, + eventParams.upHandler, + true + ); + } $.addEvent( $.MouseTracker.captureElement, eventParams.upName, @@ -1402,6 +1410,14 @@ eventParams = getCaptureEventParams( tracker, $.MouseTracker.havePointerEvents ? 'pointerevent' : pointerType ); // We emulate mouse capture by hanging listeners on the document object. // (Note we listen on the capture phase so the captured handlers will get called first) + if (isInIframe() && canAccessEvents(window.top)) { + $.removeEvent( + window.top, + eventParams.upName, + eventParams.upHandler, + true + ); + } $.removeEvent( $.MouseTracker.captureElement, eventParams.moveName, @@ -3248,5 +3264,33 @@ } ); } } + + /** + * @function + * @private + * @inner + * @returns {Boolean} True if inside an iframe, otherwise false. + */ + function isInIframe () { + try { + return window.self !== window.top; + } catch (e) { + return true; + } + } + + /** + * @function + * @private + * @inner + * @returns {Boolean} True if the target has access rights to events, otherwise false. + */ + function canAccessEvents (target) { + try { + return target.addEventListener && target.removeEventListener; + } catch (e) { + return false; + } + } } ( OpenSeadragon ) ); From 2ab6f18cee598383297597d14c9e21953fe0c1f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20=C3=96berg?= Date: Wed, 9 Dec 2015 11:04:37 +0100 Subject: [PATCH 2/3] Changed isInIframe to a variable for caching --- src/mousetracker.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/mousetracker.js b/src/mousetracker.js index 425b22e7..1b26fab8 100644 --- a/src/mousetracker.js +++ b/src/mousetracker.js @@ -1367,7 +1367,7 @@ eventParams = getCaptureEventParams( tracker, $.MouseTracker.havePointerEvents ? 'pointerevent' : pointerType ); // We emulate mouse capture by hanging listeners on the document object. // (Note we listen on the capture phase so the captured handlers will get called first) - if (isInIframe() && canAccessEvents(window.top)) { + if (isInIframe && canAccessEvents(window.top)) { $.addEvent( window.top, eventParams.upName, @@ -1410,7 +1410,7 @@ eventParams = getCaptureEventParams( tracker, $.MouseTracker.havePointerEvents ? 'pointerevent' : pointerType ); // We emulate mouse capture by hanging listeners on the document object. // (Note we listen on the capture phase so the captured handlers will get called first) - if (isInIframe() && canAccessEvents(window.top)) { + if (isInIframe && canAccessEvents(window.top)) { $.removeEvent( window.top, eventParams.upName, @@ -3266,19 +3266,19 @@ } /** - * @function + * True if inside an iframe, otherwise false. + * @member {Boolean} isInIframe * @private * @inner - * @returns {Boolean} True if inside an iframe, otherwise false. */ - function isInIframe () { + var isInIframe = (function() { try { return window.self !== window.top; } catch (e) { return true; } - } - + })(); + /** * @function * @private From 8f9d2a9bfe8cbed68a284f08127eb180944f960d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20=C3=96berg?= Date: Wed, 9 Dec 2015 18:28:41 +0100 Subject: [PATCH 3/3] Converted jsdoc to plain comments --- src/mousetracker.js | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/mousetracker.js b/src/mousetracker.js index 1b26fab8..a57993de 100644 --- a/src/mousetracker.js +++ b/src/mousetracker.js @@ -3265,12 +3265,10 @@ } } - /** - * True if inside an iframe, otherwise false. - * @member {Boolean} isInIframe - * @private - * @inner - */ + // True if inside an iframe, otherwise false. + // @member {Boolean} isInIframe + // @private + // @inner var isInIframe = (function() { try { return window.self !== window.top; @@ -3279,12 +3277,10 @@ } })(); - /** - * @function - * @private - * @inner - * @returns {Boolean} True if the target has access rights to events, otherwise false. - */ + // @function + // @private + // @inner + // @returns {Boolean} True if the target has access rights to events, otherwise false. function canAccessEvents (target) { try { return target.addEventListener && target.removeEventListener;