diff --git a/packages/board/examples/features/parent.html b/packages/board/examples/features/parent.html index 8c858a5..3562972 100644 --- a/packages/board/examples/features/parent.html +++ b/packages/board/examples/features/parent.html @@ -4,8 +4,9 @@ diff --git a/packages/board/examples/features/top.html b/packages/board/examples/features/top.html new file mode 100644 index 0000000..e3d6767 --- /dev/null +++ b/packages/board/examples/features/top.html @@ -0,0 +1,22 @@ + +
+ + + + + + + + + + + \ No newline at end of file diff --git a/packages/board/src/lib/screen-watcher.ts b/packages/board/src/lib/screen-watcher.ts index a82788b..bcd0cde 100644 --- a/packages/board/src/lib/screen-watcher.ts +++ b/packages/board/src/lib/screen-watcher.ts @@ -1,9 +1,9 @@ import { TypePoint } from '@idraw/types'; -import util from '@idraw/util'; +// import util from '@idraw/util'; import { BoardEvent, TypeBoardEventArgMap } from './event'; import { TempData } from './watcher-temp'; -const { throttle } = util.time; +// const { throttle } = util.time; // const isInIframe = window.self === window.top; @@ -52,23 +52,41 @@ export class ScreenWatcher { canvas.addEventListener('mouseup', this._listenCanvasMoveEnd.bind(this), true); canvas.addEventListener('mouseover', this._listenCanvasMoveOver.bind(this), true); canvas.addEventListener('mouseleave', this._listenCanvasMoveLeave.bind(this), true); - - // If in iframe - if (window.self !== window.parent) { - // If in same origin - if (window.self.origin === window.parent.self.origin) { - window.parent.window.addEventListener( - 'mousemove', - throttle(this._listSameOriginParentWindow.bind(this), 16), - false); - } - } + this._initParentEvent(); + // container.addEventListener('touchstart', this._listenMoveStart.bind(this), true); // container.addEventListener('touchmove', this._listenMove.bind(this), true); // container.addEventListener('touchend', this._listenMoveEnd.bind(this), true); } + _initParentEvent() { + let target = window; + let targetOrigin = target.origin; + while (target.self !== target.top) { + // If in iframe + if (target.self !== target.parent) { + // If in same origin + if (target.origin === targetOrigin) { + // window.parent.window.addEventListener( + // 'mousemove', + // throttle(this._listSameOriginParentWindow.bind(this), 16), + // false); + window.parent.window.addEventListener( + 'mousemove', + this._listSameOriginParentWindow.bind(this), + false); + } + } + // @ts-ignore + target = target.parent; + if (!target) { + break; + } + } + + } + _listenHover(e: MouseEvent|TouchEvent): void { e.preventDefault(); const p = this._getPosition(e); diff --git a/packages/core/examples/features/parent.html b/packages/core/examples/features/parent.html index 9f37c17..108b253 100644 --- a/packages/core/examples/features/parent.html +++ b/packages/core/examples/features/parent.html @@ -4,8 +4,8 @@ diff --git a/packages/core/examples/features/top.html b/packages/core/examples/features/top.html new file mode 100644 index 0000000..3591a33 --- /dev/null +++ b/packages/core/examples/features/top.html @@ -0,0 +1,22 @@ + + + + + + + + + + + + + \ No newline at end of file