1class ClassNameWatcher { 2 3 constructor(targetNode, classToWatch, classAddedCallback, classRemovedCallback) { 4 this.targetNode = targetNode 5 this.classToWatch = classToWatch 6 this.classAddedCallback = classAddedCallback 7 this.classRemovedCallback = classRemovedCallback 8 this.observer = null 9 this.lastClassState = targetNode.classList.contains(this.classToWatch) 10 11 this.init() 12 } 13 14 init() { 15 this.observer = new MutationObserver(this.mutationCallback) 16 this.observe() 17 } 18 19 observe() { 20 this.observer.observe(this.targetNode, { attributes: true }) 21 } 22 23 disconnect() { 24 this.observer.disconnect() 25 } 26 27 mutationCallback = mutationsList => { 28 for(let mutation of mutationsList) { 29 if (mutation.type === 'attributes' && mutation.attributeName === 'class') { 30 let currentClassState = mutation.target.classList.contains(this.classToWatch) 31 if(this.lastClassState !== currentClassState) { 32 this.lastClassState = currentClassState 33 if(currentClassState) { 34 this.classAddedCallback() 35 } 36 else { 37 this.classRemovedCallback() 38 } 39 } 40 } 41 } 42 } 43}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.