<commit_before>{div, input, a, button, strong, textarea, svg, g, path, span, circle, ul, li} = React.DOM

SHOW_LONGEVITY_WARNING = false

ModalDialog = React.createFactory require './modal-dialog-view'
getQueryParam = require '../utils/get-query-param'

tr = require '../utils/translate'
socialIcons = require 'svg-social-icons/lib/icons.json'

SocialIcon = React.createFactory React.createClass

  displayName: 'SocialIcon'

  getInitialState: ->
    data: socialIcons[@props.icon]

  clicked: ->
    window.open @props.url

  render: ->
    (a {className: 'social-icon', href: @props.url, target: '_blank'},
      (div {className: 'social-container'},
        (svg {className: 'social-svg', viewBox: '0 0 64 64'},
          (g {className: 'social-svg-background'},
            (circle {cx: 32, cy: 32, r: 31})
          )
          (g {className: 'social-svg-icon'},
            (path {d: @state.data.icon})
          )
          (g {className: 'social-svg-mask', style: {fill: @state.data.color}},
            (path {d: @state.data.mask})
          )
        )
      )
    )

module.exports = React.createClass

  displayName: 'ShareDialogView'

  getInitialState: ->
    link: @getShareLink()
    embed: @getEmbed()
    pageType: "autolaunch"
    codapServerUrl: "https://codap.concord.org/releases/latest/"
    launchButtonText: "Launch"
    fullscreenScaling: true
    graphVisToggles: false
    tabSelected: 'link'

  getSharedDocumentId: ->
    # extract sharedDocumentId from CloudContent
    if @props.client.isShared()
      @props.client.state.currentContent?.get "sharedDocumentId"
    else
      null

  getShareLink: ->
    sharedDocumentId = @getSharedDocumentId()
    if sharedDocumentId
      # share link combines document URL with sharedDocumentId
      "#{@props.client.getCurrentUrl()}#shared=#{sharedDocumentId}"
    else
      null

  getEmbed: ->
    if @getShareLink()
      """<iframe width="398px" height="313px" frameborder="no" scrolling="no" allowfullscreen="true" webkitallowfullscreen="true" mozallowfullscreen="true" src="#{@getShareLink()}"></iframe>"""
    else
      null

  getLara: ->
    sharedDocumentId = @getSharedDocumentId()
    if sharedDocumentId
      documentServer = getQueryParam('documentServer') or 'https://document-store.concord.org'
      documentServer = documentServer.slice(0, -1) while documentServer.substr(-1) is '/'  # remove trailing slash
      server = encodeURIComponent(@state.codapServerUrl)
      buttonText = if @state.pageType is 'launch' then "&buttonText=#{encodeURIComponent(@state.launchButtonText)}" else ''
      fullscreenScaling = if @state.pageType is 'autolaunch' and @state.fullscreenScaling then '&scaling' else ''
      graphVisToggles = if @state.graphVisToggles then '&app=is' else ''
      "#{documentServer}/v2/documents/#{sharedDocumentId}/#{@state.pageType}?server=#{server}#{buttonText}#{fullscreenScaling}#{graphVisToggles}"
    else
      null

  # adapted from https://github.com/sudodoki/copy-to-clipboard/blob/master/index.js
  copy: (e) ->
    e.preventDefault()
    copied = false
    toCopy = @state[@state.tabSelected]
    try
      mark = document.createElement 'mark'
      mark.innerText = toCopy
      document.body.appendChild mark

      selection = document.getSelection()
      selection.removeAllRanges()

      range = document.createRange()
      range.selectNode mark
      selection.addRange range

      copied = document.execCommand 'copy'
    catch
      try
        window.clipboardData.setData 'text', toCopy
        copied = true
      catch
        copied = false
    finally
      if selection
        if typeof selection.removeRange is 'function'<commit_msg>Fix copy link in LARA share dialog<commit_after>{div, input, a, button, strong, textarea, svg, g, path, span, circle, ul, li} = React.DOM

SHOW_LONGEVITY_WARNING = false

