<commit_before>class @SharingTags.BaseShare

  url: null
  title: null
  description: null

  constructor: ({@url, @title, @description})->
    @_assert_vars 'url'

  _open_popup: (api_url, params)->
    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 @_checkSharing(share_url, share_window, iteration)
        clearInterval @interval
        jQuery("body").trigger("sharing_tags.shared") if jQuery
    ), 500)

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

  _after_callback: =>
    jQuery?("body").trigger("sharing_tags.shared")

  _assert_vars: (vars...)->
    for var_name in vars
      if ! @[var_name]
        arguments_list = ''
        arguments_list += " #{var_name}: '#{@[var_name]}'" for arg, val in vars
        throw new SharingTags.Error("Error could not initialize sharing class, with params: #{arguments_list}")

class @SharingTags.FacebookShare extends @SharingTags.BaseShare

  # available providers: sharer, fb_ui, dialog
  @default_provider: "fb_ui"

  app_id:     null
  return_url: null
  provider:   null

  constructor: ({@app_id, @return_url, @provider})->
    @provider = @_detect_provider() if !@provider

    # todo: throw error for invalid provider
    @constructor.init() if not FB? if @provider is 'fb_ui'

    super

  @init: (locale="en_US")->
    if not FB?
      jQuery.ajax(
        url: "//connect.facebook.net/#{locale}/all.js"
        dataType: "script"
        cache: true
      )

  share: ()->
    @["_#{@provider}"]()

  _sharer: ->
    @_assert_vars "url"
    @_open_popup("http://www.facebook.com/sharer.php", u: @url)

  _fb_ui: =>
    @_assert_vars "url", "app_id"
    return @constructor.init().done(@_fb_ui) if not FB?<commit_msg>fix FB.ui init<commit_after>class @SharingTags.BaseShare

  url: null
  title: null
  description: null

  constructor: ({@url, @title, @description})->
    @_assert_vars 'url'

  _open_popup: (api_url, params)->
    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 @_checkSharing(share_url, share_window, iteration)
        clearInterval @interval
        jQuery("body").trigger("sharing_tags.shared") if jQuery
    ), 500)

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

  _after_callback: =>
    jQuery?("body").trigger("sharing_tags.shared")

  _assert_vars: (vars...)->
    for var_name in vars
      if ! @[var_name]
        arguments_list = ''
        arguments_list += " #{var_name}: '#{@[var_name]}'" for arg, val in vars
        throw new SharingTags.Error("Error could not initialize sharing class, with params: #{arguments_list}")

class @SharingTags.FacebookShare extends @SharingTags.BaseShare

  # available providers: sharer, fb_ui, dialog
  @default_provider: "fb_ui"

  app_id:     null
  return_url: null
  provider:   null

  constructor: ({@app_id, @return_url, @provider})->
    @provider = @_detect_provider() if !@provider

    # todo: throw error for invalid provider
    @constructor.init() if @provider is 'fb_ui' and not FB?

    super

  @init: (locale="en_US")->
    if not FB?
      jQuery.ajax(
        url: "//connect.facebook.net/#{locale}/all.js"
        dataType: "script"
        cache: true
      )

  share: ()->
    @["_#{@provider}"]()

  _sharer: ->
    @_assert_vars "url"
    @_open_popup("http://www.facebook.com/sharer.php", u: @url)

  _fb_ui: =>
    @_assert_vars "url", "app_id"
    return @constructor.init().done(@_fb_ui) if not FB?
{'fraction_non_alphanumeric': 0.14473033151905, 'fraction_numerical': 0.005937654626422563, 'mean_word_length': 3.442857142857143, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6537968', 'n_tokens_mistral': 1376, 'n_tokens_neox': 1314, 'n_words': 315}