<commit_before>class @SharingTags

  @share: (network, attributes, callback)->
    share_object = if attributes?.mobile then SharingTags.MobileShare else SharingTags.Share
    share_object[network]?(attributes, callback)

  class @Error extends Error
    constructor: -> super

  class @Share

    @line: ({url}, callback) ->
      share_url = "http://line.me/R/msg/text/?#{encodeURIComponent(url)}"
      @_share(share_url, null, callback)

    @facebook: ({url, app_id}, callback) ->
      if app_id
        social_share = new SharingTags.FacebookShare url: url, app_id: app_id
        social_share.share()
      else
        @_share("http://www.facebook.com/sharer.php", u: url, callback)

    @twitter: ({url, message}, callback) ->
      @_share("http://twitter.com/intent/tweet", text: message, url: url, callback)

    @vkontakte: ({title, url, message, image}, callback) ->
      social_share = new SharingTags.VkontakteShare url: url, title: title, description: message, image: image
      social_share.share()

    @google: ({url}, callback) ->
      @_share("https://plus.google.com/share", url: url, callback)

    @odnoklassniki: ({url, message}, callback) ->
      @_share("http://www.odnoklassniki.ru/dk",
        'st._surl': url, 'st.comments': message, 'st.cmd': 'addShare', 'st.s': 1, callback)

    @mailru: ({url, title, image, message}, callback) ->
      @_share('http://connect.mail.ru/share', url: url, title: title, description: message, imageurl: image, callback)

    @linkedin: ({url, title, message}, callback) ->
      @_share('http://www.linkedin.com/shareArticle',
        mini: true, url: url, title: title, summary: message,
        callback
      )

    @_share: (api_url, params, callback) ->
      share_url = if params then "#{api_url}?#{$.param(params)}" else api_url
      share_window = window.open share_url, 'Sharing', 'width=740,height=440'

      clearInterval(@interval)
      iteration = 0
      @interval = setInterval((=>
        iteration++
        if @_open_popup_check(share_url, share_window, iteration)
          clearInterval @interval
          callback() if callback
          jQuery?("body").trigger("sharing_tags.shared")
      ), 500)

    @_checkSharing: (share_url, share_window, iteration)=>
      # console.log("check desktop sharing", share_url, share_window, iteration)
      share_window?.closed || iteration >= 15

  class @MobileShare extends @Share

    @facebook: ({url, return_url, app_id}, callback) ->
#      if app_id
#        return_url = url if !return_url<commit_msg>Facebook js (events): fix renaming  _checkSharing to _open_popup_check<commit_after>class @SharingTags

  @share: (network, attributes, callback)->
    share_object = if attributes?.mobile then SharingTags.MobileShare else SharingTags.Share
    share_object[network]?(attributes, callback)

  class @Error extends Error
    constructor: -> super

  class @Share

    @line: ({url}, callback) ->
      share_url = "http://line.me/R/msg/text/?#{encodeURIComponent(url)}"
      @_share(share_url, null, callback)

    @facebook: ({url, app_id}, callback) ->
      if app_id
        social_share = new SharingTags.FacebookShare url: url, app_id: app_id
        social_share.share()
      else
        @_share("http://www.facebook.com/sharer.php", u: url, callback)

    @twitter: ({url, message}, callback) ->
      @_share("http://twitter.com/intent/tweet", text: message, url: url, callback)

    @vkontakte: ({title, url, message, image}, callback) ->
      social_share = new SharingTags.VkontakteShare url: url, title: title, description: message, image: image
      social_share.share()

    @google: ({url}, callback) ->
      @_share("https://plus.google.com/share", url: url, callback)

    @odnoklassniki: ({url, message}, callback) ->
      @_share("http://www.odnoklassniki.ru/dk",
        'st._surl': url, 'st.comments': message, 'st.cmd': 'addShare', 'st.s': 1, callback)

    @mailru: ({url, title, image, message}, callback) ->
      @_share('http://connect.mail.ru/share', url: url, title: title, description: message, imageurl: image, callback)

    @linkedin: ({url, title, message}, callback) ->
      @_share('http://www.linkedin.com/shareArticle',
        mini: true, url: url, title: title, summary: message,
        callback
      )

    @_share: (api_url, params, callback) ->
      share_url = if params then "#{api_url}?#{$.param(params)}" else api_url
      share_window = window.open share_url, 'Sharing', 'width=740,height=440'

      clearInterval(@interval)
      iteration = 0
      @interval = setInterval((=>
        iteration++
        if @_open_popup_check(share_url, share_window, iteration)
          clearInterval @interval
          callback() if callback
          jQuery?("body").trigger("sharing_tags.shared")
      ), 500)

    @_open_popup_check: (share_url, share_window, iteration)=>
      # console.log("check desktop sharing", share_url, share_window, iteration)
      share_window?.closed || iteration >= 15

  class @MobileShare extends @Share

    @facebook: ({url, return_url, app_id}, callback) ->
#      if app_id
#        return_url = url if !return_url
{'fraction_non_alphanumeric': 0.14773830324208892, 'fraction_numerical': 0.005047563579887401, 'mean_word_length': 3.333052985702271, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 33, 'https://': 2, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '670663', 'n_tokens_mistral': 1639, 'n_tokens_neox': 1587, 'n_words': 388}