* @private
()
| 995 | * @private |
| 996 | */ |
| 997 | bindResponsiveEvents() { |
| 998 | if (!this._responsiveListeners) { |
| 999 | this._responsiveListeners = {}; |
| 1000 | } |
| 1001 | const listeners = this._responsiveListeners; |
| 1002 | const platform = this.platform; |
| 1003 | |
| 1004 | const _add = (type, listener) => { |
| 1005 | platform.addEventListener(this, type, listener); |
| 1006 | listeners[type] = listener; |
| 1007 | }; |
| 1008 | const _remove = (type, listener) => { |
| 1009 | if (listeners[type]) { |
| 1010 | platform.removeEventListener(this, type, listener); |
| 1011 | delete listeners[type]; |
| 1012 | } |
| 1013 | }; |
| 1014 | |
| 1015 | const listener = (width, height) => { |
| 1016 | if (this.canvas) { |
| 1017 | this.resize(width, height); |
| 1018 | } |
| 1019 | }; |
| 1020 | |
| 1021 | let detached; // eslint-disable-line prefer-const |
| 1022 | const attached = () => { |
| 1023 | _remove('attach', attached); |
| 1024 | |
| 1025 | this.attached = true; |
| 1026 | this.resize(); |
| 1027 | |
| 1028 | _add('resize', listener); |
| 1029 | _add('detach', detached); |
| 1030 | }; |
| 1031 | |
| 1032 | detached = () => { |
| 1033 | this.attached = false; |
| 1034 | |
| 1035 | _remove('resize', listener); |
| 1036 | |
| 1037 | // Stop animating and remove metasets, so when re-attached, the animations start from beginning. |
| 1038 | this._stop(); |
| 1039 | this._resize(0, 0); |
| 1040 | |
| 1041 | _add('attach', attached); |
| 1042 | }; |
| 1043 | |
| 1044 | if (platform.isAttached(this.canvas)) { |
| 1045 | attached(); |
| 1046 | } else { |
| 1047 | detached(); |
| 1048 | } |
| 1049 | } |
| 1050 | |
| 1051 | /** |
| 1052 | * @private |
no test coverage detected