<commit_before>_                       = require 'underscore'
Backbone                = require 'backbone'
Artworks                = require '../../../models/artwork.coffee'
sd                      = require('sharify').data
analytics               = require '../../../lib/analytics.coffee'
CurrentUser             = require '../../../models/current_user.coffee'
FeedItems               = require '../collections/feed_items.coffee'
Profile                 = require '../../../models/profile.coffee'
FollowProfiles          = require '../../../collections/follow_profiles.coffee'
FeedItem                = require '../models/feed_item.coffee'
FeedItemView            = require('./feed_item.coffee').FeedItemView
FeedItemPost            = require('../../post/client/feed_item_post.coffee').FeedItemPost
feedItemsTemplate       = -> require('../templates/feed_items.jade') arguments...
FollowProfileButton     = require '../../../apps/partners/client/follow_profiles_button.coffee'
{ readCookie, deleteCookie, createCookie } = require '../../util/cookie.coffee'
feedItemsContainerTemplate = -> require('../templates/feed_items_container.jade') arguments...

module.exports = class FeedView extends Backbone.View

  rendered: false
  marginLeftRight: 110
  maxWidth: 1194
  minWidth: 950
  textColumnWidth: 404
  textColumnMargin: 80
  feedItemClass: 'feed-item-partner-show'
  analyticsFollowMessage: 'Followed partner profile from feed'
  analyticsUnfollowMessage: 'Unfollowed partner profile from feed'
  feedName: 'Shows Feed'
  items: []

  initialize: (options) ->
    throw 'Requires options' unless options
    throw 'Requires options.feedItems' unless options.feedItems?

    @$window = $(window)
    @windowHeight = @$window.innerHeight()
    @$htmlBody = $('html, body')
    @storeOptions options
    @setupCurrentUser()

    @initialFeedItems = @feedItems.removeFlagged()
    if @currentUser
      @currentUser.fetch success: =>
        @followProfiles = new FollowProfiles
        @render @initialFeedItems
    else
      @render @initialFeedItems

    throttledInfiniteScroll = _.throttle (=> @infiniteScroll()), 250
    @$window.on 'scroll.feed', throttledInfiniteScroll

    if @onResize
      throttledOnResize = _.throttle (=> @onResize()), 250
      @$window.on 'resize.feed', throttledOnResize

  scrollToLastClickedLink: =>
    cursor = readCookie 'clicked-feed-item-cursor'
    href = readCookie 'clicked-feed-item-href'
    pathname = readCookie 'clicked-feed-item-pathname'
    deleteCookie 'clicked-feed-item-cursor'
    deleteCookie 'clicked-feed-item-href'
    deleteCookie 'clicked-feed-item-pathname'
    return unless cursor and location.pathname is pathname
    imagesLoaded = require '../../../lib/vendor/imagesloaded.js'

    $el = @$("a[href='#{href}']")
    return unless $el.length
    @$htmlBody.scrollTop $el.offset().top - 200
    @$el.prepend """
      <div class='feed-previous-button'>
        <button class='avant-garde-button-text'>
          Load previous items
        </button>
      </div>
    """
    @$htmlBody.imagesLoaded => @$htmlBody.scrollTop $el.offset().top - 200

  storeOptions: (options) ->
    @feedItems             = options.feedItems

    # for Fair labels
    @headingText           = options.headingText or false
    @headingSortOrder      = options.headingSortOrder or false

    @afterFetchCont        = options.afterFetch
    @widthOffset           = options.widthOffset or 0
    @sortOrder             = options.sortOrder
    @limitPostBodyHeight   = options.limitPostBodyHeight
    @additionalParams      = options.additionalParams

  render: (items) =>
    @latestItems = items

    @fixedWidth = @getFixedWidth()
    @imageWidth = @getImageWidth()
