<commit_before>###
Determines if the view is in visible in the browser window.

Example usage:
	Just require the mixin from your component.
	Use the optional offset props like:

	large-copy(
		:in-viewport-offset-top="300"
		:in-viewport-offset-bottom="0.5"

		# Only add the `in-viewport` class once per page load
		:in-viewport-once="false"
	)

###

# Deps
win = require 'window-event-mediator'
visibility = require './visibility'

# Mixin definiton
module.exports =

	# Settings
	props:

		# Add listeners and check if in viewport immediately
		inViewportActive:
			type: 'Boolean'
			default: true

		# Whether to only update in-viewport class once
		inViewportOnce:
			type: 'Boolean'
			default: true

		# Whether to only update in-viewport class once
		inViewportClass:
			type: 'string'
			default: 'in-viewport'

		# A positive offset triggers "late" when scrolling down
		inViewportOffsetTop:
			type: Number
			default: 0

		# A negative offset triggers "early" when scrolling down
		inViewportOffsetBottom:
			type: Number
			default: 0

	# Boolean stores whether component is in viewport
	data: -> inViewport: false

	# Add handlers when vm is added to dom unless init is false
	ready: -> @addInViewportHandlers() if @inViewportActive

	# If comonent is destroyed, clean up listeners
	destroyed: -> @removeInViewportHandlers()

	# Vars to watch
	watch:

		# Adds handlers if they weren't added at runtime
		inViewportActive: (ready) ->
			@addInViewportHandlers() if ready

		# Adds the `in-viewport` class when the component is in bounds/
		inViewport: (visible) ->
			@removeInViewportHandlers() if @inViewportOnce and visible
			$(@$el).toggleClass(@inViewportClass, visible) if @inViewportClass

	# Public API
	methods:

		# Update viewport status on scroll
		onInViewportScroll: ->
			@inViewport =   @isInViewport @$el,
				offsetTop:    @inViewportOffsetTop
				offsetBottom: @inViewportOffsetBottom

		# Add listeners
		addInViewportHandlers: ->
			return if @handlersAdded
			@handlersAdded = true
			win.on 'scroll', @onInViewportScroll
			win.on 'resize', @onInViewportScroll
			@onInViewportScroll()

		# Remove listeners
		removeInViewportHandlers: ->
			return unless @handlersAdded
			@handlersAdded = false
			win.off 'scroll', @onInViewportScroll
			win.off 'resize', @onInViewportScroll

		# Public API for invoking visibility test
		isInViewport: (el, options) -> visibility.isInViewport(el, options)<commit_msg>Namespacing instance var<commit_after>###
Determines if the view is in visible in the browser window.

Example usage:
	Just require the mixin from your component.
	Use the optional offset props like:

	large-copy(
		:in-viewport-offset-top="300"
		:in-viewport-offset-bottom="0.5"

		# Only add the `in-viewport` class once per page load
		:in-viewport-once="false"
	)

###

# Deps
win = require 'window-event-mediator'
visibility = require './visibility'

# Mixin definiton
module.exports =

	# Settings
	props:

		# Add listeners and check if in viewport immediately
		inViewportActive:
			type: 'Boolean'
			default: true

		# Whether to only update in-viewport class once
		inViewportOnce:
			type: 'Boolean'
			default: true

		# Whether to only update in-viewport class once
		inViewportClass:
			type: 'string'
			default: 'in-viewport'

		# A positive offset triggers "late" when scrolling down
		inViewportOffsetTop:
			type: Number
			default: 0

		# A negative offset triggers "early" when scrolling down
		inViewportOffsetBottom:
			type: Number
			default: 0

	# Boolean stores whether component is in viewport
	data: -> inViewport: false

	# Add handlers when vm is added to dom unless init is false
	ready: -> @addInViewportHandlers() if @inViewportActive

	# If comonent is destroyed, clean up listeners
	destroyed: -> @removeInViewportHandlers()

	# Vars to watch
	watch:

		# Adds handlers if they weren't added at runtime
		inViewportActive: (ready) ->
			@addInViewportHandlers() if ready

		# Adds the `in-viewport` class when the component is in bounds/
		inViewport: (visible) ->
			@removeInViewportHandlers() if @inViewportOnce and visible
			$(@$el).toggleClass(@inViewportClass, visible) if @inViewportClass

	# Public API
	methods:

		# Update viewport status on scroll
		onInViewportScroll: ->
			@inViewport =   @isInViewport @$el,
				offsetTop:    @inViewportOffsetTop
				offsetBottom: @inViewportOffsetBottom

		# Add listeners
		addInViewportHandlers: ->
			return if @inViewportHandlersAdded
			@inViewportHandlersAdded = true
			win.on 'scroll', @onInViewportScroll
			win.on 'resize', @onInViewportScroll
			@onInViewportScroll()

		# Remove listeners
		removeInViewportHandlers: ->
			return unless @inViewportHandlersAdded
			@inViewportHandlersAdded = false
			win.off 'scroll', @onInViewportScroll
			win.off 'resize', @onInViewportScroll

		# Public API for invoking visibility test
		isInViewport: (el, options) -> visibility.isInViewport(el, options)
{'fraction_non_alphanumeric': 0.0866572180603361, 'fraction_numerical': 0.0028345818991698723, 'mean_word_length': 4.0152284263959395, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '2583245', 'n_tokens_mistral': 1747, 'n_tokens_neox': 1517, 'n_words': 489}