<commit_before><template>
  <div>
    <div v-bind:class="{'vue-affix': affixed}"
      v-bind:style="styles">
      <slot></slot>
    </div>
  </div>
</template>

<script>
import coerceNumber from './utils/coerceNumber.js'
import $ from './utils/NodeList.js'

export default {
  props: {
    offset: {
      type: Number,
      coerce: coerceNumber,
      default: 0
    }
  },
  data () {
    return {
      affixed: false,
      styles: {}
    }
  },
  methods: {
    scrolling () {
      const scrollTop = this.getScroll(window, true)
      const elementOffset = this.getOffset(this.$el)
      if (!this.affixed && scrollTop > elementOffset.top) {
        this.affixed = true
        this.styles = {
          top: this.offset + 'px',
          left: elementOffset.left + 'px',
          width: this.$el.offsetWidth + 'px'
        }
      }
      if (this.affixed && scrollTop < elementOffset.top) {
        this.affixed = false
        this.styles = {}
      }
    },
    // from https://github.com/ant-design/ant-design/blob/master/components/affix/index.jsx#L20
    getScroll (w, top) {
      let ret = w['page' + (top ? 'Y' : 'X') + 'Offset']
      const method = 'scroll' + (top ? 'Top' : 'Left')
      if (typeof ret !== 'number') {
        const d = w.document
        // ie6,7,8 standard mode
        ret = d.documentElement[method]
        if (typeof ret !== 'number') {
          // quirks mode
          ret = d.body[method]
        }
      }
      return ret
    },
    getOffset (element) {
      const rect = element.getBoundingClientRect()
      const body = document.body
      const clientTop = element.clientTop || body.clientTop || 0
      const clientLeft = element.clientLeft || body.clientLeft || 0
      const scrollTop = this.getScroll(window, true)
      const scrollLeft = this.getScroll(window)
      return {
        top: rect.top + scrollTop - clientTop,
        left: rect.left + scrollLeft - clientLeft
      }
    }
  },
  ready () {
    $(window).on('scroll resize', () => this.scrolling())
  },
  beforeDestroy () {
    $(window).off('scroll resize', () => this.scrolling())
  }
}
</script>

<style>
  .vue-affix {
    position: fixed;
  }
</style><commit_msg>Affix now work more like the original bootstrap<commit_after><template>
  <div class="hidden-print hidden-xs hidden-sm">
    <nav class="bs-docs-sidebar" :class="{affix:affixed}" :style="{marginTop:top}">
      <slot></slot>
    </nav>
  </div>
</template>

<script>
import coerceNumber from './utils/coerceNumber.js'
import $ from './utils/NodeList.js'

export default {
  props: {
    offset: {
      type: Number,
      coerce: coerceNumber,
      default: 0
    }
  },
  data () {
    return {
      affixed:false
    }
  },
  computed: {
    top () {
      return this.offset > 0 ? this.offset + 'px' : null
    }
  },
  methods: {
    // from https://github.com/ant-design/ant-design/blob/master/components/affix/index.jsx#L20
    checkScroll () {
      // if is hidden don't calculate anything
      if (!(this.$el.offsetWidth || this.$el.offsetHeight || this.$el.getClientRects().length)) { return }
      // get window scroll and element position to detect if have to be normal or affixed
      let scroll = {}
      let element = {}
      const rect = this.$el.getBoundingClientRect()
      const body = document.body
      for(let type of ['Top','Left']) {
        let t = type.toLowerCase()
        let ret = window['page' + (type==='Top' ? 'Y' : 'X') + 'Offset']
        const method = 'scroll' + type
        if (typeof ret !== 'number') {
          // ie6,7,8 standard mode
          ret = document.documentElement[method]
          if (typeof ret !== 'number') {
            // quirks mode
            ret = document.body[method]
          }
        }
        scroll[t] = ret
        element[t] = scroll[t] + rect[t] - (this.$el['client'+type] || body['client'+type] || 0)
      }
      let fix = scroll.top > element.top - this.offset
      if (this.affixed !== fix) { this.affixed = fix }
    }
  },
  ready () {
    this.checkScroll()
    $(window).on('scroll resize', () => this.checkScroll())
  },
  beforeDestroy () {
    $(window).off('scroll resize', () => this.checkScroll())
  }
}
</script>
{'fraction_non_alphanumeric': 0.1587942084025635, 'fraction_numerical': 0.0037977688108236413, 'mean_word_length': 2.185185185185185, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 32, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5235290', 'n_tokens_mistral': 1361, 'n_tokens_neox': 1337, 'n_words': 304}