<commit_before>define ['jquery'], ($)->

  class Authenticator

    @version = '0.0.12'

    @options =
      forumPostsUrlTemplate: '//www.lonelyplanet.com/thorntree/profile.jspa?username=[USERNAME]'
      membersUrl: '//www.lonelyplanet.com/members'
      messagesUrl: '//www.lonelyplanet.com/members/messages'
      registerLink: 'https://secure.lonelyplanet.com/members/registration/new'
      signOutUrl: 'https://secure.lonelyplanet.com/sign-in/logout'
    
    constructor: ->
      @userState = @userSignedIn()
      @widget = $('nav.user-nav')
      @options = Authenticator.options
      @signonWidget()
      
    userSignedIn: ->
      @lpUserName = @getLocalData('lp-uname')
      if (@lpUserName and (@lpUserName isnt '') and (@lpUserName isnt 'undefined'))
        true
      else
        false

    signonWidget: ->
      if @userState is true
        @showUserBox()
      else
        @showLoginAndRegister()
        
    showLoginAndRegister: ()->
      @emptyUserNav()
      joinElement = "<a class='nav__item--primary--user js-user-join' href='#{@options.registerLink}'>Join</a>"
      signinElement = "<a class='nav__item--primary--user js-user-signin' href='#{@signInUrl()}'>Sign-In</a>"
      $('nav.js-user-nav').prepend(signinElement + joinElement)

    showUserBox: ->
      @emptyUserNav()
      $('nav.js-user-nav').addClass('is-signed-in')
      userBoxElement = "<div class='nav__item nav__item--user user-box js-user-box nav__submenu__trigger'><img class='user-box__img js-box-handler' src='#{@userAvatar()}'/></div>"
      $('nav.js-user-nav').append(userBoxElement)
      $('div.js-user-box').append(@userOptionsMenu())

    emptyUserNav: -> 
      $('nav.js-user-nav').removeClass('is-signed-in')
      $('a.js-user-join, a.js-user-signin, div.js-user-box').remove()

    userOptionsMenu: ->
      userOptions = [
        {title: 'My Profile', uri: "#{@options.membersUrl}", style:"js-user-profile"},
        {title: 'Settings', uri: "#{@options.membersUrl}/#{@lpUserName}/edit",  style:"js-user-settings"},
        # {title: 'Messages', uri: "#{@options.messagesUrl}", style:"js-user-msg"},
        {title: 'Forum Activity', uri: "#{@options.forumPostsUrlTemplate.replace('[USERNAME]', @lpUserName)}", style:"nav-user-options__item--forum js-user-forum" },
        {title: 'Sign-Out', uri: "#{@options.signOutUrl}", style:"nav-user-options__item--signout js-user-signout" }
      ]
      optionElements =  ("<a class='nav__item nav__submenu__item nav__submenu__link nav-user-options__item #{u.style}' href='#{u.uri}'>#{u.title}#{u.extra || ''}</a>" for u in userOptions).join('')

      userMenu = "<div class='nav__submenu'><nav class='nav--stacked nav__submenu__content nav__submenu__content--user nav-user-options js-user-options'><h3 class='nav__submenu__item nav__submenu__title'>#{@lpUserName}</h3>#{optionElements}</nav></div>"
    
    signInUrl:->
      "https://secure.lonelyplanet.com/sign-in/login?service=#{escape(window.location)}"
    
    userAvatar: ->
      "#{@options.membersUrl}/#{@lpUserName}/mugshot/mini"

    update: ->
      @setLocalData("lp-uname", window.lpLoggedInUsername)<commit_msg>Added helper class to the user--submenu<commit_after>define ['jquery'], ($)->

  class Authenticator

    @version = '0.0.12'

    @options =
      forumPostsUrlTemplate: '//www.lonelyplanet.com/thorntree/profile.jspa?username=[USERNAME]'
      membersUrl: '//www.lonelyplanet.com/members'
      messagesUrl: '//www.lonelyplanet.com/members/messages'
      registerLink: 'https://secure.lonelyplanet.com/members/registration/new'
      signOutUrl: 'https://secure.lonelyplanet.com/sign-in/logout'
    
    constructor: ->
      @userState = @userSignedIn()
      @widget = $('nav.user-nav')
      @options = Authenticator.options
      @signonWidget()
      
    userSignedIn: ->
      @lpUserName = @getLocalData('lp-uname')
      if (@lpUserName and (@lpUserName isnt '') and (@lpUserName isnt 'undefined'))
        true
      else
        false

    signonWidget: ->
      if @userState is true
        @showUserBox()
      else
        @showLoginAndRegister()
        
    showLoginAndRegister: ()->
      @emptyUserNav()
      joinElement = "<a class='nav__item--primary--user js-user-join' href='#{@options.registerLink}'>Join</a>"
      signinElement = "<a class='nav__item--primary--user js-user-signin' href='#{@signInUrl()}'>Sign-In</a>"
      $('nav.js-user-nav').prepend(signinElement + joinElement)

    showUserBox: ->
      @emptyUserNav()
      $('nav.js-user-nav').addClass('is-signed-in')
      userBoxElement = "<div class='nav__item nav__item--user user-box js-user-box nav__submenu__trigger'><img class='user-box__img js-box-handler' src='#{@userAvatar()}'/></div>"
      $('nav.js-user-nav').append(userBoxElement)
      $('div.js-user-box').append(@userOptionsMenu())

    emptyUserNav: -> 
      $('nav.js-user-nav').removeClass('is-signed-in')
      $('a.js-user-join, a.js-user-signin, div.js-user-box').remove()

    userOptionsMenu: ->
      userOptions = [
        {title: 'My Profile', uri: "#{@options.membersUrl}", style:"js-user-profile"},
        {title: 'Settings', uri: "#{@options.membersUrl}/#{@lpUserName}/edit",  style:"js-user-settings"},
        # {title: 'Messages', uri: "#{@options.messagesUrl}", style:"js-user-msg"},
        {title: 'Forum Activity', uri: "#{@options.forumPostsUrlTemplate.replace('[USERNAME]', @lpUserName)}", style:"nav-user-options__item--forum js-user-forum" },
        {title: 'Sign-Out', uri: "#{@options.signOutUrl}", style:"nav-user-options__item--signout js-user-signout" }
      ]
      optionElements =  ("<a class='nav__item nav__submenu__item nav__submenu__link nav-user-options__item #{u.style}' href='#{u.uri}'>#{u.title}#{u.extra || ''}</a>" for u in userOptions).join('')

      userMenu = "<div class='nav__submenu nav__submenu--user'><nav class='nav--stacked nav__submenu__content nav__submenu__content--user nav-user-options js-user-options'><h3 class='nav__submenu__item nav__submenu__title'>#{@lpUserName}</h3>#{optionElements}</nav></div>"
    
    signInUrl:->
      "https://secure.lonelyplanet.com/sign-in/login?service=#{escape(window.location)}"
    
    userAvatar: ->
      "#{@options.membersUrl}/#{@lpUserName}/mugshot/mini"

    update: ->
      @setLocalData("lp-uname", window.lpLoggedInUsername)
{'fraction_non_alphanumeric': 0.1862884160756501, 'fraction_numerical': 0.0018912529550827422, 'mean_word_length': 3.503903477643719, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 55, 'https://': 6, 'lorem ipsum': 0, 'www.': 6, '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': '1686944', 'n_tokens_mistral': 2151, 'n_tokens_neox': 2131, 'n_words': 293}