Sha256: 68e6355857c9570c58658b55c8232fd114f6a77c78c2a4bc0b4415eda6733d96

Contents?: true

Size: 1.24 KB

Versions: 1

Compression:

Stored size: 1.24 KB

Contents

module PhraseApp
  module InContextEditor
    module ViewHelpers
      def phraseapp_in_context_editor_js
        return "" unless PhraseApp::InContextEditor.enabled?

        js_config = ["projectId: '#{PhraseApp::InContextEditor.project_id}'"]
        if PhraseApp::InContextEditor.api_host.present? && PhraseApp::InContextEditor.api_host != "https://api.phraseapp.com"
          js_config << "apiBaseUrl: '#{PhraseApp::InContextEditor.api_host}/api/v2'"
        end

        js = <<-eos
                <script>
                  window.PHRASEAPP_CONFIG = {
                        #{js_config.join(', ')}
                      };
                  (function() {
                    var phraseapp = document.createElement('script'); phraseapp.type = 'text/javascript'; phraseapp.async = true;
                    phraseapp.src = ['#{PhraseApp::InContextEditor.js_use_ssl ? 'https' : 'http'}://', '#{PhraseApp::InContextEditor.js_host}/assets/in-context-editor/2.0/app.js?', new Date().getTime()].join('');
                    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(phraseapp, s);
                  })();
                </script>
             eos
        js.respond_to?(:html_safe) ? js.html_safe : js
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
phraseapp-in-context-editor-ruby-1.0.1 lib/phraseapp-in-context-editor-ruby/view_helpers.rb