<commit_before>###*
#
# ElementScrollVisibility component.
#
# This component will watch it's state within the viewport
# and react with the following classes:
#
# - is-partially-visible
# - is-fully-visible
# - has-exited
#
# Example usage:
#
# <div class="js-component-scroll-monitor" data-offset="500"></div>
#
# @author 14islands
#
###

class FOURTEEN.ElementScrollVisibility

    CSS_PARTIALLY_VISIBLE_CLASS = 'is-partially-visible'
    CSS_FULLY_VISIBLE_CLASS = 'is-fully-visible'
    CSS_ANIMATE_CLASS = 'animate'
    CSS_ANIMATED_CLASS = 'has-animated'
    CSS_EXIT_CLASS = 'has-exited'
    DATA_OFFSET = 'offset'
    DATA_REPEAT = 'scroll-repeat'

    constructor: (@$context, data) ->
        @context = @$context.get(0)
        @repeat = @$context.data DATA_REPEAT or 0
        @$body = $(document.body)

        @repeat = JSON.parse @repeat

        if data?.isPjax
            @$body.one FOURTEEN.PjaxNavigation.EVENT_ANIMATION_SHOWN, @addEventListeners
        else
            @addEventListeners()

    destroy: () =>
        @removeEventListeners()

    addEventListeners: () =>
        offset = @$context.data('offset') or -100
        if scrollMonitor?
            @watcher = scrollMonitor.create @$context, offset
            @watcher.enterViewport @onEnterViewport
            @watcher.fullyEnterViewport @onFullyEnterViewport
            @watcher.exitViewport @onExitViewport
            @watcher.recalculateLocation()

    removeEventListeners: () =>
        if @watcher
            @watcher.destroy()
            @watcher = null
<commit_msg>element-scroll-visibility: nasty bug, check if defined first<commit_after>###*
#
# ElementScrollVisibility component.
#
# This component will watch it's state within the viewport
# and react with the following classes:
#
# - is-partially-visible
# - is-fully-visible
# - has-exited
#
# Example usage:
#
# <div class="js-component-scroll-monitor" data-offset="500"></div>
#
# @author 14islands
#
###

class FOURTEEN.ElementScrollVisibility

    CSS_PARTIALLY_VISIBLE_CLASS = 'is-partially-visible'
    CSS_FULLY_VISIBLE_CLASS = 'is-fully-visible'
    CSS_ANIMATE_CLASS = 'animate'
    CSS_ANIMATED_CLASS = 'has-animated'
    CSS_EXIT_CLASS = 'has-exited'
    DATA_OFFSET = 'offset'
    DATA_REPEAT = 'scroll-repeat'

    constructor: (@$context, data) ->
        @context = @$context.get(0)
        @repeat = @$context.data DATA_REPEAT or 0
        @$body = $(document.body)

        if @repeat?
            @repeat = JSON.parse(@repeat)

        if data?.isPjax
            @$body.one FOURTEEN.PjaxNavigation.EVENT_ANIMATION_SHOWN, @addEventListeners
        else
            @addEventListeners()

    destroy: () =>
        @removeEventListeners()

    addEventListeners: () =>
        offset = @$context.data('offset') or -100
        if scrollMonitor?
            @watcher = scrollMonitor.create @$context, offset
            @watcher.enterViewport @onEnterViewport
            @watcher.fullyEnterViewport @onFullyEnterViewport
            @watcher.exitViewport @onExitViewport
            @watcher.recalculateLocation()

    removeEventListeners: () =>
        if @watcher
            @watcher.destroy()
            @watcher = null

{'fraction_non_alphanumeric': 0.115, 'fraction_numerical': 0.00625, 'mean_word_length': 2.7836879432624113, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, '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': '5895345', 'n_tokens_mistral': 1023, 'n_tokens_neox': 997, 'n_words': 191}