<commit_before>sharingController = null

$(document).ready ->
  sharingController = new SharingController('.sharing')
  



class SharingController
  constructor: (containerSelector)->
    @firstRun = true;
    @$container = $(containerSelector)
    @$dropdown = @$container.find('#sharing_select')
    
    @sharingView = new SharingView(containerSelector)
    @shareSettings = new Share()
    
    @$container.find('.listSelection').click( (event) =>
      if @sharingView.isExpanded
        @sharingView.contractCurrentView()
      else
        currentSelection = @$dropdown.val()
        @sharingView.expandCurrentView(currentSelection)
    )
    
    @$dropdown.change( (event) =>
      # get the new icon path
      newSelection = @$dropdown.val()
      switch newSelection
        when "0"
          iconFileSource = 'private-24-select.png'
        when "50"
          iconFileSource = 'anon-24-select.png'
        when "150"
          iconFileSource = 'friend-follower-24.png'
        when "200"
          iconFileSource = 'friend-24.png'
        when "500"
          iconFileSource = 'sharing-24-select.png'
      
      iconSource = '/images/icons/' + iconFileSource
      $(event.currentTarget).parent().find('.listSelection').attr('src', iconSource)
      
      if !@firstRun
        @sharingView.expandCurrentView(newSelection)
      else
        @setupDefaultSharingLevel()
        @firstRun = false
      
      @shareSettings = new Share(newSelection)
    )
    
    #setup Default Sharing dropdown
    if window.BrowserDetect.browser isnt "Safari" and window.BrowserDetect.browser isnt "Chrome"
      @$dropdown.val(@$container.data('id'))
      @$dropdown.change()
      
    @$container.find('.target').hide()
    
  setupDefaultSharingLevel: ->
    @$dropdown.val($('#sharingList').find('option:selected').val())


class SharingView
  constructor: (containerSelector, type = 'everyone')->
    @$container = $(containerSelector)
    @type = type
    
  contractCurrentView: ->
    @isExpanded = false
    
    @$container.find('.target').slideUp(250)
    $('#bodyClick').remove()
    
  expandCurrentView: (type) -><commit_msg>fixing the sharing bug that wasnt changing on edit entry<commit_after>sharingController = null

$(document).ready ->
  sharingController = new SharingController('.sharing')
  



class SharingController
  constructor: (containerSelector)->
    @firstRun = true;
    @$container = $(containerSelector)
    @$dropdown = @$container.find('#sharing_select')
    
    @sharingView = new SharingView(containerSelector)
    @shareSettings = new Share()
    
    @$container.find('.listSelection').click( (event) =>
      if @sharingView.isExpanded
        @sharingView.contractCurrentView()
      else
        currentSelection = @$dropdown.val()
        @sharingView.expandCurrentView(currentSelection)
    )
    
    @$dropdown.change( (event) =>
      @sharingChangeHandler(event)
    )
    
    #setup Default Sharing dropdown
    @$dropdown.val($('.sharingWrap .sharing').data('id'))
    #@$dropdown.change()
    @sharingChangeHandler() 
    @$container.find('.target').hide()
  
  sharingChangeHandler: () ->
    # get the new icon path
    newSelection = @$dropdown.val()
    switch newSelection
      when "0"
        iconFileSource = 'private-24-select.png'
      when "50"
        iconFileSource = 'anon-24-select.png'
      when "150"
        iconFileSource = 'friend-follower-24.png'
      when "200"
        iconFileSource = 'friend-24.png'
      when "500"
        iconFileSource = 'sharing-24-select.png'
    
    iconSource = '/images/icons/' + iconFileSource
    $('.listSelection').attr('src', iconSource)
    
    if !@firstRun
      @sharingView.expandCurrentView(newSelection)
    else
      @firstRun = false
    
    @shareSettings = new Share(newSelection)


class SharingView
  constructor: (containerSelector, type = 'everyone')->
    @$container = $(containerSelector)
    @type = type
    
  contractCurrentView: ->
    @isExpanded = false
    
    @$container.find('.target').slideUp(250)
    $('#bodyClick').remove()
    
  expandCurrentView: (type) ->
{'fraction_non_alphanumeric': 0.13152147537005582, 'fraction_numerical': 0.012132977432661975, 'mean_word_length': 2.845149253731343, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '6579827', 'n_tokens_mistral': 1247, 'n_tokens_neox': 1184, 'n_words': 224}