webapis-media-query.ts
1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {NestedEventListenerOrEventListenerObject, patchEventTargetMethods} from '../common/utils';
((_global: any) => {
// patch MediaQuery
patchMediaQuery(_global);
function patchMediaQuery(_global: any) {
if (!_global['MediaQueryList']) {
return;
}
patchEventTargetMethods(
_global['MediaQueryList'].prototype, 'addListener', 'removeListener', (self, args) => {
return {
useCapturing: false,
eventName: 'mediaQuery',
handler: args[0],
target: self || _global,
name: 'mediaQuery',
invokeAddFunc: function(
addFnSymbol: any, delegate: Task|NestedEventListenerOrEventListenerObject) {
if (delegate && (<Task>delegate).invoke) {
return this.target[addFnSymbol]((<Task>delegate).invoke);
} else {
return this.target[addFnSymbol](delegate);
}
},
invokeRemoveFunc: function(
removeFnSymbol: any, delegate: Task|NestedEventListenerOrEventListenerObject) {
if (delegate && (<Task>delegate).invoke) {
return this.target[removeFnSymbol]((<Task>delegate).invoke);
} else {
return this.target[removeFnSymbol](delegate);
}
}
};
});
}
})(typeof window === 'object' && window || typeof self === 'object' && self || global);