<commit_before>_ = require 'underscore'
sd = require('sharify').data
CTABarView = require '../../../components/cta_bar/view.coffee'
Backbone = require 'backbone'
analyticsHooks = require '../../../lib/analytics_hooks.coffee'
marketoForm = -> require('../templates/marketo_form.jade') arguments...

module.exports = class GalleryInsightsView extends Backbone.View

  initialize: ->
    return unless @eligibleToSignUp()
    @createAndShowCTAForm()
    @setupCTAWaypoints()

  inGIArticlePage: ->
    sd.GALLERY_INSIGHTS_SECTION_ID in (sd.ARTICLE?.section_ids or [])

  inGIVerticalPage: ->
    sd.SECTION?.id is sd.GALLERY_INSIGHTS_SECTION_ID

  eligibleToSignUp: ->
    (@inGIArticlePage() or @inGIVerticalPage()) and not sd.MAILCHIMP_SUBSCRIBED

  createAndShowCTAForm: ->
    @ctaBarView = new CTABarView
      headline: 'Artsy Insights for Galleries'
      mode: 'gallery-insights'
      name: 'gallery-insights-signup'
      persist: true
      subHeadline: "Receive periodical insights from Artsy's Gallery Team"
    @$('.articles-insights-show').show()
    @$('.articles-insights-section').show()

  setupCTAWaypoints: ->
    return if @ctaBarView.previouslyDismissed()
    @ctaBarView.render()
    MktoForms2?.whenReady (form) -> $('#mktoForm_1230').removeAttr 'id'
    @ctaBarView.$el?.find('.cta-bar-small-form').replaceWith marketoForm()
    @$el.append @ctaBarView.$el
    if @inGIArticlePage()
      @$(".article-container[data-id=#{sd.ARTICLE.id}]").waypoint (direction) =>
        @ctaBarView.transitionIn() if direction is 'down'
      , { offset: -200 }
      @$(".article-container[data-id=#{sd.ARTICLE.id}]").waypoint (direction) =>
        @ctaBarView.transitionOut() if direction is 'down'
        @ctaBarView.transitionIn() if direction is 'up'
      , { offset: 'bottom-in-view' }
    else if @inGIVerticalPage()
      @$('.js-articles-feed-articles').waypoint (direction) =>
        @ctaBarView.transitionIn() if direction is 'down'
      ,{ offset: '50%' }
      @$('.js-articles-feed-articles').waypoint (direction) =>
        @ctaBarView.transitionOut() if direction is 'down'
        @ctaBarView.transitionIn() if direction is 'up'
      , { offset: 'bottom-in-view' }<commit_msg>add comment and better wrapping<commit_after>_ = require 'underscore'
sd = require('sharify').data
CTABarView = require '../../../components/cta_bar/view.coffee'
Backbone = require 'backbone'
analyticsHooks = require '../../../lib/analytics_hooks.coffee'
marketoForm = -> require('../templates/marketo_form.jade') arguments...

module.exports = class GalleryInsightsView extends Backbone.View

  initialize: ->
    return unless @eligibleToSignUp()
    @createAndShowCTAForm()
    @setupCTAWaypoints()

  inGIArticlePage: ->
    sd.GALLERY_INSIGHTS_SECTION_ID in (sd.ARTICLE?.section_ids or [])

  inGIVerticalPage: ->
    sd.SECTION?.id is sd.GALLERY_INSIGHTS_SECTION_ID

  eligibleToSignUp: ->
    (@inGIArticlePage() or @inGIVerticalPage()) and not sd.MAILCHIMP_SUBSCRIBED

  createAndShowCTAForm: ->
    @ctaBarView = new CTABarView
      headline: 'Artsy Insights for Galleries'
      mode: 'gallery-insights'
      name: 'gallery-insights-signup'
      persist: true
      subHeadline: "Receive periodical insights from Artsy's Gallery Team"
    @$('.articles-insights-show').show()
    @$('.articles-insights-section').show()

  setupCTAWaypoints: ->
    return if @ctaBarView.previouslyDismissed()
    # We have to wait for the first Marketo form embedded at the bottom of
    # the page to render and remove the Marketo id from the element. Otherwise
    # Marketo will try to render the form in both places, causing the form to
    # appear twice at the bottom of the page.
    MktoForms2.whenReady _.once (form) =>
      @$('#mktoForm_1230').removeAttr 'id'
      @ctaBarView.render()
      @ctaBarView.$el?.find('.cta-bar-small-form').replaceWith marketoForm()
      @$el.append @ctaBarView.$el
      if @inGIArticlePage()
        @$(".article-container[data-id=#{sd.ARTICLE.id}]").waypoint (direction) =>
          @ctaBarView.transitionIn() if direction is 'down'
        , { offset: -200 }
        @$(".article-container[data-id=#{sd.ARTICLE.id}]").waypoint (direction) =>
          @ctaBarView.transitionOut() if direction is 'down'
          @ctaBarView.transitionIn() if direction is 'up'
        , { offset: 'bottom-in-view' }
      else if @inGIVerticalPage()
        @$('.js-articles-feed-articles').waypoint (direction) =>
          @ctaBarView.transitionIn() if direction is 'down'
        ,{ offset: '50%' }
        @$('.js-articles-feed-articles').waypoint (direction) =>
          @ctaBarView.transitionOut() if direction is 'down'
          @ctaBarView.transitionIn() if direction is 'up'
        , { offset: 'bottom-in-view' }
{'fraction_non_alphanumeric': 0.14534761604704893, 'fraction_numerical': 0.004200798151648814, 'mean_word_length': 3.413345690454124, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, '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': '5516400', 'n_tokens_mistral': 1610, 'n_tokens_neox': 1567, 'n_words': 320}