From c2e82c4f086fdfdfd3ad1484380fd17cab287669 Mon Sep 17 00:00:00 2001 From: Javan Makhmali Date: Fri, 17 Jun 2016 12:28:49 -0400 Subject: [PATCH] Revert "Ensure "focus" event is triggered when autofocusing" This is not the right behavior and triggered "focus" when the browser naturally wouldn't (window not focused, element hidden). This reverts commit b4745a816d1f508e6055e439fa9fcd96ae476645. --- src/trix/elements/trix_editor_element.coffee | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) 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: ->