webapis-media-query.umd.js 3.3 KB

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