diff --git a/src/trix/elements/trix_editor_element.coffee b/src/trix/elements/trix_editor_element.coffee index 27375f71..aaed2dab 100644 --- a/src/trix/elements/trix_editor_element.coffee +++ b/src/trix/elements/trix_editor_element.coffee @@ -10,6 +10,11 @@ Trix.registerElement "trix-editor", do -> # Contenteditable support helpers + autofocus = (element) -> + unless document.querySelector(":focus") + if element.hasAttribute("autofocus") and document.querySelector("[autofocus]") is element + element.focus() + makeEditable = (element) -> return if element.hasAttribute("contenteditable") element.setAttribute("contenteditable", "") @@ -137,23 +142,13 @@ Trix.registerElement "trix-editor", do -> @editorController ?= new Trix.EditorController(editorElement: this, html: @defaultValue = @value) @editorController.registerSelectionManager() @registerResetListener() - @autofocus() + autofocus(this) requestAnimationFrame => @notify("initialize") detachedCallback: -> @editorController?.unregisterSelectionManager() @unregisterResetListener() - # Autofocus support - - autofocus: -> - unless document.querySelector(":focus") - if @hasAttribute("autofocus") and document.querySelector("[autofocus]") is this - focusTriggered = false - handleEventOnce("focus", onElement: this, withCallback: -> focusTriggered = true) - @focus() - triggerEvent("focus", onElement: this) unless focusTriggered - # Form reset support registerResetListener: ->