版博士V2.0程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

62 строки
1.8 KiB

  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. const DOMException_1 = __importDefault(require("../exception/DOMException"));
  7. const MutationListener_1 = __importDefault(require("./MutationListener"));
  8. /**
  9. * The MutationObserver interface provides the ability to watch for changes being made to the DOM tree.
  10. *
  11. * @see https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver
  12. */
  13. class MutationObserver {
  14. /**
  15. * Constructor.
  16. *
  17. * @param callback Callback.
  18. */
  19. constructor(callback) {
  20. this.target = null;
  21. this.listener = null;
  22. this.callback = callback;
  23. }
  24. /**
  25. * Starts observing.
  26. *
  27. * @param target Target.
  28. * @param options Options.
  29. */
  30. observe(target, options) {
  31. if (!target) {
  32. throw new DOMException_1.default('Failed to observer. The first parameter "target" should be of type "Node".');
  33. }
  34. options = Object.assign({}, options, {
  35. attributeFilter: options.attributeFilter
  36. ? options.attributeFilter.map((name) => name.toLowerCase())
  37. : null
  38. });
  39. this.target = target;
  40. this.listener = new MutationListener_1.default();
  41. this.listener.options = options;
  42. this.listener.callback = this.callback.bind(this);
  43. target._observe(this.listener);
  44. }
  45. /**
  46. * Disconnects.
  47. */
  48. disconnect() {
  49. if (this.target) {
  50. this.target._unobserve(this.listener);
  51. this.target = null;
  52. }
  53. }
  54. /**
  55. * Takes records.
  56. */
  57. takeRecords() {
  58. return [];
  59. }
  60. }
  61. exports.default = MutationObserver;
  62. //# sourceMappingURL=MutationObserver.js.map