<commit_before>/**
  * vue-scroll-behavior v0.2.0
  * (c) 2017 jeneser
  * @license MIT
  */

import { setOption, isIgnoreRoute, getScrollPosition, setScrollPosition,
  cleanHistoryList } from './utils/helpers'

const vueScrollBehavior = {
  _maxLength: 50,
  _ignore: [],
  _delay: 0
}

/**
 * Plugin API
 * vsbHistoryList [property]
 * vueScrollBehavior [function]
 */
vueScrollBehavior.install = function (Vue, options) {

  // Init options
  setOption(options)

  // Global property
  Vue.vsbHistoryList = []

  // Global method
  Vue.vueScrollBehavior = function (router) {

    if (typeof router === 'object' && typeof router.beforeEach === 'function') {
      // Router beforeEach
      router.beforeEach((to, from, next) => {

        // Ignore route
        if (isIgnoreRoute(from)) {

          next()

        } else {

          let _historyList = this.vsbHistoryList
          let position = getScrollPosition()
          let currentPathIndex = _historyList.findIndex(e => {
            return e.path === from.fullPath
          })

          // Cleaning historyList
          if (_historyList.length >= vueScrollBehavior._maxLength) {
            cleanHistoryList(_historyList)
          }

          if (currentPathIndex !== -1) {
            _historyList[currentPathIndex].position = position
          } else {
            _historyList.push({
              path: from.fullPath,
              position: position
            })
          }

          next()
        }

      })

      // Router afterEach
      router.afterEach(route => {

        if (isIgnoreRoute(route)) {
          setScrollPosition(Vue)
        } else {

          let savedPosition = this.vsbHistoryList.find(e => {
            return e.path === route.fullPath
          })

          if (typeof savedPosition !== 'undefined') {
            setScrollPosition(Vue, savedPosition.position)
          } else {
            setScrollPosition(Vue)
          }
        }

      })

    } else {
      console.warn('Vue-scroll-behavior dependent on vue-router! ' +
        'Please create the router instance.')
    }
  }

  Vue.vueScrollBehavior(options.router)
}

/**
 * Auto install
 */
if (typeof window !== 'undefined' && window.Vue) {
  window.Vue.use(vueScrollBehavior)
}

export default vueScrollBehavior<commit_msg>Remove auto install, fix maxLength of undefined error<commit_after>/**
  * vue-scroll-behavior v0.2.0
  * (c) 2017 jeneser
  * @license MIT
  */

import { setOption, isIgnoreRoute, getScrollPosition, setScrollPosition,
  cleanHistoryList } from './utils/helpers'

const vueScrollBehavior = {
  _maxLength: 50,
  _ignore: [],
  _delay: 0
}

/**
 * Plugin API
 * vsbHistoryList [property]
 * vueScrollBehavior [function]
 */
vueScrollBehavior.install = function (Vue, options) {

  // Init options
  setOption(options)

  // Global property
  Vue.vsbHistoryList = []

  // Global method
  Vue.vueScrollBehavior = function (router) {

    if (typeof router === 'object' && typeof router.beforeEach === 'function') {
      // Router beforeEach
      router.beforeEach((to, from, next) => {

        // Ignore route
        if (isIgnoreRoute(from)) {

          next()

        } else {

          let _historyList = this.vsbHistoryList
          let position = getScrollPosition()
          let currentPathIndex = _historyList.findIndex(e => {
            return e.path === from.fullPath
          })

          // Cleaning historyList
          if (_historyList.length >= vueScrollBehavior._maxLength) {
            cleanHistoryList(_historyList)
          }

          if (currentPathIndex !== -1) {
            _historyList[currentPathIndex].position = position
          } else {
            _historyList.push({
              path: from.fullPath,
              position: position
            })
          }

          next()
        }

      })

      // Router afterEach
      router.afterEach(route => {

        if (isIgnoreRoute(route)) {
          setScrollPosition(Vue)
        } else {

          let savedPosition = this.vsbHistoryList.find(e => {
            return e.path === route.fullPath
          })

          if (typeof savedPosition !== 'undefined') {
            setScrollPosition(Vue, savedPosition.position)
          } else {
            setScrollPosition(Vue)
          }
        }

      })

    } else {
      console.warn('Vue-scroll-behavior dependent on vue-router! ' +
        'Please create the router instance.')
    }
  }

  Vue.vueScrollBehavior(options.router)
}

export default vueScrollBehavior
{'fraction_non_alphanumeric': 0.1118711385701677, 'fraction_numerical': 0.0048543689320388345, 'mean_word_length': 1.9960343688037012, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, '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': '6244427', 'n_tokens_mistral': 1326, 'n_tokens_neox': 1269, 'n_words': 268}