Skip to content

Commit

Permalink
Only scroll to element if focused from preview
Browse files Browse the repository at this point in the history
With the former change of focusing the element on every click we get issues if the element body is longer than the viewport. We had this problem before, but as we now focus the element on each click this is getting more annoying.

Solved by only scrolling the element editor into view when focusing the element from within the preview frame.
  • Loading branch information
tvdeyen committed Jan 22, 2018
1 parent bc1054a commit a9d7309
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 a9d7309

Please sign in to comment.