diff --git a/app/assets/javascripts/lib/social-share-button.coffee b/app/assets/javascripts/lib/social-share-button.coffee new file mode 100644 index 000000000..8e97d0eff --- /dev/null +++ b/app/assets/javascripts/lib/social-share-button.coffee @@ -0,0 +1,34 @@ +window.SocialShareButton = + openUrl : (url) -> + window.open(url) + false + + share : (el) -> + site = $(el).data('site') + title = encodeURIComponent($(el).parent().data('title')) + img = encodeURIComponent($(el).parent().data("img")) + fb_url = encodeURIComponent($(el).parent().data("fb_url")) + url = encodeURIComponent(location.href) + fb_full_url = encodeURIComponent("#{fb_url}?orig_url=#{location.href}") + switch site + when "weibo" + SocialShareButton.openUrl("http://v.t.sina.com.cn/share/share.php?url=#{url}&pic=#{img}&title=#{title}&content=utf-8") + when "twitter" + SocialShareButton.openUrl("https://twitter.com/home?status=#{title}: #{url}") + when "douban" + SocialShareButton.openUrl("http://www.douban.com/recommend/?url=#{url}&title=#{title}&image=#{img}") + when "facebook" + SocialShareButton.openUrl("http://www.facebook.com/sharer.php?t=#{title}&u=#{fb_full_url}") + when "qq" + SocialShareButton.openUrl("http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=#{url}&title=#{title}&pics=#{img}") + when "tqq" + SocialShareButton.openUrl("http://share.v.t.qq.com/index.php?c=share&a=index&url=#{url}&title=#{title}&pic=#{img}") + when "baidu" + SocialShareButton.openUrl("http://apps.hi.baidu.com/share/?url=#{url}&title=#{title}&content=") + when "kaixin001" + SocialShareButton.openUrl("http://www.kaixin001.com/rest/records.php?url=#{url}&content=#{title}&style=11&pic=#{img}") + when "renren" + SocialShareButton.openUrl("http://widget.renren.com/dialog/share?resourceUrl=#{url}&title=#{title}&description=") + when "google_plus" + SocialShareButton.openUrl("https://plus.google.com/share?url=#{url}&t=#{title}") + false \ No newline at end of file diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 5fd9de5c9..bf9da2f71 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -106,6 +106,13 @@ class ApplicationController < ActionController::Base render :text => '404 Not Found' end end + + def render_share + object_class = params[:model].classify.constantize + @object = object_class.find(params[:id]) + @orig_url = params[:orig_url] + render 'shared/render_share', :layout => false + end protected diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 8fb553151..be2ab2706 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -162,7 +162,8 @@ module ApplicationHelper end javascripts << "\n" javascripts << "\n" - javascripts << "\n" + # javascripts << "\n" + javascripts << "\n" javascripts << "\n" page.design.javascripts.each do |js| # javascripts << "" @@ -220,8 +221,8 @@ module ApplicationHelper js << "\n" rescue '' js << "\n" rescue '' content_tag :div, :class => 'fb' do - concat social_share_button_tag - concat javascript_tag "$('head').append('#{j js}');" + concat social_share_button_tag(object.title, :fb_url => "http://#{request.env['HTTP_HOST']}/share/#{object.class.to_s.underscore}/#{object.id}", :image => "http://#{request.env['HTTP_HOST']}#{object.image.url}") + # concat javascript_tag "$('head').append('#{j js}');" end end diff --git a/app/views/shared/render_share.html.erb b/app/views/shared/render_share.html.erb new file mode 100644 index 000000000..110d30f57 --- /dev/null +++ b/app/views/shared/render_share.html.erb @@ -0,0 +1,11 @@ + + +
+ + + + + + + + \ No newline at end of file diff --git a/config/initializers/override_and_new_class_methods.rb b/config/initializers/override_and_new_class_methods.rb index 8170d674f..075158042 100644 --- a/config/initializers/override_and_new_class_methods.rb +++ b/config/initializers/override_and_new_class_methods.rb @@ -3,3 +3,24 @@ Integer.class_eval do !self.zero? end end + +module SocialShareButton + module Helper + def social_share_button_tag(title = "", opts = {}) + rel = opts[:rel] + html = [] + html << " " + raw html.join("\n") + end + end +end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index b281dd33b..91a28d60e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -140,6 +140,8 @@ Orbit::Application.routes.draw do match '/panel/:app_name/front_end/:app_action' => 'pages#index_from_link', :constraints => lambda { |request| !request.query_string.include?("inner=true") } + + match '/share/:model/:id' => 'application#render_share' # routes for gridfs files match "/gridfs/*path" => "gridfs#serve"