[6a3a178] | 1 | 'use strict';
|
---|
| 2 | /**
|
---|
| 3 | * @license Angular v12.0.0-next.0
|
---|
| 4 | * (c) 2010-2020 Google LLC. https://angular.io/
|
---|
| 5 | * License: MIT
|
---|
| 6 | */
|
---|
| 7 | /**
|
---|
| 8 | * @license
|
---|
| 9 | * Copyright Google LLC All Rights Reserved.
|
---|
| 10 | *
|
---|
| 11 | * Use of this source code is governed by an MIT-style license that can be
|
---|
| 12 | * found in the LICENSE file at https://angular.io/license
|
---|
| 13 | */
|
---|
| 14 | Zone.__load_patch('mediaQuery', (global, Zone, api) => {
|
---|
| 15 | function patchAddListener(proto) {
|
---|
| 16 | api.patchMethod(proto, 'addListener', (delegate) => (self, args) => {
|
---|
| 17 | const callback = args.length > 0 ? args[0] : null;
|
---|
| 18 | if (typeof callback === 'function') {
|
---|
| 19 | const wrapperedCallback = Zone.current.wrap(callback, 'MediaQuery');
|
---|
| 20 | callback[api.symbol('mediaQueryCallback')] = wrapperedCallback;
|
---|
| 21 | return delegate.call(self, wrapperedCallback);
|
---|
| 22 | }
|
---|
| 23 | else {
|
---|
| 24 | return delegate.apply(self, args);
|
---|
| 25 | }
|
---|
| 26 | });
|
---|
| 27 | }
|
---|
| 28 | function patchRemoveListener(proto) {
|
---|
| 29 | api.patchMethod(proto, 'removeListener', (delegate) => (self, args) => {
|
---|
| 30 | const callback = args.length > 0 ? args[0] : null;
|
---|
| 31 | if (typeof callback === 'function') {
|
---|
| 32 | const wrapperedCallback = callback[api.symbol('mediaQueryCallback')];
|
---|
| 33 | if (wrapperedCallback) {
|
---|
| 34 | return delegate.call(self, wrapperedCallback);
|
---|
| 35 | }
|
---|
| 36 | else {
|
---|
| 37 | return delegate.apply(self, args);
|
---|
| 38 | }
|
---|
| 39 | }
|
---|
| 40 | else {
|
---|
| 41 | return delegate.apply(self, args);
|
---|
| 42 | }
|
---|
| 43 | });
|
---|
| 44 | }
|
---|
| 45 | if (global['MediaQueryList']) {
|
---|
| 46 | const proto = global['MediaQueryList'].prototype;
|
---|
| 47 | patchAddListener(proto);
|
---|
| 48 | patchRemoveListener(proto);
|
---|
| 49 | }
|
---|
| 50 | else if (global['matchMedia']) {
|
---|
| 51 | api.patchMethod(global, 'matchMedia', (delegate) => (self, args) => {
|
---|
| 52 | const mql = delegate.apply(self, args);
|
---|
| 53 | if (mql) {
|
---|
| 54 | // try to patch MediaQueryList.prototype
|
---|
| 55 | const proto = Object.getPrototypeOf(mql);
|
---|
| 56 | if (proto && proto['addListener']) {
|
---|
| 57 | // try to patch proto, don't need to worry about patch
|
---|
| 58 | // multiple times, because, api.patchEventTarget will check it
|
---|
| 59 | patchAddListener(proto);
|
---|
| 60 | patchRemoveListener(proto);
|
---|
| 61 | patchAddListener(mql);
|
---|
| 62 | patchRemoveListener(mql);
|
---|
| 63 | }
|
---|
| 64 | else if (mql['addListener']) {
|
---|
| 65 | // proto not exists, or proto has no addListener method
|
---|
| 66 | // try to patch mql instance
|
---|
| 67 | patchAddListener(mql);
|
---|
| 68 | patchRemoveListener(mql);
|
---|
| 69 | }
|
---|
| 70 | }
|
---|
| 71 | return mql;
|
---|
| 72 | });
|
---|
| 73 | }
|
---|
| 74 | });
|
---|