Module: PlataformaSocial::Helpers
- Included in:
- ActionController::Base
- Defined in:
- lib/plataforma_social/helpers.rb
Instance Method Summary collapse
- #custom_redirect_to(path, options = {}, protocol = '') ⇒ Object
- #from_admin? ⇒ Boolean
- #from_facebook? ⇒ Boolean
- #link_to_facebook(*args, &block) ⇒ Object
- #plataforma_social_config_script ⇒ Object
- #plataforma_social_javascripts ⇒ Object
- #plataforma_social_script_tag ⇒ Object
- #signed_request_javascript ⇒ Object
Instance Method Details
#custom_redirect_to(path, options = {}, protocol = '') ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/plataforma_social/helpers.rb', line 75 def custom_redirect_to path, = {}, protocol = '' .each_pair do |key, value| [key] = value end protocol = "#{protocol}:" if protocol.present? render :text => %Q{ <script type="text/javascript" charset="utf-8"> window.top.location = "#{protocol}//apps.facebook.com/#{PlataformaSocial.facebook_app_namespace}#{path}"; </script> } end |
#from_admin? ⇒ Boolean
93 94 95 |
# File 'lib/plataforma_social/helpers.rb', line 93 def from_admin? params.present? && params[:controller].present? && params[:controller].index(PlataformaSocial.admin_controller_name) == 0 end |
#from_facebook? ⇒ Boolean
89 90 91 |
# File 'lib/plataforma_social/helpers.rb', line 89 def from_facebook? request.referer && request.referer.index('facebook.com') end |
#link_to_facebook(*args, &block) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/plataforma_social/helpers.rb', line 97 def link_to_facebook *args, &block if block_given? href = capture(&block) args.unshift(href) link_to_facebook *args else args[2] ||= {} server_domain = request.env['HTTP_HOST'] url = 'apps.facebook.com/' + PlataformaSocial.facebook_app_namespace if args[1].include? server_domain args[1].gsub! server_domain, url else args[1] = request.protocol + url + args[1] end args[2][:target] = '_top' return link_to *args end end |
#plataforma_social_config_script ⇒ Object
12 13 14 15 16 17 |
# File 'lib/plataforma_social/helpers.rb', line 12 def %Q{<script type="text/javascript" charset="utf-8"> $P.init({ apiKey: '#{PlataformaSocial.api_key}' }); window._FACEBOOK_APP_URL = 'http://apps.facebook.com/#{PlataformaSocial.facebook_app_namespace}'; </script>}.html_safe end |
#plataforma_social_javascripts ⇒ Object
4 5 6 |
# File 'lib/plataforma_social/helpers.rb', line 4 def + + signed_request_javascript end |
#plataforma_social_script_tag ⇒ Object
8 9 10 |
# File 'lib/plataforma_social/helpers.rb', line 8 def %Q{<script src="#{PlataformaSocial.domains('js')}/socialp.js" type="text/javascript" charset="utf-8"></script>}.html_safe end |
#signed_request_javascript ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/plataforma_social/helpers.rb', line 19 def signed_request_javascript default_params = { :signed_request => params[:signed_request] || nil, :code => params[:code] || nil } %Q{ <script type="text/javascript" charset="utf-8"> if($ && jQuery){ $(function(){ $(document).ajaxSend(function(elm, xhr, s){ var method = s.type; var defaultParams = #{default_params.to_json}; var params = {}; var query = []; var data = method == "POST" ? s.data : s.url.split('?')[1]; if(data){ var splittedData = data.split('&'); var splittedDataLength = splittedData.length; if(splittedDataLength){ for(var i = 0; i < splittedDataLength; i++){ var param = splittedData[i].split('='); params[param[0]] = param[1]; } // for } } // if for(var i in defaultParams){ if(!params[i]) params[i] = defaultParams[i]; } for(var i in params){ query.push(decodeURIComponent(i) + '=' + decodeURIComponent(params[i])); } query = query.join('&'); if(method == "POST"){ s.data = query; } else { s.url = s.url.split('?')[0] + '?' + query; } xhr.setRequestHeader("Content-type", s.contentType); }); }); } </script> }.html_safe end |