webapis-media-query.umd.js 3.0 KB

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