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nC,WAAO,CAAC,WAAW,GAAG,OAAO,CAAC,KAAK,IAAI,EAAE,CAAC;GAC3C,CAAC;;AAEF,aAAW,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,GAAG,UAAS,KAAK,EAAE;AAC1D,QAAM,OAAO,GAAO,KAAK,CAAC,MAAM,CAAC;AACjC,QAAM,UAAU,GAAI,OAAO,CAAC,WAAW,CAAC;AACxC,QAAI,UAAU,KAAK,OAAO,CAAC,KAAK,EAAE;;AAChC,UAAM,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;AAC/D,YAAM,CAAC,SAAS,CAAC,QAAQ,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;AACzC,aAAO,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;KAC/B;GACF,CAAC;CACH,CAAC,CAAC","file":"focus.js","sourcesContent":["// Support for element focus.\n\n\nconst DOM = require('./index');\n\n\nconst FOCUS_ELEMENTS = ['INPUT', 'SELECT', 'TEXTAREA', 'BUTTON', 'ANCHOR'];\n\n\n// The element in focus.\n//\n// If no element has the focus, return the document.body.\nDOM.HTMLDocument.prototype.__defineGetter__('activeElement', function() {\n return this._inFocus || this.body;\n});\n\n// Change the current element in focus (or null for blur)\nfunction setFocus(document, element) {\n const inFocus = document._inFocus;\n if (element !== inFocus) {\n if (inFocus) {\n const onblur = document.createEvent('HTMLEvents');\n onblur.initEvent('blur', false, false);\n inFocus.dispatchEvent(onblur);\n }\n if (element) { // null to blur\n const onfocus = document.createEvent('HTMLEvents');\n onfocus.initEvent('focus', false, false);\n element.dispatchEvent(onfocus);\n document._inFocus = element;\n document.defaultView.browser.emit('focus', element);\n }\n }\n}\n\n// All HTML elements have a no-op focus/blur methods.\nDOM.HTMLElement.prototype.focus = function() {\n};\nDOM.HTMLElement.prototype.blur = function() {\n};\n\n// Input controls have active focus/blur elements. JSDOM implements these as\n// no-op, so we have to over-ride each prototype individually.\nconst CONTROLS = [DOM.HTMLInputElement, DOM.HTMLSelectElement, DOM.HTMLTextAreaElement, DOM.HTMLButtonElement, DOM.HTMLAnchorElement];\n\nCONTROLS.forEach(function(elementType) {\n elementType.prototype.focus = function() {\n setFocus(this.ownerDocument, this);\n };\n\n elementType.prototype.blur = function() {\n setFocus(this.ownerDocument, null);\n };\n\n // Capture the autofocus element and use it to change focus\n const setAttribute = elementType.prototype.setAttribute;\n elementType.prototype.setAttribute = function(name, value) {\n setAttribute.call(this, name, value);\n if (name === 'autofocus') {\n const document = this.ownerDocument;\n if (~FOCUS_ELEMENTS.indexOf(this.tagName) && !document._inFocus)\n this.focus();\n }\n };\n});\n\n\n// When changing focus onto form control, store the current value. When changing\n// focus to different control, if the value has changed, trigger a change event.\nconst INPUTS = [DOM.HTMLInputElement, DOM.HTMLTextAreaElement, DOM.HTMLSelectElement];\n\nINPUTS.forEach(function(elementType) {\n elementType.prototype._eventDefaults.focus = function(event) {\n const element = event.target;\n element._focusValue = element.value || '';\n };\n\n elementType.prototype._eventDefaults.blur = function(event) {\n const element = event.target;\n const focusValue = element._focusValue;\n if (focusValue !== element.value) { // null == undefined\n const change = element.ownerDocument.createEvent('HTMLEvents');\n change.initEvent('change', false, false);\n element.dispatchEvent(change);\n }\n };\n});\n\n"]}