Fix and improve doc picker tab navigation

Rel #609.
pull/385/merge
Thibaut Courouble 8 years ago
parent 54c7c0df5c
commit a8073b3a12

@ -167,7 +167,8 @@ $.scrollTo = (el, parent, position = 'center', options = {}) ->
return unless parent return unless parent
parentHeight = parent.clientHeight parentHeight = parent.clientHeight
return unless parent.scrollHeight > parentHeight parentScrollHeight = parent.scrollHeight
return unless parentScrollHeight > parentHeight
top = $.offset(el, parent).top top = $.offset(el, parent).top
offsetTop = parent.firstElementChild.offsetTop offsetTop = parent.firstElementChild.offsetTop
@ -181,14 +182,17 @@ $.scrollTo = (el, parent, position = 'center', options = {}) ->
scrollTop = parent.scrollTop scrollTop = parent.scrollTop
height = el.offsetHeight height = el.offsetHeight
lastElementOffset = parent.lastElementChild.offsetTop + parent.lastElementChild.offsetHeight
offsetBottom = if lastElementOffset > 0 then parentScrollHeight - lastElementOffset else 0
# If the target element is above the visible portion of its scrollable # If the target element is above the visible portion of its scrollable
# ancestor, move it near the top with a gap = options.topGap * target's height. # ancestor, move it near the top with a gap = options.topGap * target's height.
if top - offsetTop <= scrollTop + height * (options.topGap or 1) if top - offsetTop <= scrollTop + height * (options.topGap or 1)
parent.scrollTop = top - offsetTop - height * (options.topGap or 1) parent.scrollTop = top - offsetTop - height * (options.topGap or 1)
# If the target element is below the visible portion of its scrollable # If the target element is below the visible portion of its scrollable
# ancestor, move it near the bottom with a gap = options.bottomGap * target's height. # ancestor, move it near the bottom with a gap = options.bottomGap * target's height.
else if top >= scrollTop + parentHeight - height * ((options.bottomGap or 1) + 1) else if top + offsetBottom >= scrollTop + parentHeight - height * ((options.bottomGap or 1) + 1)
parent.scrollTop = top - parentHeight + height * ((options.bottomGap or 1) + 1) parent.scrollTop = top + offsetBottom - parentHeight + height * ((options.bottomGap or 1) + 1)
return return
$.scrollToWithImageLock = (el, parent, args...) -> $.scrollToWithImageLock = (el, parent, args...) ->

@ -11,7 +11,6 @@ class app.views.Settings extends app.View
@events: @events:
submit: 'onSubmit' submit: 'onSubmit'
click: 'onClick' click: 'onClick'
focus: 'onFocus'
@shortcuts: @shortcuts:
enter: 'onEnter' enter: 'onEnter'
@ -69,10 +68,6 @@ class app.views.Settings extends app.View
app.router.show '/' app.router.show '/'
return return
onFocus: (event) =>
$.scrollTo event.target, @el, 'continuous', bottomGap: 2
return
onAppCacheProgress: (event) => onAppCacheProgress: (event) =>
if event.lengthComputable if event.lengthComputable
percentage = Math.round event.loaded * 100 / event.total percentage = Math.round event.loaded * 100 / event.total

@ -67,7 +67,7 @@ class app.views.DocPicker extends app.View
onDOMFocus: (event) => onDOMFocus: (event) =>
target = event.target target = event.target
if target.tagName is 'INPUT' if target.tagName is 'INPUT'
$.scrollTo target.parentNode, null, 'continuous', bottomGap: 2 $.scrollTo target.parentNode, null, 'continuous'
else if target.classList.contains(app.views.ListFold.targetClass) else if target.classList.contains(app.views.ListFold.targetClass)
target.blur() target.blur()
unless @mouseDown and @mouseDown > Date.now() - 100 unless @mouseDown and @mouseDown > Date.now() - 100

@ -12,13 +12,13 @@
&._in { display: block; } &._in { display: block; }
._sidebar { ._sidebar {
display: block !important;
&:after { // padding bottom &:after { // padding bottom
content: ''; content: '';
display: block; display: block;
height: $headerHeight; height: $headerHeight;
} }
._sidebar-hidden & { display: block; }
} }
._header { justify-content: space-between; } ._header { justify-content: space-between; }

@ -47,12 +47,11 @@
<button type="button" class="_settings-tab active" data-tab="doc-picker" hidden>Docs</button><button type="button" class="_settings-tab" data-tab="settings" hidden>Settings</button> <button type="button" class="_settings-tab active" data-tab="doc-picker" hidden>Docs</button><button type="button" class="_settings-tab" data-tab="settings" hidden>Settings</button>
</nav> </nav>
</div> </div>
<div class="_sidebar"> <div class="_sidebar" tabindex="-1"></div>
<div class="_sidebar-footer"> <div class="_sidebar-footer">
<button type="submit" class="_settings-btn"> <button type="submit" class="_settings-btn">
<svg viewBox="0 0 24 24"><path d="M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"></path></svg> Apply <svg viewBox="0 0 24 24"><path d="M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"></path></svg> Apply
</button> </button>
</div>
</div> </div>
</form> </form>
</div> </div>

Loading…
Cancel
Save