ModalDialog = React.createFactory require './modal-dialog-view'
getQueryParam = require '../utils/get-query-param'

tr = require '../utils/translate'
socialIcons = require 'svg-social-icons/lib/icons.json'

SocialIcon = React.createFactory React.createClass

  displayName: 'SocialIcon'

  getInitialState: ->
    data: socialIcons[@props.icon]

  clicked: ->
    window.open @props.url

  render: ->
    (a {className: 'social-icon', href: @props.url, target: '_blank'},
      (div {className: 'social-container'},
        (svg {className: 'social-svg', viewBox: '0 0 64 64'},
          (g {className: 'social-svg-background'},
            (circle {cx: 32, cy: 32, r: 31})
          )
          (g {className: 'social-svg-icon'},
            (path {d: @state.data.icon})
          )
          (g {className: 'social-svg-mask', style: {fill: @state.data.color}},
            (path {d: @state.data.mask})
          )
        )
      )
    )

module.exports = React.createClass

  displayName: 'ShareDialogView'

  getInitialState: ->
    link: @getShareLink()
    embed: @getEmbed()
    pageType: "autolaunch"
    codapServerUrl: "https://codap.concord.org/releases/latest/"
    launchButtonText: "Launch"
    fullscreenScaling: true
    graphVisToggles: false
    tabSelected: 'link'

  getSharedDocumentId: ->
    # extract sharedDocumentId from CloudContent
    if @props.client.isShared()
      @props.client.state.currentContent?.get "sharedDocumentId"
    else
      null

  getShareLink: ->
    sharedDocumentId = @getSharedDocumentId()
    if sharedDocumentId
      # share link combines document URL with sharedDocumentId
      "#{@props.client.getCurrentUrl()}#shared=#{sharedDocumentId}"
    else
      null

  getEmbed: ->
    if @getShareLink()
      """<iframe width="398px" height="313px" frameborder="no" scrolling="no" allowfullscreen="true" webkitallowfullscreen="true" mozallowfullscreen="true" src="#{@getShareLink()}"></iframe>"""
    else
      null

  getLara: ->
    sharedDocumentId = @getSharedDocumentId()
    if sharedDocumentId
      documentServer = getQueryParam('documentServer') or 'https://document-store.concord.org'
      documentServer = documentServer.slice(0, -1) while documentServer.substr(-1) is '/'  # remove trailing slash
      server = encodeURIComponent(@state.codapServerUrl)
      buttonText = if @state.pageType is 'launch' then "&buttonText=#{encodeURIComponent(@state.launchButtonText)}" else ''
      fullscreenScaling = if @state.pageType is 'autolaunch' and @state.fullscreenScaling then '&scaling' else ''
      graphVisToggles = if @state.graphVisToggles then '&app=is' else ''
      "#{documentServer}/v2/documents/#{sharedDocumentId}/#{@state.pageType}?server=#{server}#{buttonText}#{fullscreenScaling}#{graphVisToggles}"
    else
      null

  # adapted from https://github.com/sudodoki/copy-to-clipboard/blob/master/index.js
  copy: (e) ->
    e.preventDefault()
    copied = false
    toCopy = switch @state.tabSelected
      when 'embed' then @getEmbed()
      when 'link' then @getShareLink()
      when 'lara' then @getLara()
    try
      mark = document.createElement 'mark'
      mark.innerText = toCopy
      document.body.appendChild mark

      selection = document.getSelection()
      selection.removeAllRanges()

      range = document.createRange()
      range.selectNode mark
      selection.addRange range

      copied = document.execCommand 'copy'
    catch
      try
        window.clipboardData.setData 'text', toCopy
        copied = true
      catch
        copied = false
    finally
      if selection
        if typeof selection.removeRange is 'function'
{'fraction_non_alphanumeric': 0.12842077159257775, 'fraction_numerical': 0.005873715124816446, 'mean_word_length': 3.1622222222222223, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 25, 'https://': 6, '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': '1675470', 'n_tokens_mistral': 2320, 'n_tokens_neox': 2267, 'n_words': 498}