diff --git a/Gemfile b/Gemfile index 17a7383..1cc90a6 100644 --- a/Gemfile +++ b/Gemfile @@ -61,3 +61,6 @@ gem 'acts-as-taggable-on', '~> 3.4' # Use debugger # gem 'debugger', group: [:development, :test] gem 'rails_12factor', group: :production + +#Use Social-Share-Button for sharing to external social sites +gem 'social-share-button', '~>0.2.1' diff --git a/Gemfile.lock b/Gemfile.lock index 03fafcd..db29afa 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -144,6 +144,9 @@ GEM sdoc (0.4.2) json (~> 1.7, >= 1.7.7) rdoc (~> 4.0) + social-share-button (0.2.1) + coffee-rails + sass-rails spring (1.7.2) sprockets (2.12.4) hike (~> 1.2) @@ -189,6 +192,7 @@ DEPENDENCIES rspec-rails (~> 3.5) sass-rails (~> 4.0.3) sdoc (~> 0.4.0) + social-share-button (~> 0.2.1) spring uglifier (>= 1.3.0) diff --git a/app/assets/javascripts/social-share-button.coffee b/app/assets/javascripts/social-share-button.coffee new file mode 100644 index 0000000..0ebfd11 --- /dev/null +++ b/app/assets/javascripts/social-share-button.coffee @@ -0,0 +1,88 @@ +#= require social-share-button + +window.SocialShareButton = + openUrl : (url,popup) -> + if popup == "true" + window.open(url,'popup','height=500,width=500') + else + window.open(url) + false + + share : (el) -> + site = $(el).data('site') + appkey = $(el).data('appkey') || '' + $parent = $(el).parent() + title = encodeURIComponent($(el).data(site + '-title') || $parent.data('title') || '') + img = encodeURIComponent($parent.data("img") || '') + url = encodeURIComponent($parent.data("url") || '') + via = encodeURIComponent($parent.data("via") || '') + desc = encodeURIComponent($parent.data("desc") || ' ') + popup = encodeURIComponent($parent.data("popup") || 'false') + + if url.length == 0 + url = encodeURIComponent(location.href) + switch site + when "email" + location.href = "mailto:?to=&subject=#{title}&body=#{url}" + when "weibo" + SocialShareButton.openUrl("http://service.weibo.com/share/share.php?url=#{url}&type=3&pic=#{img}&title=#{title}&appkey=#{appkey}",popup) + when "twitter" + via_str = '' + via_str = "&via=#{via}" if via.length > 0 + SocialShareButton.openUrl("https://twitter.com/intent/tweet?url=#{url}&text=#{title}#{via_str}",popup) + when "douban" + SocialShareButton.openUrl("http://shuo.douban.com/!service/share?href=#{url}&name=#{title}&image=#{img}&sel=#{desc}",popup) + when "facebook" + SocialShareButton.openUrl("http://www.facebook.com/sharer.php?u=#{url}",popup) + when "qq" + SocialShareButton.openUrl("http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=#{url}&title=#{title}&pics=#{img}&summary=#{desc}&site=#{appkey}", popup) + when "tqq" + SocialShareButton.openUrl("http://share.v.t.qq.com/index.php?c=share&a=index&url=#{url}&title=#{title}&pic=#{img}&appkey=#{appkey}", popup) + when "baidu" + SocialShareButton.openUrl("http://hi.baidu.com/pub/show/share?url=#{url}&title=#{title}&content=#{desc}", popup) + when "kaixin001" + SocialShareButton.openUrl("http://www.kaixin001.com/rest/records.php?url=#{url}&content=#{title}&style=11&pic=#{img}&aid=#{appkey}", popup) + when "renren" + SocialShareButton.openUrl("http://widget.renren.com/dialog/share?resourceUrl=#{url}&srcUrl=#{url}&title=#{title}&pic=#{img}&description=#{desc}", popup) + when "google_plus" + SocialShareButton.openUrl("https://plus.google.com/share?url=#{url}", popup) + when "google_bookmark" + SocialShareButton.openUrl("https://www.google.com/bookmarks/mark?op=edit&output=popup&bkmk=#{url}&title=#{title}", popup) + when "delicious" + SocialShareButton.openUrl("http://www.delicious.com/save?url=#{url}&title=#{title}&jump=yes&pic=#{img}", popup) + when "plurk" + SocialShareButton.openUrl("http://www.plurk.com/?status=#{title}: #{url}&qualifier=shares", popup) + when "pinterest" + SocialShareButton.openUrl("http://www.pinterest.com/pin/create/button/?url=#{url}&media=#{img}&description=#{title}", popup) + when "linkedin" + SocialShareButton.openUrl("https://www.linkedin.com/shareArticle?mini=true&url=#{url}&title=#{title}&summary=#{desc}") + when "tumblr" + get_tumblr_extra = (param) -> + cutom_data = $(el).attr("data-#{param}") + encodeURIComponent(cutom_data) if cutom_data + + tumblr_params = -> + path = get_tumblr_extra('type') || 'link' + + params = switch path + when 'text' + title = get_tumblr_extra('title') || title + "title=#{title}" + when 'photo' + title = get_tumblr_extra('caption') || title + source = get_tumblr_extra('source') || img + "caption=#{title}&source=#{source}" + when 'quote' + quote = get_tumblr_extra('quote') || title + source = get_tumblr_extra('source') || '' + "quote=#{quote}&source=#{source}" + else # actually, it's a link clause + title = get_tumblr_extra('title') || title + url = get_tumblr_extra('url') || url + "name=#{title}&url=#{url}" + + + "/#{path}?#{params}" + + SocialShareButton.openUrl("http://www.tumblr.com/share#{tumblr_params()}", popup) + false diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 3c3adc6..8fe40c1 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -12,6 +12,7 @@ * *= require_tree . *= require_self + *= require social-share-button */ // Include this here so the bootstrap variables that it contains are set before diff --git a/app/assets/stylesheets/resources.css.scss b/app/assets/stylesheets/resources.css.scss index 89e9e44..39a6501 100644 --- a/app/assets/stylesheets/resources.css.scss +++ b/app/assets/stylesheets/resources.css.scss @@ -175,6 +175,13 @@ #return-to-top { display: none; } + + .share-buttons { + a { + transform: scale(1.5, 1.5); + margin-right: 11px; + } + } } .dropdown { diff --git a/app/views/resources/index.html.erb b/app/views/resources/index.html.erb index b64f348..d1fbaac 100644 --- a/app/views/resources/index.html.erb +++ b/app/views/resources/index.html.erb @@ -48,6 +48,9 @@