Skip to content

Commit

Permalink
Merge pull request #1425 from projectblacklight/rails5-dev
Browse files Browse the repository at this point in the history
Support turbolinks 5.x events, while maintaining backwards compatibility
  • Loading branch information
mejackreed committed Jul 1, 2016
2 parents 4e48a19 + de0f797 commit c0bf7f1
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .solr_wrapper
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Place any default configuration for solr_wrapper here
# port: 8983
collection:
dir: solr/conf/
name: blacklight-core
6 changes: 3 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ else
end
end

if ENV['RAILS_VERSION'].nil? || ENV['RAILS_VERSION'] =~ /^4\.2/
if ENV['RAILS_VERSION'].nil? || ENV['RAILS_VERSION'] =~ /^5\.0/ || ENV['RAILS_VERSION'] == 'edge'
gem 'rspec-rails', '>= 3.5.0.beta4', '~> 3.5'
elsif ENV['RAILS_VERSION'] =~ /^4\.2/
gem 'responders', "~> 2.0"
gem 'sass-rails', ">= 5.0"
elsif ENV['RAILS_VERSION'] =~ /^5\.0/ || ENV['RAILS_VERSION'] == 'edge'
# nop
else
gem 'bootstrap-sass', '< 3.3.5' # 3.3.5 requires sass 3.3, incompatible with sass-rails 4.x
gem 'sass-rails', "< 5.0"
Expand Down
24 changes: 19 additions & 5 deletions app/assets/javascripts/blacklight/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,31 @@ Blacklight = function() {
for(var i = 0; i < buffer.length; i++) {
buffer[i].call();
}
},

listeners: function () {
var listeners = [];
if (Turbolinks && Turbolinks.supported) {
// Turbolinks 5
if (Turbolinks.BrowserAdapter) {
listeners.push('turbolinks:load');
} else {
// Turbolinks < 5
listeners.push('page:load', 'ready');
}
} else {
listeners.push('ready');
}

return listeners.join(' ');
}
}
};
}();

// turbolinks triggers page:load events on page transition
// If app isn't using turbolinks, this event will never be triggered, no prob.
$(document).on('page:load', function() {
$(document).on(Blacklight.listeners(), function() {
Blacklight.activate();
});

$(document).ready(function() {
Blacklight.activate();
});

12 changes: 2 additions & 10 deletions spec/test_app_templates/Gemfile.extra
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@

if ENV['RAILS_VERSION'] =~ /^5\.0/ || ENV['RAILS_VERSION'] == 'edge'
gem 'rails-controller-testing', github: 'rails/rails-controller-testing'
gem 'rspec-mocks', github: 'rspec/rspec-mocks' # we need 3.5.0 to be released
gem 'rspec-expectations', github: 'rspec/rspec-expectations' # we need 3.5.0 to be released
gem 'rspec-support', github: 'rspec/rspec-support' # we need 3.5.0 to be released
gem 'rspec', github: 'rspec/rspec' # we need 3.5.0 to be released
gem 'rspec-core', github: 'rspec/rspec-core' # we need 3.5.0 to be released
gem 'rspec-rails', github: 'rspec/rspec-rails' # we need 3.5.0 to be released
gem 'kaminari', github: 'amatsuda/kaminari' # need > 0.16.3
if ENV['RAILS_VERSION'].nil? || ENV['RAILS_VERSION'] =~ /^5\.0/ || ENV['RAILS_VERSION'] == 'edge'
gem 'rails-controller-testing'
gem 'deprecation', github: 'jcoyne/deprecation', branch: 'no_alias_method_chain'
end

0 comments on commit c0bf7f1

Please sign in to comment.