<commit_before># Integrations for SBK's map service
jQuery ($) ->
  if $("body.test, body.development").length then mapEnv = "test" else mapEnv = "prod"

  # Used for iframe with single POI
  urlForInlineMap = (streetAddress) ->
    encodeURI "//kartor.malmo.se/init/?appid=adresskarta-v1&poi=#{streetAddress}"

  # Used for full map with single POI
  urlForFullMap = (streetAddress) ->
    encodeURI "http://malmo.se/karta?poi=#{streetAddress}&zoomlevel=4&maptype=karta"

  # Rewrite href attr on load to enable right click open in full map
  $("[data-poi]").attr "href", ->
    urlForFullMap($(@).attr("data-poi"))

  # Replace `data-map-selector` contents with the iframe and set the src from `data-poi`
  $("body").on "click", "[data-poi]", (event) ->
    event.preventDefault()
    $selector = $($(@).attr("data-map-selector"))

    if $selector.length

      # Map exists, remove it
      if $selector.find("iframe").length
        $(@).text("Visa på karta")
        $selector.empty().hide()

      # Create map
      else
        $iframe = $('<iframe scrolling="no" frameborder="0" src=""></iframe>')

        $(@).text("Dölj karta")
        # Set selector position to relative so we can place the close link on it
        $selector.css("position", "relative") if $selector.css("position") is "static"

        # Inject the iframe
        $selector.show().html($iframe.attr("src", urlForInlineMap($(@).attr("data-poi"))))

        # After injection, scroll to the top of `data-scroll-to` or the $selector
        if $(@).is("[data-scroll-to]")
          $('html, body').animate
            scrollTop: $($(@).attr("data-scroll-to")).offset().top - 45
          , 100

  # Show theme map
  $(".theme-map button").click ->
    $(@).blur()
    $box = $(@).parent()

    # Create a map if not present
    if $box.find("iframe").length < 1
      $(@).text("Dölj karta")
      $box.append $("<div class='map-box'><iframe scrolling='no' frameborder='0' src='#{$(@).attr("data-url")}'></iframe></div>")

      # After injection, scroll to the top of the $box
      $('html, body').animate
        scrollTop: $(@).offset().top - 60
      , 100

    # Map is present, remove it
    else
      $(@).text("Visa på karta")
      $box.find(".map-box").remove()<commit_msg>Store original map button text in data-text<commit_after># Integrations for SBK's map service
jQuery ($) ->
  if $("body.test, body.development").length then mapEnv = "test" else mapEnv = "prod"

  # Used for iframe with single POI
  urlForInlineMap = (streetAddress) ->
    encodeURI "//kartor.malmo.se/init/?appid=adresskarta-v1&poi=#{streetAddress}"

  # Used for full map with single POI
  urlForFullMap = (streetAddress) ->
    encodeURI "http://malmo.se/karta?poi=#{streetAddress}&zoomlevel=4&maptype=karta"

  # Rewrite href attr on load to enable right click open in full map
  $("[data-poi]").attr "href", ->
    urlForFullMap($(@).attr("data-poi"))

  # Replace `data-map-selector` contents with the iframe and set the src from `data-poi`
  $("body").on "click", "[data-poi]", (event) ->
    event.preventDefault()
    $selector = $($(@).attr("data-map-selector"))

    if $selector.length

      # Map exists, remove it
      if $selector.find("iframe").length
        $(@).text("Visa på karta")
        $selector.empty().hide()

      # Create map
      else
        $iframe = $('<iframe scrolling="no" frameborder="0" src=""></iframe>')

        $(@).text("Dölj karta")
        # Set selector position to relative so we can place the close link on it
        $selector.css("position", "relative") if $selector.css("position") is "static"

        # Inject the iframe
        $selector.show().html($iframe.attr("src", urlForInlineMap($(@).attr("data-poi"))))

        # After injection, scroll to the top of `data-scroll-to` or the $selector
        if $(@).is("[data-scroll-to]")
          $('html, body').animate
            scrollTop: $($(@).attr("data-scroll-to")).offset().top - 45
          , 100

  # Show theme map
  $(".theme-map button").click ->
    $(@).blur()
    $box = $(@).parent()

    # Create a map if not present
    if $box.find("iframe").length < 1
      $(@).attr('data-text', $(@).text())
      $(@).text("Dölj karta")
      $box.append $("<div class='map-box'><iframe scrolling='no' frameborder='0' src='#{$(@).attr("data-url")}'></iframe></div>")

      # After injection, scroll to the top of the $box
      $('html, body').animate
        scrollTop: $(@).offset().top - 60
      , 100

    # Map is present, remove it
    else
      $(@).text($(@).attr('data-text'))
      $box.find(".map-box").remove()
{'fraction_non_alphanumeric': 0.189928369871934, 'fraction_numerical': 0.006511829824180595, 'mean_word_length': 2.9621668099742045, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 27, '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': '2632482', 'n_tokens_mistral': 1561, 'n_tokens_neox': 1476, 'n_words': 381}