Sha256: a250bd9b7c1b920c6abd0150d76c54983a368d32abe362f763aac399ada4e85e

Contents?: true

Size: 1.15 KB

Versions: 7

Compression:

Stored size: 1.15 KB

Contents

e = up.element

# Gives `<body>` a right padding in the width of a scrollbar.
# Also gives elements anchored to the right side of the screen
# an increased `right`.
#
# This is to prevent the body and elements from jumping when we add the
# modal overlay, which has its own scroll bar.
# This is screwed up, but Bootstrap does the same.
class up.BodyShifter

  constructor: ->
    @unshiftFns = []

  shift: ->
    return unless up.viewport.rootHasVerticalScrollbar()

    body = document.body
    overflowElement = up.viewport.rootOverflowElement()

    scrollbarWidth = up.viewport.scrollbarWidth()

    bodyRightPadding = e.styleNumber(body, 'paddingRight')
    bodyRightShift = scrollbarWidth + bodyRightPadding

    @unshiftFns.push e.setTemporaryStyle(body, paddingRight: bodyRightShift)
    @unshiftFns.push e.setTemporaryStyle(overflowElement, overflowY: 'hidden')

    for anchor in up.viewport.anchoredRight()
      elementRight = e.styleNumber(anchor, 'right')
      elementRightShift = scrollbarWidth + elementRight
      @unshiftFns.push e.setTemporaryStyle(anchor, right: elementRightShift)

  unshift: ->
    while unshiftFn = @unshiftFns.pop()
      unshiftFn()

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
unpoly-rails-0.62.0 lib/assets/javascripts/unpoly/classes/body_shifter.coffee
unpoly-rails-0.61.1 lib/assets/javascripts/unpoly/classes/body_shifter.coffee
unpoly-rails-0.61.0 lib/assets/javascripts/unpoly/classes/body_shifter.coffee
unpoly-rails-0.60.3 lib/assets/javascripts/unpoly/classes/body_shifter.coffee
unpoly-rails-0.60.2 lib/assets/javascripts/unpoly/classes/body_shifter.coffee
unpoly-rails-0.60.1 lib/assets/javascripts/unpoly/classes/body_shifter.coffee
unpoly-rails-0.60.0 lib/assets/javascripts/unpoly/classes/body_shifter.coffee