Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only scroll to element if focused from preview #1351

Merged
merged 1 commit into from
Jan 22, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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