<commit_msg>improve returning to scroll position<commit_after>_                       = require 'underscore'
Backbone                = require 'backbone'
Artworks                = require '../../../models/artwork.coffee'
sd                      = require('sharify').data
analytics               = require '../../../lib/analytics.coffee'
CurrentUser             = require '../../../models/current_user.coffee'
FeedItems               = require '../collections/feed_items.coffee'
Profile                 = require '../../../models/profile.coffee'
FollowProfiles          = require '../../../collections/follow_profiles.coffee'
FeedItem                = require '../models/feed_item.coffee'
FeedItemView            = require('./feed_item.coffee').FeedItemView
FeedItemPost            = require('../../post/client/feed_item_post.coffee').FeedItemPost
feedItemsTemplate       = -> require('../templates/feed_items.jade') arguments...
FollowProfileButton     = require '../../../apps/partners/client/follow_profiles_button.coffee'
{ readCookie, deleteCookie, createCookie } = require '../../util/cookie.coffee'
feedItemsContainerTemplate = -> require('../templates/feed_items_container.jade') arguments...

module.exports = class FeedView extends Backbone.View

  rendered: false
  marginLeftRight: 110
  maxWidth: 1194
  minWidth: 950
  textColumnWidth: 404
  textColumnMargin: 80
  feedItemClass: 'feed-item-partner-show'
  analyticsFollowMessage: 'Followed partner profile from feed'
  analyticsUnfollowMessage: 'Unfollowed partner profile from feed'
  feedName: 'Shows Feed'
  items: []

  initialize: (options) ->
    throw 'Requires options' unless options
    throw 'Requires options.feedItems' unless options.feedItems?

    @$window = $(window)
    @windowHeight = @$window.innerHeight()
    @$htmlBody = $('html, body')
    @storeOptions options
    @setupCurrentUser()

    @initialFeedItems = @feedItems.removeFlagged()
    if @currentUser
      @currentUser.fetch success: =>
        @followProfiles = new FollowProfiles
        @render @initialFeedItems
    else
      @render @initialFeedItems

    throttledInfiniteScroll = _.throttle (=> @infiniteScroll()), 250
    @$window.on 'scroll.feed', throttledInfiniteScroll

    if @onResize
      throttledOnResize = _.throttle (=> @onResize()), 250
      @$window.on 'resize.feed', throttledOnResize

  scrollToLastClickedLink: =>
    cursor = readCookie 'clicked-feed-item-cursor'
    href = readCookie 'clicked-feed-item-href'
    pathname = readCookie 'clicked-feed-item-pathname'
    deleteCookie 'clicked-feed-item-cursor'
    deleteCookie 'clicked-feed-item-href'
    deleteCookie 'clicked-feed-item-pathname'
    return unless cursor and location.pathname is pathname
    imagesLoaded = require '../../../lib/vendor/imagesloaded.js'

    $el = @$("a[href='#{href}']")
    return unless $el.length
    @$el.prepend """
      <div class='feed-previous-button'>
        <button class='avant-garde-button-text'>
          Load previous items
        </button>
      </div>
    """
    @$htmlBody.imagesLoaded =>
      @$htmlBody.scrollTop($el.offset().top - 200)

  storeOptions: (options) ->
    @feedItems             = options.feedItems

    # for Fair labels
    @headingText           = options.headingText or false
    @headingSortOrder      = options.headingSortOrder or false

    @afterFetchCont        = options.afterFetch
    @widthOffset           = options.widthOffset or 0
    @sortOrder             = options.sortOrder
    @limitPostBodyHeight   = options.limitPostBodyHeight
    @additionalParams      = options.additionalParams

  render: (items) =>
    @latestItems = items

    @fixedWidth = @getFixedWidth()
    @imageWidth = @getImageWidth()

{'fraction_non_alphanumeric': 0.12651250336111858, 'fraction_numerical': 0.007125571390158645, 'mean_word_length': 2.7419517102615694, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 31, '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': '6181760', 'n_tokens_mistral': 2182, 'n_tokens_neox': 2086, 'n_words': 434}