Skip to content

Commit

Permalink
Support turbolinks 5.x events, while maintaining backwards compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Aug 28, 2016
1 parent e639134 commit 165d9d7
Showing 1 changed file with 19 additions and 5 deletions.
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();
});

0 comments on commit 165d9d7

Please sign in to comment.