<commit_before>(function ($, L) {
  function screenSize () {
    return $(window).width() > 600 ? 'large' : 'small'
  }

  var map = new L.Map('map')

  var mapControl = (function () {
    var component = {}
    component.show = function () {
      $('.leaflet-control').css('display', 'inherit')
    }
    component.hide = function () {
      $('.leaflet-control').css('display', 'none')
    }
    return component
  })()

  var loading = (function (mapControl, s) {
    var settings = s || { image: 'reload.svg' }
    var component = {}
    var $overlay = $('<div class="app loading overlay"></div>')
    var $loading = $('<div class="app loading container"><img src="' + settings.image + '"></div>')

    component.mount = function () {
      component.close()
      $('body').append($overlay, $loading)
    }

    component.open = function () {
      mapControl.hide()
      $overlay.show()
      $loading.show()
    }

    component.close = function () {
      mapControl.show()
      $overlay.hide()
      $loading.hide()
    }

    return component
  })(mapControl, {
    image: 'reload.svg'
  })

  var modal = (function (mapControl, screenSize) {
    var settings = {
      width: screenSize() === 'large' ? $(window).width() / 1.5 : $(window).width() / 1.1,
      height: screenSize() === 'large' ? 'auto' : $(window).height() / 1.1
    }
    var component = {}
    var $overlay = $('<div class="app modal overlay"></div>')
    var $modal = $('<div class="app modal container"></div>')
    var $content = $('<div class="app modal content"></div>')
    var $close = $('<a class="app modal close" href="#">close</a>')

    component.mount = function () {
      component.close()
      $modal.append($close, $content)
      $('body').append($overlay, $modal)
    }

    component.center = function () {
      var top, left
      top = Math.max($(window).height() - $modal.outerHeight(), 0) / 2
      left = Math.max($(window).width() - $modal.outerWidth(), 0) / 2
      $modal.css({
        top: top + $(window).scrollTop(),
        left: left + $(window).scrollLeft()
      })
    }

    component.open = function (content) {
      mapControl.hide()
      $modal.css({
        width: settings.width || 'auto',
        height: settings.height || 'auto'
      })
      $content.append(content)
      component.center()
      $(window).bind('resize.modal', component.center)
      $modal.show()
      $overlay.show()
    }

    component.close = function () {
      mapControl.show()
      $modal.hide()
      $overlay.hide()
      $(window).unbind('resize.modal')
      $content.children().remove()
    }

    component.scroll = $content.scroll.bind($content)

    $overlay.click(function (e) {
      e.preventDefault()
      component.close()
    })

    $close.click(function (e) {
      e.preventDefault()
      component.close()
    })

    return component
  })(mapControl, screenSize)

  var addStation = (function (map, modal, loading, screenSize) {
    var component = {}
    var $dialog = $('<div class="app add-station dialog"></div>')
    var $overlay = $('<div class="app add-station dialog overlay"></div>')
    var $add = $('<button class="ui primary button">加</button>')
    var $cancel = $('<button class="ui button">取消</button>')
    var $submit = $('<button class="ui submit primary button">送出</button>')
    var $anchor = $('<i class="add-station anchor"></i>')
    var $close = $('<a class="app dialog close" href="#">close</a>')
    var $fieldDescription = $('<div class="field"><label>飲水點說明</label><input name="description" placeholder="位置、負責單位、如何找到它⋯⋯" type="text"></div>')
    var $fieldAddress = $('<div class="field"><label>地址</label><input name="address" placeholder="" type="text"></div>')
    var $fieldTemperature = $('<div class="inline fields"><label>水溫</label>' +
      '<div class="field"><div class="ui checkbox"><input name="iced" value="iced" type="checkbox"><label>冰</label></div></div>' +
      '<div class="field"><div class="ui checkbox"><input name="cold" value="cold" type="checkbox"><label>冷</label></div></div>' +
      '<div class="field"><div class="ui checkbox"><input name="warm" value="warm" type="checkbox"><label>溫</label></div></div>' +
      '<div class="field"><div class="ui checkbox"><input name="hot"  value="hot"  type="checkbox"><label>熱</label></div></div>' +
      '</div>')
    var $fieldIndoor = $('<div class="inline fields"><label>位置</label>' +
      '<div class="field"><div class="ui radio checkbox"><input name="indoor" type="radio" value="yes" checked="checked"><label>室內</label></div></div>' +
      '<div class="field"><div class="ui radio checkbox"><input name="indoor" type="radio" value="no"                   ><label>室外</label></div></div>' +
      '</div>')
    var $fieldLevel = $('<div class="inline fields"><label>樓層</label>' +
      '<div class="field"><select class="ui search selection dropdown"><option value="-5">B5</option><option value="-4">B4</option><option value="-3">B3</option><option value="-2">B2</option><option value="-1">B1</option><option value="0">GF</option><option value="1" selected="selected">1F</option><option value="2">2F</option><option value="3">3F</option><option value="4">4F</option><option value="5">5F</option><option value="6">6F</option><option value="7">7F</option><option value="8">8F</option><option value="9">9F</option><option value="10">10F</option></select></div>' +
      '</div>')
    var $fieldPrecise = $('<div class="field"><div class="ui slider checkbox"><input name="precise" type="checkbox"><label>這個資訊是準確的</label></div></div>')
    var opened = false
    var point

    component.mount = function () {
      $overlay.hide()
      $dialog.hide()
      $('body').append($overlay, $dialog)
    }
    component.open = function (opt) {
      point = opt.containerPoint
      if (opened) return
      component.close()
      $add.click(function (e) {
        e.preventDefault()
        component.fillData()
      })
      $cancel.click(function (e) {
        e.preventDefault()
        component.close()
      })
      $close.click(function (e) {
        e.preventDefault()
        component.close()
      })

      $dialog.append(
        $close,
        $anchor,
        $('<div class="add-station content ui form"><h4>加一個飲水點？</h4></div>')
        .append($add, $cancel, '<p>請儘量提供完整訊息，以協助社群驗證資料正確性。</p>')
      )
      component.pointTo(point.x, point.y)
      $dialog.show()
      opened = true
    }
    component.close = function () {
      $dialog.children().remove()
      $dialog.removeClass('tl tr bl br')
      $dialog.hide()
      opened = false
    }
    component.pointTo = function (x, y) {
      var leftRightThreshhold = Math.floor($(window).width() / 2)
      var topBottomThreshold = Math.max($dialog.outerHeight(), ($(window).height() * 1 / 5))
      var direction = (y < topBottomThreshold ? 'b' : 't') + (x < leftRightThreshhold ? 'r' : 'l')
      $dialog.addClass(direction)
      if (screenSize() === 'small')  {
        $dialog.css({
          top: (direction[0] === 'b' ? y : y - $dialog.outerHeight()),
          left: 8,
          right: 8
        })
        $anchor.css({
          left: x - 8 - 15, // 8 (container spacing) + 15 (icon width/2)
          zIndex: 10
        })
      } else {
        var xx =  x - $dialog.outerWidth() < 0 ? 0 : x - $dialog.outerWidth()
        $dialog.css({
          top: (direction[0] === 'b' ? y : y - $dialog.outerHeight()),
          left: (direction[1] === 'r' ? x : xx),
          maxWidth: 300
        })
        if (x - $dialog.outerWidth() < 0) {
          $anchor.css({
            right: $dialog.outerWidth() - x,
            zIndex: 10
          })
        }
      }
    }
    component.fillData = function () {
      component.close()
      $submit.click(function (e) {
        e.preventDefault()
        component.submit()
      })
      $cancel.click(function (e) {
        e.preventDefault()
        modal.close()
      })
      var $content = $('<form class="app add-station ui form"></form>')
      $content.append(
        $fieldDescription, $fieldAddress, $fieldTemperature, $fieldIndoor, $fieldLevel,
        $fieldPrecise)
      $content.append($submit, $cancel)
      modal.open($content)
    }
    component.submit = function () {
      modal.close()
      loading.open()
      var latLng = map.containerPointToLatLng(point)
      var noteText = '#飲水地圖 #drinking_water\n' +
        '說明：' + $fieldDescription.children('input')[0].value + '\n' +
        '地址：' + 'addr:full=' + $fieldAddress.children('input')[0].value + '\n' +
        '溫度：' + $fieldTemperature.find('input').map(function () {
          return $(this).prop('checked') ? $(this).val() + '_water=yes' : null
        }).toArray().join(' ') + '\n' +
        '位置：' + $fieldIndoor.find('input').map(function () {<commit_msg>minor fix to form data<commit_after>(function ($, L) {
  function screenSize () {
    return $(window).width() > 600 ? 'large' : 'small'
  }

  var map = new L.Map('map')

  var mapControl = (function () {
    var component = {}
    component.show = function () {
      $('.leaflet-control').css('display', 'inherit')
    }
    component.hide = function () {
      $('.leaflet-control').css('display', 'none')
    }
    return component
  })()

  var loading = (function (mapControl, s) {
    var settings = s || { image: 'reload.svg' }
    var component = {}
    var $overlay = $('<div class="app loading overlay"></div>')
    var $loading = $('<div class="app loading container"><img src="' + settings.image + '"></div>')

    component.mount = function () {
      component.close()
      $('body').append($overlay, $loading)
    }

    component.open = function () {
      mapControl.hide()
      $overlay.show()
      $loading.show()
    }

    component.close = function () {
      mapControl.show()
      $overlay.hide()
      $loading.hide()
    }

    return component
  })(mapControl, {
    image: 'reload.svg'
  })

  var modal = (function (mapControl, screenSize) {
    var settings = {
      width: screenSize() === 'large' ? $(window).width() / 1.5 : $(window).width() / 1.1,
      height: screenSize() === 'large' ? 'auto' : $(window).height() / 1.1
    }
    var component = {}
    var $overlay = $('<div class="app modal overlay"></div>')
    var $modal = $('<div class="app modal container"></div>')
    var $content = $('<div class="app modal content"></div>')
    var $close = $('<a class="app modal close" href="#">close</a>')

    component.mount = function () {
      component.close()
      $modal.append($close, $content)
      $('body').append($overlay, $modal)
    }

    component.center = function () {
      var top, left
      top = Math.max($(window).height() - $modal.outerHeight(), 0) / 2
      left = Math.max($(window).width() - $modal.outerWidth(), 0) / 2
      $modal.css({
        top: top + $(window).scrollTop(),
        left: left + $(window).scrollLeft()
      })
    }

    component.open = function (content) {
      mapControl.hide()
      $modal.css({
        width: settings.width || 'auto',
        height: settings.height || 'auto'
      })
      $content.append(content)
      component.center()
      $(window).bind('resize.modal', component.center)
      $modal.show()
      $overlay.show()
    }

    component.close = function () {
      mapControl.show()
      $modal.hide()
      $overlay.hide()
      $(window).unbind('resize.modal')
      $content.children().remove()
    }

    component.scroll = $content.scroll.bind($content)

    $overlay.click(function (e) {
      e.preventDefault()
      component.close()
    })

    $close.click(function (e) {
      e.preventDefault()
      component.close()
    })

    return component
  })(mapControl, screenSize)

  var addStation = (function (map, modal, loading, screenSize) {
    var component = {}
    var $dialog = $('<div class="app add-station dialog"></div>')
    var $overlay = $('<div class="app add-station dialog overlay"></div>')
    var $add = $('<button class="ui primary button">加</button>')
    var $cancel = $('<button class="ui button">取消</button>')
    var $submit = $('<button class="ui submit primary button">送出</button>')
    var $anchor = $('<i class="add-station anchor"></i>')
    var $close = $('<a class="app dialog close" href="#">close</a>')
    var $fieldDescription = $('<div class="field"><label>飲水點說明</label><input name="description" placeholder="位置、負責單位、如何找到它⋯⋯" type="text"></div>')
    var $fieldAddress = $('<div class="field"><label>地址</label><input name="address" placeholder="" type="text"></div>')
    var $fieldTemperature = $('<div class="inline fields"><label>水溫</label>' +
      '<div class="field"><div class="ui checkbox"><input name="iced" value="iced" type="checkbox"><label>冰</label></div></div>' +
      '<div class="field"><div class="ui checkbox"><input name="cold" value="cold" type="checkbox"><label>冷</label></div></div>' +
      '<div class="field"><div class="ui checkbox"><input name="warm" value="warm" type="checkbox"><label>溫</label></div></div>' +
      '<div class="field"><div class="ui checkbox"><input name="hot"  value="hot"  type="checkbox"><label>熱</label></div></div>' +
      '</div>')
    var $fieldIndoor = $('<div class="inline fields"><label>位置</label>' +
      '<div class="field"><div class="ui radio checkbox"><input name="indoor" type="radio" value="yes" checked="checked"><label>室內</label></div></div>' +
      '<div class="field"><div class="ui radio checkbox"><input name="indoor" type="radio" value="no"                   ><label>室外</label></div></div>' +
      '</div>')
    var $fieldLevel = $('<div class="inline fields"><label>樓層</label>' +
      '<div class="field"><select class="ui search selection dropdown"><option value="-5">B5</option><option value="-4">B4</option><option value="-3">B3</option><option value="-2">B2</option><option value="-1">B1</option><option value="0">GF</option><option value="1" selected="selected">1F</option><option value="2">2F</option><option value="3">3F</option><option value="4">4F</option><option value="5">5F</option><option value="6">6F</option><option value="7">7F</option><option value="8">8F</option><option value="9">9F</option><option value="10">10F</option></select></div>' +
      '</div>')
    var $fieldPrecise = $('<div class="field"><div class="ui slider checkbox"><input name="precise" type="checkbox"><label>這個資訊是準確的</label></div></div>')
    var opened = false
    var point

    component.mount = function () {
      $overlay.hide()
      $dialog.hide()
      $('body').append($overlay, $dialog)
    }
    component.open = function (opt) {
      point = opt.containerPoint
      if (opened) return
      component.close()
      $add.click(function (e) {
        e.preventDefault()
        component.fillData()
      })
      $cancel.click(function (e) {
        e.preventDefault()
        component.close()
      })
      $close.click(function (e) {
        e.preventDefault()
        component.close()
      })

      $dialog.append(
        $close,
        $anchor,
        $('<div class="add-station content ui form"><h4>加一個飲水點？</h4></div>')
        .append($add, $cancel, '<p>請儘量提供完整訊息，以協助社群驗證資料正確性。</p>')
      )
      component.pointTo(point.x, point.y)
      $dialog.show()
      opened = true
    }
    component.close = function () {
      $dialog.children().remove()
      $dialog.removeClass('tl tr bl br')
      $dialog.hide()
      opened = false
    }
    component.pointTo = function (x, y) {
      var leftRightThreshhold = Math.floor($(window).width() / 2)
      var topBottomThreshold = Math.max($dialog.outerHeight(), ($(window).height() * 1 / 5))
      var direction = (y < topBottomThreshold ? 'b' : 't') + (x < leftRightThreshhold ? 'r' : 'l')
      $dialog.addClass(direction)
      if (screenSize() === 'small')  {
        $dialog.css({
          top: (direction[0] === 'b' ? y : y - $dialog.outerHeight()),
          left: 8,
          right: 8
        })
        $anchor.css({
          left: x - 8 - 15, // 8 (container spacing) + 15 (icon width/2)
          zIndex: 10
        })
      } else {
        var xx =  x - $dialog.outerWidth() < 0 ? 0 : x - $dialog.outerWidth()
        $dialog.css({
          top: (direction[0] === 'b' ? y : y - $dialog.outerHeight()),
          left: (direction[1] === 'r' ? x : xx),
          maxWidth: 300
        })
        if (x - $dialog.outerWidth() < 0) {
          $anchor.css({
            right: $dialog.outerWidth() - x,
            zIndex: 10
          })
        }
      }
    }
    component.fillData = function () {
      component.close()
      $submit.click(function (e) {
        e.preventDefault()
        component.submit()
      })
      $cancel.click(function (e) {
        e.preventDefault()
        modal.close()
      })
      var $content = $('<form class="app add-station ui form"></form>')
      $content.append(
        $fieldDescription, $fieldAddress, $fieldTemperature, $fieldIndoor, $fieldLevel,
        $fieldPrecise)
      $content.append($submit, $cancel)
      modal.open($content)
    }
    component.submit = function () {
      modal.close()
      loading.open()
      var latLng = map.containerPointToLatLng(point)
      var noteText = '#飲水地圖 #drinking_water\n' +
        '說明：' + $fieldDescription.children('input')[0].value + '\n' +
        '地址：' + ($fieldAddress.children('input')[0].value ? 'addr:full=' + $fieldAddress.children('input')[0].value : '') + '\n' +
        '溫度：' + $fieldTemperature.find('input').map(function () {
          return $(this).prop('checked') ? $(this).val() + '_water=yes' : null
        }).toArray().join(' ') + '\n' +
        '位置：' + $fieldIndoor.find('input').map(function () {
{'fraction_non_alphanumeric': 0.20199331785491817, 'fraction_numerical': 0.008550880570813749, 'mean_word_length': 2.8399652098282235, 'pattern_counts': {'":': 0, '<': 295, '<?xml version=': 0, '>': 289, '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': '5223628', 'n_tokens_mistral': 5701, 'n_tokens_neox': 5595, 'n_words': 1107}