Module: UservoiceWidget::MainHelper

Defined in:
app/helpers/uservoice_widget/main_helper.rb

Instance Method Summary collapse

Instance Method Details

#uservoice_widget(account = UservoiceWidget::Account.default, options = {}) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/helpers/uservoice_widget/main_helper.rb', line 3

def uservoice_widget( = UservoiceWidget::Account.default, options = {})
   = .dup.update_attributes(options)

  javascript_tag do
    code = <<-JS
      (function() {
        var uv = document.createElement('script'); uv.type = 'text/javascript'; uv.async = true;
        uv.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'widget.uservoice.com/#{.key}.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(uv, s);
      })();
    JS
    code.html_safe
  end + 
  javascript_tag do
    "UserVoice = window.UserVoice || []; UserVoice.push(['showTab', 'classic_widget', #{.to_json}])".html_safe
  end
end