Sha256: 6fbae9f3925517854a8dad193b460912bc9c61ab2ef57b965e5d6fac8168812e

Contents?: true

Size: 809 Bytes

Versions: 3

Compression:

Stored size: 809 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 {
          $('div.pages').html(#{render_to_string("#{action}.html.erb").to_json});
          $(document).trigger('end.pjax');

          var title = $.trim($('div.pages').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 & 1 rubygems

Version Path
pjax-rails-0.1.2 ./lib/pjax.rb
pjax-rails-0.1.1 ./lib/pjax.rb
pjax-rails-0.1 ./lib/pjax.rb