Sha256: fa1f613c67a5a89fe7d8e67ab977c130aca93162baff866af8e773594ce29af0

Contents?: true

Size: 833 Bytes

Versions: 3

Compression:

Stored size: 833 Bytes

Contents

module Pjax
  extend ActiveSupport::Concern
  
  included do
    layout ->(c) { pjax_request? ? false : 'application' }
  end
  
  private  
    def redirect_pjax_to(action, url = nil)
      new_url = url_for(url ? url : { action: action })
      
      render js: <<-EJS
        if (!window.history || !window.history.pushState) {
          window.location.href = '#{new_url}';
        } else {
          $('[data-pjax-container]').html(#{render_to_string("#{action}.html.erb").to_json});
          $(document).trigger('end.pjax');

          var title = $.trim($('[data-pjax-container]').find('title').remove().text());
          if (title) document.title = title;
          window.history.pushState({}, document.title, '#{new_url}');
        }
      EJS
    end

    def pjax_request?
      env['HTTP_X_PJAX'].present?
    end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
pjax_rails-0.1.5 ./lib/pjax.rb
pjax-rails-0.1.4 ./lib/pjax.rb
pjax-rails-0.1.3 ./lib/pjax.rb