<commit_before>class $.model.Menu extends $.model.BaseModel
  @property 'title', '.ui-menuHeader'
  
  pin:          -> $(@rootElement).addClass    'ui-pinned'
  unpin:        -> $(@rootElement).removeClass 'ui-pinned'
  togglePinned: -> $(@rootElement).toggleClass 'ui-pinned'
  isPinned:     -> $(@rootElement).hasClass    'ui-pinned'
  
  addHTML: (html) ->
    $('<li>').html(html).appendTo this.find('.ui-menuContent')
  
  addCheckbox: (label, fn) ->
    uuid = Math.uuid()
    this.addHTML("""
      <input id="#{uuid}" type="checkbox">
      <label for="#{uuid}"></label>
    """)
    .find('input').click(fn).end()
    .find('label').text(label).end()
  
  addSelect: (label, {values, defaultValue}, fn) ->
    uuid = Math.uuid()
    populator = if $.isArray values
    then (select) -> $('<option>').text(value).appendTo(select) for value in values
    else (select) -> $('<option>').text(label).val(value).appendTo(select) for label, value of values
    this.addHTML("""
      <label for="#{uuid}"></label>
      <select name="#{uuid}"></select>
    """)
    .find('select').tap(populator).val(defaultValue).change(fn).end()
    .find('label').text(label).end()
  
  addLink: (label, fn) ->
    this.addHTML('<li><a></a></li>')
    .find('a').tap (link) ->
      if typeof fn is 'function'
      then link.click(fn)
      else link.attr(href: fn)

$('.ui-menu .ui-menuHeader').live 'click', (event) ->
  $(this).closest('.ui-menu').model().togglePinned()

$ ->
  currentVariantPattern = /// url\( "? variants/ ([^\s"]+) \.css "? \) ///i
  
  $('#main-menu').model().addSelect 'variant',
    values: MessageStyle.variants.getOwnKeys(),
    defaultValue: $('#mainStyle').text().match(currentVariantPattern)?[1]
  , ->
    $('#mainStyle').text("""@import url("Variants/#{$(this).val()}.css");""")
    $('#main-menu').model().unpin()
    scrollToBottom()<commit_msg>fix missing label text in menu items created by Menu::addLink<commit_after>class $.model.Menu extends $.model.BaseModel
  @property 'title', '.ui-menuHeader'
  
  pin:          -> $(@rootElement).addClass    'ui-pinned'
  unpin:        -> $(@rootElement).removeClass 'ui-pinned'
  togglePinned: -> $(@rootElement).toggleClass 'ui-pinned'
  isPinned:     -> $(@rootElement).hasClass    'ui-pinned'
  
  addHTML: (html) ->
    $('<li>').html(html).appendTo this.find('.ui-menuContent')
  
  addCheckbox: (label, fn) ->
    uuid = Math.uuid()
    this.addHTML("""
      <input id="#{uuid}" type="checkbox">
      <label for="#{uuid}"></label>
    """)
    .find('input').click(fn).end()
    .find('label').text(label).end()
  
  addSelect: (label, {values, defaultValue}, fn) ->
    uuid = Math.uuid()
    populator = if $.isArray values
    then (select) -> $('<option>').text(value).appendTo(select) for value in values
    else (select) -> $('<option>').text(label).val(value).appendTo(select) for label, value of values
    this.addHTML("""
      <label for="#{uuid}"></label>
      <select name="#{uuid}"></select>
    """)
    .find('select').tap(populator).val(defaultValue).change(fn).end()
    .find('label').text(label).end()
  
  addLink: (label, fn) ->
    this.addHTML("<li><a>#{label.escapeEntities()}</a></li>")
    .find('a').tap (link) ->
      if typeof fn is 'function'
      then link.click(fn)
      else link.attr(href: fn)

$('.ui-menu .ui-menuHeader').live 'click', (event) ->
  $(this).closest('.ui-menu').model().togglePinned()

$ ->
  currentVariantPattern = /// url\( "? variants/ ([^\s"]+) \.css "? \) ///i
  
  $('#main-menu').model().addSelect 'variant',
    values: MessageStyle.variants.getOwnKeys(),
    defaultValue: $('#mainStyle').text().match(currentVariantPattern)?[1]
  , ->
    $('#mainStyle').text("""@import url("Variants/#{$(this).val()}.css");""")
    $('#main-menu').model().unpin()
    scrollToBottom()
{'fraction_non_alphanumeric': 0.23723487824037706, 'fraction_numerical': 0.0005236973029588898, 'mean_word_length': 3.3657142857142857, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 59, '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': '1027495', 'n_tokens_mistral': 1301, 'n_tokens_neox': 1301, 'n_words': 220}