a zip code crypto-currency system good for red ONLY

webapis-resize-observer.ts 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /**
  2. * @license
  3. * Copyright Google Inc. All Rights Reserved.
  4. *
  5. * Use of this source code is governed by an MIT-style license that can be
  6. * found in the LICENSE file at https://angular.io/license
  7. */
  8. Zone.__load_patch('ResizeObserver', (global: any, Zone: any, api: _ZonePrivate) => {
  9. const ResizeObserver = global['ResizeObserver'];
  10. if (!ResizeObserver) {
  11. return;
  12. }
  13. const resizeObserverSymbol = api.symbol('ResizeObserver');
  14. api.patchMethod(global, 'ResizeObserver', (delegate: Function) => (self: any, args: any[]) => {
  15. const callback = args.length > 0 ? args[0] : null;
  16. if (callback) {
  17. args[0] = function(entries: any, observer: any) {
  18. const zones: {[zoneName: string]: any} = {};
  19. const currZone = Zone.current;
  20. for (let entry of entries) {
  21. let zone = entry.target[resizeObserverSymbol];
  22. if (!zone) {
  23. zone = currZone;
  24. }
  25. let zoneEntriesInfo = zones[zone.name];
  26. if (!zoneEntriesInfo) {
  27. zones[zone.name] = zoneEntriesInfo = {entries: [], zone: zone};
  28. }
  29. zoneEntriesInfo.entries.push(entry);
  30. }
  31. Object.keys(zones).forEach(zoneName => {
  32. const zoneEntriesInfo = zones[zoneName];
  33. if (zoneEntriesInfo.zone !== Zone.current) {
  34. zoneEntriesInfo.zone.run(
  35. callback, this, [zoneEntriesInfo.entries, observer], 'ResizeObserver');
  36. } else {
  37. callback.call(this, zoneEntriesInfo.entries, observer);
  38. }
  39. });
  40. };
  41. }
  42. return args.length > 0 ? new ResizeObserver(args[0]) : new ResizeObserver();
  43. });
  44. api.patchMethod(ResizeObserver.prototype, 'observe', (delegate: Function) => (self: any, args: any[]) => {
  45. const target = args.length > 0 ? args[0] : null;
  46. if (!target) {
  47. return delegate.apply(self, args);
  48. }
  49. let targets = self[resizeObserverSymbol];
  50. if (!targets) {
  51. targets = self[resizeObserverSymbol] = [];
  52. }
  53. targets.push(target);
  54. target[resizeObserverSymbol] = Zone.current;
  55. return delegate.apply(self, args);
  56. });
  57. api.patchMethod(ResizeObserver.prototype, 'unobserve', (delegate: Function) => (self: any, args: any[]) => {
  58. const target = args.length > 0 ? args[0] : null;
  59. if (!target) {
  60. return delegate.apply(self, args);
  61. }
  62. let targets = self[resizeObserverSymbol];
  63. if (targets) {
  64. for (let i = 0; i < targets.length; i ++) {
  65. if (targets[i] === target) {
  66. targets.splice(i, 1);
  67. break;
  68. }
  69. }
  70. }
  71. target[resizeObserverSymbol] = undefined;
  72. return delegate.apply(self, args);
  73. });
  74. api.patchMethod(ResizeObserver.prototype, 'disconnect', (delegate: Function) => (self: any, args: any[]) => {
  75. const targets = self[resizeObserverSymbol];
  76. if (targets) {
  77. targets.forEach((target: any) => {target[resizeObserverSymbol] = undefined;});
  78. self[resizeObserverSymbol] = undefined;
  79. }
  80. return delegate.apply(self, args);
  81. });
  82. });