Sha256: 1015d1f06d896f49afffbba8918186d86d2590bce5023c718313e99056115fba

Contents?: true

Size: 1.68 KB

Versions: 42

Compression:

Stored size: 1.68 KB

Contents

class ShareBar
  constructor: ->
    $('body').on 'click', '.js-fb-share', @present_fb_share
    $('body').on 'click', '.js-fb-like', @show_fb_like_widget
    @load_fb_share_count()
    @load_tweet_count()

    if window.fb_api_disabled
      $('.js-fb-share, .js-fb-like').hide()


  load_fb_share_count: =>
    info_url = "#{window.location.protocol}//api.facebook.com/method/links.getStats?urls=#{encodeURIComponent(window.page_url)}&format=json&callback=?"

    $.getJSON info_url, (response) =>
      if response and response[0] and response[0].share_count
        share_count = response[0].share_count

        if share_count
          $share_count_tpl = $("<span class='fb-share-count count'>(#{share_count})</span>")
          $(".js-fb-share").each ->
            $share_count = $share_count_tpl.clone()
            $(this).append($share_count)

  load_tweet_count: =>
    info_url = "#{window.location.protocol}//urls.api.twitter.com/1/urls/count.json?url=#{encodeURIComponent(window.page_url)}&callback=?"

    $.getJSON info_url, (response) =>
      if response and response.count
        $tweet_count_tpl = $("<span class='tweet-count count'>(#{response.count})</span>")
        $(".js-tweet-button").each ->
          $tweet_count = $tweet_count_tpl.clone()
          $(this).append($tweet_count)

  present_fb_share: (e) =>
    e.preventDefault()

    $link = $(e.currentTarget)

    FB.ui({
      method: 'share',
      href: $link.attr("data-share-uri")
    })

  show_fb_like_widget: (e) =>
    e.preventDefault()
    $el = $(e.currentTarget)
    $wrap = $el.parents(".share-links-wrap").first()

    $wrap.find(".like-widget-wrap").toggleClass("hidden", 0)


$ -> new ShareBar if $('.share-links').length

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
virgo-0.3.17 app/assets/javascripts/virgo/components/share_bar.coffee
virgo-0.3.16 app/assets/javascripts/virgo/components/share_bar.coffee
virgo-0.3.15 app/assets/javascripts/virgo/components/share_bar.coffee
virgo-0.3.14 app/assets/javascripts/virgo/components/share_bar.coffee
virgo-0.3.13 app/assets/javascripts/virgo/components/share_bar.coffee
virgo-0.3.12 app/assets/javascripts/virgo/components/share_bar.coffee
virgo-0.3.11 app/assets/javascripts/virgo/components/share_bar.coffee
virgo-0.3.10 app/assets/javascripts/virgo/components/share_bar.coffee
virgo-0.3.9 app/assets/javascripts/virgo/components/share_bar.coffee
virgo-0.3.8 app/assets/javascripts/virgo/components/share_bar.coffee
virgo-0.3.7 app/assets/javascripts/virgo/components/share_bar.coffee
virgo-0.3.6 app/assets/javascripts/virgo/components/share_bar.coffee
virgo-0.3.4 app/assets/javascripts/virgo/components/share_bar.coffee
virgo-0.3.3 app/assets/javascripts/virgo/components/share_bar.coffee
virgo-0.3.2 app/assets/javascripts/virgo/components/share_bar.coffee
virgo-0.3.1 app/assets/javascripts/virgo/components/share_bar.coffee
virgo-0.3 app/assets/javascripts/virgo/components/share_bar.coffee
virgo-0.2.9 app/assets/javascripts/virgo/components/share_bar.coffee
virgo-0.2.8 app/assets/javascripts/virgo/components/share_bar.coffee
virgo-0.2.7 app/assets/javascripts/virgo/components/share_bar.coffee