Blame view

lib/jsdom/living/nodes/HTMLDetailsElement-impl.js 923 Bytes
858f2bdf5   Boyan Georgiev   fixes
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
  "use strict";
  
  const { fireAnEvent } = require("../helpers/events");
  
  const HTMLElementImpl = require("./HTMLElement-impl").implementation;
  
  class HTMLDetailsElementImpl extends HTMLElementImpl {
    constructor(globalObject, args, privateData) {
      super(globalObject, args, privateData);
  
      this._taskQueue = null;
    }
  
    _dispatchToggleEvent() {
      this._taskQueue = null;
  
      fireAnEvent("toggle", this);
    }
  
    _attrModified(name, value, oldValue) {
      super._attrModified(name, value, oldValue);
  
      if (name === "open" && this._taskQueue === null) {
        // Check that the attribute is added or removed, not merely changed
        if ((value !== oldValue && value !== null && oldValue === null) ||
            (value === null && oldValue !== null)) {
          this._taskQueue = setTimeout(this._dispatchToggleEvent.bind(this), 0);
        }
      }
    }
  }
  
  module.exports = {
    implementation: HTMLDetailsElementImpl
  };