Skip to content

Commit

Permalink
Merge pull request #1351 from tvdeyen/fix/element-focus
Browse files Browse the repository at this point in the history
Only scroll to element if focused from preview
  • Loading branch information
tvdeyen authored Jan 22, 2018
2 parents bc1054a + a9d7309 commit 1a36b6a
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions app/assets/javascripts/alchemy/alchemy.element_editors.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ Alchemy.ElementEditors =
# If we have folded parents we need to unfold each of them
# and then finally scroll to or unfold ourself
$folded_parents = $element.parents('.element-editor.folded')
@selectElement($element)
if $folded_parents.length > 0
@unfoldParents $folded_parents, =>
@scrollToOrUnfold(element_id)
Expand All @@ -82,10 +81,10 @@ Alchemy.ElementEditors =

# Marks an element as selected in the element window and scrolls to it.
#
selectElement: ($element) ->
selectElement: ($element, scroll = false) ->
$("#element_area .element-editor").not($element[0]).removeClass("selected")
$element.addClass("selected")
@scrollToElement($element)
@scrollToElement($element) if scroll
return

# Unfolds given parents until the last one is reached, then calls callback
Expand All @@ -108,17 +107,18 @@ Alchemy.ElementEditors =
#
scrollToOrUnfold: (element_id, callback) ->
$el = $("#element_#{element_id}")
@selectElement($el)
if $el.hasClass("folded")
@toggleFold(element_id, callback)
else
@selectElement($el, true)
return

# Scrolls the element window to given element editor dom element.
#
scrollToElement: (el) ->
$("#element_area").scrollTo el,
duration: 400
offset: -10
offset: -6

# Expands or folds a element editor
#
Expand Down Expand Up @@ -205,6 +205,7 @@ Alchemy.ElementEditors =
id = $(e.currentTarget).data('element-toggle')
@toggle(id)
e.preventDefault()
e.stopPropagation()
return

# Handles the custom 'FocusElementEditor.Alchemy' event.
Expand Down

0 comments on commit 1a36b6a

Please sign in to comment.